-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-utils.php
80 lines (67 loc) · 1.73 KB
/
test-utils.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
75
76
77
78
79
80
<?php
require 'vendor/autoload.php';
$fields = [
"ch-1" => [
"currentlyInfected",
"infectionsByRequestedTime"
],
"ch-2" => [
"severeCasesByRequestedTime",
"hospitalBedsByRequestedTime"
],
"ch-3" => [
"casesForICUByRequestedTime",
"casesForVentilatorsByRequestedTime",
'dollarsInFlight'
]
];
function getImpactDataStructure($challenge)
{
return [
"impact" => [],
"severeImpact" => [],
];
}
function valueOnFields($input, $output, $challenge)
{
$fields = $GLOBALS['fields'];
$values = array_reduce($fields[$challenge], function ($table, $f) use ($input, $output) {
array_push($table, [
$f,
$input["impact"][$f],
$output["impact"][$f],
]);
array_push($table, [
$f,
$input["severeImpact"][$f],
$output["severeImpact"][$f],
]);
return $table;
}, []);
return $values;
}
function convertEstimatesToArray($response_object)
{
$data = (array) $response_object->data;
$data["region"] = (array) $data["region"];
$estimate = (array) $response_object->estimate;
$estimate["impact"] = (array) $estimate["impact"];
$estimate["severeImpact"] = (array) $estimate["severeImpact"];
return [
"data" => $data,
"estimate" => $estimate,
];
}
function mockEstimatorFor($periodType)
{
$client = new GuzzleHttp\Client(['base_uri' => 'https://us-central1-buildforsdg.cloudfunctions.net/api/']);
$response_object = null;
try {
$response = $client->request('GET', 'gen/covid-19-scenario/' . strtolower($periodType));
$response_object = json_decode($response->getBody());
// $response_object = json_decode($data);
} catch (GuzzleHttp\Exception\RequestException $e) {
throw new Exception($e);
}
return $response_object;
}