Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --sloccount-format flag to print a more SLOCCount like COCOMO calculation #302

Merged
merged 2 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ package main

import (
"fmt"
"os"

"github.com/boyter/scc/v3/processor"
"github.com/spf13/cobra"
"os"
)

//go:generate go run scripts/include.go
Expand Down Expand Up @@ -120,6 +121,12 @@ func main() {
1.0,
"the effort adjustment factor derived from the cost drivers (1.0 if rated nominal)",
)
flags.BoolVar(
&processor.SLOCCountFormat,
"sloccount-format",
false,
"print a more SLOCCount like COCOMO calculation",
)
flags.BoolVar(
&processor.Cocomo,
"no-cocomo",
Expand Down
35 changes: 30 additions & 5 deletions processor/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,11 @@ func fileSummarizeLong(input chan *FileJob) string {
str.WriteString(getTabularWideBreak())

if !Cocomo {
calculateCocomo(sumCode, &str)
str.WriteString(getTabularWideBreak())
if SLOCCountFormat {
calcolateCocomoSLOCCount(sumCode, &str)
} else {
calculateCocomo(sumCode, &str)
}
}
if !Size {
calculateSize(sumBytes, &str)
Expand Down Expand Up @@ -970,7 +973,11 @@ func fileSummarizeShort(input chan *FileJob) string {
str.WriteString(getTabularShortBreak())

if !Cocomo {
calculateCocomo(sumCode, &str)
if SLOCCountFormat {
calcolateCocomoSLOCCount(sumCode, &str)
} else {
calculateCocomo(sumCode, &str)
}
str.WriteString(getTabularShortBreak())
}
if !Size {
Expand All @@ -987,6 +994,24 @@ func trimNameShort(summary LanguageSummary, trimmedName string) string {
return trimmedName
}

func calcolateCocomoSLOCCount(sumCode int64, str *strings.Builder) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo in the function name.

estimatedEffort := EstimateEffort(int64(sumCode), EAF)
estimatedScheduleMonths := EstimateScheduleMonths(estimatedEffort)
estimatedPeopleRequired := estimatedEffort / estimatedScheduleMonths
estimatedCost := EstimateCost(estimatedEffort, AverageWage, Overhead)

p := gmessage.NewPrinter(language.Make(os.Getenv("LANG")))

str.WriteString(p.Sprintf("Total Physical Source Lines of Code (SLOC) = %d\n", sumCode))
str.WriteString(p.Sprintf("Development Effort Estimate, Person-Years (Person-Months) = %.2f (%.2f)\n", estimatedEffort/12, estimatedEffort))
str.WriteString(p.Sprintf(" (Basic COCOMO model, Person-Months = %.2f*(KSLOC**%.2f)*%.2f)\n", projectType[CocomoProjectType][0], projectType[CocomoProjectType][1], EAF))
str.WriteString(p.Sprintf("Schedule Estimate, Years (Months) = %.2f (%.2f)\n", estimatedScheduleMonths/12, estimatedScheduleMonths))
str.WriteString(p.Sprintf(" (Basic COCOMO model, Months = %.2f*(person-months**%.2f))\n", projectType[CocomoProjectType][2], projectType[CocomoProjectType][3]))
str.WriteString(p.Sprintf("Estimated Average Number of Developers (Effort/Schedule) = %.2f\n", estimatedPeopleRequired))
str.WriteString(p.Sprintf("Total Estimated Cost to Develop = %s%.0f\n", CurrencySymbol, estimatedCost))
str.WriteString(p.Sprintf(" (average salary = %s%d/year, overhead = %.2f)\n", CurrencySymbol, AverageWage, Overhead))
}

func calculateCocomo(sumCode int64, str *strings.Builder) {
estimatedEffort := EstimateEffort(int64(sumCode), EAF)
estimatedCost := EstimateCost(estimatedEffort, AverageWage, Overhead)
Expand All @@ -996,11 +1021,11 @@ func calculateCocomo(sumCode int64, str *strings.Builder) {
p := gmessage.NewPrinter(language.Make(os.Getenv("LANG")))

str.WriteString(p.Sprintf("Estimated Cost to Develop (%s) %s%d\n", CocomoProjectType, CurrencySymbol, int64(estimatedCost)))
str.WriteString(p.Sprintf("Estimated Schedule Effort (%s) %f months\n", CocomoProjectType, estimatedScheduleMonths))
str.WriteString(p.Sprintf("Estimated Schedule Effort (%s) %.2f months\n", CocomoProjectType, estimatedScheduleMonths))
if math.IsNaN(estimatedPeopleRequired) {
str.WriteString(p.Sprintf("Estimated People Required 1 Grandparent\n"))
} else {
str.WriteString(p.Sprintf("Estimated People Required (%s) %f\n", CocomoProjectType, estimatedPeopleRequired))
str.WriteString(p.Sprintf("Estimated People Required (%s) %.2f\n", CocomoProjectType, estimatedPeopleRequired))
}
}

Expand Down
6 changes: 5 additions & 1 deletion processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package processor
import (
"encoding/base64"
"fmt"
jsoniter "github.com/json-iterator/go"
"io/ioutil"
"os"
"path/filepath"
Expand All @@ -15,6 +14,8 @@ import (
"strconv"
"strings"
"sync"

jsoniter "github.com/json-iterator/go"
)

// Version indicates the version of the application
Expand Down Expand Up @@ -73,6 +74,9 @@ var More = false
// Cocomo toggles the COCOMO calculation
var Cocomo = false

// Print a more SLOCCount like COCOMO calculation
var SLOCCountFormat = false

// CocomoProjectType allows the flipping between project types which impacts the calculation
var CocomoProjectType = "organic"

Expand Down