-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNutritionList.cpp
More file actions
76 lines (73 loc) · 2.47 KB
/
NutritionList.cpp
File metadata and controls
76 lines (73 loc) · 2.47 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
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
// NutritionList.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <cpprest/http_client.h>
#include <json/json.h>
#include <json/value.h>
#include "Graph.h"
#include "User.h"
using namespace std;
void addEdges(vector<node> ¤tlist,Graph& productGraph) {
for (unsigned int j = 0; j < currentlist.size(); j++) {
for (unsigned int k = 0; k < currentlist.size(); k++) {
if (k != j) {
productGraph.insertEdge(currentlist[j], currentlist[k], currentlist[k].protien);
}
}
}
currentlist.clear();
}
int main()
{
static vector<node> products;
std::cout << "Hello World!\n";
vector<string> ids;
// ReadFile("food.csv", ids);
Graph productGraph;
vector<node> highProtein;
vector<node> highFat;
vector<node> neutral;
vector<node> highCarbs;
vector<node> other;
std::cout << "Processing Data.." << endl;
std::ifstream people_file("foodData2.json", std::ifstream::binary);
Json::Value food1;
people_file >> food1;
people_file.close();
for (unsigned int i = 0; i < food1["SurveyFoods"].size(); i++) {
// cout << food1["SurveyFoods"][i] << endl;
node temp;
temp.protien = food1["SurveyFoods"][i]["foodNutrients"][0]["amount"].asFloat();
temp.carb = food1["SurveyFoods"][i]["foodNutrients"][2]["amount"].asFloat();
temp.fat = food1["SurveyFoods"][i]["foodNutrients"][1]["amount"].asFloat();
temp.name = food1["SurveyFoods"][i]["description"].asString();
temp.ID = food1["SurveyFoods"][i]["fdcId"].asInt();
if (temp.protien > 10) {
if (highProtein.size() >= 10) {
addEdges(highProtein, productGraph);
}
highProtein.push_back(temp);
}
if (temp.fat > 10) {
if (highFat.size() >= 10) {
addEdges(highFat, productGraph);
}
highFat.push_back(temp);
}
if (temp.carb > 10) {
if (highCarbs.size() >= 10) {
addEdges(highCarbs, productGraph);
}
highCarbs.push_back(temp);
}
if (temp.carb <= 10 && temp.fat <= 10 && temp.protien <= 10) {
if (other.size() >= 10) {
addEdges(other, productGraph);
}
other.push_back(temp);
}
}
productGraph.printGraph();
productGraph.BFSsearch("products[1].name");
return 0;
}