8000 Tweak json to have ULOC output by boyter · Pull Request #495 · boyter/scc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Tweak json to have ULOC output #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10000
66 changes: 33 additions & 33 deletions SCC-OUTPUT-REPORT.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@
<tbody><tr>
<th>Go</th>
<th>30</th>
<th>9519</th>
<th>1462</th>
<th>459</th>
<th>7598</th>
<th>9518</th>
<th>1461</th>
<th>456</th>
<th>7601</th>
<th>1517</th>
<th>254152</th>
<th>4052</th>
<th>254263</th>
<th>4051</th>
</tr><tr>
<td>processor/formatters.go</td>
<td></td>
<td>1607</td>
<td>209</td>
<td>46</td>
<td>1352</td>
<td>1605</td>
<td>208</td>
<td>43</td>
<td>1354</td>
<td>289</td>
<td>47930</td>
<td>795</td>
<td>48017</td>
<td>793</td>
</tr><tr>
<td>processor/workers_test.go</td>
<td></td>
Expand Down Expand Up @@ -133,13 +133,13 @@
</tr><tr>
<td>processor/structs.go</td>
<td></td>
<td>198</td>
<td>199</td>
<td>21</td>
<td>18</td>
<td>159</td>
<td>160</td>
<td>17</td>
<td>5872</td>
<td>138</td>
<td>5896</td>
<td>139</td>
</tr><tr>
<td>processor/workers_regression_test.go</td>
<td></td>
Expand Down Expand Up @@ -250,16 +250,6 @@
<td>0</td>
<td>2222</td>
<td>35</td>
</tr><tr>
<td>processor/bloom.go</td>
<td></td>
<td>37</td>
<td>7</td>
<td>12</td>
<td>18</td>
<td>2</td>
<td>1062</td>
<td>29</td>
</tr><tr>
<td>processor/cocomo_test.go</td>
<td></td>
Expand All @@ -270,6 +260,16 @@
<td>6</td>
<td>699</td>
<td>23</td>
</tr><tr>
<td>processor/bloom.go</td>
<td></td>
<td>37</td>
<td>7</td>
<td>12</td>
<td>18</td>
<td>2</td>
<td>1062</td>
<td>29</td>
</tr><tr>
<td>processor/helpers_test.go</td>
<td></td>
Expand Down Expand Up @@ -324,15 +324,15 @@
<tfoot><tr>
<th>Total</th>
<th>30</th>
<th>9519</th>
<th>1462</th>
<th>459</th>
<th>7598</th>
<th>9518</th>
<th>1461</th>
<th>456</th>
<th>7601</th>
<th>1517</th>
<th>254152</th>
<th>4052</th>
<th>254263</th>
<th>4051</th>
</tr>
<tr>
<th colspan="9">Estimated Cost to Develop (organic) $227,158<br>Estimated Schedule Effort (organic) 7.83 months<br>Estimated People Required (organic) 2.58<br></th>
<th colspan="9">Estimated Cost to Develop (organic) $227,252<br>Estimated Schedule Effort (organic) 7.83 months<br>Estimated People Required (organic) 2.58<br></th>
</tr></tfoot>
</table></body></html>
60 changes: 29 additions & 31 deletions processor/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ func toHtmlTable(input chan *FileJob) string {
<tbody>`)

for _, r := range language {
fmt.Fprintf(str, `<tr>
_, _ = fmt.Fprintf(str, `<tr>
<th>%s</th>
<th>%d</th>
<th>%d</th>
Expand All @@ -647,7 +647,7 @@ func toHtmlTable(input chan *FileJob) string {
sortSummaryFiles(&r)

for _, res := range r.Files {
fmt.Fprintf(str, `<tr>
_, _ = fmt.Fprintf(str, `<tr>
<td>%s</td>
<td></td>
<td>%d</td>
Expand All @@ -663,7 +663,7 @@ func toHtmlTable(input chan *FileJob) string {

}

fmt.Fprintf(str, `</tbody>
_, _ = fmt.Fprintf(str, `</tbody>
<tfoot><tr>
<th>Total</th>
<th>%d</th>
Expand All @@ -679,7 +679,7 @@ func toHtmlTable(input chan *FileJob) string {
if !Cocomo {
var sb strings.Builder
calculateCocomo(sumCode, &sb)
fmt.Fprintf(str, `
_, _ = fmt.Fprintf(str, `
<tr>
<th colspan="9">%s</th>
</tr></tfoot>
Expand Down Expand Up @@ -707,7 +707,7 @@ func toSqlInsert(input chan *FileJob) string {

dir, _ := filepath.Split(res.Location)

fmt.Fprintf(str, "\ninsert into t values('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, %d);",
_, _ = fmt.Fprintf(str, "\ninsert into t values('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, %d);",
escapeSQLString(projectName),
escapeSQLString(res.Language),
escapeSQLString(res.Location),
Expand All @@ -727,7 +727,7 @@ func toSqlInsert(input chan *FileJob) string {
currentTime := time.Now()
es := float64(makeTimestampMilli()-startTimeMilli) * 0.001
str.WriteString("\nbegin transaction;")
fmt.Fprintf(str, "\ninsert into metadata values('%s', '%s', %f, %f, %f, %f);",
_, _ = fmt.Fprintf(str, "\ninsert into metadata values('%s', '%s', %f, %f, %f, %f);",
currentTime.Format("2006-01-02 15:04:05"),
projectName,
es,
Expand Down Expand Up @@ -1193,14 +1193,14 @@ func fileSummarizeShort(input chan *FileJob) string {
trimmedName = trimNameShort(summary, trimmedName)

if !Complexity {
fmt.Fprintf(str, tabularShortFormatBody, trimmedName, summary.Count, summary.Lines, summary.Blank, summary.Comment, summary.Code, summary.Complexity)
_, _ = fmt.Fprintf(str, tabularShortFormatBody, trimmedName, summary.Count, summary.Lines, summary.Blank, summary.Comment, summary.Code, summary.Complexity)
} else {
fmt.Fprintf(str, tabularShortFormatBodyNoComplexity, trimmedName, summary.Count, summary.Lines, summary.Blank, summary.Comment, summary.Code)
_, _ = fmt.Fprintf(str, tabularShortFormatBodyNoComplexity, trimmedName, summary.Count, summary.Lines, summary.Blank, summary.Comment, summary.Code)
}

if Percent {
if !Complexity {
fmt.Fprintf(str,
_, _ = fmt.Fprintf(str,
tabularShortPercentLanguageFormatBody,
float64(len(summary.Files))/float64(sumFiles)*100,
float64(summary.Lines)/float64(sumLines)*100,
Expand All @@ -1210,7 +1210,7 @@ func fileSummarizeShort(input chan *FileJob) string {
float64(summary.Complexity)/float64(sumComplexity)*100,
)
} else {
fmt.Fprintf(str,
_, _ = fmt.Fprintf(str,
tabularShortPercentLanguageFormatBodyNoComplexity,
float64(len(summary.Files))/float64(sumFiles)*100,
float64(summary.Lines)/float64(sumLines)*100,
Expand All @@ -1225,9 +1225,9 @@ func fileSummarizeShort(input chan *FileJob) string {

if MaxMean {
if !Complexity {
fmt.Fprintf(str, tabularShortFormatFileMaxMean, maxIn(summary.LineLength), meanIn(summary.LineLength))
_, _ = fmt.Fprintf(str, tabularShortFormatFileMaxMean, maxIn(summary.LineLength), meanIn(summary.LineLength))
} else {
fmt.Fprintf(str, tabularShortFormatFileMaxMeanNoComplexity, maxIn(summary.LineLength), meanIn(summary.LineLength))
_, _ = fmt.Fprintf(str, tabularShortFormatFileMaxMeanNoComplexity, maxIn(summary.LineLength), meanIn(summary.LineLength))
}

addBreak = true
Expand All @@ -1242,23 +1242,19 @@ func fileSummarizeShort(input chan *FileJob) string {

if !Complexity {
tmp = unicodeAwareRightPad(tmp, 30)
fmt.Fprintf(str, tabularShortFormatFile, tmp, res.Lines, res.Blank, res.Comment, res.Code, res.Complexity)
_, _ = fmt.Fprintf(str, tabularShortFormatFile, tmp, res.Lines, res.Blank, res.Comment, res.Code, res.Complexity)
} else {
tmp = unicodeAwareRightPad(tmp, 34)
fmt.Fprintf(str, tabularShortFormatFileNoComplexity, tmp, res.Lines, res.Blank, res.Comment, res.Code)
_, _ = fmt.Fprintf(str, tabularShortFormatFileNoComplexity, tmp, res.Lines, res.Blank, res.Comment, res.Code)
}

// if MaxMean {
// fmt.Fprintf(str, tabularShortFormatFileMaxMean, maxIn(res.LineLength), meanIn(res.LineLength))
// }
}
}

if UlocMode {
if !Complexity {
fmt.Fprintf(str, tabularShortUlocLanguageFormatBody, len(ulocLanguageCount[summary.Name]))
_, _ = fmt.Fprintf(str, tabularShortUlocLanguageFormatBody, len(ulocLanguageCount[summary.Name]))
} else {
fmt.Fprintf(str, tabularShortUlocLanguageFormatBodyNoComplexity, len(ulocLanguageCount[summary.Name]))
_, _ = fmt.Fprintf(str, tabularShortUlocLanguageFormatBodyNoComplexity, len(ulocLanguageCount[summary.Name]))
}

addBreak = true
Expand All @@ -1277,17 +1273,17 @@ func fileSummarizeShort(input chan *FileJob) string {

str.WriteString(getTabularShortBreak())
if !Complexity {
fmt.Fprintf(str, tabularShortFormatBody, "Total", sumFiles, sumLines, sumBlank, sumComment, sumCode, sumComplexity)
_, _ = fmt.Fprintf(str, tabularShortFormatBody, "Total", sumFiles, sumLines, sumBlank, sumComment, sumCode, sumComplexity)
} else {
fmt.Fprintf(str, tabularShortFormatBodyNoComplexity, "Total", sumFiles, sumLines, sumBlank, sumComment, sumCode)
_, _ = fmt.Fprintf(str, tabularShortFormatBodyNoComplexity, "Total", sumFiles, sumLines, sumBlank, sumComment, sumCode)
}
str.WriteString(getTabularShortBreak())

if UlocMode {
fmt.Fprintf(str, tabularShortUlocGlobalFormatBody, len(ulocGlobalCount))
_, _ = fmt.Fprintf(str, tabularShortUlocGlobalFormatBody, len(ulocGlobalCount))
if Dryness {
dryness := float64(len(ulocGlobalCount)) / float64(sumLines)
fmt.Fprintf(str, "DRYness %% %30.2f\n", dryness)
_, _ = fmt.Fprintf(str, "DRYness %% %30.2f\n", dryness)
}
str.WriteString(getTabularShortBreak())
}
Expand Down Expand Up @@ -1446,18 +1442,18 @@ func isLeapYear(year int) bool {
}

func aggregateLanguageSummary(input chan *FileJob) []LanguageSummary {
languages := map[string]LanguageSummary{}
langs := map[string]LanguageSummary{}

for res := range input {
_, ok := languages[res.Language]
_, ok := langs[res.Language]

if !ok {
files := []*FileJob{}
if Files {
files = append(files, res)
}

languages[res.Language] = LanguageSummary{
langs[res.Language] = LanguageSummary{
Name: res.Language,
Lines: res.Lines,
Code: res.Code,
Expand All @@ -1467,15 +1463,16 @@ func aggregateLanguageSummary(input chan *FileJob) []LanguageSummary {
Count: 1,
Files: files,
Bytes: res.Bytes,
ULOC: len(ulocLanguageCount[res.Language]),
}
} else {
tmp := languages[res.Language]
tmp := langs[res.Language]
files := tmp.Files
if Files {
files = append(files, res)
}

languages[res.Language] = LanguageSummary{
langs[res.Language] = LanguageSummary{
Name: res.Language,
Lines: tmp.Lines + res.Lines,
Code: tmp.Code + res.Code,
Expand All @@ -1485,12 +1482,13 @@ func aggregateLanguageSummary(input chan *FileJob) []LanguageSummary {
Count: tmp.Count + 1,
Files: files,
Bytes: res.Bytes + tmp.Bytes,
ULOC: len(ulocLanguageCount[res.Language]),
}
}
}

language := make([]LanguageSummary, 0, len(languages))
for _, summary := range languages {
language := make([]LanguageSummary, 0, len(langs))
for _, summary := range langs {
language = append(language, summary)
}

Expand Down
1 change: 1 addition & 0 deletions processor/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type LanguageSummary struct {
WeightedComplexity float64
Files []*FileJob
LineLength []int
ULOC int
}

// OpenClose is used to hold an open/close pair for matching such as multi line comments
Expand Down
9 changes: 9 additions & 0 deletions test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,15 @@ else
exit
fi

if ./scc -f json -a | grep -q "ULOC"; then
echo -e "${GREEN}PASSED json uloc check"
else
echo -e "${RED}======================================================="
echo -e "FAILED json uloc check"
echo -e "=======================================================${NC}"
exit
fi

if ./scc -f json2 | grep -q "Bytes"; then
echo -e "${GREEN}PASSED json2 bytes check"
else
Expand Down
Loading
0