-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.php
47 lines (38 loc) · 1.79 KB
/
graph.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
require 'vendor/autoload.php';
$configs = new Geneticdrift\Config;
$templates = new League\Plates\Engine($configs->config['web_root'] . '/templates');
$templates->loadExtension(new League\Plates\Extension\Asset($configs->config['web_root']));
$status = $configs->appStatus();
if (!$status) {
header('Cache-Control: no-cache, must-revalidate');
echo $templates->render('maintenance', ['adminEmail' => $configs->config['admin_email']]);
exit;
}
try {
if (!$_GET['key']) {
throw new Exception('Invalid GET request. No data received.');
}
$key = urldecode($_GET['key']);
$token = urldecode($_GET['token']);
$graph = urldecode($_GET['graph']);
$content = file_get_contents('logs/' . urlencode($key) . '.json');
if ($content == false) {
throw new Exception('Invalid key supplied.');
}
$array = json_decode($content, true);
header('Cache-Control: no-cache, must-revalidate');
if ($graph == 'allele') {
echo $templates->render('graph', ['graph' => 'allele', 'numAllele' => $array['numAllele'], 'dataArray' => $array['alleleFeq'], 'graphXAxis' => $array['generations'], 'graphYAxis' => $array['population'] * 2]);
}
elseif ($graph == 'hetero') {
echo $templates->render('graph', ['graph' => 'hetero', 'numAllele' => $array['numAllele'], 'dataArray' => $array['hetero'], 'graphXAxis' => $array['generations'], 'graphYAxis' => $array['population']]);
}
else {
throw new Exception ('Invalid GET request. Invalid value for $_GET[\'graph\']');
}
}
catch (Exception $e) {
header('Cache-Control: no-cache, must-revalidate');
echo $templates->render('exception', ['showError' => true, 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString(), 'adminEmail' => $configs->config['admin_email']]);
}