Reworked how test results get submitted

This commit is contained in:
Gregory Ballantine 2024-06-03 10:36:18 -04:00
parent de8e523c2c
commit 05b1374d1d
8 changed files with 56 additions and 123 deletions

View File

@ -11,24 +11,6 @@ use BitGoblin\Colossus\Models\Test;
class ResultController extends Controller {
public function getList(Request $request, Response $response): Response {
$results = Result::orderByDesc('updated_at')->get();
$view = Twig::fromRequest($request);
return $view->render($response, 'result/list.twig', [
'results' => $results,
]);
}
public function getAdd(Request $request, Response $response): Response {
$tests = Test::all();
$view = Twig::fromRequest($request);
return $view->render($response, 'result/add.twig', [
'tests' => $tests,
]);
}
public function postAdd(Request $request, Response $response): Response {
$params = (array)$request->getParsedBody();
@ -36,10 +18,9 @@ class ResultController extends Controller {
$result->test_id = $params['result_test'];
$result->component = $params['result_component'];
$result->benchmark = $params['result_benchmark'];
$result->type = $params['result_type'];
$result->average = $params['result_avg'];
$result->minimum = $params['result_min'];
$result->maximum = $params['result_max'];
$result->minimum = $params['result_min'] ?? null;
$result->maximum = $params['result_max'] ?? null;
$result->save();

View File

@ -16,4 +16,8 @@ class Benchmark extends Model {
return $this->belongsToMany(Test::class);
}
public function results() {
return $this->hasMany(Result::class):
}
}

View File

@ -15,4 +15,8 @@ class Component extends Model {
return $this->hasMany(Test::class);
}
public function results() {
return $this->hasMany(Result::class):
}
}

View File

@ -17,4 +17,12 @@ class Result extends Model {
return $this->belongsTo(Test::class);
}
public function component() {
return $this->belongsTo(Component::class):
}
public function benchmark() {
return $this->belongsTo(Benchmark::class);
}
}

View File

@ -28,7 +28,5 @@ $app->group('/test', function(RouteCollectorProxy $group) {
});
$app->group('/result', function(RouteCollectorProxy $group) {
$group->get('', '\\BitGoblin\\Colossus\\Controllers\\ResultController:getList')->setName('result.list');
$group->get('/add', '\\BitGoblin\\Colossus\\Controllers\\ResultController:getAdd')->setName('result.add');
$group->post('/add', '\\BitGoblin\\Colossus\\Controllers\\ResultController:postAdd');
$group->post('/add', '\\BitGoblin\\Colossus\\Controllers\\ResultController:postAdd')->setName('result.add');
});

View File

@ -1,62 +0,0 @@
{% extends 'layout.twig' %}
{% block title %}Add Benchmark Result{% endblock %}
{% block content %}
<div class="row">
<div class="twelve columns">
<h1>Add new benchmark result</h1>
</div>
</div>
<div class="row">
<div class="twelve columns">
<form action="{{ url_for('result.add') }}" method="POST" class="u-full-width">
<div class="row">
<div class="four columns">
<label for="result_test">Associated test:</label>
<select name="result_test" id="result_test" class="u-full-width">
{% for t in tests %}
<option value="{{ t.id }}">{{ t.name }}</option>
{% endfor %}
</select>
</div>
<div class="four columns">
<label for="result_component">Hardware name:</label>
<input type="text" id="result_component" class="u-full-width" name="result_component">
</div>
<div class="four columns">
<label for="result_benchmark">Benchmark used:</label>
<input type="text" id="result_benchmark" class="u-full-width" name="result_benchmark">
</div>
</div>
<div class="row">
<div class="six columns">
<label for="result_type">Score type:</label>
<select id="result_type" class="u-full-width" name="result_type">
<option value="fps">Frames per second</option>
<option value="points">Point value</option>
</select>
</div>
<div class="two columns">
<label for="result_avg">Average:</label>
<input type="number" id="result_avg" class="u-full-width" name="result_avg">
</div>
<div class="two columns">
<label for="result_min">Minimum:</label>
<input type="number" id="result_min" class="u-full-width" name="result_min">
</div>
<div class="two columns">
<label for="result_max">Maximum:</label>
<input type="number" id="result_max" class="u-full-width" name="result_max">
</div>
</div>
<input class="button button-primary u-full-width" type="submit" value="Submit">
</form>
</div>
</div>
{% endblock %}

View File

@ -1,34 +0,0 @@
{% extends 'layout.twig' %}
{% block title %}List of Results{% endblock %}
{% block content %}
<p>Results list...</p>
<table class="u-full-width">
<thead>
<tr>
<th>Hardware name</th>
<th>Benchmark</th>
<th>Result type</th>
<th>Avg.</th>
<th>Min.</th>
<th>Max.</th>
<th>Last updated</th>
</tr>
</thead>
<tbody>
{% for r in results %}
<tr>
<td>{{ r.component }}</td>
<td>{{ r.benchmark }}</td>
<td>{{ r.type | capitalize }}</td>
<td>{{ r.average }}</td>
<td>{{ r.minimum ? r.minimum : 'N/a' }}</td>
<td>{{ r.maximum ? r.maximum : 'N/a' }}</td>
<td>{{ r.updated_at | date("F jS \\a\\t g:ia") }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@ -17,10 +17,44 @@
<hr>
<div class="row">
<div class="twelve columns">
<form id="result-form" class="u-full-width" action="{{ url_for('result.add') }}" method="POST">
<div class="row">
<div class="four columns">
<select name="result_benchmark">
{% for b in test.benchmarks() %}
<option value="{{ b.id }}">{{ b.name }}</option>
{% endfor %}
</select>
</div>
<div class="two columns">
<input type="number" step="0.01" name="result_avg" placeholder="0.0">
</div>
<div class="two columns">
<input type="number" step="0.01" name="result_min" placeholder="0.0">
</div>
<div class="two columns">
<input type="number" step="0.01" name="result_max" placeholder="0.0">
</div>
<div class="two columns">
<button class="button-primary" type="submit" name="button">Submit</button>
</div>
</div>
<input type="hidden" name="result_test" value="{{ test.id }}">
<input type="hidden" name="result_component" value="{{ test.component().id }}">
</form>
</div>
</div>
<hr>
<div class="row">
<div class="twelve columns">
<h3>Test results:</h3>
<p><a href="{{ url_for('result.add') }}">Add new result</a></p>
{% if test.results | length > 0 %}
<table class="u-full-width">