-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessData.php
More file actions
40 lines (33 loc) · 1.11 KB
/
processData.php
File metadata and controls
40 lines (33 loc) · 1.11 KB
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
<?php
$dataArry = $_GET['userData'];
$r = shell_exec("python processData.py '" . json_encode($dataArry). "'");
// Decode the result
$processed = json_decode($r, true);
if ($processed["status"] != "OK") {
echo "python processData.py '" . json_encode($dataArry). "'\n";
echo "Processing Error";
return http_response_code (400);
}
$r = shell_exec("python normalize.py '" . json_encode($processed["data"]). "'");
// Decode the result
$normalized = json_decode($r, true);
if ($normalized["status"] != "OK") {
echo "Normalization Error";
return http_response_code (400);
}
$r = shell_exec("python k-means.py '" . json_encode($normalized["data"]). "'");
$kMeans = json_decode($r, true);
if ($kMeans["status"] != "OK") {
echo "K-means Processing Error";
return http_response_code (400);
}
$scoresMap = array();
for ($i = 0; $i < count($kMeans['data']['Scores']); $i++) {
array_push ($scoresMap, array(
"Score" => $kMeans['data']['Scores'][$i],
"Origin" => $dataArry[$i]
));
}
$kMeans['data']['Scores'] = $scoresMap;
echo json_encode($kMeans);
?>