Skip to content

Commit

Permalink
Log more data changes #39
Browse files Browse the repository at this point in the history
  • Loading branch information
Zackhardtoname committed Feb 18, 2021
1 parent af4c717 commit 75a5d06
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 5 additions & 5 deletions time_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ def handle_in_session(self, user_id, reset):
in_session_std_time = float(in_session_std_time) if in_session_std_time else 0
std_incr = utilities.timedelta_to_hours(cur_time - last_record_time) - in_session_std_time

f = self.data_change_logger.info if std_incr >= 0 else self.data_change_logger.critical
f(f'{utilities.get_time()} incr: {std_incr}\ncur_time: {cur_time}\nlast_record_time: {last_record_time}\npast_in_session_time: {in_session_std_time}\nuser_id: {user_id}')

neg_msg = f"std_incr Negative: {std_incr}\n" if std_incr < 0 else ""
std_incr = max(std_incr, 0)
in_session_std_time = 0 if reset else std_incr + in_session_std_time
self.redis_client.hset(in_session_std_time_name, user_id, in_session_std_time)

utilities.increment_studytime(category_key_names, self.redis_client, user_id,
in_session_incrs=in_session_incrs, std_incr=std_incr)
monthly_now, all_time_now = utilities.increment_studytime(category_key_names, self.redis_client, user_id,
in_session_incrs=in_session_incrs, std_incr=std_incr)
log_msg = f'{utilities.get_time()}\n{neg_msg}monthly_now: {monthly_now}\nall_time_now: {all_time_now}\nincr: {std_incr}\ncur_time: {cur_time}\nlast_record_time: {last_record_time}\npast_in_session_time: {in_session_std_time}\nuser_id: {user_id}'
self.data_change_logger.info(log_msg)

async def get_info_from_leaderboard(self, sorted_set_name, start=0, end=-1):
if start < 0:
Expand Down
11 changes: 10 additions & 1 deletion utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,18 @@ def increment_studytime(category_key_names, redis_client, user_id, in_session_in
if std_incr is None:
std_incr = timedelta_to_hours(get_time() - last_time)

monthly_now = "undefined"
all_time_now = "undefined"

for i, sorted_set_name in enumerate(category_key_names):
incr = in_session_incrs[i] if i < num_intervals else std_incr
redis_client.zincrby(sorted_set_name, incr, user_id)
change = redis_client.zincrby(sorted_set_name, incr, user_id)
if i == len(category_key_names) - 2:
monthly_now = change
elif i == len(category_key_names) - 1:
all_time_now = change

return monthly_now, all_time_now


def commit_or_rollback(session):
Expand Down

0 comments on commit 75a5d06

Please sign in to comment.