From ffd67d57b2ed8297ee01e88e032f1c9ff36dd410 Mon Sep 17 00:00:00 2001 From: Hojagulyyev Date: Mon, 20 Nov 2023 21:03:58 +0500 Subject: [PATCH] feat(diary): add additional xp for star filling bonus --- apps/diaries/services.py | 22 +++++++++++++++++----- rp2/business_logic.py | 2 ++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/apps/diaries/services.py b/apps/diaries/services.py index aee6fe9..e4210dc 100644 --- a/apps/diaries/services.py +++ b/apps/diaries/services.py @@ -1,14 +1,26 @@ -from rp2.business_logic import XP_PER_DAIRY_COMMIT, MESSAGE_LENGTH_WHICH_BRINGS_XP_IN_DIARY_COMMIT +from rp2.business_logic import ( + XP_PER_DAIRY_COMMIT, + MESSAGE_LENGTH_WHICH_BRINGS_XP_IN_DIARY_COMMIT, + STAR_FILLING_BONUS_VALUE, + ADDITIONAL_XP_FOR_STAR_FILLING, +) from .models import DiaryCommit def calculate_diary_commit_xp(commit: DiaryCommit): - additional_xp_for_more_detailed_message = int( - len(commit.message) / MESSAGE_LENGTH_WHICH_BRINGS_XP_IN_DIARY_COMMIT - ) total_xp = [ XP_PER_DAIRY_COMMIT, - additional_xp_for_more_detailed_message, ] + + # additional xp for more detailed message + additional_xp_for_more_detailed_message = int( + len(commit.message) / MESSAGE_LENGTH_WHICH_BRINGS_XP_IN_DIARY_COMMIT + ) + total_xp.append(additional_xp_for_more_detailed_message) + + # additional xp for star filling bonus + if commit.diary.commits.count() == STAR_FILLING_BONUS_VALUE: + total_xp.append(ADDITIONAL_XP_FOR_STAR_FILLING) + return sum(total_xp) diff --git a/rp2/business_logic.py b/rp2/business_logic.py index 6d22552..06faacf 100644 --- a/rp2/business_logic.py +++ b/rp2/business_logic.py @@ -3,6 +3,8 @@ XP_PER_DAIRY_COMMIT = 5 MESSAGE_LENGTH_WHICH_BRINGS_XP_IN_DIARY_COMMIT = 50 LEVEL_STEP_THAT_CHANGE_COLOR_DESIGN = 3 +STAR_FILLING_BONUS_VALUE = 5 +ADDITIONAL_XP_FOR_STAR_FILLING = 28 # ===== RULES COMMIT_MIN_LENGTH = 10