Skip to content

Commit

Permalink
json2 output format
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed May 2, 2024
1 parent ff5c899 commit 32db2f5
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,<auto-generated />])
Expand Down
60 changes: 30 additions & 30 deletions SCC-OUTPUT-REPORT.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
<tbody><tr>
<th>Go</th>
<th>30</th>
<th>9298</th>
<th>1451</th>
<th>9335</th>
<th>1458</th>
<th>453</th>
<th>7394</th>
<th>1513</th>
<th>394637</th>
<th>3912</th>
<th>7424</th>
<th>1516</th>
<th>395688</th>
<th>3929</th>
</tr><tr>
<td>processor/workers_test.go</td>
<td></td>
Expand All @@ -33,13 +33,13 @@
</tr><tr>
<td>processor/formatters.go</td>
<td></td>
<td>1463</td>
<td>193</td>
<td>1500</td>
<td>200</td>
<td>43</td>
<td>1227</td>
<td>277</td>
<td>44617</td>
<td>709</td>
<td>1257</td>
<td>280</td>
<td>45661</td>
<td>727</td>
</tr><tr>
<td>processor/formatters_test.go</td>
<td></td>
Expand Down Expand Up @@ -88,7 +88,7 @@
<td>6</td>
<td>362</td>
<td>10</td>
<td>8483</td>
<td>8490</td>
<td>242</td>
</tr><tr>
<td>cmd/badges/main.go</td>
Expand Down Expand Up @@ -220,16 +220,6 @@
<td>20</td>
<td>949</td>
<td>31</td>
</tr><tr>
<td>processor/filereader.go</td>
<td></td>
<td>52</td>
<td>10</td>
<td>10</td>
<td>32</td>
<td>6</td>
<td>1329</td>
<td>37</td>
</tr><tr>
<td>cmd/badges/simplecache_test.go</td>
<td></td>
Expand All @@ -240,6 +230,16 @@
<td>9</td>
<td>1041</td>
<td>30</td>
</tr><tr>
<td>processor/filereader.go</td>
<td></td>
<td>52</td>
<td>10</td>
<td>10</td>
<td>32</td>
<td>6</td>
<td>1329</td>
<td>37</td>
</tr><tr>
<td>processor/cocomo.go</td>
<td></td>
Expand Down Expand Up @@ -324,15 +324,15 @@
<tfoot><tr>
<th>Total</th>
<th>30</th>
<th>9298</th>
<th>1451</th>
<th>9335</th>
<th>1458</th>
<th>453</th>
<th>7394</th>
<th>1513</th>
<th>394637</th>
<th>3912</th>
<th>7424</th>
<th>1516</th>
<th>395688</th>
<th>3929</th>
</tr>
<tr>
<th colspan="9">Estimated Cost to Develop (organic) $220,759<br>Estimated Schedule Effort (organic) 7.75 months<br>Estimated People Required (organic) 2.53<br></th>
<th colspan="9">Estimated Cost to Develop (organic) $221,699<br>Estimated Schedule Effort (organic) 7.76 months<br>Estimated People Required (organic) 2.54<br></th>
</tr></tfoot>
</table></body></html>
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
37 changes: 37 additions & 0 deletions processor/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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":
Expand Down
9 changes: 9 additions & 0 deletions test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 32db2f5

Please sign in to comment.