Compare commits

..

70 Commits

Author SHA1 Message Date
a1fba9829c Added titles to a few pages 2025-08-01 17:23:01 -04:00
32632b2303 Added a details page for test results; added an API route for removing test results 2025-08-01 17:21:03 -04:00
078edf5ab0 Added a test edit page; fixed some styles 2025-08-01 00:19:21 -04:00
9dedba6364 Added ability to show minimum FPS for FPS tests; added title to benchmark charts 2025-07-04 19:06:43 -04:00
bbe9c6575a Updated app dependencies; updated dev environment to PHP 8.4 and Node v24 2025-07-04 15:54:12 -04:00
295c7d1923 Updated the footer to look good with bootstrap; changed colors on the navbar 2025-07-02 18:05:50 -04:00
7a8b5a674c Increased size of the benchmark charts; disabled the chart display while the chart is being generated 2025-07-02 17:52:26 -04:00
3f5f374a36 Added functionality to clear the chart canvas so charts can be more easily created 2025-06-29 02:00:40 -04:00
fec91b1c1c Added ability to generate a basic chart using chart.js 2025-06-29 01:56:17 -04:00
Gregory Ballantine
728c249c15 Removing old SCSS file 2025-06-26 15:34:26 -04:00
Gregory Ballantine
de9e082961 Switched CSS framework to Bootstrap 2025-06-26 15:34:02 -04:00
Gregory Ballantine
e59d606f8c Added app and PHP version displays to the footer 2025-06-26 14:29:38 -04:00
Gregory Ballantine
4f0cb54190 Added ability to edit benchmarks 2025-06-26 12:57:27 -04:00
Gregory Ballantine
23cfbc2efa Made some style changes (not great, but I think it's a little better) 2025-06-26 12:50:05 -04:00
Gregory Ballantine
e9e43187e4 Added ability to edit hardware components 2025-06-26 12:17:05 -04:00
Gregory Ballantine
1a7e41edb2 Fixed the benchmark.view and component.view views so they now link to tests that reference them 2025-06-26 11:51:05 -04:00
6e67d58a8b Updated the reports page to use the new API endpoints 2025-06-25 17:24:31 -04:00
1b4fd8dec9 Added dynamic adding and loading of results on the test page 2025-06-25 17:14:19 -04:00
fad6899683 Fixed small issue with displaying number of benchmarks in a test 2025-06-10 11:38:11 -04:00
e42f453161 Fixed a few small typos 2025-06-10 11:30:00 -04:00
12b7743660 Added windows .bat scripts for docker-build and docker-run 2024-11-19 13:49:38 -05:00
Gregory Ballantine
b4bd116367 Added function to report generation page to change the selection of tests based on the benchmark wanted to compare 2024-06-03 13:18:38 -04:00
Gregory Ballantine
cedad0e48d Switched javascript to CoffeeScript 2024-06-03 12:48:05 -04:00
Gregory Ballantine
004a2ddef6 Switched javascript to CoffeeScript 2024-06-03 12:46:22 -04:00
Gregory Ballantine
f473bdf9ab Switched javascript to CoffeeScript 2024-06-03 12:44:13 -04:00
Gregory Ballantine
4a4f694831 Added API handler for getting a benchmark's tests 2024-06-03 12:39:33 -04:00
Gregory Ballantine
10df46be3b Added API handler for getting a benchmark's info 2024-06-03 12:37:44 -04:00
Gregory Ballantine
b9b881ec0c Added API handler for getting a benchmark's info 2024-06-03 12:37:13 -04:00
Gregory Ballantine
94794f2ca1 Updated styles for multiple option selectors 2024-06-03 12:29:24 -04:00
Gregory Ballantine
b293254a41 Updated styles for multiple option selectors 2024-06-03 12:29:03 -04:00
Gregory Ballantine
a4aaae0cd4 Fixed name of ReportController 2024-06-03 12:26:18 -04:00
Gregory Ballantine
27c9267261 Added report generation page 2024-06-03 12:25:29 -04:00
Gregory Ballantine
de01e4b144 Fixed typo in Test model 2024-06-03 11:42:05 -04:00
Gregory Ballantine
e0c6e3ef68 Fixed division by zero error 2024-06-03 11:41:30 -04:00
Gregory Ballantine
acbbbeb74f Added test result averages 2024-06-03 11:37:01 -04:00
Gregory Ballantine
af9d788fe0 Added test result averages 2024-06-03 11:36:47 -04:00
Gregory Ballantine
0510c80c34 Reworked test view page 2024-06-03 11:28:24 -04:00
Gregory Ballantine
0fde8c082e Fixed typos in the test view page 2024-06-03 10:54:19 -04:00
Gregory Ballantine
e3285bbaeb Fixed typos in the result add route 2024-06-03 10:53:50 -04:00
Gregory Ballantine
2f42f19c26 Fixed some styles on the test view page 2024-06-03 10:52:29 -04:00
Gregory Ballantine
9aa0b57298 Removed references to old result routes; fixed typos in some models 2024-06-03 10:52:00 -04:00
Gregory Ballantine
c81d6f0e32 Fixed calls to the benchmarks array on the test view page 2024-06-03 10:51:20 -04:00
Gregory Ballantine
4fab94b271 Fixed some styles on the test view page 2024-06-03 10:50:53 -04:00
Gregory Ballantine
ca940932a7 Removed references to old result routes; fixed typos in some models 2024-06-03 10:45:33 -04:00
Gregory Ballantine
9b575f8717 Reworked how test results get submitted 2024-06-03 10:37:20 -04:00
Gregory Ballantine
05b1374d1d Reworked how test results get submitted 2024-06-03 10:36:18 -04:00
Gregory Ballantine
de8e523c2c Fixed some things with the test add functions 2024-06-03 09:43:33 -04:00
Gregory Ballantine
6079524c4e Fixed typo in the test view 2024-06-03 09:42:50 -04:00
Gregory Ballantine
0844c8aead Fixed typo in the test add view 2024-06-03 08:40:45 -04:00
Gregory Ballantine
0b2c1b083c Fixed typo in the SCSS file 2024-06-03 08:39:50 -04:00
Gregory Ballantine
9e164485ed Fixed some styles/layout on the test add page 2024-06-03 08:38:28 -04:00
Gregory Ballantine
f27490e192 Modified some views, routes and models to work with the new many-to-many for tests and benchmarks 2024-06-03 08:32:37 -04:00
Gregory Ballantine
15377da52d Fixed derp problem with many-to-many relationship table for tests and benchmarks 2024-06-03 08:23:06 -04:00
Gregory Ballantine
6eaf7a0ba9 Added many-to-many relationship table for tests and benchmarks 2024-06-03 08:22:09 -04:00
Gregory Ballantine
bd4c79a6fc Changed database structure a bit; fixed code style problems in the old migrations 2024-06-03 08:18:35 -04:00
33c9bf5cb5 Updated test views and routes for the new test attributes 2024-04-06 12:08:23 -04:00
0c1df2e7e6 Added script to run phinx migrations; updated tests table to have better labels 2024-04-06 11:54:45 -04:00
96a69a94ba Updated entrypoint to automatically run dev environment migrations 2024-02-26 13:17:17 -05:00
987ecde7c7 Re-worked test views and routes for new DB schema 2023-10-07 21:45:21 -06:00
3349d42985 Added routes and views for adding and listing benchmarks and components 2023-10-07 11:45:11 -06:00
0dd7098681 Started work to re-work database; add new models for benchmarks and components 2023-09-22 23:03:24 -06:00
e176398f41 Updated README with development instructions 2023-09-20 20:09:28 -06:00
Gregory Ballantine
408b3baf8f Added Dockerfiles and scripts to run the dev build of Colossus through Docker 2023-07-05 13:52:15 -04:00
d6a72fcee3 Added batch scripts to run/develop the app on Windows 2023-05-08 12:57:03 -04:00
950b12ee10 Ordered result and test searches by last updated date 2022-11-25 21:30:56 -05:00
005b31dbd7 Changed where the result.add route redirects to; added some more links around the site for easier navigation 2022-11-25 19:46:31 -05:00
ca62be49b6 Added Test class to track benchmark groups 2022-11-25 19:39:51 -05:00
9a65b5f27a Added eloquent and phinx to project to handle database interactions and migrations; added Result model for storing benchmark results 2022-11-25 16:48:54 -05:00
323152a8f5 Added Grunt for compiling CSS/JS; added start of Result controller 2022-11-25 16:30:22 -05:00
ade48ccb2f Initial PHP Slim project structure 2022-11-25 15:46:18 -05:00
63 changed files with 8937 additions and 21 deletions

28
.gitignore vendored
View File

@@ -1,23 +1,13 @@
# ---> Go # Composer dependencies
# If you prefer the allow list template instead of the deny list, see community template: /vendor/
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c` # Local data directory
*.test data/
# Output of the go coverage tool, specifically when used with LiteIDE # NPM dependencies for Grunt
*.out node_modules/
# Dependency directories (remove the comment below to include it) # Compiled CSS and JS
# vendor/ public/css/
public/js/
# Go workspace file
go.work

25
Dockerfile Normal file
View File

@@ -0,0 +1,25 @@
# PHP composer to get dependencies
FROM composer:2.5 AS composer
WORKDIR /usr/src/colossus/
COPY composer.* /usr/src/colossus/
# Install dependencies
RUN composer install
RUN composer update
# Actual PHP runtime
FROM php:8.4-cli
WORKDIR /usr/src/colossus/
COPY --from=composer /usr/src/colossus/vendor/ /usr/src/colossus/vendor/
COPY . /usr/src/colossus/
VOLUME /usr/src/colossus/vendor/
EXPOSE 8080
# Run the app
CMD [ "bash", "entrypoints/dev.sh" ]

13
Dockerfile.grunt Normal file
View File

@@ -0,0 +1,13 @@
# Node.js runtime
FROM node:24
WORKDIR /usr/src/colossus/
COPY package.* /usr/src/colossus/
RUN npm install
VOLUME /usr/src/colossus/node_modules/
# Run the app
CMD [ "npm", "run", "grunt" ]

65
Gruntfile.js Normal file
View File

@@ -0,0 +1,65 @@
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
dist: {
options: {
style: 'compressed'
},
files: [{
expand: true,
cwd: 'assets/styles',
src: ['**/*.scss'],
dest: 'public/css',
ext: '.css'
}]
}
},
coffee: {
options: {
sourceMap: true,
style: 'compressed'
},
files: {
expand: true,
flatten: true,
cwd: 'assets/scripts',
src: ['*.coffee'],
dest: 'public/js',
ext: '.js'
}
},
watch: {
css: {
files: ['assets/styles/**/*.scss'],
tasks: ['sass'],
options: {
atBegin: true,
spawn: false
}
},
coffee: {
files: ['assets/scripts/**/*.coffee'],
tasks: ['coffee'],
options: {
atBegin: true,
spawn: false
}
}
}
});
// Load plugins.
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-coffee');
// CLI tasks.
grunt.registerTask('default', ['sass', 'coffee']);
};

View File

@@ -1,4 +1,4 @@
Copyright (c) <year> <owner> Copyright (c) 2022 Bit Goblin
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

View File

@@ -1,3 +1,26 @@
# colossus # colossus
Self-hosted database for organizing PC hardware benchmarking results Self-hosted database for organizing PC hardware benchmarking results.
## Project Goals
The goals of this project are to:
* Record benchmarking results from multiple devices - e.g. log from a laptop or a phone.
* Group results into tests - it's good practice to run a benchmark multiple times for accuracy.
* Create comparisons of hardware tests to compare performance.
* Generate graphs of hardware comparisons for usage in videos and articles.
## Development
The recommended way to run the development server for Colossus is using [Docker](https://docker.com/).
There are some shell and batch scripts in `bin/` to build and run the containers. To build the containers:
`bin/docker-build.sh` or `bin/docker-build.bat`
And then to run the containers:
`bin/docker-run.sh` or `bin/docker-run.bat`
This will build the containers for Apache and Grunt to serve the web pages and build front-end assets, respectively. If everything is running successfully you can open your browser and go to https://localhost:8080.

View File

@@ -0,0 +1,23 @@
$ ->
console.log('ready.')
$('#report-benchmarks').on 'change', ->
try
benchmarkSearchParams = new URLSearchParams
benchmark_id: $('#report-benchmarks').val()
benchmarkRes = await fetch("/api/v1/benchmark/tests?#{benchmarkSearchParams}")
benchmarkData = await benchmarkRes.json()
# clear old contents from the selector
$('#report-tests').empty()
# add new elements to the selector
addOption(test) for test in benchmarkData
catch error
console.error 'An error occurred while fetching benchmark results.', error
addOption = (test) ->
$('#report-tests').append(
$('<option/>')
.attr('value', test.id)
.text(test.title)
)

View File

@@ -0,0 +1,110 @@
$ ->
chartInstance = null
$('#reports-download').on 'click', ->
canvas = $('#benchmark-chart')[0]
a = document.createElement 'a'
a.href = canvas.toDataURL 'image/png'
a.download = 'chart.png'
a.click()
$('#reports-button').on 'click', (e) ->
$('#reports-download').attr('disabled', true)
chartInstance.destroy() if chartInstance
benchmarkId = $('#report-benchmarks').val()
testIds = $('#report-tests').val()
benchmarkSearchParams = new URLSearchParams
benchmark_id: benchmarkId
benchmarkRes = await fetch("/api/v1/benchmark/details?#{benchmarkSearchParams}")
benchmarkData = await benchmarkRes.json()
data =
labels: []
datasets: []
switch benchmarkData.scoring
when 'pts'
data.datasets.push({
label: 'Average Score'
data: []
})
when 'fps'
data.datasets.push({
label: 'Average FPS'
data: []
})
data.datasets.push({
label: 'Minimum FPS'
data: []
})
when 'ms'
data.datasets.push({
label: 'Average Frame Time'
data: []
})
data.datasets.push({
label: 'Minimum Frame Time'
data: []
})
for testId in testIds
try
testSearchParams = new URLSearchParams
test_id: testId
testRes = await fetch("/api/v1/test/details?#{testSearchParams}")
testData = await testRes.json()
resultSearchParams = new URLSearchParams
test_id: testId
benchmark_id: benchmarkId
resultRes = await fetch("/api/v1/result/list?#{resultSearchParams}")
resultData = await resultRes.json()
avg_total = 0
min_total = 0
max_total = 0
for result in resultData
avg_total += result.average
min_total += result.minimum if result.minimum
max_total += result.maximum if result.maximum
data.labels.push(testData.title)
data.datasets[0].data.push(avg_total / resultData.length)
switch benchmarkData.scoring
when 'fps', 'ms'
data.datasets[1].data.push(min_total / resultData.length)
catch error
console.error 'An error occurred while fetching benchmark results.', error
ctx = $('#benchmark-chart')[0].getContext('2d')
options =
indexAxis: 'y'
plugins:
title:
display: true
text: benchmarkData.name
font:
size: '24'
datalabels:
anchor: 'end'
align: 'left'
color: 'black'
font:
weight: 'bold'
formatter: (value) -> value
scales:
y:
beginAtZero: true
chartInstance = new Chart ctx,
type: 'bar'
data: data
options: options
plugins: [ChartDataLabels]
$('#reports-download').attr('disabled', false)
$('#benchmark-chart').removeClass('disabled')

View File

@@ -0,0 +1,64 @@
testId = $('#results-table').data('test-id')
$ ->
$('#result-form').on 'submit', (e) ->
e.preventDefault()
form = $(this)
formData = $(this).serialize()
benchmarkId = $(this).find('[name="result_benchmark"]').val()
$.post '/api/v1/result/add', formData, (response) ->
if response == 'success'
fetchTestBenchmarkResults(testId, benchmarkId)
form[0].reset()
fetchTestBenchmarkResults = (testId, benchmarkId) ->
try
benchmarkSearchParams = new URLSearchParams
benchmark_id: benchmarkId
benchmarkRes = await fetch("/api/v1/benchmark/details?#{benchmarkSearchParams}")
benchmarkData = await benchmarkRes.json()
resultSearchParams = new URLSearchParams
test_id: testId
benchmark_id: benchmarkId
resultRes = await fetch("/api/v1/result/list?#{resultSearchParams}")
resultData = await resultRes.json()
avg_total = 0
min_total = 0
max_total = 0
for result in resultData
avg_total += result.average
min_total += result.minimum if result.minimum
max_total += result.maximum if result.maximum
tableRow = $("#results-table tr[data-benchmark-id=#{benchmarkId}]")
tableRow.empty()
tableRow.append('<td><a href="/benchmark/' + benchmarkData.id + '">' + benchmarkData.name + '</a></td>')
tableRow.append('<td>' + benchmarkData.scoring + '</td>')
tableRow.append('<td>' + resultData.length + '</td>')
if resultData.length != 0
tableRow.append('<td>' + (avg_total / resultData.length) + '</td>')
else
tableRow.append('<td>N/a</td>')
if min_total != 0
tableRow.append('<td>' + (min_total / resultData.length) + '</td>')
tableRow.append('<td>' + (max_total / resultData.length) + '</td>')
else
tableRow.append('<td>N/a</td>')
tableRow.append('<td>N/a</td>')
tableRow.append('<td><a href="/test/' + testId + '/results">Details</a></td>')
catch error
console.error 'An error occurred while fetching benchmark results.', error
$('#results-table tbody tr').each (index, tr) ->
benchmarkId = $(tr).data('benchmark-id')
console.log("Fetching results for benchmark id: " + benchmarkId)
fetchTestBenchmarkResults(testId, benchmarkId)

34
assets/styles/nardah.scss Normal file
View File

@@ -0,0 +1,34 @@
$primary-color: navy;
$primary-color-highlight: lighten($primary-color, 10%);
$nav-height: 65px;
$textarea-min-height: 100px;
$shadow-normal: rgba(17, 12, 46, 0.15) 0px 48px 100px 0px;
$shadow-light: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
$shadow-heavy: rgba(0, 0, 0, 0.25) 0px 54px 55px, rgba(0, 0, 0, 0.12) 0px -12px 30px, rgba(0, 0, 0, 0.12) 0px 4px 6px, rgba(0, 0, 0, 0.17) 0px 12px 13px, rgba(0, 0, 0, 0.09) 0px -3px 5px;
.disabled{
display: none;
}
body{
background: rgb(240, 235, 248);
font-size: 18px;
}
table{
border: 1px solid #eee;
}
a{
transition: color 210ms ease-in-out;
}
#main-wrapper{
padding: 1.5rem 2rem;
background: white;
border: 1px solid #bbb;
border-radius: 8px;
}

4
bin/docker-build.bat Normal file
View File

@@ -0,0 +1,4 @@
@ECHO OFF
docker build -t colossus-php .
docker build -t colossus-grunt -f Dockerfile.grunt .

4
bin/docker-build.sh Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
docker build -t colossus-php .
docker build -t colossus-grunt -f Dockerfile.grunt .

3
bin/docker-composer.bat Normal file
View File

@@ -0,0 +1,3 @@
@ECHO OFF
docker run --rm -w "/usr/src/colossus" -v "%cd%:/usr/src/colossus" --name colossus_composer composer "%*"

3
bin/docker-phinx.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/sh
docker exec colossus-php ./vendor/bin/phinx $@

4
bin/docker-run.bat Normal file
View File

@@ -0,0 +1,4 @@
@ECHO OFF
docker run --rm -d -w "/usr/src/colossus" -v "%cd%:/usr/src/colossus" -p 8080:8080 --name colossus-php colossus-php
docker run --rm -d -w "/usr/src/colossus" -v "%cd%:/usr/src/colossus" --name colossus-grunt colossus-grunt npm run grunt watch

4
bin/docker-run.sh Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
docker run --rm -d -w "/usr/src/colossus" -v "$(pwd):/usr/src/colossus" -p 8080:8080 --name colossus-php colossus-php
docker run --rm -d -w "/usr/src/colossus" -v "$(pwd):/usr/src/colossus" --name colossus-grunt colossus-grunt npm run grunt watch

4
bin/run-php.sh Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
# start a local instance of the app using PHP's built-in webserver
php -S localhost:8080 -t public/ public/index.php

31
composer.json Normal file
View File

@@ -0,0 +1,31 @@
{
"name": "bitgoblin/colossus",
"version": "0.1.0",
"description": "Self-hosted database for organizing PC hardware benchmarking results",
"type": "project",
"license": "BSD-2-Clause",
"autoload": {
"psr-4": {
"BitGoblin\\Colossus\\": "src/"
}
},
"authors": [
{
"name": "Gregory Ballantine",
"email": "gballantine@bitgoblin.tech"
}
],
"minimum-stability": "stable",
"require": {
"slim/slim": "^4.14",
"slim/psr7": "^1.7",
"php-di/php-di": "^7.0",
"slim/twig-view": "^3.4",
"illuminate/database": "^12.19",
"robmorgan/phinx": "^0.16",
"hassankhan/config": "^3.2"
},
"scripts": {
"phinx": "./vendor/bin/phinx"
}
}

3743
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

6
conf/defaults.json Normal file
View File

@@ -0,0 +1,6 @@
{
"database": {
"driver": "sqlite",
"database": "./data/colossus.db"
}
}

0
data/.gitkeep Normal file
View File

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class AddInitialTables extends AbstractMigration {
public function change(): void {
// hardware components
$components_table = $this->table('components');
$components_table->addColumn('name', 'string', ['null' => false])
->addColumn('type', 'string', ['null' => false])
->addTimestamps()
->addIndex(['name', 'type'])
->create();
// benchmarks
$benchmarks_table = $this->table('benchmarks');
$benchmarks_table->addColumn('name', 'string', ['null' => false])
->addColumn('description', 'string')
->addColumn('scoring', 'string', ['null' => false])
->addTimestamps()
->addIndex(['name', 'scoring'])
->create();
}
}

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class AddTestsTable extends AbstractMigration {
public function change(): void {
$table = $this->table('tests');
$table->addColumn('title', 'string', ['null' => false])
->addColumn('description', 'string')
->addColumn('component_id', 'integer', ['null' => false])
->addForeignKey('component_id', 'components', 'id', ['delete'=> 'CASCADE', 'update'=> 'CASCADE'])
->addTimestamps()
->create();
$table = $this->table('benchmark_test');
$table->addColumn('test_id', 'integer', ['null' => false])
->addColumn('benchmark_id', 'integer', ['null' => false])
->addForeignKey('test_id', 'tests', 'id', ['delete'=> 'CASCADE', 'update'=> 'CASCADE'])
->addForeignKey('benchmark_id', 'benchmarks', 'id', ['delete'=> 'CASCADE', 'update'=> 'CASCADE'])
->create();
}
}

View File

@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class AddResultsTable extends AbstractMigration {
public function change(): void {
// benchmark test results
$table = $this->table('results');
$table->addColumn('average', 'integer', ['null' => false])
->addColumn('minimum', 'integer')
->addColumn('maximum', 'integer')
->addColumn('test_id', 'integer', ['null' => false])
->addColumn('benchmark_id', 'integer', ['null' => false])
->addForeignKey('test_id', 'tests', 'id', ['delete'=> 'CASCADE', 'update'=> 'CASCADE'])
->addForeignKey('benchmark_id', 'benchmarks', 'id', ['delete'=> 'CASCADE', 'update'=> 'CASCADE'])
->addTimestamps()
->create();
}
}

7
entrypoints/dev.sh Normal file
View File

@@ -0,0 +1,7 @@
#!/bin/sh
# run database migrations before starting
vendor/bin/phinx migrate -e development
# run the app through the PHP built-in dev server
php -S 0.0.0.0:8080 -t public/ public/index.php

3132
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

26
package.json Normal file
View File

@@ -0,0 +1,26 @@
{
"name": "colossus",
"version": "1.0.0",
"description": "Self-hosted database for organizing PC hardware benchmarking results",
"main": "index.js",
"scripts": {
"grunt": "grunt",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://git.metaunix.net/BitGoblin/colossus"
},
"keywords": [
"inventory"
],
"author": "Gregory Ballantine <gballantine@bitgoblin.tech>",
"license": "BSD-2-Clause",
"dependencies": {
"grunt": "^1.5.3",
"grunt-contrib-sass": "^2.0.0",
"grunt-contrib-coffee": "^2.1.0",
"grunt-contrib-watch": "^1.1.0",
"sass": "^1.56.1"
}
}

37
phinx.php Normal file
View File

@@ -0,0 +1,37 @@
<?php
return
[
'paths' => [
'migrations' => '%%PHINX_CONFIG_DIR%%/db/migrations',
'seeds' => '%%PHINX_CONFIG_DIR%%/db/seeds'
],
'environments' => [
'default_migration_table' => 'phinxlog',
'default_environment' => 'development',
'production' => [
'adapter' => 'mysql',
'host' => 'localhost',
'name' => 'production_db',
'user' => 'root',
'pass' => '',
'port' => '3306',
'charset' => 'utf8',
],
'development' => [
'adapter' => 'sqlite',
'name' => './data/colossus',
'suffix' => '.db',
],
'testing' => [
'adapter' => 'mysql',
'host' => 'localhost',
'name' => 'testing_db',
'user' => 'root',
'pass' => '',
'port' => '3306',
'charset' => 'utf8',
]
],
'version_order' => 'creation'
];

5
public/.htaccess Normal file
View File

@@ -0,0 +1,5 @@
# rewrite rules
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

24
public/index.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
// if we're looking for static files in dev, return false so they can be served.
if (PHP_SAPI == 'cli-server') {
$url = parse_url($_SERVER['REQUEST_URI']);
$file = __DIR__ . $url['path'];
// check the file types, only serve standard files
if (preg_match('/\.(?:png|js|jpg|jpeg|gif|css)$/', $file)) {
// does the file exist? If so, return it
if (is_file($file))
return false;
// file does not exist. return a 404
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
printf('"%s" does not exist', $_SERVER['REQUEST_URI']);
return false;
}
}
require_once __DIR__ . '/../src/app.php';
$app->run();

View File

@@ -0,0 +1,97 @@
<?php
namespace BitGoblin\Colossus\Controllers;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Routing\RouteContext;
use BitGoblin\Colossus\Models\Benchmark;
use BitGoblin\Colossus\Models\Result;
use BitGoblin\Colossus\Models\Test;
class ApiController extends Controller {
public function getBenchmarkDetails(Request $request, Response $response, array $args): Response {
$urlParams = $request->getQueryParams();
$benchmark = Benchmark::where('id', $urlParams['benchmark_id'])->first();
$payload = json_encode($benchmark);
$response->getBody()->write($payload);
return $response
->withHeader('Content-Type', 'application/json');
}
public function getBenchmarkTests(Request $request, Response $response, array $args): Response {
$urlParams = $request->getQueryParams();
$benchmark = Benchmark::where('id', $urlParams['benchmark_id'])->first();
$payload = json_encode($benchmark->tests);
$response->getBody()->write($payload);
return $response
->withHeader('Content-Type', 'application/json');
}
public function getResultList(Request $request, Response $response, array $args): Response {
$urlParams = $request->getQueryParams();
$results = Result::where([
['benchmark_id', '=', $urlParams['benchmark_id']],
['test_id', '=', $urlParams['test_id']],
])->get();
$payload = json_encode($results);
$response->getBody()->write($payload);
return $response
->withHeader('Content-Type', 'application/json');
}
public function postResultAdd(Request $request, Response $response, array $args): Response {
$params = (array)$request->getParsedBody();
$result = new Result;
$result->test_id = $params['result_test'];
$result->benchmark_id = $params['result_benchmark'];
$result->average = $params['result_avg'];
$result->minimum = $params['result_min'] ?? null;
$result->maximum = $params['result_max'] ?? null;
$result->save();
$payload = json_encode('success');
$response->getBody()->write($payload);
return $response
->withHeader('Content-Type', 'application/json');
}
public function getResultDelete(Request $request, Response $response, array $args): Response {
$result = Result::where('id', $args['result_id'])->delete();
$payload = json_encode($result);
$referrer = $request->getHeaderLine('Referer');
if ($referrer) {
return $response
->withHeader('Location', $referrer)
->withStatus(302);
}
$response->getBody()->write($payload);
return $response
->withHeader('Content-Type', 'application/json');
}
public function getTestDetails(Request $request, Response $response, array $args): Response {
$urlParams = $request->getQueryParams();
$test = Test::where('id', $urlParams['test_id'])->first();
$payload = json_encode($test);
$response->getBody()->write($payload);
return $response
->withHeader('Content-Type', 'application/json');
}
}

View File

@@ -0,0 +1,91 @@
<?php
namespace BitGoblin\Colossus\Controllers;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Routing\RouteContext;
use Slim\Views\Twig;
use BitGoblin\Colossus\Models\Benchmark;
class BenchmarkController extends Controller {
public function getIndex(Request $request, Response $response): Response {
// redirect the user back to the home page
$routeContext = RouteContext::fromRequest($request);
$routeParser = $routeContext->getRouteParser();
return $response
->withHeader('Location', $routeParser->urlFor('benchmark.list'))
->withStatus(302);
}
public function getList(Request $request, Response $response): Response {
$benchmarks = Benchmark::orderByDesc('updated_at')->get();
$view = Twig::fromRequest($request);
return $view->render($response, 'benchmark/list.twig', [
'benchmarks' => $benchmarks,
]);
}
public function getView(Request $request, Response $response, array $args): Response {
$benchmark = Benchmark::where('id', $args['benchmark_id'])->first();
$view = Twig::fromRequest($request);
return $view->render($response, 'benchmark/view.twig', [
'benchmark' => $benchmark,
]);
}
public function getAdd(Request $request, Response $response): Response {
$view = Twig::fromRequest($request);
return $view->render($response, 'benchmark/add.twig');
}
public function postAdd(Request $request, Response $response): Response {
$params = (array)$request->getParsedBody();
$benchmark = new Benchmark;
$benchmark->name = $params['benchmark_name'];
$benchmark->description = $params['benchmark_description'];
$benchmark->scoring = $params['benchmark_scoring'];
$benchmark->save();
// redirect the user back to the home page
$routeContext = RouteContext::fromRequest($request);
$routeParser = $routeContext->getRouteParser();
return $response
->withHeader('Location', $routeParser->urlFor('benchmark.list'))
->withStatus(302);
}
public function getEdit(Request $request, Response $response, array $args): Response {
$benchmark = Benchmark::where('id', $args['benchmark_id'])->first();
$view = Twig::fromRequest($request);
return $view->render($response, 'benchmark/edit.twig', [
'benchmark' => $benchmark,
]);
}
public function postEdit(Request $request, Response $response, array $args): Response {
$benchmark = Benchmark::where('id', $args['benchmark_id'])->first();
$params = (array)$request->getParsedBody();
$benchmark->name = $params['benchmark_name'];
$benchmark->description = $params['benchmark_description'];
$benchmark->scoring = $params['benchmark_scoring'];
$benchmark->save();
// redirect the user back to the home page
$routeContext = RouteContext::fromRequest($request);
$routeParser = $routeContext->getRouteParser();
return $response
->withHeader('Location', $routeParser->urlFor('benchmark.view', ['benchmark_id' => $benchmark->id]))
->withStatus(302);
}
}

View File

@@ -0,0 +1,89 @@
<?php
namespace BitGoblin\Colossus\Controllers;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Routing\RouteContext;
use Slim\Views\Twig;
use BitGoblin\Colossus\Models\Component;
class ComponentController extends Controller {
public function getIndex(Request $request, Response $response): Response {
// redirect the user back to the home page
$routeContext = RouteContext::fromRequest($request);
$routeParser = $routeContext->getRouteParser();
return $response
->withHeader('Location', $routeParser->urlFor('component.list'))
->withStatus(302);
}
public function getList(Request $request, Response $response): Response {
$components = Component::orderByDesc('updated_at')->get();
$view = Twig::fromRequest($request);
return $view->render($response, 'component/list.twig', [
'components' => $components,
]);
}
public function getView(Request $request, Response $response, array $args): Response {
$component = Component::where('id', $args['component_id'])->first();
$view = Twig::fromRequest($request);
return $view->render($response, 'component/view.twig', [
'component' => $component,
]);
}
public function getAdd(Request $request, Response $response): Response {
$view = Twig::fromRequest($request);
return $view->render($response, 'component/add.twig');
}
public function postAdd(Request $request, Response $response): Response {
$params = (array)$request->getParsedBody();
$component = new Component;
$component->name = $params['component_name'];
$component->type = $params['component_type'];
$component->save();
// redirect the user back to the home page
$routeContext = RouteContext::fromRequest($request);
$routeParser = $routeContext->getRouteParser();
return $response
->withHeader('Location', $routeParser->urlFor('component.list'))
->withStatus(302);
}
public function getEdit(Request $request, Response $response, array $args): Response {
$component = Component::where('id', $args['component_id'])->first();
$view = Twig::fromRequest($request);
return $view->render($response, 'component/edit.twig', [
'component' => $component,
]);
}
public function postEdit(Request $request, Response $response, array $args): Response {
$component = Component::where('id', $args['component_id'])->first();
$params = (array)$request->getParsedBody();
$component->name = $params['component_name'];
$component->type = $params['component_type'];
$component->save();
// redirect the user back to the home page
$routeContext = RouteContext::fromRequest($request);
$routeParser = $routeContext->getRouteParser();
return $response
->withHeader('Location', $routeParser->urlFor('component.view', ['component_id' => $component->id]))
->withStatus(302);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace BitGoblin\Colossus\Controllers;
use Psr\Container\ContainerInterface;
class Controller {
protected $container;
public function __construct(ContainerInterface $container) {
$this->container = $container;
}
public function get(string $name) {
return $this->container->get($name);
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace BitGoblin\Colossus\Controllers;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig;
class HomeController extends Controller {
public function getIndex(Request $request, Response $response): Response {
$view = Twig::fromRequest($request);
return $view->render($response, 'index.twig');
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace BitGoblin\Colossus\Controllers;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Routing\RouteContext;
use Slim\Views\Twig;
use BitGoblin\Colossus\Models\Benchmark;
class ReportController extends Controller {
public function getGenerate(Request $request, Response $response): Response {
$benchmarks = Benchmark::get();
$view = Twig::fromRequest($request);
return $view->render($response, 'reports/generate.twig', [
'benchmarks' => $benchmarks,
]);
}
}

View File

@@ -0,0 +1,121 @@
<?php
namespace BitGoblin\Colossus\Controllers;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Routing\RouteContext;
use Slim\Views\Twig;
use BitGoblin\Colossus\Models\Benchmark;
use BitGoblin\Colossus\Models\Component;
use BitGoblin\Colossus\Models\Test;
class TestController extends Controller {
public function getList(Request $request, Response $response): Response {
$tests = Test::orderByDesc('updated_at')->get();
$view = Twig::fromRequest($request);
return $view->render($response, 'test/list.twig', [
'tests' => $tests,
]);
}
public function getView(Request $request, Response $response, array $args): Response {
$test = Test::where('id', $args['test_id'])->first();
$view = Twig::fromRequest($request);
return $view->render($response, 'test/view.twig', [
'test' => $test,
]);
}
public function getAdd(Request $request, Response $response): Response {
$benchmarks = Benchmark::all();
$components = Component::all();
$view = Twig::fromRequest($request);
return $view->render($response, 'test/add.twig', [
'benchmarks' => $benchmarks,
'components' => $components,
]);
}
public function postAdd(Request $request, Response $response): Response {
$params = (array)$request->getParsedBody();
$test = new Test;
$test->title = $params['test_title'];
$test->description = $params['test_description'];
$test->component_id = $params['test_component'];
$test->save();
// attach benchmarks to test
foreach ($params['test_benchmarks'] as $b) {
$test->benchmarks()->attach($b);
}
// redirect the user back to the home page
$routeContext = RouteContext::fromRequest($request);
$routeParser = $routeContext->getRouteParser();
return $response
->withHeader('Location', $routeParser->urlFor('test.list'))
->withStatus(302);
}
public function getEdit(Request $request, Response $response, array $args): Response {
$test = Test::where('id', $args['test_id'])->first();
$benchmarks = Benchmark::all();
$components = Component::all();
$view = Twig::fromRequest($request);
return $view->render($response, 'test/edit.twig', [
'test' => $test,
'benchmarks' => $benchmarks,
'components' => $components,
]);
}
public function postEdit(Request $request, Response $response, array $args): Response {
$params = (array)$request->getParsedBody();
$test = Test::where('id', $args['test_id'])->first();
$test->title = $params['test_title'];
$test->description = $params['test_description'];
$test->component_id = $params['test_component'];
$test->save();
// attach benchmarks to test that aren't already attached
foreach ($params['test_benchmarks'] as $b) {
if (!$test->isBenchmarkSelected($b)) {
$test->benchmarks()->attach($b);
}
}
// remove benchmarks are not in the list
foreach ($test->benchmarks as $b) {
if (!in_array($b->id, $params['test_benchmarks'])) {
$test->benchmarks()->detach($b);
}
}
// redirect the user back to the home page
$routeContext = RouteContext::fromRequest($request);
$routeParser = $routeContext->getRouteParser();
return $response
->withHeader('Location', $routeParser->urlFor('test.view', [ 'test_id' => $test->id ]))
->withStatus(302);
}
public function getResults(Request $request, Response $response, array $args): Response {
$test = Test::where('id', $args['test_id'])->first();
$view = Twig::fromRequest($request);
return $view->render($response, 'test/results.twig', [
'test' => $test,
]);
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace BitGoblin\Colossus\Middleware;
use Psr\Http\Message\ServerRequestInterface as Request;
class AppInfo {
protected $view;
public function __construct($view) {
$this->view = $view;
}
public function __invoke(Request $request, $handler) {
// add running app version
$composer = json_decode(file_get_contents(__DIR__ . '/../../composer.json'), true);
$this->view->getEnvironment()->addGlobal('APP_VERSION', $composer['version'] ?? 'unknown');
// add running PHP version
$this->view->getEnvironment()->addGlobal('PHP_VERSION', PHP_VERSION);
return $handler->handle($request);
}
}

23
src/Models/Benchmark.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
namespace BitGoblin\Colossus\Models;
use Illuminate\Database\Eloquent\Model;
class Benchmark extends Model {
protected $fillable = [
'name',
'description',
'scoring',
];
public function tests() {
return $this->belongsToMany(Test::class);
}
public function results() {
return $this->hasMany(Result::class);
}
}

22
src/Models/Component.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
namespace BitGoblin\Colossus\Models;
use Illuminate\Database\Eloquent\Model;
class Component extends Model {
protected $fillable = [
'name',
'type',
];
public function tests() {
return $this->hasMany(Test::class);
}
public function results() {
return $this->hasMany(Result::class);
}
}

25
src/Models/Result.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
namespace BitGoblin\Colossus\Models;
use Illuminate\Database\Eloquent\Model;
class Result extends Model {
protected $fillable = [
'test_id',
'benchmark_id',
'average',
'minimum',
'maximum',
];
public function test() {
return $this->belongsTo(Test::class);
}
public function benchmark() {
return $this->belongsTo(Benchmark::class);
}
}

72
src/Models/Test.php Normal file
View File

@@ -0,0 +1,72 @@
<?php
namespace BitGoblin\Colossus\Models;
use Illuminate\Database\Eloquent\Model;
class Test extends Model {
protected $fillable = [
'date_tag',
'benchmark_id',
'component_id',
];
public function results() {
return $this->hasMany(Result::class);
}
public function benchmarks() {
return $this->belongsToMany(Benchmark::class);
}
public function component() {
return $this->belongsTo(Component::class);
}
public function isBenchmarkSelected($benchmarkId) {
return $this->benchmarks()
->where('benchmarks.id', $benchmarkId)
->exists();
}
public function benchmarkResults() {
$data = [];
foreach ($this->benchmarks as $i => $b) {
$benchmarkResults = $this->results()->where('benchmark_id', $b->id)->get();
if (count($benchmarkResults) > 0) {
$averageResults = [];
$minimumResults = [];
$maximumResults = [];
foreach ($benchmarkResults as $r) {
array_push($averageResults, $r->average);
array_push($minimumResults, $r->minimum);
array_push($maximumResults, $r->maximum);
}
$data[$i] = [
'name' => $b->name,
'scoring' => $b->scoring,
'count' => count($benchmarkResults),
'average' => (array_sum($averageResults) / count($averageResults)),
'minimum' => (array_sum($minimumResults) / count($minimumResults)),
'maximum' => (array_sum($maximumResults) / count($maximumResults)),
];
} else {
$data[$i] = [
'name' => $b->name,
'scoring' => $b->scoring,
'count' => count($benchmarkResults),
'average' => 0,
'minimum' => 0,
'maximum' => 0,
];
}
}
return $data;
}
}

47
src/app.php Normal file
View File

@@ -0,0 +1,47 @@
<?php
use DI\Container;
use Noodlehaus\Config;
use Noodlehaus\Parser\Json;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use Slim\Views\Twig;
use Slim\Views\TwigMiddleware;
use BitGoblin\Colossus\Middleware\AppInfo;
require __DIR__ . '/../vendor/autoload.php';
// Load app configuration
$config = Config::load(__DIR__ . '/../conf/defaults.json');
// Create new container object and add our config object to it
$container = new Container();
$container->set('config', function () use ($config) {
return $config;
});
// Load database configuration
require_once __DIR__ . '/database.php';
// Set container to create App with on AppFactory
AppFactory::setContainer($container);
$app = AppFactory::create();
// Allow body parsing for POST parameters
$app->addBodyParsingMiddleware();
// Add Error Handling Middleware
$app->addErrorMiddleware(true, false, false);
// Create Twig
$twig = Twig::create(__DIR__ . '/../views', ['cache' => false]);
// Add Twig-View Middleware
$app->add(TwigMiddleware::create($app, $twig));
// Add middleware for injecting global vars for app's info
$app->add(new AppInfo($twig));
// Register routes
require_once __DIR__ . '/routes.php';

10
src/database.php Normal file
View File

@@ -0,0 +1,10 @@
<?php
$capsule = new \Illuminate\Database\Capsule\Manager;
$capsule->addConnection($config->get('database'));
$capsule->setAsGlobal();
$capsule->bootEloquent();
$container->set('db', function () use ($capsule) {
return $capsule;
});

65
src/routes.php Normal file
View File

@@ -0,0 +1,65 @@
<?php
use Slim\Routing\RouteCollectorProxy;
$app->get('/', '\\BitGoblin\\Colossus\\Controllers\\HomeController:getIndex')->setName('dashboard');
$app->group('/benchmark', function(RouteCollectorProxy $group) {
$group->get('', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getIndex')->setName('benchmark.index');
$group->get('/list', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getList')->setName('benchmark.list');
$group->get('/add', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getAdd')->setName('benchmark.add');
$group->post('/add', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:postAdd');
$group->group('/{benchmark_id}', function(RouteCollectorProxy $benchmark) {
$benchmark->get('', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getView')->setName('benchmark.view');
$benchmark->get('/edit', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getEdit')->setName('benchmark.edit');
$benchmark->post('/edit', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:postEdit');
});
});
$app->group('/component', function(RouteCollectorProxy $group) {
$group->get('', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:getIndex')->setName('component.index');
$group->get('/list', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:getList')->setName('component.list');
$group->get('/add', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:getAdd')->setName('component.add');
$group->post('/add', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:postAdd');
$group->group('/{component_id}', function(RouteCollectorProxy $component) {
$component->get('', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:getView')->setName('component.view');
$component->get('/edit', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:getEdit')->setName('component.edit');
$component->post('/edit', '\\BitGoblin\\Colossus\\Controllers\\ComponentController:postEdit');
});
});
$app->group('/test', function(RouteCollectorProxy $group) {
$group->get('', '\\BitGoblin\\Colossus\\Controllers\\TestController:getList')->setName('test.list');
$group->get('/add', '\\BitGoblin\\Colossus\\Controllers\\TestController:getAdd')->setName('test.add');
$group->post('/add', '\\BitGoblin\\Colossus\\Controllers\\TestController:postAdd');
$group->group('/{test_id}', function(RouteCollectorProxy $test) {
$test->get('', '\\BitGoblin\\Colossus\\Controllers\\TestController:getView')->setName('test.view');
$test->get('/edit', '\\BitGoblin\\Colossus\\Controllers\\TestController:getEdit')->setName('test.edit');
$test->post('/edit', '\\BitGoblin\\Colossus\\Controllers\\TestController:postEdit');
$test->get('/results', '\\BitGoblin\\Colossus\\Controllers\\TestController:getResults')->setName('test.results');
});
});
$app->group('/reports', function(RouteCollectorProxy $group) {
$group->get('/generate', '\\BitGoblin\\Colossus\Controllers\ReportController:getGenerate')->setName('reports.generate');
});
$app->group('/api', function(RouteCollectorProxy $group) {
$group->group('/v1', function(RouteCollectorProxy $apiv1) {
$apiv1->get('/benchmark/details', '\\BitGoblin\\Colossus\\Controllers\\ApiController:getBenchmarkDetails')->setName('api.benchmarkDetails');
$apiv1->get('/benchmark/tests', '\\BitGoblin\\Colossus\\Controllers\\ApiController:getBenchmarkTests')->setName('api.benchmarkTests');
$apiv1->get('/result/list', '\\BitGoblin\\Colossus\\Controllers\\ApiController:getResultList')->setName('api.resultList');
$apiv1->post('/result/add', '\\BitGoblin\\Colossus\\Controllers\\ApiController:postResultAdd')->setName('api.resultAdd');
$apiv1->get('/result/{result_id}/delete', '\\BitGoblin\\Colossus\\Controllers\\ApiController:getResultDelete')->setName('api.resultDelete');
$apiv1->get('/test/details', '\\BitGoblin\\Colossus\\Controllers\\ApiController:getTestDetails')->setName('api.testDetails');
});
});

42
views/benchmark/add.twig Normal file
View File

@@ -0,0 +1,42 @@
{% extends 'layout.twig' %}
{% block title %}Add New Benchmark{% endblock %}
{% block content %}
<div class="row mb-4">
<div class="col-12">
<h1>Add new benchmark</h1>
</div>
</div>
<div class="row">
<form action="{{ url_for('benchmark.add') }}" method="POST">
<div class="row">
<div class="col-9 mb-3">
<label class="form-label" for="benchmark_name">Benchmark name:</label>
<input id="benchmark_name" class="form-control" type="text" name="benchmark_name">
</div>
<div class="col-3 mb-3">
<label class="form-label" for="benchmark_scoring">Scoring type:</label>
<select id="benchmark_scoring" class="form-select" name="benchmark_scoring">
<option value="fps">Frames per Second (fps)</option>
<option value="ms">Frame Time (ms)</option>
<option value="pts">Total Points</option>
</select>
</div>
</div>
<div class="row mb-3">
<div class="col-12">
<label for="benchmark_description">Description</label>
<textarea id="benchmark_description" class="form-control" name="benchmark_description" rows="5" placeholder="Describe this benchmark..."></textarea>
</div>
</div>
<input class="btn btn-primary" type="submit" value="Create Benchmark">
</form>
</div>
{% endblock %}

42
views/benchmark/edit.twig Normal file
View File

@@ -0,0 +1,42 @@
{% extends 'layout.twig' %}
{% block title %}Editing Benchmark: {{ benchmark.name }}{% endblock %}
{% block content %}
<div class="row mb-4">
<div class="col-12">
<h1>Editing Benchmark: {{ benchmark.name }}</h1>
</div>
</div>
<div class="row">
<form action="{{ url_for('benchmark.edit', { benchmark_id: benchmark.id }) }}" method="POST">
<div class="row">
<div class="col-9 mb-3">
<label class="form-label" for="benchmark_name">Benchmark name:</label>
<input id="benchmark_name" class="form-control" type="text" name="benchmark_name" value="{{ benchmark.name }}">
</div>
<div class="col-3 mb-3">
<label class="form-label" for="benchmark_scoring">Scoring type:</label>
<select id="benchmark_scoring" class="form-select" name="benchmark_scoring">
<option value="fps" {% if benchmark.scoring == 'fps' %}selected{% endif %}>Frames per Second (fps)</option>
<option value="ms" {% if benchmark.scoring == 'ms' %}selected{% endif %}>Frame Time (ms)</option>
<option value="pts" {% if benchmark.scoring == 'pts' %}selected{% endif %}>Total Points</option>
</select>
</div>
</div>
<div class="row mb-3">
<div class="col-12">
<label for="benchmark_description">Description</label>
<textarea id="benchmark_description" class="form-control" name="benchmark_description" rows="5" placeholder="Describe this benchmark...">{{ benchmark.description }}</textarea>
</div>
</div>
<input class="btn btn-primary" type="submit" value="Submit Changes">
</form>
</div>
{% endblock %}

34
views/benchmark/list.twig Normal file
View File

@@ -0,0 +1,34 @@
{% extends 'layout.twig' %}
{% block title %}List of Benchmarks{% endblock %}
{% block content %}
<h1>List of Benchmarks</h1>
<p><a href="{{ url_for('benchmark.add') }}">Create new Benchmark</a></p>
{% if benchmarks | length > 0 %}
<table class="table table-hover table-responsive">
<thead class="table-light">
<tr>
<th>Benchmark name</th>
<th>Description</th>
<th>Scoring type</th>
<th>Last updated</th>
</tr>
</thead>
<tbody>
{% for b in benchmarks %}
<tr>
<td><a href="{{ url_for('benchmark.view', { benchmark_id: b.id }) }}">{{ b.name }}</a></td>
<td>{{ b.description | slice(0, 100) }}</td>
<td>{{ b.scoring }}</td>
<td>{{ b.updated_at | date("F jS \\a\\t g:ia") }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>There are no benchmarks in the database - perhaps you should <a href="{{ url_for('benchmark.add') }}">create one</a>?</p>
{% endif %}
{% endblock %}

44
views/benchmark/view.twig Normal file
View File

@@ -0,0 +1,44 @@
{% extends 'layout.twig' %}
{% block title %}Test: {{ test.name }}{% endblock %}
{% block content %}
<div class="row">
<div class="col-12">
<h1>{{ benchmark.name }}</h1>
<p><a href="{{ url_for('benchmark.edit', { benchmark_id: benchmark.id }) }}">Edit</a></p>
<p>{{ benchmark.description }}</p>
</div>
</div>
<hr>
<div class="row">
<div class="col-12">
<h3 class="mb-3">Tests using this benchmark:</h3>
{% if benchmark.tests | length > 0 %}
<table class="table table-hover table-responsive">
<thead class="table-light">
<tr>
<th>Test title</th>
<th>Benchmarks</th>
<th>Last updated</th>
</tr>
</thead>
<tbody>
{% for t in benchmark.tests %}
<tr>
<td><a href="{{ url_for('test.view', { test_id: t.id }) }}">{{ t.title }}</a></td>
<td>{{ t.benchmarks | length }}</td>
<td>{{ t.updated_at }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>There are no tests associated with this benchmark.</p>
{% endif %}
</div>
</div>
{% endblock %}

36
views/component/add.twig Normal file
View File

@@ -0,0 +1,36 @@
{% extends 'layout.twig' %}
{% block title %}Add New Component{% endblock %}
{% block content %}
<div class="row mb-4">
<div class="col-12">
<h1>Add new component</h1>
</div>
</div>
<div class="row">
<div class="col-12">
<form action="{{ url_for('component.add') }}" method="POST">
<div class="row mb-3">
<div class="col-9">
<label class="form-label" for="component_name">Component name:</label>
<input id="component_name" class="form-control" type="text" name="component_name">
</div>
<div class="col-3">
<label class="form-label" for="component_type">Component type:</label>
<select id="component_type" class="form-select" name="component_type">
<option value="gpu">Graphics card</option>
<option value="cpu">Processor</option>
</select>
</div>
</div>
<input class="btn btn-primary" type="submit" value="Create Component">
</form>
</div>
</div>
{% endblock %}

36
views/component/edit.twig Normal file
View File

@@ -0,0 +1,36 @@
{% extends 'layout.twig' %}
{% block title %}Editing Component: {{ component.name }}{% endblock %}
{% block content %}
<div class="row mb-4">
<div class="col-12">
<h1>Editing Component: {{ component.name }}</h1>
</div>
</div>
<div class="row">
<div class="col-12">
<form action="{{ url_for('component.edit', { component_id: component.id }) }}" method="POST" class="u-full-width">
<div class="row mb-3">
<div class="col-9">
<label class="form-label" for="component_name">Component name:</label>
<input id="component_name" class="form-control" type="text" name="component_name" value="{{ component.name }}">
</div>
<div class="col-3">
<label class="form-label" for="component_type">Component type:</label>
<select id="component_type" class="form-select" name="component_type">
<option value="gpu" {% if component.type == 'gpu' %}selected{% endif %}>Graphics card</option>
<option value="cpu" {% if component.type == 'cpu' %}selected{% endif %}>Processor</option>
</select>
</div>
</div>
<input class="btn btn-primary" type="submit" value="Submit Changes">
</form>
</div>
</div>
{% endblock %}

32
views/component/list.twig Normal file
View File

@@ -0,0 +1,32 @@
{% extends 'layout.twig' %}
{% block title %}List of Hardware Components{% endblock %}
{% block content %}
<h1>List of Hardware Components</h1>
<p><a href="{{ url_for('component.add') }}">Create new Hardware Component</a></p>
{% if components | length > 0 %}
<table class="table table-hover table-responsive">
<thead class="table-light">
<tr>
<th>Component name</th>
<th>Type</th>
<th>Last updated</th>
</tr>
</thead>
<tbody>
{% for c in components %}
<tr>
<td><a href="{{ url_for('component.view', { component_id: c.id }) }}">{{ c.name }}</a></td>
<td>{{ c.type }}</td>
<td>{{ c.updated_at | date("F jS \\a\\t g:ia") }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>There are no hardware components in the database - perhaps you should <a href="{{ url_for('component.add') }}">create one</a>?</p>
{% endif %}
{% endblock %}

44
views/component/view.twig Normal file
View File

@@ -0,0 +1,44 @@
{% extends 'layout.twig' %}
{% block title %}Component: {{ component.name }}{% endblock %}
{% block content %}
<div class="row">
<div class="col-12">
<h1>{{ component.name }}</h1>
<p><a href="{{ url_for('component.edit', { component_id: component.id }) }}">Edit</a></p>
<p>{{ component.type }}</p>
</div>
</div>
<hr>
<div class="row">
<div class="col-12">
<h3>Tests using this component:</h3>
{% if component.tests | length > 0 %}
<table class="table table-hover table-responsive">
<thead class="table-light">
<tr>
<th>Test title</th>
<th>Benchmarks</th>
<th>Last updated</th>
</tr>
</thead>
<tbody>
{% for t in component.tests %}
<tr>
<td><a href="{{ url_for('test.view', { test_id: t.id }) }}">{{ t.title }}</a></td>
<td>{{ t.benchmarks | length }}</td>
<td>{{ t.updated_at }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>There are no tests associated with this component.</p>
{% endif %}
</div>
</div>
{% endblock %}

23
views/index.twig Normal file
View File

@@ -0,0 +1,23 @@
{% extends 'layout.twig' %}
{% block title %}Dashboard{% endblock %}
{% block content %}
<div class="row">
<div class="col-12">
<h1>Welcome to Colossus!</h1>
<p>Using Colossus, you can easily organize your hardware benchmark results.</p>
</div>
</div>
<hr>
<div class="row">
<div class="col-12">
<p><a href="{{ url_for('test.list') }}">View current tests</a></p>
<p><a href="{{ url_for('test.add') }}">Add a new test</a></p>
</div>
</div>
{% endblock %}

23
views/layout.twig Normal file
View File

@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}{% endblock %} | Colossus</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/nardah.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.7/js/bootstrap.min.js"></script>
<script src="/js/bedabin.js"></script>
{% block scripts %}{% endblock %}
</head>
<body class="d-flex flex-column min-vh-100">
{% include 'partials/navbar.twig' %}
<div id="main-wrapper" class="container mb-5">
{% block content %}{% endblock %}
</div>
{% include 'partials/footer.twig' %}
</body>
</html>

View File

@@ -0,0 +1,10 @@
<footer id="main-footer" class="bg-light py-4 mt-auto">
<div class="container">
<div class="row">
<div class="col-12">
<p class="text-center mb-0">Colossus version {{ APP_VERSION }}</p>
<p class="text-center mb-0">Running PHP version {{ PHP_VERSION }}</p>
</div>
</div>
</div>
</footer>

View File

@@ -0,0 +1,29 @@
<nav id="main-nav" class="navbar navbar-expand-md navbar-dark bg-primary mb-3">
<div class="container-fluid">
<a class="navbar-brand mb-0 h1" href="#">Colossus</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-md-0">
<li class="nav-item">
<a class="nav-link" href="{{ url_for('dashboard') }}">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('benchmark.list') }}">Benchmarks</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('component.list') }}">Components</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('test.list') }}">Test</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('reports.generate') }}">Reports</a>
</li>
</ul>
</div>
</div>
</nav>

View File

@@ -0,0 +1,53 @@
{% extends 'layout.twig' %}
{% block title %}Dashboard{% endblock %}
{% block scripts %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.1/chart.umd.min.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chartjs-plugin-datalabels/2.2.0/chartjs-plugin-datalabels.min.js" charset="utf-8"></script>
<script src="/js/reports.js" charset="utf-8"></script>
{% endblock %}
{% block content %}
<div class="row">
<div class="twelve columns">
<h1>Generate a Report</h1>
</div>
</div>
<hr>
<div class="row">
<div class="col-5">
<select id="report-benchmarks" class="form-select">
{% for b in benchmarks %}
<option value="{{ b.id }}">{{ b.name }}</option>
{% endfor %}
</select>
</div>
<div class="col-7">
<select id="report-tests" class="form-select" multiple>
{% for t in benchmarks[0].tests %}
<option value="{{ t.id }}">{{ t.title }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="row">
<div class="col-12">
<button id="reports-button" class="btn btn-primary" type="button" name="button">Generate Chart</button>
<button id="reports-download" class="btn btn-primary" type="button" name="button" disabled>Download Chart</button>
</div>
</div>
<div class="row">
<div class="col-12">
<canvas id="benchmark-chart" class="disabled" width="1200" height="720"></canvas>
</div>
</div>
{% endblock %}

55
views/test/add.twig Normal file
View File

@@ -0,0 +1,55 @@
{% extends 'layout.twig' %}
{% block title %}Add New Test{% endblock %}
{% block content %}
<div class="row mb-4">
<div class="col-12">
<h1>Add new test</h1>
</div>
</div>
<div class="row">
<div class="col-12">
<form action="{{ url_for('test.add') }}" method="POST">
<div class="row mb-3">
<div class="col-6">
<label class="form-label" for="test_title">Test title:</label>
<input id="test_title" class="form-control" type="text" name="test_title" placeholder="My new test">
</div>
<div class="col-6">
<label class="form-label" for="test_component">Hardware component:</label>
<select id="test_component" class="form-select" name="test_component">
{% for c in components %}
<option value="{{ c.id }}">{{ c.name }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="row">
<div class="col-12 mb-3">
<label class="form-label" for="test_benchmarks">Benchmarks:</label>
<select id="test_benchmarks" class="form-select" name="test_benchmarks[]" multiple>
{% for b in benchmarks %}
<option value="{{ b.id }}">{{ b.name }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="row mb-3">
<div class="col-12">
<label class="form-label" for="test_description">Test description:</label>
<textarea id="test_description" class="form-control" name="test_description" rows="8"></textarea>
</div>
</div>
<input class="btn btn-primary" type="submit" value="Create Test">
</form>
</div>
</div>
{% endblock %}

55
views/test/edit.twig Normal file
View File

@@ -0,0 +1,55 @@
{% extends 'layout.twig' %}
{% block title %}Editing: {{ test.title }}{% endblock %}
{% block content %}
<div class="row mb-4">
<div class="col-12">
<h1>Editing: {{ test.title }}</h1>
</div>
</div>
<div class="row">
<div class="col-12">
<form action="{{ url_for('test.edit', { test_id: test.id }) }}" method="POST">
<div class="row mb-3">
<div class="col-6">
<label class="form-label" for="test_title">Test title:</label>
<input id="test_title" class="form-control" type="text" name="test_title" placeholder="My new test" value="{{ test.title }}">
</div>
<div class="col-6">
<label class="form-label" for="test_component">Hardware component:</label>
<select id="test_component" class="form-select" name="test_component">
{% for c in components %}
<option value="{{ c.id }}" {% if test.component.id == c.id %}selected{% endif %}>{{ c.name }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="row">
<div class="col-12 mb-3">
<label class="form-label" for="test_benchmarks">Benchmarks:</label>
<select id="test_benchmarks" class="form-select" name="test_benchmarks[]" multiple>
{% for b in benchmarks %}
<option value="{{ b.id }}" {% if test.isBenchmarkSelected(b.id) %}selected{% endif %}>{{ b.name }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="row mb-3">
<div class="col-12">
<label class="form-label" for="test_description">Test description:</label>
<textarea id="test_description" class="form-control" name="test_description" rows="8">{{ test.description }}</textarea>
</div>
</div>
<input class="btn btn-primary" type="submit" value="Submit Changes">
</form>
</div>
</div>
{% endblock %}

34
views/test/list.twig Normal file
View File

@@ -0,0 +1,34 @@
{% extends 'layout.twig' %}
{% block title %}List of Tests{% endblock %}
{% block content %}
<h1>List of Hardware Tests</h1>
<p><a href="{{ url_for('test.add') }}">Create new test</a></p>
{% if tests | length > 0 %}
<table class="table table-hover table-responsive">
<thead class="table-light">
<tr>
<th>Test title</th>
<th>Hardware</th>
<th># of benchmarks</th>
<th>Last updated</th>
</tr>
</thead>
<tbody>
{% for t in tests %}
<tr>
<td><a href="{{ url_for('test.view', { test_id: t.id }) }}">{{ t.title }}</a></td>
<td>{{ t.component.name }}</td>
<td>{{ t.benchmarks().get() | length }}</td>
<td>{{ t.updated_at | date("F jS \\a\\t g:ia") }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>There are no tests in the database - perhaps you should <a href="{{ url_for('test.add') }}">create one</a>?</p>
{% endif %}
{% endblock %}

44
views/test/results.twig Normal file
View File

@@ -0,0 +1,44 @@
{% extends 'layout.twig' %}
{% block title %}Result Details for {{ test.title }}{% endblock %}
{% block content %}
<div class="row mb-3">
<div class="col-12">
<h1>Result Details for {{ test.title }}</h1>
<p><a href="{{ url_for('test.view', { test_id: test.id }) }}">Back</a></p>
</div>
</div>
<hr class="mb-4">
<div class="row mb-4">
{% for b in test.benchmarks %}
<div class="col-12 mb-3">
<h2><a href="{{ url_for('benchmark.view', { benchmark_id: b.id }) }}">{{ b.name }}</a></h2>
<table class="table table-hover table-responsive">
<thead>
<tr>
<th>Average</th>
<th>Minimum</th>
<th>Maximum</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
{% for r in b.results().where('test_id', test.id).get() %}
<tr>
<td>{{ r.average }}</td>
<td>{{ r.minimum }}</td>
<td>{{ r.maximum }}</td>
<td><a href="#">Edit</a></td>
<td><a href="{{ url_for('api.resultDelete', { result_id: r.id }) }}">Delete</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endfor %}
</div>
{% endblock %}

77
views/test/view.twig Normal file
View File

@@ -0,0 +1,77 @@
{% extends 'layout.twig' %}
{% block title %}Test: {{ test.title }}{% endblock %}
{% block content %}
<div class="row mb-3">
<div class="col-12">
<h1>{{ test.title }}</h1>
<p><a href="{{ url_for('test.edit', { test_id: test.id }) }}">Edit</a></p>
<p>{{ test.description }}</p>
</div>
</div>
<hr class="mb-4">
<div class="row mb-4">
<div class="col-12">
<form id="result-form" action="{{ url_for('api.resultAdd') }}" method="POST">
<div class="row">
<div class="col-4">
<select class="form-select" name="result_benchmark">
{% for b in test.benchmarks %}
<option value="{{ b.id }}">{{ b.name }}</option>
{% endfor %}
</select>
</div>
<div class="col-2">
<input class="form-control" type="number" step="0.01" name="result_avg" placeholder="0.0">
</div>
<div class="col-2">
<input class="form-control" type="number" step="0.01" name="result_min" placeholder="0.0">
</div>
<div class="col-2">
<input class="form-control" type="number" step="0.01" name="result_max" placeholder="0.0">
</div>
<div class="col-2">
<button class="btn btn-primary w-100" type="submit" name="button">Submit Result</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 class="mb-4">
<div class="row">
<div class="col-12">
<h3 class="mb-3">Benchmark results:</h3>
<table id="results-table" class="table table-hover table-responsive" data-test-id="{{ test.id }}">
<thead class="table-light">
<tr>
<th>Benchmark</th>
<th>Scoring</th>
<th># Results</th>
<th>Avg.</th>
<th>Min.</th>
<th>Max.</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for b in test.benchmarks %}
<tr data-benchmark-id="{{ b.id }}"></tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
<script src="/js/test.js"></script>
{% endblock %}