/
timchenko.ai
/
adaptive-learning-path-advisor
Обзор
Документация
Войти
/
timchenko.ai
/
adaptive-learning-path-advisor
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/behavior_analyzer.py
34 строки
1 KB
unknown
fix: add missing docstrings and update flake8 config
28 дек 2025, 20:49
28 дек 2025, 20:49
f8d4bcf
Код
Авторство
О чём код?
"""Module for analyzing behavioral patterns in learning activity.""" import pandas as pd from datetime import timedelta def detect_procrastination(df: pd.DataFrame, deadline: str = "2025-12-10") -> bool: """Detect activity within 24h before deadline.""" deadline_dt = pd.to_datetime(deadline) window_start = deadline_dt - timedelta(hours=24) recent = df[ (df["timestamp"] >= window_start) & (df["timestamp"] <= deadline_dt) & (df["event_type"].isin(["assignment_submit", "quiz_attempt"])) ] return len(recent) > 0 def detect_repeated_views(df: pd.DataFrame) -> int: """Count resources viewed by a user more than once.""" views = df[df["event_type"] == "view"] if views.empty: return 0 repeated = views.groupby(["user_id", "resource"]).size() return len(repeated[repeated > 1]) def get_activity_by_hour(df: pd.DataFrame) -> int: """Return the hour (0-23) with the highest activity.""" if df.empty: return -1 df = df.copy() df["hour"] = df["timestamp"].dt.hour hour_counts = df["hour"].value_counts() return int(hour_counts.idxmax())