chip colors actually work now
This commit is contained in:
@@ -95,6 +95,7 @@ const sendToPlan = () => {
|
|||||||
Axios.post('http://3.219.93.142:8000/api/week_meals', {net_id: ReactSession.get("net_id"), item_list: sendItems,}).then((response) => {
|
Axios.post('http://3.219.93.142:8000/api/week_meals', {net_id: ReactSession.get("net_id"), item_list: sendItems,}).then((response) => {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
});
|
});
|
||||||
|
Progress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -94,9 +94,9 @@ function weekStart(){
|
|||||||
|
|
||||||
const net_id = ReactSession.get("net_id");
|
const net_id = ReactSession.get("net_id");
|
||||||
|
|
||||||
//Get history of plans for this week
|
//Get history of plans
|
||||||
const [pastPlans, setPastPlans] = useState([{}]);
|
const [pastPlans, setPastPlans] = useState([{}]);
|
||||||
const makePastURL = (net_id) => `http://3.219.93.142:8000/api/${net_id}`;
|
const makePastURL = (net_id) => `http://3.219.93.142:8000/api/all_goal/${net_id}`;
|
||||||
|
|
||||||
const getPastPlans = () => {
|
const getPastPlans = () => {
|
||||||
const net_id = ReactSession.get("net_id");
|
const net_id = ReactSession.get("net_id");
|
||||||
@@ -109,7 +109,7 @@ const net_id = ReactSession.get("net_id");
|
|||||||
}
|
}
|
||||||
//Get history of actual totals for weekly plan (progress)
|
//Get history of actual totals for weekly plan (progress)
|
||||||
const [past, setPast] = useState([{}]);
|
const [past, setPast] = useState([{}]);
|
||||||
const makeURL = (net_id) => `http://3.219.93.142:8000/api/${net_id}`;
|
const makeURL = (net_id) => `http://3.219.93.142:8000/api/result/${net_id}`;
|
||||||
|
|
||||||
const getPast = () => {
|
const getPast = () => {
|
||||||
const net_id = ReactSession.get("net_id");
|
const net_id = ReactSession.get("net_id");
|
||||||
@@ -128,13 +128,6 @@ const net_id = ReactSession.get("net_id");
|
|||||||
getPastPlans()
|
getPastPlans()
|
||||||
console.log('Past plans in')
|
console.log('Past plans in')
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ThemeProvider theme={theme}>
|
<ThemeProvider theme={theme}>
|
||||||
|
|||||||
@@ -60,24 +60,27 @@ const displayWeek = () => {
|
|||||||
setWeek(() => weekStart());
|
setWeek(() => weekStart());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//get start of week (sunday)
|
||||||
|
function getLastSunday() {
|
||||||
|
const date = new Date();
|
||||||
|
const today = date.getDate();
|
||||||
|
const currentDay = date.getDay();
|
||||||
|
const newDate = date.setDate(today - (currentDay || 7));
|
||||||
|
return new Date(newDate);
|
||||||
|
}
|
||||||
|
|
||||||
//get the start of each week and reformat to Oracle date type
|
//get the start of each week and reformat to Oracle date type
|
||||||
function weekStart(){
|
function weekStart(){
|
||||||
var date_str = new Date();
|
|
||||||
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
|
var date_str = getLastSunday();
|
||||||
var weekday = days[date_str.getDay()]
|
|
||||||
|
|
||||||
if (weekday != 'Sunday'){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var date_str = new Date();
|
|
||||||
var curr_day = String(date_str.getDate()).padStart(2, '0');
|
var curr_day = String(date_str.getDate()).padStart(2, '0');
|
||||||
|
console.log(curr_day);
|
||||||
const months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
|
const months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'];
|
||||||
|
|
||||||
var curr_month = months[date_str.getMonth()];
|
var curr_month = months[date_str.getMonth()];
|
||||||
var curr_year = String(date_str.getFullYear());
|
var curr_year = String(date_str.getFullYear());
|
||||||
var db_date = curr_day + '-' + curr_month + '-' + curr_year.slice(2);
|
var db_date = curr_day + '-' + curr_month + '-' + curr_year.slice(2);
|
||||||
|
console.log(db_date)
|
||||||
return db_date;
|
return db_date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ const net_id = ReactSession.get("net_id");
|
|||||||
}
|
}
|
||||||
//Get sum of totals for weekly plan (progress)
|
//Get sum of totals for weekly plan (progress)
|
||||||
const [goals, setGoals] = useState([{}]);
|
const [goals, setGoals] = useState([{}]);
|
||||||
const goalURL = (net_id) => `http://3.219.93.142:8000/api/week_goal/${net_id}`;
|
const goalURL = (net_id) => `http://3.219.93.142:8000/api/goal/${net_id}`;
|
||||||
|
|
||||||
const getGoal = () => {
|
const getGoal = () => {
|
||||||
const net_id = ReactSession.get("net_id");
|
const net_id = ReactSession.get("net_id");
|
||||||
@@ -158,42 +158,82 @@ const net_id = ReactSession.get("net_id");
|
|||||||
|
|
||||||
const setColors = () => {
|
const setColors = () => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var dayFactor = planDay() / 7;
|
var dayFactor = planDay() / 7;
|
||||||
|
console.log(dayFactor)
|
||||||
|
console.log('Sum calories:')
|
||||||
|
console.log(sum.calories);
|
||||||
|
console.log('Goals calories:')
|
||||||
|
console.log(goals.calories);
|
||||||
|
console.log(goals.calories*dayFactor);
|
||||||
|
|
||||||
//set green
|
//set green
|
||||||
if(sum.calories < (1.1*goals.calories/dayFactor) && sum.calories >= (0.9*goals.calories/dayFactor)){
|
if(sum.calories < (1.1*goals.total_cal*dayFactor) && sum.calories >= (0.9*goals.total_cal*dayFactor)){
|
||||||
setCals(true)
|
setCals(true)
|
||||||
}
|
}
|
||||||
if(sum.fat_g < (1.1*goals.fat_g/dayFactor) && sum.fat_g >= (0.9*goals.fat_g/dayFactor)){
|
else {
|
||||||
|
setCals(false)
|
||||||
|
}
|
||||||
|
if(sum.fat_g < (1.1*goals.total_fat*dayFactor) && sum.fat_g >= (0.9*goals.total_fat*dayFactor)){
|
||||||
setFat(true)
|
setFat(true)
|
||||||
}
|
}
|
||||||
console.log(fat);
|
else {
|
||||||
if(sum.trans_fat_g < (1.1*goals.trans_fat_g/dayFactor) && sum.trans_fat_g >= (0.9*goals.trans_fat_g/dayFactor)){
|
setFat(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
if(sum.trans_fat_g < (1.1*goals.total_trans_fat*dayFactor) && sum.trans_fat_g >= (0.9*goals.total_trans_fat*dayFactor)){
|
||||||
setTrans(true)
|
setTrans(true)
|
||||||
}
|
}
|
||||||
if(sum.carbs_g < (1.1*goals.carbs_g/dayFactor) && sum.carbs_g >= (0.9*goals.carbs_g/dayFactor)){
|
else {
|
||||||
|
setTrans(false)
|
||||||
|
}
|
||||||
|
if(sum.carbs_g < (1.1*goals.total_carbs*dayFactor) && sum.carbs_g >= (0.9*goals.total_carbs*dayFactor)){
|
||||||
setCarbs(true)
|
setCarbs(true)
|
||||||
}
|
}
|
||||||
if(sum.sugar_g < (1.1*goals.sugar_g/dayFactor) && sum.sugar_g >= (0.9*goals.sugar_g/dayFactor)){
|
else {
|
||||||
|
setCarbs(false)
|
||||||
|
}
|
||||||
|
if(sum.sugar_g < (1.1*goals.total_sugar*dayFactor) && sum.sugar_g >= (0.9*goals.total_sugar*dayFactor)){
|
||||||
setSugar(true)
|
setSugar(true)
|
||||||
}
|
}
|
||||||
if(sum.protein_g < (1.1*goals.protein_g/dayFactor) && sum.protein_g >= (0.9*goals.protein_g/dayFactor)){
|
else {
|
||||||
|
setSugar(false)
|
||||||
|
}
|
||||||
|
if(sum.protein_g < (1.1*goals.total_protein*dayFactor) && sum.protein_g >= (0.9*goals.total_protein*dayFactor)){
|
||||||
setProtein(true)
|
setProtein(true)
|
||||||
}
|
}
|
||||||
if(sum.fiber_g < (1.1*goals.fiber_g/dayFactor) && sum.fiber_g >= (0.9*goals.fiber_g/dayFactor)){
|
else {
|
||||||
|
setProtein(false)
|
||||||
|
}
|
||||||
|
if(sum.fiber_g < (1.1*goals.total_fiber*dayFactor) && sum.fiber_g >= (0.9*goals.total_fiber*dayFactor)){
|
||||||
setFiber(true)
|
setFiber(true)
|
||||||
}
|
}
|
||||||
if(sum.cholesterol_mg < (1.1*goals.cholesterol_mg/dayFactor) && sum.cholesterol_mg >= (0.9*goals.cholesterol_mg/dayFactor)){
|
else {
|
||||||
|
setFiber(false)
|
||||||
|
}
|
||||||
|
if(sum.cholesterol_mg < (1.1*goals.total_cholesterol*dayFactor) && sum.cholesterol_mg >= (0.9*goals.total_cholesterol*dayFactor)){
|
||||||
setChol(true)
|
setChol(true)
|
||||||
}
|
}
|
||||||
if(sum.sodium_mg < (1.1*goals.sodium_mg/dayFactor) && sum.sodium_mg >= (0.9*goals.sodium_mg/dayFactor)){
|
else {
|
||||||
|
setChol(false)
|
||||||
|
}
|
||||||
|
if(sum.sodium_mg < (1.1*goals.total_sodium*dayFactor) && sum.sodium_mg >= (0.9*goals.total_sodium*dayFactor)){
|
||||||
setSodium(true)
|
setSodium(true)
|
||||||
}
|
}
|
||||||
if(sum.sat_fat_g < (1.1*goals.sat_fat_g/dayFactor) && sum.sat_fat_g >= (0.9*goals.sat_fat_g/dayFactor)){
|
else {
|
||||||
|
setSodium(false)
|
||||||
|
}
|
||||||
|
if(sum.sat_fat_g < (1.1*goals.total_sat_fat*dayFactor) && sum.sat_fat_g >= (0.9*goals.total_sat_fat*dayFactor)){
|
||||||
setSat(true)
|
setSat(true)
|
||||||
}
|
}
|
||||||
if(sum.potassium_mg < (1.1*goals.potassium_mg/dayFactor) && sum.potassium_mg >= (0.9*goals.potassium_mg/dayFactor)){
|
else {
|
||||||
|
setSat(false)
|
||||||
|
}
|
||||||
|
if(sum.potassium_mg < (1.1*goals.total_potassium*dayFactor) && sum.potassium_mg >= (0.9*goals.total_potassium*dayFactor)){
|
||||||
setPotassium(true)
|
setPotassium(true)
|
||||||
|
} else {
|
||||||
|
setPotassium(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -209,7 +249,7 @@ const net_id = ReactSession.get("net_id");
|
|||||||
console.log('History in')
|
console.log('History in')
|
||||||
getSum()
|
getSum()
|
||||||
console.log('Sum in')
|
console.log('Sum in')
|
||||||
//getGoal()
|
getGoal()
|
||||||
console.log('Goal in')
|
console.log('Goal in')
|
||||||
setColors()
|
setColors()
|
||||||
console.log('Colors set')
|
console.log('Colors set')
|
||||||
|
|||||||
Reference in New Issue
Block a user