1 /**
2 Copyright: Copyright (c) 2018, 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_long_term_view;
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 : MutantSample, reportSelectedAliveMutants;
19 import dextool.plugin.mutate.backend.report.html.constants;
20 import dextool.plugin.mutate.backend.report.html.js;
21 import dextool.plugin.mutate.backend.report.html.tmpl : tmplBasicPage, tmplDefaultTable;
22 import dextool.plugin.mutate.backend.type : Mutation;
23 import dextool.plugin.mutate.config : ConfigReport;
24 import dextool.plugin.mutate.type : MutationKind;
25 import dextool.type : AbsolutePath;
26 
27 auto makeLongTermView(ref Database db, ref const ConfigReport conf,
28         const(MutationKind)[] humanReadableKinds, const(Mutation.Kind)[] kinds) @trusted {
29     import std.datetime : Clock;
30 
31     auto doc = tmplBasicPage;
32     auto s = doc.root.childElements("head")[0].addChild("script");
33     s.addChild(new RawSource(doc, js_index));
34     doc.mainBody.setAttribute("onload", "init()");
35     doc.title(format("Long Term View %(%s %) %s", humanReadableKinds, Clock.currTime));
36 
37     toHtml(reportSelectedAliveMutants(db, kinds, 10), doc.mainBody);
38 
39     return doc.toPrettyString;
40 }
41 
42 private:
43 
44 void toHtml(const MutantSample mut_sample, Element root) {
45     import std.path : buildPath;
46     import dextool.plugin.mutate.backend.report.html.page_files : pathToHtmlLink;
47 
48     root.addChild("h2", "High Interest Mutants");
49 
50     if (mut_sample.hardestToKill.length != 0) {
51         root.addChild("h3", "Longest surviving Mutants");
52         root.addChild("p", "These mutants survived countless test runs.");
53         auto tbl_container = root.addChild("div").addClass("tbl_container");
54         auto tbl = tmplDefaultTable(tbl_container, [
55                 "Link", "Discovered", "Last Updated", "Survived"
56                 ]);
57 
58         foreach (const mutst; mut_sample.hardestToKill) {
59             const mut = mut_sample.mutants[mutst.statusId];
60             auto r = tbl.appendRow();
61             r.addChild("td").addChild("a", format("%s:%s", mut.file,
62                     mut.sloc.line)).href = format("%s#%s", buildPath(htmlFileDir,
63                     pathToHtmlLink(mut.file)), mut.id);
64             r.addChild("td", mutst.added.isNull ? "unknown" : mutst.added.get.toString);
65             r.addChild("td", mutst.updated.toString);
66             r.addChild("td", format("%s times", mutst.testCnt));
67         }
68     }
69 
70     if (mut_sample.oldest.length != 0) {
71         root.addChild("p", format("This is a list of the %s oldest mutants. This list contains information when they where last tested and had their status updated.",
72                 mut_sample.oldest.length));
73 
74         auto tbl_container = root.addChild("div").addClass("tbl_container");
75         auto tbl = tmplDefaultTable(tbl_container, ["Link", "Updated"]);
76 
77         foreach (const mutst; mut_sample.oldest) {
78             auto mut = mut_sample.mutants[mutst.id];
79             auto r = tbl.appendRow();
80             r.addChild("td").addChild("a", format("%s:%s", mut.file,
81                     mut.sloc.line)).href = format("%s#%s", buildPath(htmlFileDir,
82                     pathToHtmlLink(mut.file)), mut.id);
83             r.addChild("td", mutst.updated.toString);
84         }
85     }
86 }