From e983cd5c56946daa8d744c08ab7a7a93572c4555 Mon Sep 17 00:00:00 2001 From: Peter Howell Date: Thu, 24 Jul 2025 14:20:25 -0700 Subject: [PATCH] user tracking improved slightly --- users.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/users.py b/users.py index 3c996b1..d7ffd63 100644 --- a/users.py +++ b/users.py @@ -6,6 +6,8 @@ import pytz, time import pandas as pd import matplotlib.pyplot as plt + + #from pandas import TimeGrouper from PIL import Image from collections import defaultdict @@ -51,7 +53,7 @@ lds_stamp = parser.parse(log_default_startdate) recvd_date = '2023-01-01T00:00:00Z' num_threads = 25 -max_log_count = 250000 +max_log_count = 500000 ########## @@ -1763,6 +1765,23 @@ def track_user_q(id, q): q.task_done() + +def count_courses(csv_file="cache/users/logs/45268.csv"): + course_counts = defaultdict(int) + course_regex = r'courses/(\d+)/' + + with open(csv_file, mode='r') as file: + reader = csv.reader(file) + for row in reader: + match = re.search(course_regex, row[1]) + if match: + course_id = match.group(1) + course_counts[course_id] += 1 + + for course_id, count in course_counts.items(): + print(f"Course ID {course_id}: {count} occurrences") + + # honestly it doesn't make much sense to get full histories this way if they're # already in the canvas data tables.... @@ -1801,8 +1820,9 @@ def track_user(id=0,qid=0): url_addition = "" if 1: # hard code dates - start_date = "2024-01-01T00:00:00-07:00" - end_date = dt.now().strftime("%Y-%m-%dT%H:%M:%S-07:00") # "2024-10-01T00:00:00-07:00" + start_date = "2022-01-01T00:00:00-07:00" + end_date = dt.now().strftime("%Y-%m-%dT%H:%M:%S-07:00") # + end_date = "2022-07-01T00:00:00-07:00" url_addition = f"?start_time={start_date}&end_time={end_date}" elif 'last_days_log' in info: print("There's existing log data for %s (%s)" % (info['name'] , info['sis_user_id'])) @@ -2639,7 +2659,8 @@ if __name__ == "__main__": 8: ['Gather teacher history, a variety of stats.', getTeachersInfoMain], 9: ['test rtr.', read_training_records], 10: ['Get a users logs', track_user], - 11: ['test: oneYearSchedule', oneYearSchedule], + 11: ['tally a users logs from csv file', count_courses], + #11: ['test: oneYearSchedule', oneYearSchedule], 12: ['summarize hit activity', activity_summary], 13: ['Get all users logs in a class', track_users_in_class], 14: ['Get logs for 1 user', track_a_user ],