Skip to content

Commit

Permalink
Add in percentage as per Issue 325 (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed May 10, 2024
1 parent 416bd23 commit 0de4eb4
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 40 deletions.
62 changes: 31 additions & 31 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>9335</th>
<th>1458</th>
<th>453</th>
<th>7424</th>
<th>1516</th>
<th>401573</th>
<th>3929</th>
<th>9384</th>
<th>1462</th>
<th>454</th>
<th>7468</th>
<th>1520</th>
<th>403311</th>
<th>3958</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>1500</td>
<td>200</td>
<td>1539</td>
<td>203</td>
<td>43</td>
<td>1257</td>
<td>280</td>
<td>45661</td>
<td>727</td>
<td>1293</td>
<td>284</td>
<td>47181</td>
<td>750</td>
</tr><tr>
<td>processor/formatters_test.go</td>
<td></td>
Expand All @@ -63,13 +63,13 @@
</tr><tr>
<td>processor/processor.go</td>
<td></td>
<td>641</td>
<td>136</td>
<td>100</td>
<td>405</td>
<td>644</td>
<td>137</td>
<td>101</td>
<td>406</td>
<td>87</td>
<td>18512</td>
<td>419</td>
<td>18618</td>
<td>421</td>
</tr><tr>
<td>processor/detector_test.go</td>
<td></td>
Expand All @@ -83,13 +83,13 @@
</tr><tr>
<td>main.go</td>
<td></td>
<td>378</td>
<td>385</td>
<td>10</td>
<td>6</td>
<td>362</td>
<td>369</td>
<td>10</td>
<td>8482</td>
<td>242</td>
<td>8594</td>
<td>246</td>
</tr><tr>
<td>cmd/badges/main.go</td>
<td></td>
Expand Down Expand Up @@ -324,15 +324,15 @@
<tfoot><tr>
<th>Total</th>
<th>30</th>
<th>9335</th>
<th>1458</th>
<th>453</th>
<th>7424</th>
<th>1516</th>
<th>401573</th>
<th>3929</th>
<th>9384</th>
<th>1462</th>
<th>454</th>
<th>7468</th>
<th>1520</th>
<th>403311</th>
<th>3958</th>
</tr>
<tr>
<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>
<th colspan="9">Estimated Cost to Develop (organic) $223,079<br>Estimated Schedule Effort (organic) 7.78 months<br>Estimated People Required (organic) 2.55<br></th>
</tr></tfoot>
</table></body></html>
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ func main() {

flags := rootCmd.PersistentFlags()

flags.BoolVarP(
&processor.Percent,
"percent",
"p",
false,
"include percentage values in output",
)
flags.BoolVarP(
&processor.UlocMode,
"uloc",
Expand Down
53 changes: 46 additions & 7 deletions processor/formatters.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var shortFormatFileTruncate = 29
var shortNameTruncate = 20

var tabularShortUlocLanguageFormatBody = "(ULOC) %33d\n"
var tabularShortPercentLanguageFormatBody = "%29.1f%% %8.1f%% %7.1f%% %8.1f%% %7.1f%% %9.1f%%\n"
var tabularShortUlocGlobalFormatBody = "Unique Lines of Code (ULOC) %12d\n"

var tabularShortFormatHeadNoComplexity = "%-22s %11s %11s %10s %11s %9s\n"
Expand All @@ -40,6 +41,7 @@ var tabularShortFormatFileNoComplexity = "%s %11d %10d %11d %9d\n"
var longNameTruncate = 22

var tabularShortUlocLanguageFormatBodyNoComplexity = "(ULOC) %39d\n"
var tabularShortPercentLanguageFormatBodyNoComplexity = "%33.1f%% %10.1f%% %9.1f%% %10.1f%% %8.1f%%\n"

var tabularWideBreak = "─────────────────────────────────────────────────────────────────────────────────────────────────────────────\n"
var tabularWideBreakCi = "-------------------------------------------------------------------------------------------------------------\n"
Expand All @@ -50,6 +52,7 @@ var wideFormatFileTruncate = 42

var tabularWideUlocLanguageFormatBody = "(ULOC) %46d\n"
var tabularWideUlocGlobalFormatBody = "Unique Lines of Code (ULOC) %25d\n"
var tabularWideFormatBodyPercent = "%42.1f%% %8.1f%% %7.1f%% %8.1f%% %7.1f%% %9.1f%%\n"

var openMetricsMetadata = `# TYPE scc_files count
# HELP scc_files Number of sourcecode files.
Expand Down Expand Up @@ -994,6 +997,19 @@ func fileSummarizeLong(input chan *FileJob) string {

str.WriteString(fmt.Sprintf(tabularWideFormatBody, trimmedName, summary.Count, summary.Lines, summary.Blank, summary.Comment, summary.Code, summary.Complexity, summary.WeightedComplexity))

if Percent {
str.WriteString(fmt.Sprintf(
tabularWideFormatBodyPercent,
float64(len(summary.Files))/float64(sumFiles)*100,
float64(summary.Lines)/float64(sumLines)*100,
float64(summary.Blank)/float64(sumBlank)*100,
float64(summary.Comment)/float64(sumComment)*100,
float64(summary.Code)/float64(sumCode)*100,
float64(summary.Complexity)/float64(sumComplexity)*100,
))

}

if UlocMode {
str.WriteString(fmt.Sprintf(tabularWideUlocLanguageFormatBody, len(ulocLanguageCount[summary.Name])))
if !Files && summary.Name != language[len(language)-1].Name {
Expand Down Expand Up @@ -1156,15 +1172,26 @@ func fileSummarizeShort(input chan *FileJob) string {
str.WriteString(fmt.Sprintf(tabularShortFormatBodyNoComplexity, trimmedName, summary.Count, summary.Lines, summary.Blank, summary.Comment, summary.Code))
}

if UlocMode {
if Percent {
if !Complexity {
str.WriteString(fmt.Sprintf(tabularShortUlocLanguageFormatBody, len(ulocLanguageCount[summary.Name])))
str.WriteString(fmt.Sprintf(
tabularShortPercentLanguageFormatBody,
float64(len(summary.Files))/float64(sumFiles)*100,
float64(summary.Lines)/float64(sumLines)*100,
float64(summary.Blank)/float64(sumBlank)*100,
float64(summary.Comment)/float64(sumComment)*100,
float64(summary.Code)/float64(sumCode)*100,
float64(summary.Complexity)/float64(sumComplexity)*100,
))
} else {
str.WriteString(fmt.Sprintf(tabularShortUlocLanguageFormatBodyNoComplexity, len(ulocLanguageCount[summary.Name])))
}

if !Files && summary.Name != language[len(language)-1].Name {
str.WriteString(tabularShortBreakCi)
str.WriteString(fmt.Sprintf(
tabularShortPercentLanguageFormatBodyNoComplexity,
float64(len(summary.Files))/float64(sumFiles)*100,
float64(summary.Lines)/float64(sumLines)*100,
float64(summary.Blank)/float64(sumBlank)*100,
float64(summary.Comment)/float64(sumComment)*100,
float64(summary.Code)/float64(sumCode)*100,
))
}
}

Expand All @@ -1184,6 +1211,18 @@ func fileSummarizeShort(input chan *FileJob) string {
}
}
}

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

if !Files && summary.Name != language[len(language)-1].Name {
str.WriteString(tabularShortBreakCi)
}
}
}

if Debug {
Expand Down
7 changes: 5 additions & 2 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var More = false
// Cocomo toggles the COCOMO calculation
var Cocomo = false

// Print a more SLOCCount like COCOMO calculation
// SLOCCountFormat prints a more SLOCCount like COCOMO calculation
var SLOCCountFormat = false

// CocomoProjectType allows the flipping between project types which impacts the calculation
Expand Down Expand Up @@ -105,6 +105,9 @@ var DisableCheckBinary = false
// UlocMode toggles checking for binary files using NUL bytes
var UlocMode = false

// Percent toggles checking for binary files using NUL bytes
var Percent = false

// Dryness toggles checking for binary files using NUL bytes
var Dryness = false

Expand Down Expand Up @@ -168,7 +171,7 @@ var AverageWage int64 = 56286
// Overhead is the overhead multiplier for corporate overhead (facilities, equipment, accounting, etc.)
var Overhead float64 = 2.4

// the effort adjustment factor derived from the cost drivers, i.e. 1.0 if rated nominal
// EAF is the effort adjustment factor derived from the cost drivers, i.e. 1.0 if rated nominal
var EAF float64 = 1.0

// GcFileCount is the number of files to process before turning the GC back on
Expand Down

0 comments on commit 0de4eb4

Please sign in to comment.