1 /** 2 Copyright: Copyright (c) 2020, Joakim Brännström. All rights reserved. 3 License: MPL-2 4 Author: Joakim Brännström (joakim.brannstrom@gmx.com) 5 6 This Source Code Form is subject to the terms of the Mozilla Public License, 7 v.2.0. If a copy of the MPL was not distributed with this file, You can obtain 8 one at http://mozilla.org/MPL/2.0/. 9 */ 10 module dextool.plugin.mutate.backend.report.html.page_stats; 11 12 import logger = std.experimental.logger; 13 import std.datetime : Clock, dur; 14 import std.format : format; 15 16 import arsd.dom : Element, Link; 17 18 import dextool.plugin.mutate.backend.database : Database; 19 import dextool.plugin.mutate.backend.report.analyzers : MutationStat, 20 reportStatistics, reportSyncStatus, SyncStatus; 21 import dextool.plugin.mutate.backend.report.html.constants; 22 import dextool.plugin.mutate.backend.report.html.tmpl : tmplDefaultTable, 23 PieGraph, TimeScalePointGraph; 24 import dextool.plugin.mutate.backend.type : Mutation; 25 26 void makeStats(ref Database db, const(Mutation.Kind)[] kinds, string tag, Element root) @trusted { 27 DashboardCss.h2(root.addChild(new Link(tag, null)).setAttribute("id", tag[1 .. $]), "Overview"); 28 overallStat(reportStatistics(db, kinds), root.addChild("div")); 29 syncStatus(reportSyncStatus(db, kinds, 100), root); 30 } 31 32 private: 33 34 // TODO: this function contains duplicated logic from the one in ../utility.d 35 void overallStat(const MutationStat s, Element base) { 36 import std.conv : to; 37 import std.typecons : tuple; 38 39 base.addChild("p").appendHtml(format("Mutation Score <b>%.3s</b>", s.score)); 40 base.addChild("p", format("Time spent: %s", s.totalTime)); 41 42 if (s.untested > 0 && s.predictedDone > 0.dur!"msecs") { 43 const pred = Clock.currTime + s.predictedDone; 44 base.addChild("p", format("Remaining: %s (%s)", s.predictedDone, pred.toISOExtString)); 45 } 46 47 PieGraph("score", [ 48 PieGraph.Item("alive", "red", s.alive), 49 PieGraph.Item("killed", "green", s.killed), 50 PieGraph.Item("Untested", "grey", s.untested), 51 PieGraph.Item("Timeout", "lightgreen", s.timeout) 52 ]).html(base, PieGraph.Width(50)); 53 54 auto tbl = tmplDefaultTable(base, ["Type", "Value"]); 55 foreach (const d; [ 56 tuple("Total", s.total), 57 tuple("Killed by compiler", cast(long) s.killedByCompiler), 58 tuple("Worklist", cast(long) s.worklist), 59 ]) { 60 tbl.appendRow(d[0], d[1]); 61 } 62 63 base.addChild("p").appendHtml( 64 "<i>worklist</i> is the number of mutants that are in the queue to be tested/retested."); 65 66 if (s.aliveNoMut != 0) { 67 tbl.appendRow("NoMut", s.aliveNoMut.to!string); 68 tbl.appendRow("NoMut/total", format("%.3s", s.suppressedOfTotal)); 69 70 auto p = base.addChild("p", "NoMut is the number of mutants that are alive but ignored."); 71 p.appendHtml(" They are <i>suppressed</i>."); 72 p.appendText(" This result in those mutants increasing the mutation score."); 73 p.appendText(" The suppressed/total is how much it has increased."); 74 p.appendHtml(" You <b>should</b> react if it is high."); 75 } 76 } 77 78 void syncStatus(SyncStatus status, Element root) { 79 auto ts = TimeScalePointGraph("SyncStatus"); 80 81 ts.put("Test", TimeScalePointGraph.Point(status.test, 1.6)); 82 ts.setColor("Test", "lightBlue"); 83 84 ts.put("Code", TimeScalePointGraph.Point(status.code, 1.4)); 85 ts.setColor("Code", "lightGreen"); 86 87 ts.put("Coverage", TimeScalePointGraph.Point(status.coverage, 1.2)); 88 ts.setColor("Coverage", "purple"); 89 90 if (status.mutants.length != 0) { 91 double y = 0.8; 92 foreach (v; status.mutants) { 93 ts.put("Mutant", TimeScalePointGraph.Point(v.updated, y)); 94 y += 0.3 / status.mutants.length; 95 } 96 ts.setColor("Mutant", "red"); 97 } 98 ts.html(root, TimeScalePointGraph.Width(50)); 99 100 root.addChild("p").appendHtml("<i>sync status</i> is how old the information about mutants and their status is compared to when the tests or source code where last changed"); 101 }