Skip to content

Commit

Permalink
fit: smoothen threshold average
Browse files Browse the repository at this point in the history
  • Loading branch information
hellos3b committed Feb 19, 2024
1 parent 517306a commit 002a9c4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/fitness/src/MondayRecap.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ const add = (a, b) => a + b;
const average = (nums) =>
nums.length === 0 ? 0 : nums.reduce(add, 0) / nums.length;

// calculates an average in a way that smoothens out high or low numbers
const smoothAverage = (nums) => {
const sets = [];
for (let i = 0; i < nums.length - 2; i++) {
const thisSet = nums.slice(i).slice(0, 3);
sets.push(average(thisSet));
}
return average(sets);
};

// Returns how much a user gets per week on average.
// returns -1 if not enough data
const expByWeek = (workouts) =>
Expand Down Expand Up @@ -44,7 +54,7 @@ const getStreak = (weeklyExp, exp) => {
if (!weeklyExp.length) return Streak.NOOB;
if (weeklyExp.length < 3) return Streak.CONSISTENT;

const avg = average(weeklyExp);
const avg = smoothAverage(weeklyExp);
if (exp < avg * 0.6) return Streak.COLD;
if (exp > avg * 1.4) return Streak.HOT;
return Streak.CONSISTENT;
Expand Down Expand Up @@ -107,6 +117,10 @@ export const createRecap = (discord, db) => async () => {
),
);

console.log(member.user.username);
console.log("EXP", exp);
console.log(prevWeekExps);

return {
username: member.nickname ?? member.user.username,
count: workouts.length,
Expand Down

0 comments on commit 002a9c4

Please sign in to comment.