Skip to content

Commit

Permalink
new report : radar chart, with repartition
Browse files Browse the repository at this point in the history
  • Loading branch information
Halleck45 committed Dec 16, 2014
1 parent dd74c6b commit 266d75b
Show file tree
Hide file tree
Showing 26 changed files with 280 additions and 72 deletions.
Binary file modified build/phpmetrics.phar
Binary file not shown.
10 changes: 7 additions & 3 deletions src/Hal/Application/Formater/Summary/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Hal\Application\Score\Scoring;


/**
Expand Down Expand Up @@ -63,9 +64,12 @@ public function terminate(ResultCollection $collection, ResultCollection $groupe

// score
$score = $collection->getScore();
foreach($score->all() as $name => $value) {
$output->writeln(sprintf('%s %s', str_pad($name, 30, '.'), $value.' / 50'));
}
// if($score) {
foreach ($score->all() as $name => $value) {
$output->writeln(sprintf('%s %s', str_pad($name, 30, '.'), $value . ' / ' . Scoring::MAX));
}
$output->writeln('');
// }

}

Expand Down
3 changes: 2 additions & 1 deletion src/Hal/Application/Formater/Summary/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ public function terminate(ResultCollection $collection, ResultCollection $groupe
$twig = new \Twig_Environment($loader, array('cache' => false));
$twig->addExtension(new FormatingExtension($this->validator));


$bound = $this->bound->calculate($collection);
return $twig->render('summary/report.html.twig', array(
'keys' => array_keys(current($collection->asArray()))
, 'results' => $collection->asArray()
, 'groupedResults' => $groupedResults
, 'root' => current(current($groupedResults))
, 'relations' => $this->prepareDataRelations($collection)
, 'scores' => $collection->getScore()->all()
, 'ruleSet' => $this->validator->getRuleSet()
, 'bounds' => $bound
, 'withOOP' => null !== $bound->getSum('instability')
Expand Down
35 changes: 21 additions & 14 deletions src/Hal/Application/Score/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,36 @@
*/
class Calculator {



/**
* @var int
*/
private $limit = Scoring::MAX;

/**
* @param $good
* @param $bad
* @param $note
* @return float
*/
public function highIsBetter($good, $bad, $note) {
// we don't want to attribute score of 0. We'll use 90% bad
$bad = $bad / 100 * 90;

$good = $good - $bad;
$note = $note - $bad;

$score = (1-( $good / ($note + $good) )) * 100;

$score = (($note - $bad) / ($good - $bad)) * $this->limit;
$score = max(0, $score);
$score = min (50, $score);
$score = min ($this->limit, $score);
return round($score, 2);
}

/**
* @param $good
* @param $bad
* @param $note
* @return float
*/
public function lowIsBetter($good, $bad, $note) {

$limit = 50;
// my formula isn't perfect. Do not hesitate to contribute
$score = 1000/($good/($good+($bad-$note))*100/$good*$bad)*$limit/10;
$score = $this->limit - ($note - $good) / ($bad - $good) * $this->limit;
$score = max(0, $score);
$score = min (50, $score);
$score = min ($this->limit, $score);
return round($score, 2);
}
}
2 changes: 1 addition & 1 deletion src/Hal/Application/Score/Factor/BugPreventingFactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(Calculator $calculator)
* @inheritdoc
*/
public function calculate(ResultCollection $collection, ResultCollection $groupedResults, ResultInterface $bound) {
return round($this->calculator->lowIsBetter(0.09, 0.46, $bound->getAverage('bugs')), 2);
return round($this->calculator->lowIsBetter(0.09, 0.70, $bound->getAverage('bugs')), 2);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Hal/Application/Score/Factor/ComplexityFactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public function __construct(Calculator $calculator)
* @inheritdoc
*/
public function calculate(ResultCollection $collection, ResultCollection $groupedResults, ResultInterface $bound) {
return round($this->calculator->lowIsBetter(1, 6, $bound->getAverage('cyclomaticComplexity')), 2);
return round($this->calculator->lowIsBetter(1, 8, $bound->getAverage('cyclomaticComplexity')), 2);
}

/**
* @inheritedDoc
*/
public function getName() {
return 'Complexity';
return 'Simplicity';
}
}
2 changes: 1 addition & 1 deletion src/Hal/Application/Score/Factor/MaintenabilityFactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(Calculator $calculator)
* @inheritdoc
*/
public function calculate(ResultCollection $collection, ResultCollection $groupedResults, ResultInterface $bound) {
return round($this->calculator->highIsBetter(105, 65, $bound->getAverage('maintenabilityIndex')), 2);
return round($this->calculator->highIsBetter(108, 60, $bound->getAverage('maintenabilityIndex')), 2);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Hal/Application/Score/Factor/ReadabilityFactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(Calculator $calculator)
public function calculate(ResultCollection $collection, ResultCollection $groupedResults, ResultInterface $bound) {
$notes = array(
$this->calculator->lowIsBetter(5.8, 18, $bound->getAverage('difficulty'))
, $this->calculator->highIsBetter(42, 35, $bound->getAverage('commentWeight'))
, $this->calculator->highIsBetter(42, 32, $bound->getAverage('commentWeight'))
);
return round(array_sum($notes) / count($notes, COUNT_NORMAL), 2);
}
Expand All @@ -52,6 +52,6 @@ public function calculate(ResultCollection $collection, ResultCollection $groupe
* @inheritedDoc
*/
public function getName() {
return 'Readability';
return 'Accessibility';
}
}
5 changes: 5 additions & 0 deletions src/Hal/Application/Score/Scoring.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
*/
class Scoring implements ScoringInterface{

/**
* Maximal score
*/
const MAX = 100;

/**
* Bounds
*
Expand Down
1 change: 1 addition & 0 deletions templates/html/assets/d3js-radar.css.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.radar-chart .level{stroke:grey;stroke-width:.5}.radar-chart .axis line{stroke:grey;stroke-width:1}.radar-chart .axis .legend{font-family:sans-serif;font-size:10px}.radar-chart .axis .legend.top{dy:1em}.radar-chart .axis .legend.left{text-anchor:start}.radar-chart .axis .legend.middle{text-anchor:middle}.radar-chart .axis .legend.right{text-anchor:end}.radar-chart .tooltip{font-family:sans-serif;font-size:13px;transition:opacity 200ms;opacity:0}.radar-chart .tooltip.visible{opacity:1}.radar-chart .area{stroke-width:2;fill-opacity:.5}.radar-chart.focus .area{fill-opacity:.1}.radar-chart.focus .area.focused{fill-opacity:.7}.radar-chart .circle{fill-opacity:.9}.radar-chart .area,.radar-chart .circle{transition:opacity 300ms,fill-opacity 200ms;opacity:1}.radar-chart .d3-enter,.radar-chart .d3-exit{opacity:0}
5 changes: 5 additions & 0 deletions templates/html/assets/d3js-radar.js.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% autoescape false %}
<script type="text/javascript">
var RadarChart={defaultConfig:{containerClass:"radar-chart",w:600,h:600,factor:.95,factorLegend:1,levels:3,levelTick:!1,TickLength:10,maxValue:0,radians:2*Math.PI,color:d3.scale.category10(),axisLine:!0,axisText:!0,circles:!0,radius:5,axisJoin:function(a,b){return a.className||b},transitionDuration:300},chart:function(){function b(b){b.each(function(b){function h(b,c,d,e){return d="undefined"!=typeof d?d:1,c*(1-d*e(b*a.radians/f))}function i(a,b,c){return h(a,b,c,Math.sin)}function j(a,b,c){return h(a,b,c,Math.cos)}var c=d3.select(this);b=b.map(function(a){return a instanceof Array&&(a={axes:a}),a});var d=Math.max(a.maxValue,d3.max(b,function(a){return d3.max(a.axes,function(a){return a.value})})),e=b[0].axes.map(function(a){return a.axis}),f=e.length,g=a.factor*Math.min(a.w/2,a.h/2);c.classed(a.containerClass,1);var k=d3.range(0,a.levels).map(function(b){return g*((b+1)/a.levels)}),l=c.selectAll("g.level-group").data(k);l.enter().append("g"),l.exit().remove(),l.attr("class",function(a,b){return"level-group level-group-"+b});var m=l.selectAll(".level").data(function(a){return d3.range(0,f).map(function(){return a})});if(m.enter().append("line"),m.exit().remove(),a.levelTick?m.attr("class","level").attr("x1",function(b,c){return g==b?i(c,b):i(c,b)+a.TickLength/2*Math.cos(c*a.radians/f)}).attr("y1",function(b,c){return g==b?j(c,b):j(c,b)-a.TickLength/2*Math.sin(c*a.radians/f)}).attr("x2",function(b,c){return g==b?i(c+1,b):i(c,b)-a.TickLength/2*Math.cos(c*a.radians/f)}).attr("y2",function(b,c){return g==b?j(c+1,b):j(c,b)+a.TickLength/2*Math.sin(c*a.radians/f)}).attr("transform",function(b){return"translate("+(a.w/2-b)+", "+(a.h/2-b)+")"}):m.attr("class","level").attr("x1",function(a,b){return i(b,a)}).attr("y1",function(a,b){return j(b,a)}).attr("x2",function(a,b){return i(b+1,a)}).attr("y2",function(a,b){return j(b+1,a)}).attr("transform",function(b){return"translate("+(a.w/2-b)+", "+(a.h/2-b)+")"}),a.axisLine||a.axisText){var n=c.selectAll(".axis").data(e),o=n.enter().append("g");a.axisLine&&o.append("line"),a.axisText&&o.append("text"),n.exit().remove(),n.attr("class","axis"),a.axisLine&&n.select("line").attr("x1",a.w/2).attr("y1",a.h/2).attr("x2",function(b,c){return i(c,a.w/2,a.factor)}).attr("y2",function(b,c){return j(c,a.h/2,a.factor)}),a.axisText&&n.select("text").attr("class",function(a,b){var c=i(b,.5);return"legend "+(.4>c?"left":c>.6?"right":"middle")}).attr("dy",function(a,b){var c=j(b,.5);return.1>c?"1em":c>.9?"0":"0.5em"}).text(function(a){return a}).attr("x",function(b,c){return i(c,a.w/2,a.factorLegend)}).attr("y",function(b,c){return j(c,a.h/2,a.factorLegend)})}b.forEach(function(b){b.axes.forEach(function(b,c){b.x=i(c,a.w/2,parseFloat(Math.max(b.value,0))/d*a.factor),b.y=j(c,a.h/2,parseFloat(Math.max(b.value,0))/d*a.factor)})});var p=c.selectAll(".area").data(b,a.axisJoin);if(p.enter().append("polygon").classed({area:1,"d3-enter":1}).on("mouseover",function(){c.classed("focus",1),d3.select(this).classed("focused",1)}).on("mouseout",function(){c.classed("focus",0),d3.select(this).classed("focused",0)}),p.exit().classed("d3-exit",1).transition().duration(a.transitionDuration).remove(),p.each(function(a,b){var c={"d3-exit":0};c["radar-chart-serie"+b]=1,a.className&&(c[a.className]=1),d3.select(this).classed(c)}).style("stroke",function(b,c){return a.color(c)}).style("fill",function(b,c){return a.color(c)}).transition().duration(a.transitionDuration).attr("points",function(a){return a.axes.map(function(a){return[a.x,a.y].join(",")}).join(" ")}).each("start",function(){d3.select(this).classed("d3-enter",0)}),a.circles&&a.radius){var q=c.selectAll(".tooltip").data([1]);q.enter().append("text").attr("class","tooltip");var r=c.selectAll("g.circle-group").data(b,a.axisJoin);r.enter().append("g").classed({"circle-group":1,"d3-enter":1}),r.exit().classed("d3-exit",1).transition().duration(a.transitionDuration).remove(),r.each(function(a){var b={"d3-exit":0};a.className&&(b[a.className]=1),d3.select(this).classed(b)}).transition().duration(a.transitionDuration).each("start",function(){d3.select(this).classed("d3-enter",0)});var s=r.selectAll(".circle").data(function(a,b){return a.axes.map(function(a){return[a,b]})});s.enter().append("circle").classed({circle:1,"d3-enter":1}).on("mouseover",function(a){q.attr("x",a[0].x-10).attr("y",a[0].y-5).text(a[0].value).classed("visible",1),c.classed("focus",1),c.select(".area.radar-chart-serie"+a[1]).classed("focused",1)}).on("mouseout",function(a){q.classed("visible",0),c.classed("focus",0),c.select(".area.radar-chart-serie"+a[1]).classed("focused",0)}),s.exit().classed("d3-exit",1).transition().duration(a.transitionDuration).remove(),s.each(function(a){var b={"d3-exit":0};b["radar-chart-serie"+a[1]]=1,d3.select(this).classed(b)}).style("fill",function(b){return a.color(b[1])}).transition().duration(a.transitionDuration).attr("r",a.radius).attr("cx",function(a){return a[0].x}).attr("cy",function(a){return a[0].y}).each("start",function(){d3.select(this).classed("d3-enter",0)});var t=q.node();t.parentNode.appendChild(t)}})}var a=Object.create(RadarChart.defaultConfig);return b.config=function(c){return arguments.length?(arguments.length>1?a[arguments[0]]=arguments[1]:d3.entries(c||{}).forEach(function(b){a[b.key]=b.value}),b):a},b},draw:function(a,b,c){var d=RadarChart.chart().config(c),e=d.config();d3.select(a).select("svg").remove(),d3.select(a).append("svg").attr("width",e.w).attr("height",e.h).datum(b).call(d)}};
</script>
{% endautoescape %}
8 changes: 8 additions & 0 deletions templates/html/assets/functions.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@
}
e.className = 'active';
// update charts
updateTableView();
updateCustomChart();
updateAbstractnessChart();
updateMaintenablityChart();
updateRelationsChart();
updateScoreChart();
}
function zoom(id, callback) {
Expand Down
13 changes: 13 additions & 0 deletions templates/html/assets/styles.css.twig
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ body {
clear:left;
}

.col-6 {
float:left;
width:48%;
margin-right:2%;
}
.col-3:last-child {
margin-right: 0;
}
.col-3:last-child:after {
content:" ";
clear:left;
}

.accessibility-box {
float:right;
width: 200px;
Expand Down
27 changes: 27 additions & 0 deletions templates/html/summary/report-score.js.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% autoescape false %}
<script type="text/javascript">
function updateScoreChart() {
var score = [
{
className: 'score',
axes: [
{% for name,value in scores %}
{axis: "{{ name }}", value: {{ value |round }} },
{% endfor %}
]
}
];
var chart = RadarChart.chart();
chart.config({maxValue: 100})
var svg = d3.select('#chart-score').append('svg')
.attr('width', 500)
.attr('height', 500);
// darw one
svg.append('g').classed('focus', 1).datum(score).call(chart);
}
</script>
{% endautoescape %}
5 changes: 3 additions & 2 deletions templates/html/summary/report-tabular.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@
getCol('EC' , 'efferentCoupling' , 'average' , 'Efferent coupling'),
getCol('AC' , 'afferentCoupling' , 'average' , 'Afferent coupling'),
getCol('noc' , 'noc' , 'sum' , 'Number of classes' , false),
getCol('noca' , 'noca' , 'sum' , 'Numner of abstract classes' , false),
getCol('nocc' , 'nocc' , 'sum' , 'Number of concrete classes' , false)
getCol('noca' , 'noca' , 'sum' , 'Numner of abstract classes and interfaces' , false),
getCol('nocc' , 'nocc' , 'sum' , 'Number of concrete classes' , false),
getCol('noi' , 'noi' , 'sum' , 'Number of interfaces' , false)
]);
Expand Down
Loading

0 comments on commit 266d75b

Please sign in to comment.