Skip to content

Commit

Permalink
Give bonus hearts for chore completion
Browse files Browse the repository at this point in the history
  • Loading branch information
kronosapiens committed Jul 14, 2024
1 parent 42e48b2 commit 76c5102
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/bolt/chores.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ app.event('app_home_opened', async ({ body, event }) => {
const text = 'You missed too many chores last month, ' +
`and lost *${penaltyHeart.value.toFixed(1)}* hearts...`;
await postEphemeral(penaltyHeart.residentId, text);
} else if (penaltyHeart.value > 0) {
const text = 'You did all your chores last month, ' +
`and earned *${penaltyHeart.value.toFixed(1)}* hearts!`;
await postEphemeral(penaltyHeart.residentId, text);
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/core/chores.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,14 @@ exports.calculatePenalty = async function (residentId, penaltyTime) {
const prevMonthStart = getMonthStart(prevMonthEnd);
const choreStats = await exports.getChoreStats(residentId, prevMonthStart, prevMonthEnd);

const deficiency = Math.max(choreStats.pointsOwed - choreStats.pointsEarned, 0);
const truncatedDeficiency = Math.floor(deficiency / penaltyIncrement) * penaltyIncrement;
return truncatedDeficiency / (2 * penaltyIncrement);
const deficiency = choreStats.pointsOwed - choreStats.pointsEarned;

if (deficiency <= 0) {
return -0.5;
} else {
const truncatedDeficiency = Math.floor(deficiency / penaltyIncrement) * penaltyIncrement;
return truncatedDeficiency / (2 * penaltyIncrement);
}
};

// Chore Point Gifting
Expand Down
6 changes: 3 additions & 3 deletions test/chores.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,9 +752,9 @@ describe('Chores', async () => {
let penalty;
const penaltyTime = new Date(getNextMonthStart(feb1).getTime() + penaltyDelay);
penalty = await Chores.calculatePenalty(RESIDENT1, penaltyTime);
expect(penalty).to.equal(0);
expect(penalty).to.equal(-0.5);
penalty = await Chores.calculatePenalty(RESIDENT2, penaltyTime);
expect(penalty).to.equal(0);
expect(penalty).to.equal(-0.5);
penalty = await Chores.calculatePenalty(RESIDENT3, penaltyTime);
expect(penalty).to.equal(0.5);
});
Expand Down Expand Up @@ -794,7 +794,7 @@ describe('Chores', async () => {
let penaltyHearts;
penaltyHearts = await Chores.addChorePenalties(HOUSE, penaltyTime);
expect(penaltyHearts.length).to.equal(3);
expect(penaltyHearts[0].value).to.equal(0);
expect(penaltyHearts[0].value).to.equal(0.5);
expect(penaltyHearts[1].value).to.equal(-2.5);
expect(penaltyHearts[2].value).to.equal(-5.0);

Expand Down

0 comments on commit 76c5102

Please sign in to comment.