2
0
forked from Wavyzz/dolibarr

Prepare apstats for lines of code

This commit is contained in:
Laurent Destailleur
2024-01-13 13:12:21 +01:00
parent 7c33cc7763
commit a109bc003b
2 changed files with 63 additions and 5 deletions

View File

@@ -111,6 +111,16 @@ $output_arrtd = array();
$resexectd = 0;
exec($commandcheck, $output_arrtd, $resexectd);
// Count lines of code of dependencies
$commandcheck = 'dev/tools/github_lines_perusers.sh';
print 'Execute github_lines_perusers to count lines of code in dependencies: '.$commandcheck."\n";
$output_arrglpu = array();
$resexecglpu = 0;
exec($commandcheck, $output_arrglpu, $resexecglpu);
$arrayoflineofcode = array();
$arraycocomo = array();
$arrayofmetrics = array(
@@ -325,12 +335,18 @@ div.fiche>form>div.div-table-responsive, div.fiche>form>div.div-table-responsive
$html .= '<body>'."\n";
// Header
$html .= '<header>'."\n";
$html .= '<h1>Advanced Project Statistics</h1>'."\n";
$currentDate = date("Y-m-d H:i:s"); // Format: Year-Month-Day Hour:Minute:Second
$html .= '<span class="opacitymedium">Generated on '.$currentDate.' in '.($timeend - $timestart).' seconds</span>'."\n";
$html .= '</header>'."\n";
// Lines of code
$html .= '<section class="chapter" id="linesofcode">'."\n";
$html .= '<h2><span class="fas fa-code pictofixedwidth"></span>Lines of code</h2>'."\n";
@@ -408,6 +424,37 @@ $html .= '</div>';
$html .= '</section>'."\n";
// Contributions
$html .= '<section class="chapter" id="projectvalue">'."\n";
$html .= '<h2><span class="fas fa-dollar-sign pictofixedwidth"></span>Contributions</h2>'."\n";
$html .= '<div class="boxallwidth">'."\n";
$html .= 'TODO...';
$html .= '</div>';
$html .= '</section>'."\n";
// Contributor
$html .= '<section class="chapter" id="projectvalue">'."\n";
$html .= '<h2><span class="fas fa-tasks pictofixedwidth"></span>Contributors</h2>'."\n";
$html .= '<div class="boxallwidth">'."\n";
$html .= 'TODO...';
$html .= '</div>';
$html .= '</section>'."\n";
// Project value
$html .= '<section class="chapter" id="projectvalue">'."\n";
$html .= '<h2><span class="fas fa-dollar-sign pictofixedwidth"></span>Project value</h2>'."\n";
@@ -437,6 +484,9 @@ foreach ($output_arrtd as $line) {
}
}
// Technical debt
$html .= '<section class="chapter" id="technicaldebt">'."\n";
$html .= '<h2><span class="fas fa-book-dead pictofixedwidth"></span>Technical debt <span class="opacitymedium">(PHPStan level '.$phpstanlevel.' -> '.$nblines.' warnings)</span></h2>'."\n";
@@ -451,6 +501,9 @@ $html .= '</div>';
$html .= '</section>'."\n";
// JS code
$html .= '
<script>
$(document).ready(function() {
@@ -465,6 +518,7 @@ $( ".seedetail" ).on( "click", function() {
$html .= '</body>';
$html .= '</html>';
// Output report into a HTML file
$fh = fopen($outputpath, 'w');
if ($fh) {
fwrite($fh, $html);

View File

@@ -6,17 +6,21 @@
# shellcheck disable=2002,2086,2268
if [ "x$2" = "x" ]; then
echo "Usage: $0 origin/branchstart|tagnamestart|START origin/branchend|tagnameend|HEAD"
echo "***** github_lines_perusers.sh *****"
echo "Return the number of lines of code produced by each contributor between 2 versions"
echo "Usage: $0 origin/branchstart|tagnamestart|START origin/branchend|tagnameend|HEAD"
echo "Example: $0 origin/18.0 origin/19.0"
exit
fi
START=$1
START="$1.."
if [ "x$START" = "xSTART" ]; then
START=""
fi
echo "git log $START..$2 --shortstat | grep ... | perl ... > /tmp/github_lines_perusers.tmp"
git log $START..$2 --shortstat | grep -e 'Author:' -e 'Date:' -e ' changed' -e ' insertion' -e ' deletion' | perl -n -e '/^(.*)$/; $line = $1; if ($line =~ /(changed|insertion|deletion)/) { $line =~ s/[^0-9\s]//g; my @arr=split /\s+/, $line; $tot=0; for (1..@arr) { $tot += $arr[$_]; }; print $tot."\n"; } else { print $line."\n"; };' > /tmp/github_lines_perusers.tmp
echo "git log $START$2 --shortstat | grep ... | perl ... > /tmp/github_lines_perusers.tmp"
git log $START$2 --shortstat | grep -e 'Author:' -e 'Date:' -e ' changed' -e ' insertion' -e ' deletion' | perl -n -e '/^(.*)$/; $line = $1; if ($line =~ /(changed|insertion|deletion)/) { $line =~ s/[^0-9\s]//g; my @arr=split /\s+/, $line; $tot=0; for (1..@arr) { $tot += $arr[$_]; }; print $tot."\n"; } else { print $line."\n"; };' > /tmp/github_lines_perusers.tmp
cat /tmp/github_lines_perusers.tmp | awk 'BEGIN { FS="\n"; print "user and nb of lines"; lastuser=""; } { if ($1 ~ /Author:/) { lastuser=$1 }; if ($1 ~ /^[0-9]+$/) { aaa[lastuser]+=$1; } } END { for (var in aaa) print var," ",aaa[var]; } '
echo "Users and nb of lines";
cat /tmp/github_lines_perusers.tmp | awk 'BEGIN { FS="\n"; lastuser=""; } { if ($1 ~ /Author:/) { lastuser=$1 }; if ($1 ~ /^[0-9]+$/) { aaa[lastuser]+=$1; } } END { for (var in aaa) print var," ",aaa[var]; } '