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.trend; 11 12 import logger = std.experimental.logger; 13 import std.format : format; 14 15 import arsd.dom : Element, Link; 16 17 import dextool.plugin.mutate.backend.database : Database; 18 import dextool.plugin.mutate.backend.report.analyzers : reportTrendByCodeChange, 19 reportMutationScoreHistory, MutationScoreHistory; 20 import dextool.plugin.mutate.backend.report.html.constants; 21 import dextool.plugin.mutate.backend.type : Mutation; 22 23 void makeTrend(ref Database db, string tag, Element root, const(Mutation.Kind)[] kinds) @trusted { 24 import std.datetime : SysTime; 25 import dextool.plugin.mutate.backend.report.html.tmpl : TimeScalePointGraph; 26 27 DashboardCss.h2(root.addChild(new Link(tag, null)).setAttribute("id", tag[1 .. $]), "Trend"); 28 29 auto base = root.addChild("div"); 30 31 auto ts = TimeScalePointGraph("ScoreHistory"); 32 33 const history = reportMutationScoreHistory(db).rollingAvg; 34 if (history.data.length > 2 && history.estimate.x != SysTime.init) { 35 foreach (v; history.data) { 36 ts.put("Score", TimeScalePointGraph.Point(v.timeStamp, v.score.get)); 37 } 38 ts.setColor("Score", "blue"); 39 40 ts.put("Trend", TimeScalePointGraph.Point(history.estimate.x, history.estimate.avg)); 41 ts.put("Trend", TimeScalePointGraph.Point(history.data[$ - 1].timeStamp, 42 history.data[$ - 1].score.get)); 43 ts.put("Trend", TimeScalePointGraph.Point(history.estimate.predX, 44 history.estimate.predScore)); 45 ts.setColor("Trend", () { 46 final switch (history.estimate.trend) with (MutationScoreHistory.Trend) { 47 case undecided: 48 return "grey"; 49 case negative: 50 return "red"; 51 case positive: 52 return "green"; 53 } 54 }()); 55 56 ts.html(base, TimeScalePointGraph.Width(80)); 57 base.addChild("p") 58 .appendHtml( 59 "<i>trend</i> is a prediction of how the mutation score will change based on previous scores."); 60 } 61 62 const codeChange = reportTrendByCodeChange(db, kinds); 63 if (codeChange.sample.length > 2) { 64 ts = TimeScalePointGraph("ScoreByCodeChange"); 65 foreach (v; codeChange.sample) { 66 ts.put("Score", TimeScalePointGraph.Point(v.timeStamp, v.value.get)); 67 } 68 ts.setColor("Score", "purple"); 69 ts.html(base, TimeScalePointGraph.Width(80)); 70 base.addChild("p").appendHtml( 71 "<i>code change</i> is a prediction of how the mutation score will change based on the latest code changes."); 72 } 73 }