forked from BrodyHolden/battlesnake-node-snakenado
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
326 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
function readRankings($file) | ||
{ | ||
$mySnakes = ['Project Z', 'Tak', 'Rando', 'Keep Away', 'Tail Chase']; | ||
$rankings = json_decode(file_get_contents($file), true); | ||
$datasets = []; | ||
$labels = []; | ||
foreach ($rankings as $time => $players) { | ||
$labels[] = $time; | ||
foreach ($players as $player => $rank) { | ||
if (count($datasets) > 15 && !in_array($player, $mySnakes)) { | ||
continue; | ||
} | ||
$datasets[$player] = [ | ||
'label' => $player, | ||
'fill' => false, | ||
'data' => [], | ||
]; | ||
} | ||
} | ||
foreach ($labels as $dataIndex => $time) { | ||
foreach ($datasets as &$dataset) { | ||
$dataset['data'][$dataIndex] = null; | ||
foreach ($rankings[$time] as $player => $rank) { | ||
if ($player == $dataset['label']) { | ||
$dataset['data'][$dataIndex] = (int) $rank; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
$datasets = array_values($datasets); | ||
return [$labels, $datasets, str_replace('.json', '', basename($file))]; | ||
} | ||
?> | ||
<html ng-app="battleSnake" ng-controller="RootController"> | ||
|
||
<head> | ||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous"> | ||
</head> | ||
|
||
<body ng-cloak> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/randomcolor/0.6.1/randomColor.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> | ||
<div class="container-fluid"> | ||
<div class="row"> | ||
<?php foreach (glob(__DIR__ . '/../scrapes/*.json') as $file) : ?> | ||
<?php [$labels, $datasets, $label] = readRankings($file); ?> | ||
<div class="col-lg-4"> | ||
<canvas id="<?= $label; ?>" width="400" height="400"></canvas> | ||
</div> | ||
<script> | ||
(() => { | ||
const LABELS = <?= json_encode($labels); ?>; | ||
const DATASETS = <?= json_encode($datasets); ?>; | ||
|
||
var ctx = document.getElementById(<?= json_encode($label); ?>).getContext('2d'); | ||
window.myLine = new Chart(ctx, { | ||
type: 'line', | ||
data: { | ||
labels: LABELS.map(time => new Date(time)), | ||
datasets: DATASETS.map((d) => { | ||
const color = randomColor({ | ||
seed: d.label, | ||
}); | ||
d.backgroundColor = color; | ||
d.borderColor = color; | ||
return d; | ||
}), | ||
}, | ||
options: { | ||
responsive: true, | ||
legend: { | ||
position: 'left', | ||
}, | ||
title: { | ||
display: true, | ||
text: <?= json_encode($label); ?>, | ||
}, | ||
tooltips: { | ||
mode: 'index', | ||
intersect: false, | ||
}, | ||
hover: { | ||
mode: 'nearest', | ||
intersect: true | ||
}, | ||
scales: { | ||
xAxes: [{ | ||
display: true, | ||
type: 'time', | ||
time: { | ||
tooltipFormat: 'll HH:mm' | ||
}, | ||
scaleLabel: { | ||
display: true, | ||
labelString: 'Date' | ||
} | ||
}], | ||
yAxes: [{ | ||
display: true, | ||
ticks: { | ||
reverse: true, | ||
min: 1, | ||
}, | ||
scaleLabel: { | ||
display: true, | ||
labelString: 'Rank' | ||
} | ||
}] | ||
} | ||
} | ||
}); | ||
})(); | ||
</script> | ||
<?php endforeach; ?> | ||
</div> | ||
</div> | ||
</body> | ||
|
||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
Oops, something went wrong.