7
7
"encoding/csv"
8
8
"encoding/json"
9
9
"fmt"
10
- "github.com/mattn/go-runewidth"
11
10
"io/ioutil"
12
11
"math"
13
12
"os"
@@ -16,6 +15,8 @@ import (
16
15
"strings"
17
16
"time"
18
17
18
+ "github.com/mattn/go-runewidth"
19
+
19
20
glang "golang.org/x/text/language"
20
21
gmessage "golang.org/x/text/message"
21
22
"gopkg.in/yaml.v2"
@@ -690,7 +691,7 @@ func fileSummarizeLong(input chan *FileJob) string {
690
691
}
691
692
692
693
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
694
695
var sumWeightedComplexity float64
695
696
696
697
for res := range input {
@@ -816,23 +817,13 @@ func fileSummarizeLong(input chan *FileJob) string {
816
817
str .WriteString (getTabularWideBreak ())
817
818
818
819
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 )
833
825
str .WriteString (getTabularWideBreak ())
834
826
}
835
-
836
827
return str .String ()
837
828
}
838
829
@@ -977,8 +968,14 @@ func fileSummarizeShort(input chan *FileJob) string {
977
968
}
978
969
str .WriteString (getTabularShortBreak ())
979
970
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
+ }
982
979
return str .String ()
983
980
}
984
981
@@ -990,71 +987,65 @@ func trimNameShort(summary LanguageSummary, trimmedName string) string {
990
987
}
991
988
992
989
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
998
994
999
- p := gmessage .NewPrinter (glang .English )
995
+ p := gmessage .NewPrinter (glang .English )
1000
996
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 ))
1009
1003
}
1010
1004
}
1011
1005
1012
1006
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
- }
1052
1007
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
1055
1020
}
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
+ }
1056
1046
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 )))
1058
1049
}
1059
1050
}
1060
1051
0 commit comments