aboutsummaryrefslogtreecommitdiff
path: root/scripts/course-insights.py
diff options
context:
space:
mode:
authorAgando <roduccomm@gmail.com>2026-10-18 14:32:57 +0200
committerAgando <roduccomm@gmail.com>2026-10-18 14:32:57 +0200
commit908ef962163b23c9997cbb86ec8a2247f3e9028d (patch)
tree5da45d8ca147cb041e9fc13e29d04b7cf552971a /scripts/course-insights.py
parent3e394a86f2d4eb8b94700c6b033c77f639bd592e (diff)
course: exclude auto-open from lesson_open telemetry, add session counts, filter synthetic sids
Diffstat (limited to 'scripts/course-insights.py')
-rw-r--r--scripts/course-insights.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/scripts/course-insights.py b/scripts/course-insights.py
index 0ee891e..299b264 100644
--- a/scripts/course-insights.py
+++ b/scripts/course-insights.py
@@ -14,21 +14,23 @@ def norm_q(q):
def main():
opens, completes, fails, cmds, questions = Counter(), Counter(), Counter(), Counter(), Counter()
- projects = Counter()
+ projects = Counter(); sids = set()
files = sorted(glob.glob(os.path.join(DATA, 'events-*.jsonl')))[-2:]
for path in files:
with open(path, encoding='utf-8', errors='ignore') as f:
for line in f:
try: e = json.loads(line)
except Exception: continue
+ if (e.get('sid') or '').startswith('test'): continue
t, d = e.get('type'), e.get('detail') or {}
lesson = (d.get('lesson') or '')[:40]
- if t == 'lesson_open' and lesson: opens[lesson] += 1
- elif t == 'lesson_complete' and lesson: completes[lesson] += 1
+ if t == 'lesson_open' and lesson: opens[lesson] += 1; sids.add(e.get('sid') or '')
+ elif t == 'lesson_complete' and lesson: completes[lesson] += 1; sids.add(e.get('sid') or '')
elif t == 'exercise_fail':
if lesson: fails[lesson] += 1
c = (d.get('command') or '').strip().split(' ')[0][:40]
if c: cmds[c] += 1
+ sids.add(e.get('sid') or '')
elif t == 'question':
q = norm_q(d.get('q'))
if len(q) >= 8: questions[q] += 1
@@ -46,7 +48,7 @@ def main():
'top_failed_commands': [{'cmd': c, 'n': n} for c, n in cmds.most_common(20)],
'top_questions': [{'q': q, 'n': n} for q, n in questions.most_common(20) if n >= 2],
'projects': dict(projects),
- 'totals': {'opens': sum(opens.values()), 'completes': sum(completes.values()), 'failures': sum(fails.values())}}
+ 'totals': {'sessions': len(sids), 'opens': sum(opens.values()), 'completes': sum(completes.values()), 'failures': sum(fails.values())}}
os.makedirs(os.path.dirname(OUT), exist_ok=True)
tmp = OUT + '.tmp'
with open(tmp, 'w', encoding='utf-8') as f: json.dump(payload, f, ensure_ascii=False, indent=1)