-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change StoreHelper utility class to a Reporter to coordinate the diff…
…erent artifacts that are generated. Add an HTML report visualizing the exported csv data
- Loading branch information
Showing
7 changed files
with
212 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package reporter | ||
|
||
import commands.calculateTechnicalLag.visualization.Visualizer | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import kotlinx.serialization.json.Json | ||
import org.jetbrains.kotlinx.dataframe.DataFrame | ||
import org.jetbrains.kotlinx.dataframe.io.writeCSV | ||
import shared.analyzerResultDtos.AnalyzerResultDto | ||
import shared.project.ProjectPaths | ||
import java.io.File | ||
import java.nio.file.Path | ||
import java.util.* | ||
|
||
|
||
class Reporter(outputPath: Path) { | ||
|
||
private val json = Json { prettyPrint = true } | ||
private val outputFile = outputPath.toAbsolutePath().toFile() | ||
|
||
private val analyzerResultFile by lazy { | ||
createFileInOutputPath("${Date().time}-analyzerResult.json") | ||
} | ||
private val htmlReportFile by lazy { | ||
createFileInOutputPath("htmlReport.html") | ||
} | ||
private val csvFileName = "csvReport.csv" | ||
private val csvReportFile by lazy { | ||
outputPath.resolve(csvFileName) | ||
} | ||
|
||
private fun createFileInOutputPath(fileName: String): File { | ||
val file = outputFile.resolve(fileName) | ||
file.createNewFile() | ||
return file | ||
} | ||
|
||
fun storeAnalyzerResultInFile( | ||
result: AnalyzerResultDto, | ||
) { | ||
val jsonString = | ||
json.encodeToString(AnalyzerResultDto.serializer(), result) | ||
analyzerResultFile.writeText(jsonString) | ||
} | ||
|
||
fun storeCsvExport(df: DataFrame<Visualizer.TechnicalLagExport>) { | ||
df.writeCSV(csvReportFile.toString()) | ||
} | ||
|
||
fun generateHtmlReport( | ||
) { | ||
val resource = | ||
this.javaClass.classLoader.getResource("html-report-template.html") ?: return | ||
|
||
val htmlReportTemplate = resource.readText(Charsets.UTF_8) | ||
val htmlReport = htmlReportTemplate.replace("{{ PATH_TO_STATISTICS }}", "\"$csvFileName\"") | ||
|
||
htmlReportFile.writeText(htmlReport, Charsets.UTF_8) | ||
} | ||
|
||
suspend fun storeResultFilePathsInFile( | ||
outputDirectory: File, | ||
paths: ProjectPaths, | ||
dispatcher: CoroutineDispatcher = Dispatchers.IO | ||
): File { | ||
val outputFile = outputDirectory.resolve("dependencyGraphs.json") | ||
return withContext(dispatcher) { | ||
outputFile.createNewFile() | ||
val jsonString = | ||
json.encodeToString(ProjectPaths.serializer(), paths) | ||
outputFile.writeText(jsonString) | ||
return@withContext outputFile | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<head> | ||
<!-- Load plotly.js into the DOM --> | ||
<script src='https://cdn.plot.ly/plotly-2.32.0.min.js'></script> | ||
<script src='https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js'></script> | ||
</head> | ||
|
||
<body> | ||
<div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div> | ||
</body> | ||
|
||
<script> | ||
|
||
d3.csv( | ||
{{ PATH_TO_STATISTICS }}, | ||
function (rows) { | ||
function unpack(rows, key) { | ||
return rows.map(function (row) { | ||
return row[key]; | ||
}); | ||
} | ||
|
||
var directDeps = rows.filter((row) => { | ||
return row["scope"] == "dependencies-direct"; | ||
}); | ||
|
||
var traceDirectDeps = { | ||
meanline: { | ||
visible: true, | ||
}, | ||
legendgroup: "dependencies-direct", | ||
scalegroup: "dependencies-direct", | ||
points: "all", | ||
pointpos: -1.2, | ||
box: { | ||
visible: true, | ||
}, | ||
jitter: 0, | ||
scalemode: "count", | ||
marker: { | ||
line: { | ||
width: 2, | ||
color: "green", | ||
}, | ||
symbol: "line-ns", | ||
}, | ||
showlegend: true, | ||
side: "negative", | ||
type: "violin", | ||
name: "dependencies-direct", | ||
line: { | ||
color: "green", | ||
}, | ||
x0: "dependencies-direct-transitive", | ||
y: unpack(directDeps, "libdays"), | ||
}; | ||
|
||
var transDeps = rows.filter((row) => { | ||
return row["scope"] == "dependencies-transitive"; | ||
}); | ||
|
||
var traceTransDeps = { | ||
meanline: { | ||
visible: true, | ||
}, | ||
legendgroup: "dependencies-transitive", | ||
scalegroup: "dependencies-transitive", | ||
points: "all", | ||
pointpos: 1.2, | ||
box: { | ||
visible: true, | ||
}, | ||
jitter: 0, | ||
scalemode: "count", | ||
marker: { | ||
line: { | ||
width: 2, | ||
color: 'red', | ||
}, | ||
symbol: "line-ns", | ||
}, | ||
showlegend: true, | ||
side: "positive", | ||
type: "violin", | ||
name: "dependencies-transitive", | ||
line: { | ||
color: "red", | ||
}, | ||
x0: "dependencies-direct-transitive", | ||
y: unpack(transDeps, "libdays"), | ||
}; | ||
|
||
console.log(directDeps); | ||
console.log(transDeps); | ||
console.log(rows); | ||
var data = [traceDirectDeps, traceTransDeps] | ||
|
||
var layout = { | ||
hovermode: "closest", | ||
yaxis: { | ||
showgrid: true, | ||
}, | ||
title: "Dependency Libyears", | ||
legend: { | ||
tracegroupgap: 0, | ||
}, | ||
violingap: 0, | ||
violingroupgap: 0, | ||
violinmode: "overlay", | ||
}; | ||
|
||
Plotly.newPlot("myDiv", data, layout); | ||
} | ||
); | ||
|
||
</script> |