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, string tag, Element root, const(Mutation.Kind)[] kinds) @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("Skipped", s.skipped), tuple("Equivalent", s.equivalent), 59 tuple("Worklist", cast(long) s.worklist), 60 ]) { 61 tbl.appendRow(d[0], d[1]); 62 } 63 64 base.addChild("p").appendHtml( 65 "<i>worklist</i> is the number of mutants that are in the queue to be tested/retested."); 66 67 if (s.aliveNoMut != 0) { 68 tbl.appendRow("NoMut", s.aliveNoMut.to!string); 69 tbl.appendRow("NoMut/total", format("%.3s", s.suppressedOfTotal)); 70 71 auto p = base.addChild("p", "NoMut is the number of mutants that are alive but ignored."); 72 p.appendHtml(" They are <i>suppressed</i>."); 73 p.appendText(" This result in those mutants increasing the mutation score."); 74 p.appendText(" The suppressed/total is how much it has increased."); 75 p.appendHtml(" You <b>should</b> react if it is high."); 76 } 77 } 78 79 void syncStatus(SyncStatus status, Element root) { 80 auto ts = TimeScalePointGraph("SyncStatus"); 81 82 ts.put("Test", TimeScalePointGraph.Point(status.test, 1.6)); 83 ts.setColor("Test", "lightBlue"); 84 85 ts.put("Code", TimeScalePointGraph.Point(status.code, 1.4)); 86 ts.setColor("Code", "lightGreen"); 87 88 ts.put("Coverage", TimeScalePointGraph.Point(status.coverage, 1.2)); 89 ts.setColor("Coverage", "purple"); 90 91 if (status.mutants.length != 0) { 92 double y = 0.8; 93 foreach (v; status.mutants) { 94 ts.put("Mutant", TimeScalePointGraph.Point(v.updated, y)); 95 y += 0.3 / status.mutants.length; 96 } 97 ts.setColor("Mutant", "red"); 98 } 99 ts.html(root, TimeScalePointGraph.Width(50)); 100 101 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"); 102 }