diff --git a/db_app/src/components/LogMeals.js b/db_app/src/components/LogMeals.js index 9d4497b..3d4a38a 100644 --- a/db_app/src/components/LogMeals.js +++ b/db_app/src/components/LogMeals.js @@ -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) => { console.log(response); }); + Progress(); } diff --git a/db_app/src/components/Past.js b/db_app/src/components/Past.js index 7054ef5..9131cf7 100644 --- a/db_app/src/components/Past.js +++ b/db_app/src/components/Past.js @@ -94,9 +94,9 @@ function weekStart(){ const net_id = ReactSession.get("net_id"); - //Get history of plans for this week + //Get history of plans 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 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) 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 net_id = ReactSession.get("net_id"); @@ -128,13 +128,6 @@ const net_id = ReactSession.get("net_id"); getPastPlans() console.log('Past plans in') }, []) - - - - - - - return ( diff --git a/db_app/src/components/Plan.js b/db_app/src/components/Plan.js index f6dee47..6b64aaf 100644 --- a/db_app/src/components/Plan.js +++ b/db_app/src/components/Plan.js @@ -60,24 +60,27 @@ const displayWeek = () => { 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 function weekStart(){ - var date_str = new Date(); - const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] - var weekday = days[date_str.getDay()] - - if (weekday != 'Sunday'){ - return; - } - - var date_str = new Date(); + + var date_str = getLastSunday(); 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']; - var curr_month = months[date_str.getMonth()]; var curr_year = String(date_str.getFullYear()); var db_date = curr_day + '-' + curr_month + '-' + curr_year.slice(2); - + console.log(db_date) return db_date; } diff --git a/db_app/src/components/ThisWeek.js b/db_app/src/components/ThisWeek.js index 65593e9..938f246 100644 --- a/db_app/src/components/ThisWeek.js +++ b/db_app/src/components/ThisWeek.js @@ -116,7 +116,7 @@ const net_id = ReactSession.get("net_id"); } //Get sum of totals for weekly plan (progress) 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 net_id = ReactSession.get("net_id"); @@ -158,42 +158,82 @@ const net_id = ReactSession.get("net_id"); const setColors = () => { + + 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 - 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) } - 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) } - console.log(fat); - if(sum.trans_fat_g < (1.1*goals.trans_fat_g/dayFactor) && sum.trans_fat_g >= (0.9*goals.trans_fat_g/dayFactor)){ + else { + 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) } - 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) } - 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) } - 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) } - 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) } - 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) } - 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) } - 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) } - 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) + } else { + setPotassium(false) } @@ -209,7 +249,7 @@ const net_id = ReactSession.get("net_id"); console.log('History in') getSum() console.log('Sum in') - //getGoal() + getGoal() console.log('Goal in') setColors() console.log('Colors set')