Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendan Birdsong committed Sep 27, 2023
1 parent 470d02a commit a8dc4ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
49 changes: 26 additions & 23 deletions app/components/ChartModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,33 @@ export default function ChartModal({ user }) {
const [days, setDays] = useState(30);

const data = [];
const lastDayEntries = user.entries.slice(0, days);
const entries = sortEntries(lastDayEntries, true);
for (var i = 1; i < entries.length; i++) {
const curEntry = entries[i - 1];
const nextEntry = entries[i];

const curWeekWeight = calculateDayAverageLoss(user, curEntry, 7);
const nextWeekWeight = calculateDayAverageLoss(user, nextEntry, 7);

const curWeekCalories = calculateAverageIntake(user, curEntry, 7);
const nextWeekCalories = calculateAverageIntake(user, nextEntry, 7);

const prevDataWeightVariance = data.length > 0 ? data[i - 2].weightVariance : 0;
const prevDataCaloricVariance = data.length > 0 ? data[i - 2].caloricVariance : 0;
const prevWeightChange = data.length > 0 ? data[i - 2].weightChange : 0;
const prevCaloricChange = data.length > 0 ? data[i - 2].caloricChange : 0;

data.push({
date: curEntry.date,
weightChange: ((nextWeekWeight - curWeekWeight)) + prevWeightChange,
caloricChange: ((nextWeekCalories - curWeekCalories)) + prevCaloricChange,
weightVariance: ((nextWeekWeight - curWeekWeight)),
caloricVariance: ((nextWeekCalories - curWeekCalories)),
});
if (days) {
const lastDayEntries = user.entries.slice(0, days);
const entries = sortEntries(lastDayEntries, true);
for (var i = 1; i < entries.length; i++) {
const curEntry = entries[i - 1];
const nextEntry = entries[i];

const curWeekWeight = calculateDayAverageLoss(user, curEntry, 7);
const nextWeekWeight = calculateDayAverageLoss(user, nextEntry, 7);

const curWeekCalories = calculateAverageIntake(user, curEntry, 7);
const nextWeekCalories = calculateAverageIntake(user, nextEntry, 7);

const prevDataWeightVariance = data.length > 0 ? data[i - 2].weightVariance : 0;
const prevDataCaloricVariance = data.length > 0 ? data[i - 2].caloricVariance : 0;
const prevWeightChange = data.length > 0 ? data[i - 2].weightChange : 0;
const prevCaloricChange = data.length > 0 ? data[i - 2].caloricChange : 0;

data.push({
date: curEntry.date,
weightChange: ((nextWeekWeight - curWeekWeight)) + prevWeightChange,
caloricChange: ((nextWeekCalories - curWeekCalories)) + prevCaloricChange,
weightVariance: ((nextWeekWeight - curWeekWeight)),
caloricVariance: ((nextWeekCalories - curWeekCalories)),
});
}
}

if (user.entries.length <= 1) {
Expand Down
2 changes: 1 addition & 1 deletion app/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const calculateDayMetabolicRate = (u, entry) => {
const bodyFatPercentage = u.bodyFatPercentage / 100;
const fatMass = bodyWeightKg * bodyFatPercentage;
const leanBodyMass = bodyWeightKg - fatMass;
const gender = u.gender === 'M' ? 1 : 2;
const gender = u.gender === 'M' ? 1 : 0;
const age = moment().diff(u.birthDate, 'years');
const baseCals = (13.587 * leanBodyMass) + (9.613 * fatMass) + (198 * gender) - (3.351 * age) + 674;
const baseWithActivity = baseCals * (u.activityModifier);
Expand Down

0 comments on commit a8dc4ef

Please sign in to comment.