Skip to content

Commit 892a7c9

Browse files
committed
Unify output of fileSummarizeShort() and fileSummarizeLong().
fileSummarizeLong() is just the wider version of fileSummarizeShort() (-w flag) that additionally prints "Complexity/Lines". The COCOMO ouput was a bit out of sync through copy & paste.
1 parent 8a8c674 commit 892a7c9

File tree

1 file changed

+66
-75
lines changed

1 file changed

+66
-75
lines changed

processor/formatters.go

Lines changed: 66 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"encoding/csv"
88
"encoding/json"
99
"fmt"
10-
"github.com/mattn/go-runewidth"
1110
"io/ioutil"
1211
"math"
1312
"os"
@@ -16,6 +15,8 @@ import (
1615
"strings"
1716
"time"
1817

18+
"github.com/mattn/go-runewidth"
19+
1920
glang "golang.org/x/text/language"
2021
gmessage "golang.org/x/text/message"
2122
"gopkg.in/yaml.v2"
@@ -690,7 +691,7 @@ func fileSummarizeLong(input chan *FileJob) string {
690691
}
691692

692693
languages := map[string]LanguageSummary{}
693-
var sumFiles, sumLines, sumCode, sumComment, sumBlank, sumComplexity int64 = 0, 0, 0, 0, 0, 0
694+
var sumFiles, sumLines, sumCode, sumComment, sumBlank, sumComplexity, sumBytes int64 = 0, 0, 0, 0, 0, 0, 0
694695
var sumWeightedComplexity float64
695696

696697
for res := range input {
@@ -816,23 +817,13 @@ func fileSummarizeLong(input chan *FileJob) string {
816817
str.WriteString(getTabularWideBreak())
817818

818819
if !Cocomo {
819-
estimatedEffort := EstimateEffort(int64(sumCode), EAF)
820-
estimatedCost := EstimateCost(estimatedEffort, AverageWage, Overhead)
821-
estimatedScheduleMonths := EstimateScheduleMonths(estimatedEffort)
822-
estimatedPeopleRequired := estimatedEffort / estimatedScheduleMonths
823-
824-
p := gmessage.NewPrinter(glang.English)
825-
826-
str.WriteString(p.Sprintf("Estimated Cost to Develop $%d\n", int64(estimatedCost)))
827-
str.WriteString(fmt.Sprintf("Estimated Schedule Effort %f months\n", estimatedScheduleMonths))
828-
if math.IsNaN(estimatedPeopleRequired) {
829-
str.WriteString(fmt.Sprintf("Estimated People Required 1 Grandparent\n"))
830-
} else {
831-
str.WriteString(fmt.Sprintf("Estimated People Required %f\n", estimatedPeopleRequired))
832-
}
820+
calculateCocomo(sumCode, &str)
821+
str.WriteString(getTabularWideBreak())
822+
}
823+
if !Size {
824+
calculateSize(sumBytes, &str)
833825
str.WriteString(getTabularWideBreak())
834826
}
835-
836827
return str.String()
837828
}
838829

@@ -977,8 +968,14 @@ func fileSummarizeShort(input chan *FileJob) string {
977968
}
978969
str.WriteString(getTabularShortBreak())
979970

980-
calculateCocomo(sumCode, &str)
981-
calculateSize(sumBytes, &str)
971+
if !Cocomo {
972+
calculateCocomo(sumCode, &str)
973+
str.WriteString(getTabularShortBreak())
974+
}
975+
if !Size {
976+
calculateSize(sumBytes, &str)
977+
str.WriteString(getTabularShortBreak())
978+
}
982979
return str.String()
983980
}
984981

@@ -990,71 +987,65 @@ func trimNameShort(summary LanguageSummary, trimmedName string) string {
990987
}
991988

992989
func calculateCocomo(sumCode int64, str *strings.Builder) {
993-
if !Cocomo {
994-
estimatedEffort := EstimateEffort(int64(sumCode), EAF)
995-
estimatedCost := EstimateCost(estimatedEffort, AverageWage, Overhead)
996-
estimatedScheduleMonths := EstimateScheduleMonths(estimatedEffort)
997-
estimatedPeopleRequired := estimatedEffort / estimatedScheduleMonths
990+
estimatedEffort := EstimateEffort(int64(sumCode), EAF)
991+
estimatedCost := EstimateCost(estimatedEffort, AverageWage, Overhead)
992+
estimatedScheduleMonths := EstimateScheduleMonths(estimatedEffort)
993+
estimatedPeopleRequired := estimatedEffort / estimatedScheduleMonths
998994

999-
p := gmessage.NewPrinter(glang.English)
995+
p := gmessage.NewPrinter(glang.English)
1000996

1001-
str.WriteString(p.Sprintf("Estimated Cost to Develop (%s) %s%d\n", CocomoProjectType, CurrencySymbol, int64(estimatedCost)))
1002-
str.WriteString(fmt.Sprintf("Estimated Schedule Effort (%s) %f months\n", CocomoProjectType, estimatedScheduleMonths))
1003-
if math.IsNaN(estimatedPeopleRequired) {
1004-
str.WriteString(fmt.Sprintf("Estimated People Required 1 Grandparent\n"))
1005-
} else {
1006-
str.WriteString(fmt.Sprintf("Estimated People Required (%s) %f\n", CocomoProjectType, estimatedPeopleRequired))
1007-
}
1008-
str.WriteString(getTabularShortBreak())
997+
str.WriteString(p.Sprintf("Estimated Cost to Develop (%s) %s%d\n", CocomoProjectType, CurrencySymbol, int64(estimatedCost)))
998+
str.WriteString(fmt.Sprintf("Estimated Schedule Effort (%s) %f months\n", CocomoProjectType, estimatedScheduleMonths))
999+
if math.IsNaN(estimatedPeopleRequired) {
1000+
str.WriteString(fmt.Sprintf("Estimated People Required 1 Grandparent\n"))
1001+
} else {
1002+
str.WriteString(fmt.Sprintf("Estimated People Required (%s) %f\n", CocomoProjectType, estimatedPeopleRequired))
10091003
}
10101004
}
10111005

10121006
func calculateSize(sumBytes int64, str *strings.Builder) {
1013-
if !Size {
1014-
var size float64
1015-
1016-
switch strings.ToLower(SizeUnit) {
1017-
case "binary":
1018-
size = float64(sumBytes) / 1_048_576
1019-
case "mixed":
1020-
size = float64(sumBytes) / 1_024_000
1021-
case "xkcd-kb":
1022-
str.WriteString("1000 bytes during leap years, 1024 otherwise\n")
1023-
tim := time.Now()
1024-
if isLeapYear(tim.Year()) {
1025-
size = float64(sumBytes) / 1_000_000
1026-
}
1027-
case "xkcd-kelly":
1028-
str.WriteString("compromise between 1000 and 1024 bytes\n")
1029-
size = float64(sumBytes) / (1012 * 1012)
1030-
case "xkcd-imaginary":
1031-
str.WriteString("used in quantum computing\n")
1032-
str.WriteString(fmt.Sprintf("Processed %d bytes, %s megabytes (%s)\n", sumBytes, `¯\_(ツ)_/¯`, strings.ToUpper(SizeUnit)))
1033-
case "xkcd-intel":
1034-
str.WriteString("calculated on pentium F.P.U.\n")
1035-
size = float64(sumBytes) / (1023.937528 * 1023.937528)
1036-
case "xkcd-drive":
1037-
str.WriteString("shrinks by 4 bytes every year for marketing reasons\n")
1038-
tim := time.Now()
1039-
1040-
s := 908 - ((tim.Year() - 2013) * 4) // comic starts with 908 in 2013 hence hardcoded values
1041-
s = min(s, 908) // just in case the clock is stupidly set
1042-
1043-
size = float64(sumBytes) / float64(s*s)
1044-
case "xkcd-bakers":
1045-
str.WriteString("9 bits to the byte since you're such a good customer\n")
1046-
size = float64(sumBytes) / (1152 * 1152)
1047-
default:
1048-
// SI value of 1000 bytes
1049-
size = float64(sumBytes) / 1_000_000
1050-
SizeUnit = "SI"
1051-
}
10521007

1053-
if strings.ToLower(SizeUnit) != "xkcd-imaginary" {
1054-
str.WriteString(fmt.Sprintf("Processed %d bytes, %.3f megabytes (%s)\n", sumBytes, size, strings.ToUpper(SizeUnit)))
1008+
var size float64
1009+
1010+
switch strings.ToLower(SizeUnit) {
1011+
case "binary":
1012+
size = float64(sumBytes) / 1_048_576
1013+
case "mixed":
1014+
size = float64(sumBytes) / 1_024_000
1015+
case "xkcd-kb":
1016+
str.WriteString("1000 bytes during leap years, 1024 otherwise\n")
1017+
tim := time.Now()
1018+
if isLeapYear(tim.Year()) {
1019+
size = float64(sumBytes) / 1_000_000
10551020
}
1021+
case "xkcd-kelly":
1022+
str.WriteString("compromise between 1000 and 1024 bytes\n")
1023+
size = float64(sumBytes) / (1012 * 1012)
1024+
case "xkcd-imaginary":
1025+
str.WriteString("used in quantum computing\n")
1026+
str.WriteString(fmt.Sprintf("Processed %d bytes, %s megabytes (%s)\n", sumBytes, `¯\_(ツ)_/¯`, strings.ToUpper(SizeUnit)))
1027+
case "xkcd-intel":
1028+
str.WriteString("calculated on pentium F.P.U.\n")
1029+
size = float64(sumBytes) / (1023.937528 * 1023.937528)
1030+
case "xkcd-drive":
1031+
str.WriteString("shrinks by 4 bytes every year for marketing reasons\n")
1032+
tim := time.Now()
1033+
1034+
s := 908 - ((tim.Year() - 2013) * 4) // comic starts with 908 in 2013 hence hardcoded values
1035+
s = min(s, 908) // just in case the clock is stupidly set
1036+
1037+
size = float64(sumBytes) / float64(s*s)
1038+
case "xkcd-bakers":
1039+
str.WriteString("9 bits to the byte since you're such a good customer\n")
1040+
size = float64(sumBytes) / (1152 * 1152)
1041+
default:
1042+
// SI value of 1000 bytes
1043+
size = float64(sumBytes) / 1_000_000
1044+
SizeUnit = "SI"
1045+
}
10561046

1057-
str.WriteString(getTabularShortBreak())
1047+
if strings.ToLower(SizeUnit) != "xkcd-imaginary" {
1048+
str.WriteString(fmt.Sprintf("Processed %d bytes, %.3f megabytes (%s)\n", sumBytes, size, strings.ToUpper(SizeUnit)))
10581049
}
10591050
}
10601051

0 commit comments

Comments
 (0)