forked from DebMaster/health
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getplan.php
86 lines (82 loc) · 2.15 KB
/
getplan.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
81
82
83
84
85
86
<?php
require_once __DIR__ . '/lib/vendor/autoload.php';
require_once("model.php");
use Phpml\Classification\KNearestNeighbors;
$bmi=$_POST['bmi'];
$bmr=$_POST['bmr'];
$gender=$_POST['gender'];
$email=$_POST['email'];
$time=$_POST['time'];
$day=$_POST['day'];
$models=new model;
$weight=0;
$prefs=$models->getMyPreferences($email);
$group="Low";
if($bmi <= 25){
$weight +=1;
}else{
$weight +=2;
}
if($bmr < 1490 && $gender=="Female"){
$weight +=1;
}else if($bmr > 1490 && $gender=="Female"){
$weight +=2;
}else if($bmr < 1660 && $gender=="Male"){
$weight +=1;
}else if($bmr > 1660 && $gender=="Male"){
$weight +=2;
}
if(count($prefs) > 0){
if(strpos($prefs[0]['one'], "No") !== false){
$weight +=2;
}else if(strpos($prefs[0]['one'], "Pescatarian") !== false){
$weight +=3;
}else if(strpos($prefs[0]['one'], "Vegan") !== false){
$weight +=4;
}else if(strpos($prefs[0]['one'], "Meatatarian ") !== false){
$weight +=5;
}
if(strpos($prefs[0]['two'], "Skip") !== false){
$weight +=2;
}else if(strpos($prefs[0]['two'], "Dairy") !== false){
$weight +=3;
}else if(strpos($prefs[0]['two'], "Cereal") !== false){
$weight +=4;
}else if(strpos($prefs[0]['two'], "Refined") !== false){
$weight +=5;
}
if(strpos($prefs[0]['three'], "None") !== false){
$weight +=2;
}else if(strpos($prefs[0]['three'], "Gluten") !== false){
$weight +=3;
}else if(strpos($prefs[0]['three'], "Dairy") !== false){
$weight +=4;
}else if(strpos($prefs[0]['three'], "Pregnant") !== false){
$weight +=5;
}
if(strpos($prefs[0]['four'], "Starch") !== false){
$weight +=2;
}else if(strpos($prefs[0]['four'], "Protein") !== false){
$weight +=3;
}else if(strpos($prefs[0]['four'], "Fat") !== false){
$weight +=4;
}
}
//now lets do KNN on returned data
$results=$models->getMealPlans($time);
$all=array();
$labels=array();
$cprofile[1]=$weight;
$cprofile[0]=$day;
$count=count($results);
for($x=0; $x< $count; $x++){
$profile[1]=$results[$x]['weight'];
$profile[0]=$results[$x]['day'];
array_push($all,$profile);
array_push($labels,$results[$x]['message']);
}
$classifier = new KNearestNeighbors();
$classifier->train($all, $labels);
$arr["results"]=$classifier->predict($cprofile);
print_r(json_encode($arr));
?>