user tracking improved slightly

This commit is contained in:
Peter Howell 2025-07-24 14:20:25 -07:00
parent 0bddc4a3e4
commit e983cd5c56
1 changed files with 25 additions and 4 deletions

View File

@ -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 ],