Fixed the chart generation page with the new ChartJS version and DB schema
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
@ -1,3 +1,3 @@
|
|||||||
$ ->
|
$ ->
|
||||||
# run foundation scripts
|
# run foundation scripts
|
||||||
$(document).foundation()
|
console.log('Ready.')
|
||||||
|
@ -1,55 +1,113 @@
|
|||||||
$(document).ready ->
|
$ ->
|
||||||
$('#generate_button').on 'click', (e) ->
|
chartInstance = null
|
||||||
e.preventDefault()
|
|
||||||
$.ajax(
|
|
||||||
method: 'POST'
|
|
||||||
url: '/reports'
|
|
||||||
data:
|
|
||||||
type: $('#report_type').val()
|
|
||||||
choice: $('#report_choice').val()
|
|
||||||
compare: $('#report_compare').val()
|
|
||||||
).done (data) ->
|
|
||||||
benchChart.options.title.text = data.choice
|
|
||||||
benchChart.data.labels = data.names
|
|
||||||
benchChart.data.datasets[0].data = data.avg_results
|
|
||||||
benchChart.data.datasets[1].data = data.min_results
|
|
||||||
benchChart.update()
|
|
||||||
return
|
|
||||||
return
|
|
||||||
return
|
|
||||||
|
|
||||||
benchChart = new Chart(document.getElementById('chart_canvas').getContext('2d'),
|
$('#reports-download').on 'click', (e) ->
|
||||||
type: 'horizontalBar'
|
e.preventDefault()
|
||||||
data:
|
canvas = $('#benchmark-chart')[0]
|
||||||
labels: []
|
a = document.createElement 'a'
|
||||||
datasets: [
|
a.href = canvas.toDataURL 'image/png'
|
||||||
{
|
a.download = 'chart.png'
|
||||||
label: 'Average FPS'
|
a.click()
|
||||||
data: []
|
|
||||||
backgroundColor: 'hotpink'
|
$('#reports-button').on 'click', (e) ->
|
||||||
borderColor: '#212121'
|
e.preventDefault()
|
||||||
borderWidth: 1
|
$('#reports-download').attr('disabled', true)
|
||||||
}
|
chartInstance.destroy() if chartInstance
|
||||||
{
|
|
||||||
label: 'Minimum FPS'
|
benchmarkId = $('#report-benchmarks').val()
|
||||||
data: []
|
testIds = $('#report-tests').val()
|
||||||
backgroundColor: 'cornflowerblue'
|
|
||||||
borderColor: '#212121'
|
benchmarkSearchParams = new URLSearchParams
|
||||||
borderWidth: 1
|
benchmark_id: benchmarkId
|
||||||
}
|
benchmarkRes = await fetch("/api/v1/benchmark/details?#{benchmarkSearchParams}")
|
||||||
]
|
benchmarkData = await benchmarkRes.json()
|
||||||
options:
|
|
||||||
title:
|
data =
|
||||||
display: true
|
labels: []
|
||||||
text: 'N/a'
|
datasets: []
|
||||||
scales: xAxes: [ {
|
|
||||||
display: true
|
switch benchmarkData.scoring
|
||||||
ticks: beginAtZero: true
|
when 'pts'
|
||||||
} ]
|
data.datasets.push({
|
||||||
animation: onComplete: ->
|
label: 'Average Score'
|
||||||
dwnbtn = $('#download_button')
|
data: []
|
||||||
dwnbtn.attr 'href', benchChart.toBase64Image()
|
})
|
||||||
dwnbtn.attr 'download', 'benchmark_chart.png'
|
when 'fps'
|
||||||
dwnbtn.attr 'disabled', false
|
data.datasets.push({
|
||||||
return
|
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.avg_score
|
||||||
|
min_total += result.min_score if result.min_score
|
||||||
|
max_total += result.max_score if result.max_score
|
||||||
|
|
||||||
|
data.labels.push(testData.name)
|
||||||
|
data.datasets[0].data.push(avg_total / resultData.length)
|
||||||
|
console.log(data.datasets[0].data)
|
||||||
|
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')
|
||||||
|
55
assets/scripts/reports.coffee.bak
Normal file
55
assets/scripts/reports.coffee.bak
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
$(document).ready ->
|
||||||
|
$('#generate_button').on 'click', (e) ->
|
||||||
|
e.preventDefault()
|
||||||
|
$.ajax(
|
||||||
|
method: 'POST'
|
||||||
|
url: '/reports'
|
||||||
|
data:
|
||||||
|
type: $('#report_type').val()
|
||||||
|
choice: $('#report_choice').val()
|
||||||
|
compare: $('#report_compare').val()
|
||||||
|
).done (data) ->
|
||||||
|
benchChart.options.title.text = data.choice
|
||||||
|
benchChart.data.labels = data.names
|
||||||
|
benchChart.data.datasets[0].data = data.avg_results
|
||||||
|
benchChart.data.datasets[1].data = data.min_results
|
||||||
|
benchChart.update()
|
||||||
|
return
|
||||||
|
return
|
||||||
|
return
|
||||||
|
|
||||||
|
benchChart = new Chart(document.getElementById('chart_canvas').getContext('2d'),
|
||||||
|
type: 'horizontalBar'
|
||||||
|
data:
|
||||||
|
labels: []
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'Average FPS'
|
||||||
|
data: []
|
||||||
|
backgroundColor: 'hotpink'
|
||||||
|
borderColor: '#212121'
|
||||||
|
borderWidth: 1
|
||||||
|
}
|
||||||
|
{
|
||||||
|
label: 'Minimum FPS'
|
||||||
|
data: []
|
||||||
|
backgroundColor: 'cornflowerblue'
|
||||||
|
borderColor: '#212121'
|
||||||
|
borderWidth: 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
options:
|
||||||
|
title:
|
||||||
|
display: true
|
||||||
|
text: 'N/a'
|
||||||
|
scales: xAxes: [ {
|
||||||
|
display: true
|
||||||
|
ticks: beginAtZero: true
|
||||||
|
} ]
|
||||||
|
animation: onComplete: ->
|
||||||
|
dwnbtn = $('#download_button')
|
||||||
|
dwnbtn.attr 'href', benchChart.toBase64Image()
|
||||||
|
dwnbtn.attr 'download', 'benchmark_chart.png'
|
||||||
|
dwnbtn.attr 'disabled', false
|
||||||
|
return
|
||||||
|
)
|
@ -10,7 +10,7 @@ fetchTestBenchmarkResults = (testId, benchmarkId) ->
|
|||||||
resultSearchParams = new URLSearchParams
|
resultSearchParams = new URLSearchParams
|
||||||
test_id: testId
|
test_id: testId
|
||||||
benchmark_id: benchmarkId
|
benchmark_id: benchmarkId
|
||||||
resultRes = await fetch("/api/v1/results?#{resultSearchParams}")
|
resultRes = await fetch("/api/v1/result/list?#{resultSearchParams}")
|
||||||
resultData = await resultRes.json()
|
resultData = await resultRes.json()
|
||||||
|
|
||||||
avg_total = 0
|
avg_total = 0
|
||||||
|
@ -11,7 +11,7 @@ class GameData < Sinatra::Base
|
|||||||
json benchmark.values()
|
json benchmark.values()
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/api/v1/results' do
|
get '/api/v1/result/list' do
|
||||||
test_id = params[:test_id]
|
test_id = params[:test_id]
|
||||||
benchmark_id = params[:benchmark_id]
|
benchmark_id = params[:benchmark_id]
|
||||||
|
|
||||||
@ -20,4 +20,12 @@ class GameData < Sinatra::Base
|
|||||||
json results.map(&:values)
|
json results.map(&:values)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get '/api/v1/test/details' do
|
||||||
|
test_id = params[:test_id]
|
||||||
|
|
||||||
|
tst = Test.where(id: test_id).first()
|
||||||
|
|
||||||
|
json tst.values()
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" charset="utf-8"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js" charset="utf-8"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.7/js/bootstrap.min.js" charset="utf-8"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.7/js/bootstrap.min.js" charset="utf-8"></script>
|
||||||
<script src="/js/edgeville.js" charset="utf-8"></script>
|
<script src="/js/edgeville.js" charset="utf-8"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js" charset="utf-8"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body class="d-flex flex-column min-vh-100">
|
<body class="d-flex flex-column min-vh-100">
|
||||||
<!-- main navigation -->
|
<!-- main navigation -->
|
||||||
|
@ -2,14 +2,14 @@
|
|||||||
<form class="col-12" action="/reports" method="post">
|
<form class="col-12" action="/reports" method="post">
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-12 col-md-6">
|
<div class="col-12 col-md-6">
|
||||||
<select id="report_type" class="form-select" name="report_type" disabled>
|
<select id="report-type" class="form-select" name="report_type" disabled>
|
||||||
<option value="benchmark">Benchmark</option>
|
<option value="benchmark">Benchmark</option>
|
||||||
<option value="test">Test</option>
|
<option value="test">Test</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-12 col-md-6">
|
<div class="col-12 col-md-6">
|
||||||
<select id="report_choice" class="form-select" name="report_choice">
|
<select id="report-benchmarks" class="form-select" name="report_choice">
|
||||||
<% benchmarks.each do |b| %>
|
<% benchmarks.each do |b| %>
|
||||||
<option value="<%= b.id %>"><%= b.name %></option>
|
<option value="<%= b.id %>"><%= b.name %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
@ -18,7 +18,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-12 mb-3">
|
<div class="col-12 mb-3">
|
||||||
<select id="report_compare" class="col-12 form-select" name="report_compare[]" multiple>
|
<select id="report-tests" class="col-12 form-select" name="report_compare[]" multiple>
|
||||||
<% tests.each do |t| %>
|
<% tests.each do |t| %>
|
||||||
<option value="<%= t.id %>"><%= t.name %></option>
|
<option value="<%= t.id %>"><%= t.name %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
@ -26,16 +26,18 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-12 mb-3">
|
<div class="col-12 mb-3">
|
||||||
<input type="submit" class="btn btn-primary" id="generate_button" value="Generate">
|
<button id="reports-button" class="btn btn-primary">Generate</button>
|
||||||
<a href="#" class="btn btn-primary" id="download_button" disabled>Download</a>
|
<button id="reports-download" class="btn btn-primary" disabled>Download</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<canvas id="chart_canvas" width="100%" height="25"></canvas>
|
<canvas id="benchmark-chart" width="100%" height="25"></canvas>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- load the chart.js library -->
|
<!-- load the chart.js library -->
|
||||||
|
<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>
|
||||||
<!-- load chart functionality -->
|
<!-- load chart functionality -->
|
||||||
<script src="/js/reports.js" charset="utf-8"></script>
|
<script src="/js/reports.js" charset="utf-8"></script>
|
||||||
|
Reference in New Issue
Block a user