Skip to content

Commit

Permalink
Add --sloccount-format flag to print a more SLOCCount like COCOMO cal…
Browse files Browse the repository at this point in the history
…culation
  • Loading branch information
fschaefer committed Nov 3, 2021
1 parent ec8912f commit 1028050
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
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
34 changes: 29 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,23 @@ func trimNameShort(summary LanguageSummary, trimmedName string) string {
return trimmedName
}

func calcolateCocomoSLOCCount(sumCode int64, str *strings.Builder) {
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))
}

func calculateCocomo(sumCode int64, str *strings.Builder) {
estimatedEffort := EstimateEffort(int64(sumCode), EAF)
estimatedCost := EstimateCost(estimatedEffort, AverageWage, Overhead)
Expand All @@ -996,11 +1020,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

0 comments on commit 1028050

Please sign in to comment.