Skip to content

Commit

Permalink
Introduced Line Plot Multi for Evaluation Comparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrikBuetler committed Sep 10, 2024
1 parent 50d5e33 commit 799c47f
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
29 changes: 29 additions & 0 deletions libraries/graphs/line-plot-multi-eval/build.template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div class="box box-default" id="[[id]]">
<div class="box-header with-border">
<h3 class="box-title">Line Plot For Evaluations (multiple parameters)</h3>
</div>
<div class="box-body">
<div class="form-group">
<label>Title</label>
<input name="name" type="text" class="form-control" placeholder="Line Plot Title" value="[[name]]">
<input type="hidden" name="type" value="line-plot-multi">
<label>Configuration parameter(s) to iterate over (Comma separated)</label>
<input name="parameter" type="text" class="form-control" placeholder="Configuration Parameter(s)" value="{{IF [[parameter]] != false}}[[parameter]]{{ENDIF}}">
<label>Parameter to plot</label>
<input name="plotting" type="text" class="form-control" placeholder="Parameter to plot" value="{{IF [[plotting]] != false}}[[plotting]]{{ENDIF}}">
</div>
</div>
<div class="box-footer">
Apply aggregation function:
<br>
<input type="radio" id="agg_avg[[id]]" value="avg" name="aggregate[[id]]" checked> Average
<br>
<input type="radio" id="agg_min[[id]]" value="min" name="aggregate[[id]]" {{IF [[aggregate]] == "min"}}checked{{ENDIF}}> Minimum
<br>
<input type="radio" id="agg_max[[id]]" value="max" name="aggregate[[id]]" {{IF [[aggregate]] == "max"}}checked{{ENDIF}}> Maximum
<br>
<input type="radio" id="agg_sum[[id]]" value="sum" name="aggregate[[id]]" {{IF [[aggregate]] == "sum"}}checked{{ENDIF}}> Sum
<hr>
<button type="button" class="btn btn-danger" onclick="deletePlot('[[id]]')">Delete</button>
</div>
</div>
5 changes: 5 additions & 0 deletions libraries/graphs/line-plot-multi-eval/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Line Plot For Evaluations(multiple parameters)",
"type": "line-plot-multi-eval",
"required": "chartjs"
}
81 changes: 81 additions & 0 deletions libraries/graphs/line-plot-multi-eval/process.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/**
* Given values:
* - $data: containing the full data of the results
* - $parameter(s): containing the name(s)/basename(s) of the parameter which this plot should parse
* - $plotData: put here the values which later will be passed to the plot
*/

use DBA\Job;

/** @var $jobs Job[][] */
/** @var $parameter string|string[] */
/** @var $plotData string */
/** @var $allData array */ //these are all the values which are posted by this plot

$dataArray = ['datasets' => []];
$colors = ['#00c0ef', '#3c8dbc', '#f56954'];

$parameterData = [];
$labels = [];

if (!is_array($parameter)) {
$parameter = explode(",", $parameter);
}

// put together jobs
$arr = Util::mergeJobs($jobs, $parameter);
$jobGroups = $arr[0];
$internLabels = $arr[1];

$colorIndex = 0;
for ($i = 0; $i < sizeof($jobGroups[0]); $i++) {
$parameterData[$i]['label'] = $internLabels[$i];
$parameterData[$i]['backgroundColor'] = $colors[$colorIndex % sizeof($colors)];
$parameterData[$i]['borderColor'] = $colors[$colorIndex % sizeof($colors)];
$parameterData[$i]['fill'] = false;
$colorIndex++;
}

$arr = Util::getDifferentParameters($jobs);
$changingParameters = $arr[0];
$jobParameters = $arr[1];

foreach ($jobGroups as $jobGroup) {
/** @var $jobGroup Job[][] */
$jobIds = [];
$index = 0;
foreach ($jobGroup as $j) {
$sum = 0;
foreach ($j as $job) {
$results = json_decode($job->getResult(), true);
foreach ($parameter as $p) {
if (isset($results[$allData['plotting']])) {
$sum += floatval($results[$allData['plotting']]);
}
}
}
$parameterData[$index]['data'][] = $sum / sizeof($j);
$jobIds[] = $j[0]->getInternalId();
$index++;
}
$label = [];
foreach ($changingParameters as $changingParameter) {
if (in_array($changingParameter, $parameter)) {
continue;
} else if ($changingParameter == 'run') {
continue;
}
$label[] = $changingParameter . ": " . $jobParameters[$jobGroup[0][0]->getId()][$changingParameter];
}

$labels[] = "Jobs[" . implode(", ", $label) . "]";
}

foreach ($parameterData as $pData) {
$dataArray['datasets'][] = $pData;
$dataArray['labels'] = $labels;
}

$plotData = json_encode($dataArray);
33 changes: 33 additions & 0 deletions libraries/graphs/line-plot-multi-eval/render.template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div class="chart">
<canvas id="[[plotId]]" style="height:230px"></canvas>
</div>

<script type="text/javascript">
var config[[plotId]] = {
type: "line",
data: [[plotData]],
options: {
responsive: true,
title: {
display: false
},
tooltips: {
mode: 'index',
intersect: false,
},
hover: {
mode: 'nearest',
intersect: true
}
}
};

chart[[plotId]] = undefined;

function plot[[plotId]](){
chart[[plotId]] = new Chart($('#[[plotId]]').get(0).getContext('2d'), config[[plotId]]);
}


</script>

0 comments on commit 799c47f

Please sign in to comment.