Added back reference associations for result; added table of results to test view

This commit is contained in:
Gregory Ballantine 2024-05-29 11:52:01 -04:00
parent 8df9b7684f
commit 3eca29c2db
5 changed files with 39 additions and 5 deletions

View File

@ -12,4 +12,7 @@ type Benchmark struct {
// many-to-many test
Tests []Test `gorm:"many2many:tests_benchmarks;"`
// has many results
Results []Result
}

View File

@ -11,4 +11,7 @@ type Hardware struct {
// has many tests
Tests []Test
// has many results
Results []Result
}

View File

@ -15,4 +15,7 @@ type Test struct {
// many-to-many benchmarks
Benchmarks []Benchmark `gorm:"many2many:tests_benchmarks;"`
// has many results
Results []Result
}

View File

@ -66,7 +66,32 @@
<h4>Latest Benchmark Results:</h4>
{{ $length := len .test.Results }} {{ if eq $length 0 }}
<p>There are currently no benchmarks recorded in this test.</p>
{{ else }}
<table class="u-full-width">
<thead>
<tr>
<th>Hardware</th>
<th>Benchmark</th>
<th>Average</th>
<th>Minimum</th>
<th>Maximum</th>
</tr>
</thead>
<tbody>
{{ range $res := .test.Results }}
<tr>
<td>{{ $res.Hardware.Name }}</td>
<td>{{ $res.Benchmark.Name }}</td>
<td>{{ $res.AverageScore }}</td>
<td>{{ $res.MinimumScore }}</td>
<td>{{ $res.MaximumScore }}</td>
</tr>
{{ end }}
</tbody>
</table>
{{ end }}
<hr>

View File

@ -30,7 +30,7 @@ func TestGetView(c flamego.Context, t template.Template, data template.Data) {
// find hardware from DB
var test models.Test
models.DB.Preload("Hardware").Preload("Benchmarks").First(&test, testID)
models.DB.Preload("Hardware").Preload("Benchmarks").Preload("Results").First(&test, testID)
data["test"] = test
data["title"] = test.Name