-
Notifications
You must be signed in to change notification settings - Fork 0
/
result.php
74 lines (62 loc) · 2.6 KB
/
result.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?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['status'] == 'false') {
throw new Exception('Job failed.');
}
elseif (!$_GET['key']) {
throw new Exception('Invalid GET request. No data received.');
}
$key = urldecode($_GET['key']);
$token = urldecode($_GET['token']);
$time = urldecode($_GET['time']);
$content = file_get_contents('logs/' . urlencode($key) . '.json');
if ($content == false) {
throw new Exception('Invalid key supplied.');
}
$array = json_decode($content, true);
if ($array['reproduction'] == 1){
$reproduction = 'Random pairing (conserves resources)';
}
elseif ($array['reproduction'] == 2){
$reproduction = 'Fully random';
}
else {
throw new Exception('Data compromised.');
}
if ($array['mutationDef'] == 1) {
$mutationDef = 'Aggressive (Change in allele, including apperance of new allele)';
}
elseif ($array['mutationDef'] == 2) {
$mutationDef = 'Simplistic (Apperance of new allele which does not previously exist in the population)';
}
else {
throw new Exception('Data compromised.');
}
if ($array['mutationRate'] == 1) {
$mutationRate = '1 mutation/' . $array['mutationRate'] . ' generation';
}
else {
$mutationRate = '1 mutation/' . $array['mutationRate'] . ' generations';
}
header('Cache-Control: no-cache, must-revalidate');
echo $templates->render('result', ['jobID' => $token, 'jobKey'=> $key, 'jobSubmitted' => date('r', $time), 'jobPopulation' => $array['population'], 'jobGenerations' => $array['generations'], 'jobReproduction' => $reproduction, 'jobMutation' => $array['mutation'], 'jobMutationRate' => $mutationRate, 'jobMutationDef' => $mutationDef]);
}
catch (Exception $e) {
header('Cache-Control: no-cache, must-revalidate');
if ($e->getMessage() == 'Job failed.') {
echo $templates->render('jobFailed', ['adminEmail' => $configs->config['admin_email']]);
}
else {
echo $templates->render('exception', ['showError' => true, 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString(), 'adminEmail' => $configs->config['admin_email']]);
}
}