From 592ab39ba57e3d659cfc70c75f900bec1b42fd1e Mon Sep 17 00:00:00 2001 From: Tom Amberson Date: Wed, 21 Feb 2024 16:55:30 -0600 Subject: [PATCH 1/3] Pull review sum calculation out into function --- src/overview.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/overview.py b/src/overview.py index d630721..8ef6df6 100644 --- a/src/overview.py +++ b/src/overview.py @@ -842,6 +842,15 @@ def _update_string_time(repl: str, revlog: list = None): f'{_formatted_time(total_hrs, precision, addon_config[Config.USE_DECIMAL])} {cell_data[unit_key]}' ) + def _reviews_in_revlog(repl: str, revlog: list = None): + if revlog is None: + return 0 + + card_states = _states(repl) + filtered_logs = _logs_with_states(revlog, card_states) if card_states else revlog + + return len(filtered_logs) + def _update_string_reviews(repl: str, revlog: list = None): nonlocal updated_string @@ -849,10 +858,7 @@ def _update_string_reviews(repl: str, revlog: list = None): updated_string = re.sub(fr'(? Date: Wed, 21 Feb 2024 16:57:23 -0600 Subject: [PATCH 2/3] Add macro for the average reviews per day see https://github.com/iamjustkoi/StudyTimeStats/issues/51 --- src/consts.py | 3 +++ src/overview.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/consts.py b/src/consts.py index 93fbc9d..e2a9a26 100644 --- a/src/consts.py +++ b/src/consts.py @@ -119,6 +119,7 @@ class Macro: # Avg CMD_CARD_AVERAGE_HOURS = '%card_avg_hrs' CMD_DAY_AVERAGE_HOURS = '%day_avg_hrs' + CMD_DAY_AVERAGE_REVIEWS = '%day_avg_rev' # Previous Time CMD_PREVIOUS_RANGE_HOURS = '%prev_range_hrs' @@ -216,6 +217,8 @@ class Macro: '''average study time per card for the current range''', CMD_DAY_AVERAGE_HOURS: '''average study time per day for the current range''', + CMD_DAY_AVERAGE_REVIEWS: + '''average reviews per day for the current range''', # Previous Time CMD_PREVIOUS_RANGE_HOURS: diff --git a/src/overview.py b/src/overview.py index 8ef6df6..14991d3 100644 --- a/src/overview.py +++ b/src/overview.py @@ -436,6 +436,20 @@ def _total_due_in_tree(tree: DeckTreeNode): f'{cell_data[unit_key]}', ) + cmd = Macro.CMD_DAY_AVERAGE_REVIEWS + pattern = _time_pattern(cmd) + for match in re.findall(pattern, updated_string): + logs = _cached_log( + _cache_key(cmd, cell_data[Config.RANGE]), + addon_config[Config.EXCLUDED_DIDS], + _range_time_ms(), + ) + from_date = datetime.fromtimestamp(_range_time_ms()[0] / 1000) + to_date = datetime.fromtimestamp(_range_time_ms()[1] / 1000) + days_in_logs = (to_date - from_date).days + avg_revs = _reviews_in_revlog(match, logs) / (days_in_logs if days_in_logs > 0 else 1) + _sub_text(match, str(round(avg_revs))) + cmd = Macro.CMD_CARD_AVERAGE_HOURS pattern = _time_pattern(cmd) for match in re.findall(pattern, updated_string): From d56226acf19175361a0e12303e974939de38f210 Mon Sep 17 00:00:00 2001 From: Tom Amberson Date: Wed, 21 Feb 2024 16:57:49 -0600 Subject: [PATCH 3/3] Add macro for the average reviews per card --- src/consts.py | 3 +++ src/overview.py | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/consts.py b/src/consts.py index e2a9a26..3cdbeed 100644 --- a/src/consts.py +++ b/src/consts.py @@ -118,6 +118,7 @@ class Macro: # Avg CMD_CARD_AVERAGE_HOURS = '%card_avg_hrs' + CMD_CARD_AVERAGE_REVIEWS = '%card_avg_rev' CMD_DAY_AVERAGE_HOURS = '%day_avg_hrs' CMD_DAY_AVERAGE_REVIEWS = '%day_avg_rev' @@ -215,6 +216,8 @@ class Macro: # Avg CMD_CARD_AVERAGE_HOURS: '''average study time per card for the current range''', + CMD_CARD_AVERAGE_REVIEWS: + '''average reviews per card for the current range''', CMD_DAY_AVERAGE_HOURS: '''average study time per day for the current range''', CMD_DAY_AVERAGE_REVIEWS: diff --git a/src/overview.py b/src/overview.py index 14991d3..35b8ff5 100644 --- a/src/overview.py +++ b/src/overview.py @@ -363,6 +363,9 @@ def time_macros(): def _avg_hrs_per_card(in_logs): return (_total_hrs_in_revlog(in_logs) / len(in_logs)) if len(in_logs) > 0 else 0 + def _avg_reviews_per_card(in_logs): + return (_reviews_in_revlog(in_logs) / len(in_logs)) if len(in_logs) > 0 else 0 + cmd = Macro.CMD_ETA_HOURS pattern = _time_pattern(cmd) for match in re.findall(pattern, updated_string): @@ -463,6 +466,14 @@ def _total_due_in_tree(tree: DeckTreeNode): f'{cell_data[unit_key]}', ) + cmd = Macro.CMD_CARD_AVERAGE_REVIEWS + pattern = _time_pattern(cmd) + for match in re.findall(pattern, updated_string): + logs = _cached_log(cmd, addon_config[Config.EXCLUDED_DIDS], _range_time_ms()) + avg_revs = _avg_reviews_per_card(logs) + + _sub_text(match, str(round(avg_revs))) + cmd = Macro.CMD_HIGHEST_DAY_HOURS pattern = _time_pattern(cmd) for match in re.findall(pattern, updated_string):