Skip to content

Commit

Permalink
Replace current_season variable
Browse files Browse the repository at this point in the history
  • Loading branch information
tmllull committed Jan 2, 2025
1 parent 89d992e commit 12e416f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
7 changes: 4 additions & 3 deletions api/app/crud/rankings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
logger = log_manager.get_logger()
config = Config()
clockify = ClockifyApi()
current_season = datetime.datetime.now().year

####################
##### RANKINGS #####
Expand Down Expand Up @@ -132,7 +133,7 @@ def user_ranking_achievements(db: Session, limit: int = None):


def user_played_games(
db: Session, limit: int = None, season: int = config.CURRENT_SEASON
db: Session, limit: int = None, season: int = current_season
):
try:
stmt = (
Expand All @@ -154,7 +155,7 @@ def user_played_games(


def user_completed_games(
db: Session, limit: int = None, season: int = config.CURRENT_SEASON
db: Session, limit: int = None, season: int = current_season
):
try:
user_list = users.get_users(db)
Expand Down Expand Up @@ -273,7 +274,7 @@ def platform_played_games(db: Session, limit: int = None):
raise e


def user_ratio(db: Session, season: int = config.CURRENT_SEASON):
def user_ratio(db: Session, season: int = current_season):
try:
user_list = users.get_users(db)
data = []
Expand Down
23 changes: 12 additions & 11 deletions api/app/crud/time_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@

clockify_api = ClockifyApi()
config = Config()
current_season = datetime.datetime.now().year


def get_users_played_time(db: Session, season: int = config.CURRENT_SEASON):
def get_users_played_time(db: Session, season: int = current_season):
stmt = (
select(models.TimeEntry.user_id, func.sum(models.TimeEntry.duration))
.where(extract("year", models.TimeEntry.start) == season)
Expand All @@ -40,7 +41,7 @@ def get_users_played_time(db: Session, season: int = config.CURRENT_SEASON):


def get_user_played_time(
db: Session, user_id: str, season: int = config.CURRENT_SEASON
db: Session, user_id: str, season: int = current_season
):
stmt = (
select(
Expand All @@ -56,7 +57,7 @@ def get_user_played_time(
return db.execute(stmt).first()


def get_games_played_time(db: Session, season: int = config.CURRENT_SEASON):
def get_games_played_time(db: Session, season: int = current_season):
stmt = (
select(
models.TimeEntry.project_clockify_id, func.sum(models.TimeEntry.duration)
Expand Down Expand Up @@ -109,7 +110,7 @@ def get_time_entry_by_date(


def get_user_games_played_time(
db: Session, user_id: str, game_id: str = None, season: int = config.CURRENT_SEASON
db: Session, user_id: str, game_id: str = None, season: int = current_season
) -> list[models.TimeEntry]:
if game_id is not None:
return (
Expand Down Expand Up @@ -141,7 +142,7 @@ def get_user_games_played_time(


def get_time_entries(
db: Session, start_date: str = None, season: int = config.CURRENT_SEASON
db: Session, start_date: str = None, season: int = current_season
) -> list[models.TimeEntry]:
if start_date:
# logger.debug(start_date)
Expand All @@ -162,7 +163,7 @@ def get_time_entries_by_user(
db: Session,
user_id: int,
start_date: str = None,
season: int = config.CURRENT_SEASON,
season: int = current_season,
) -> list[models.TimeEntry]:
if start_date:
# logger.debug(start_date)
Expand All @@ -189,7 +190,7 @@ def get_played_days(
user_id: int,
start_date: str = None,
end_date: str = None,
season: int = config.CURRENT_SEASON,
season: int = current_season,
) -> list[models.TimeEntry]:
played_days = []
real_played_days = []
Expand Down Expand Up @@ -234,7 +235,7 @@ def get_played_days(
async def sync_clockify_entries_db(
db: Session, user: models.User, entries, silent: bool
):
current_season = datetime.datetime.now().year
# current_season = datetime.datetime.now().year
for entry in entries:
if entry["projectId"] is None:
logger.warning("Time entry without project: " + str(entry["id"]))
Expand Down Expand Up @@ -420,7 +421,7 @@ def get_time_entry_by_time(
user_id: int,
duration: int,
mode: int,
season: int = config.CURRENT_SEASON,
season: int = current_season,
) -> models.TimeEntry:
"""_summary_
Expand Down Expand Up @@ -467,7 +468,7 @@ def get_time_entry_by_time(


def get_played_time_by_day(
db: Session, user_id: int, season: int = config.CURRENT_SEASON
db: Session, user_id: int, season: int = current_season
):
played_start_days = (
db.query(func.DATE(models.TimeEntry.start), func.sum(models.TimeEntry.duration))
Expand All @@ -486,7 +487,7 @@ def get_time_entry_between_hours(
user_id: int,
start_hour: int,
end_hour: int,
season: int = config.CURRENT_SEASON,
season: int = current_season,
) -> list[models.TimeEntry]:
"""_summary_
Expand Down
22 changes: 11 additions & 11 deletions api/app/crud/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

clockify_api = ClockifyApi()
config = Config()
current_season = datetime.datetime.now().year

#################
##### USERS #####
Expand Down Expand Up @@ -374,7 +375,7 @@ async def add_new_game(
game: schemas.NewGameUser,
user: models.User,
start_date: str = None,
season: int = config.CURRENT_SEASON,
season: int = current_season,
silent: bool = False,
from_sync=False,
) -> models.UserGame:
Expand Down Expand Up @@ -455,7 +456,7 @@ async def add_new_game(

def update_game(db: Session, game: models.UserGame, entry_id):
current_year = datetime.datetime.now().year
if current_year == config.CURRENT_SEASON:
if current_year == current_season:
try:
stmt = (
update(models.UserGame)
Expand Down Expand Up @@ -499,9 +500,8 @@ def update_played_time_game(
user_id: str,
game_id: str,
time: int,
season: int = config.CURRENT_SEASON,
season: int = current_season,
):
current_year = datetime.datetime.now().year
try:
# logger.info("Updating played time game " + str(game_id))
# if current_year == config.CURRENT_SEASON:
Expand Down Expand Up @@ -539,7 +539,7 @@ def get_games(
user_id,
limit=None,
completed=None,
season: int = config.CURRENT_SEASON,
season: int = current_season,
) -> list[schemas.UserGame]:
if completed != None:
completed = 1 if completed == True else 0
Expand Down Expand Up @@ -671,7 +671,7 @@ def update_played_days(
def update_played_time(db: Session, user_id, played_time):
current_year = datetime.datetime.now().year
try:
if current_year == config.CURRENT_SEASON:
if current_year == current_season:
stmt = (
update(models.UserStatistics)
.where(models.UserStatistics.user_id == user_id)
Expand All @@ -692,7 +692,7 @@ def update_played_time(db: Session, user_id, played_time):


def game_is_completed(
db: Session, player, game, season: int = config.CURRENT_SEASON
db: Session, player, game, season: int = current_season
) -> bool:
stmt = select(models.UserGame).where(
models.UserGame.game == game,
Expand All @@ -711,7 +711,7 @@ async def complete_game(
user_id,
game_id,
completed_date: str = None,
season: int = config.CURRENT_SEASON,
season: int = current_season,
silent: bool = False,
from_sync=False,
):
Expand Down Expand Up @@ -816,7 +816,7 @@ async def rate_game(
user_id,
game_id,
score,
season: int = config.CURRENT_SEASON,
season: int = current_season,
) -> models.UserGame:
try:
stmt = (
Expand Down Expand Up @@ -951,7 +951,7 @@ def activate_account(db: Session, username: str):


def top_games(
db: Session, username: str, limit: int = 10, season: int = config.CURRENT_SEASON
db: Session, username: str, limit: int = 10, season: int = current_season
):
try:
user = get_user_by_username(db, username)
Expand Down Expand Up @@ -1056,7 +1056,7 @@ def top_games(
# raise e


def get_achievements(db: Session, username: str, season: int = config.CURRENT_SEASON):
def get_achievements(db: Session, username: str, season: int = current_season):
try:
user = get_user_by_username(db, username)
stmt = (
Expand Down

0 comments on commit 12e416f

Please sign in to comment.