Skip to content

Commit

Permalink
getdecision is done
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Salisbury committed Feb 13, 2017
1 parent 3c3ce56 commit e37c370
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions api/routes/decision.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,36 @@ function getProductInfo($upc) {
$theNuts[$nutrient['nutrient']['@attributes']['name']] = $nutrient['@attributes']['value'];
}

echo "<h2>The Product has...</h2>";
echo "<pre>";
print_r($theNuts);
echo "</pre>";
// echo "<h2>The Product has...</h2>";
// echo "<pre>";
// print_r($theNuts);
// echo "</pre>";

// get the rules by category
$q = new CategoryRankNutrientQuery;
$c = new CategoryQuery();


$allRules = $q->filterByCategoryId($request->getAttribute('category'))->find();
$passedRank = "Red";
//$res["food"] = $prodInfo;
$res["food"]['brand'] = $prodInfo['response']['body']['product_list']['products'][0]["@attributes"]['brand'];
$res["food"]['name'] = $prodInfo['response']['body']['product_list']['products'][0]["@attributes"]['name'];

$res["request"]["categoryRuleRun"] = $c->findPk($request->getAttribute("category"))->getName();


//default
$res["rankId"] = 0;
$res["rankName"] = "Red";

// for each rule, evaluate ingredients
foreach($allRules as $rule) {
$nut = $rule->getNutrient()->getName();
$operator = $rule->getOperator();
$threshold = $rule->getThreshold();
$presentVal = $theNuts[$nut];


$pass = 0;
switch($operator) {
case "lte":
Expand Down Expand Up @@ -185,17 +199,27 @@ function getProductInfo($upc) {
$rules[$rule->getRank()->getName()]['passedRank'] = $pass?"true" : "false";

if($pass) {
$passedRank = $rule->getRank()->getName();
$res["rankId"] = $rule->getRank()->getId();
$res["rankName"] = $rule->getRank()->getName();
}

}

echo "<h1>The rules expected...</h1>";
echo "<pre>";
print_r($rules);
echo "</pre>";
// echo "<h1>The rules expected...</h1>";
// echo "<pre>";
// print_r($rules);
// echo "</pre>";

echo "Ultimately this food is a ". $passedRank;
// echo "Ultimately this food is a ". $passedRank;

$response_json = [
"status" => [
"code" => $response->getStatusCode(),
"message" => "OK"
],
"data" => [$res]
];

$response = $response->withJSON($response_json);
return $response;
});

0 comments on commit e37c370

Please sign in to comment.