Skip to content

Commit

Permalink
feat(diary): filter banned words before give additional xp for more d…
Browse files Browse the repository at this point in the history
…etailed message
  • Loading branch information
Hojagulyyev committed Nov 23, 2023
1 parent ffd67d5 commit 1b24d02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 13 additions & 4 deletions apps/diaries/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,30 @@
MESSAGE_LENGTH_WHICH_BRINGS_XP_IN_DIARY_COMMIT,
STAR_FILLING_BONUS_VALUE,
ADDITIONAL_XP_FOR_STAR_FILLING,
BANNED_WORDS_IN_MORE_DETAILED_MESSAGE,
)

from .models import DiaryCommit


def has_commit_message_banned_words(message: str):
for word in BANNED_WORDS_IN_MORE_DETAILED_MESSAGE:
if word in message:
return True
return False


def calculate_diary_commit_xp(commit: DiaryCommit):
total_xp = [
XP_PER_DAIRY_COMMIT,
]

# 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)
if not has_commit_message_banned_words(commit.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:
Expand Down
4 changes: 4 additions & 0 deletions rp2/business_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@

# ===== RULES
COMMIT_MIN_LENGTH = 10
BANNED_WORDS_IN_MORE_DETAILED_MESSAGE = [
"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
"+0500", "Nov", "Dec", "Jan", "Feb", "Mar",
]

0 comments on commit 1b24d02

Please sign in to comment.