From 32db2f5cae9eaab5583b013b9e0697a477c453e9 Mon Sep 17 00:00:00 2001 From: Ben Boyter Date: Thu, 2 May 2024 15:32:49 +1000 Subject: [PATCH] json2 output format --- README.md | 2 +- SCC-OUTPUT-REPORT.html | 60 ++++++++++++++++++++--------------------- main.go | 2 +- processor/formatters.go | 37 +++++++++++++++++++++++++ test-all.sh | 9 +++++++ 5 files changed, 78 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index c577ae4ca..006edebfe 100644 --- a/README.md +++ b/README.md @@ -256,7 +256,7 @@ Flags: -x, --exclude-ext strings ignore file extensions (overrides include-ext) [comma separated list: e.g. go,java,js] -n, --exclude-file strings ignore files with matching names (default [package-lock.json,Cargo.lock,yarn.lock,pubspec.lock,Podfile.lock]) --file-gc-count int number of files to parse before turning the GC on (default 10000) - -f, --format string set output format [tabular, wide, json, csv, csv-stream, cloc-yaml, html, html-table, sql, sql-insert, openmetrics] (default "tabular") + -f, --format string set output format [tabular, wide, json, json2, csv, csv-stream, cloc-yaml, html, html-table, sql, sql-insert, openmetrics] (default "tabular") --format-multi string have multiple format output overriding --format [e.g. tabular:stdout,csv:file.csv,json:file.json] --gen identify generated files --generated-markers strings string markers in head of generated files (default [do not edit,]) diff --git a/SCC-OUTPUT-REPORT.html b/SCC-OUTPUT-REPORT.html index 9e4c0969c..77cd324c5 100644 --- a/SCC-OUTPUT-REPORT.html +++ b/SCC-OUTPUT-REPORT.html @@ -13,13 +13,13 @@ Go 30 - 9298 - 1451 + 9335 + 1458 453 - 7394 - 1513 - 394637 - 3912 + 7424 + 1516 + 395688 + 3929 processor/workers_test.go @@ -33,13 +33,13 @@ processor/formatters.go - 1463 - 193 + 1500 + 200 43 - 1227 - 277 - 44617 - 709 + 1257 + 280 + 45661 + 727 processor/formatters_test.go @@ -88,7 +88,7 @@ 6 362 10 - 8483 + 8490 242 cmd/badges/main.go @@ -220,16 +220,6 @@ 20 949 31 - - processor/filereader.go - - 52 - 10 - 10 - 32 - 6 - 1329 - 37 cmd/badges/simplecache_test.go @@ -240,6 +230,16 @@ 9 1041 30 + + processor/filereader.go + + 52 + 10 + 10 + 32 + 6 + 1329 + 37 processor/cocomo.go @@ -324,15 +324,15 @@ Total 30 - 9298 - 1451 + 9335 + 1458 453 - 7394 - 1513 - 394637 - 3912 + 7424 + 1516 + 395688 + 3929 - Estimated Cost to Develop (organic) $220,759
Estimated Schedule Effort (organic) 7.75 months
Estimated People Required (organic) 2.53
+ Estimated Cost to Develop (organic) $221,699
Estimated Schedule Effort (organic) 7.76 months
Estimated People Required (organic) 2.54
\ No newline at end of file diff --git a/main.go b/main.go index 52a2575ec..600aaf58e 100644 --- a/main.go +++ b/main.go @@ -125,7 +125,7 @@ func main() { "format", "f", "tabular", - "set output format [tabular, wide, json, csv, csv-stream, cloc-yaml, html, html-table, sql, sql-insert, openmetrics]", + "set output format [tabular, wide, json, json2, csv, csv-stream, cloc-yaml, html, html-table, sql, sql-insert, openmetrics]", ) flags.StringSliceVarP( &processor.AllowListExtensions, diff --git a/processor/formatters.go b/processor/formatters.go index 41274fc63..03b2d9288 100644 --- a/processor/formatters.go +++ b/processor/formatters.go @@ -240,6 +240,39 @@ func toJSON(input chan *FileJob) string { return string(jsonString) } +type Json2 struct { + LanguageSummary []LanguageSummary `json:"languageSummary"` + EstimatedCost float64 `json:"estimatedCost"` + EstimatedScheduleMonths float64 `json:"estimatedScheduleMonths"` + EstimatedPeople float64 `json:"estimatedPeople"` +} + +func toJSON2(input chan *FileJob) string { + startTime := makeTimestampMilli() + language := aggregateLanguageSummary(input) + language = sortLanguageSummary(language) + + var sumCode int64 + for _, l := range language { + sumCode += l.Code + } + + cost, schedule, people := esstimateCostScheduleMonths(sumCode) + + jsonString, _ := json.Marshal(Json2{ + LanguageSummary: language, + EstimatedCost: cost, + EstimatedScheduleMonths: schedule, + EstimatedPeople: people, + }) + + if Debug { + printDebug(fmt.Sprintf("milliseconds to build formatted string: %d", makeTimestampMilli()-startTime)) + } + + return string(jsonString) +} + func toCSV(input chan *FileJob) string { if Files { return toCSVFiles(input) @@ -751,6 +784,8 @@ func fileSummarize(input chan *FileJob) string { return fileSummarizeLong(input) case strings.ToLower(Format) == "json": return toJSON(input) + case strings.ToLower(Format) == "json2": + return toJSON2(input) case strings.ToLower(Format) == "cloc-yaml" || strings.ToLower(Format) == "cloc-yml": return toClocYAML(input) case strings.ToLower(Format) == "csv": @@ -804,6 +839,8 @@ func fileSummarizeMulti(input chan *FileJob) string { val = fileSummarizeLong(i) case "json": val = toJSON(i) + case "json2": + val = toJSON2(i) case "cloc-yaml": val = toClocYAML(i) case "cloc-yml": diff --git a/test-all.sh b/test-all.sh index 4ad6521ac..c6b87a138 100755 --- a/test-all.sh +++ b/test-all.sh @@ -647,6 +647,15 @@ else exit fi +if ./scc -f json2 | grep -q "Bytes"; then + echo -e "${GREEN}PASSED json2 bytes check" +else + echo -e "${RED}=======================================================" + echo -e "FAILED json bytes check" + echo -e "=======================================================${NC}" + exit +fi + if ./scc | grep -q "megabytes"; then echo -e "${GREEN}PASSED bytes check" else