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_test_case_stat;
11 
12 import logger = std.experimental.logger;
13 import std.format : format;
14 
15 import arsd.dom : Document, Element, require, Table, RawSource;
16 
17 import dextool.plugin.mutate.backend.database : Database;
18 import dextool.plugin.mutate.backend.report.analyzers : reportTestCaseStats, TestCaseStat;
19 import dextool.plugin.mutate.backend.report.html.constants;
20 import dextool.plugin.mutate.backend.resource;
21 import dextool.plugin.mutate.backend.report.html.tmpl : tmplBasicPage,
22     tmplDefaultTable, dashboardCss;
23 import dextool.plugin.mutate.backend.type : Mutation;
24 import dextool.plugin.mutate.config : ConfigReport;
25 import dextool.plugin.mutate.type : MutationKind;
26 import dextool.type : AbsolutePath;
27 
28 auto makeTestCaseStats(ref Database db, ref const ConfigReport conf,
29         const(MutationKind)[] humanReadableKinds, const(Mutation.Kind)[] kinds) @trusted {
30     import std.datetime : Clock;
31 
32     auto doc = tmplBasicPage.dashboardCss;
33     auto s = doc.root.childElements("head")[0].addChild("script");
34     s.addChild(new RawSource(doc, jsIndex));
35     doc.mainBody.setAttribute("onload", "init()");
36     doc.title(format("Test Case Statistics %(%s %) %s", humanReadableKinds, Clock.currTime));
37 
38     toHtml(reportTestCaseStats(db, kinds), doc.mainBody);
39 
40     return doc.toPrettyString;
41 }
42 
43 private:
44 
45 void toHtml(TestCaseStat stat, Element root) {
46     import std.conv : to;
47     import std.format : format;
48 
49     root.addChild("h2", "Test Case Statistics");
50     root.addChild("p", "The test cases sorted by how many mutants they have killed. It can be used to e.g. find too sensitive test cases or those that are particularly ineffective (kills few mutants).");
51 
52     auto tbl_container = root.addChild("div").addClass("tbl_container");
53     auto tbl = tmplDefaultTable(tbl_container, ["Ratio", "Kills", "Name"]);
54 
55     foreach (const v; stat.toSortedRange) {
56         auto r = tbl.appendRow();
57         r.addChild("td", format!"%.2f"(v.ratio));
58         r.addChild("td", v.info.killedMutants.to!string);
59         r.addChild("td", v.tc.name);
60     }
61 }