diff --git a/modules/shell/scripts/meetings_made.py b/modules/shell/scripts/meetings_made.py new file mode 100755 index 00000000..c5b6b591 --- /dev/null +++ b/modules/shell/scripts/meetings_made.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +"""Meetings made for measuring the search (D127, criterion 2): COUNT folders of MINUTES each, as Kitokey writes +them — `session.json`, a whole `transcript.jsonl` of a line every few seconds, a `minutes.md` of `minutes/v4` —, +nothing of a real meeting. The same seed makes the same meetings, so two runs measure the same files. + +Words placed for the measure, each in known meetings and nowhere else: +- « devis » said in three transcripts (the 8th, the 251st and the 494th meetings), late in each: a rare word; +- « budget » in every summary: a word found everywhere; +- « zzqx », nowhere: every file read, nothing found. + +Usage: meetings_made.py FOLDER [--count 500] [--minutes 60] [--seed 127] +""" + +import argparse +import datetime as dt +import json +import random +from pathlib import Path + +# Words of a work meeting, none of the placed ones. +WORDS = ( + "projet équipe client semaine planning livraison réunion point suivi retour produit version fonction écran " + "utilisateur test bug correctif priorité sprint objectif chiffre vente marché contrat fournisseur délai date " + "lundi mardi mercredi jeudi vendredi matin soir demain hier rapport document présentation question réponse " + "idée proposition décision action tâche responsable groupe service support serveur données sécurité accès " + "compte facture paiement commande stock prix coût marge partenaire réseau formation recrutement poste" +).split() +PLACED = {7: "devis", 250: "devis", 493: "devis"} + + +def sentence(chance: random.Random) -> str: + words = [chance.choice(WORDS) for _ in range(chance.randint(6, 16))] + return (" ".join(words) + ".").capitalize() + + +def meeting(folder: Path, at: int, started: dt.datetime, minutes: int, chance: random.Random) -> None: + folder.mkdir(parents=True) + stopped = started + dt.timedelta(minutes=minutes) + (folder / "session.json").write_text(json.dumps({ + "contract": "session-audio/v2", "started": started.isoformat(timespec="seconds"), + "stopped": stopped.isoformat(timespec="seconds"), "tracks": {}})) + lines = [{"type": "header", "contract": "transcript/v1", "engine": "whisper.cpp", "model": "ggml-large-v3-turbo-q8_0", + "language": "fr", "context": None}] + start, end_of_meeting = 0.0, minutes * 60.0 + while start < end_of_meeting - 5: + length = round(chance.uniform(2.0, 6.0), 1) + # As `transcript/v1` has it: `me` heard on `local`, `others` on `remote` — any other line the shell skips. + speaker = chance.choice(["me", "others"]) + lines.append({"type": "segment", "speaker": speaker, "track": "local" if speaker == "me" else "remote", + "voice": None, "start": round(start, 1), "end": round(start + length, 1), "text": sentence(chance)}) + start += length + round(chance.uniform(0.2, 1.5), 1) + if at in PLACED: + # Late in the meeting: a scan that stops at the first hit reads nearly all of it. + lines[-3]["text"] = f"On renvoie le {PLACED[at]} vendredi, signé." + lines.append({"type": "complete", "duration": end_of_meeting}) + (folder / "transcript.jsonl").write_text("".join(json.dumps(line, ensure_ascii=False) + "\n" for line in lines)) + made = stopped + dt.timedelta(minutes=3) + (folder / "minutes.md").write_text( + f"---\ncontract: minutes/v4\nmade: {made.isoformat(timespec='seconds')}\nprovider: local\nmodel: qwen3:8b\n" + f"context: null\ntitle: {json.dumps(f'Point {at + 1}')}\n---\n\n" + f"## Points saillants\n\nLe budget est revu. {sentence(chance)}\n\n" + f"## Actions\n\n" + "".join(f"- {sentence(chance)}\n" for _ in range(4)) + + "\n## Points clés\n\n" + "".join(f"- {sentence(chance)}\n" for _ in range(4))) + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument("folder", type=Path) + parser.add_argument("--count", type=int, default=500) + parser.add_argument("--minutes", type=int, default=60) + parser.add_argument("--seed", type=int, default=127) + asked = parser.parse_args() + if asked.folder.exists() and any(asked.folder.iterdir()): + raise SystemExit(f"{asked.folder} is not empty: the meetings are made in an empty folder") + chance = random.Random(asked.seed) + first = dt.datetime(2026, 1, 5, 9, 0, tzinfo=dt.timezone(dt.timedelta(hours=1))) + for at in range(asked.count): + started = first + dt.timedelta(hours=8 * at) + meeting(asked.folder / started.strftime("%Y-%m-%d_%H-%M"), at, started, asked.minutes, chance) + + +if __name__ == "__main__": + main() diff --git a/modules/shell/tests/search_speed.rs b/modules/shell/tests/search_speed.rs new file mode 100644 index 00000000..806dfd9c --- /dev/null +++ b/modules/shell/tests/search_speed.rs @@ -0,0 +1,81 @@ +//! How long the search takes on a set of meetings (D127, criterion 2): what `searched` does for one word typed — +//! the list read, then every summary and transcript sought —, the median of ten runs for each placed word of +//! `scripts/meetings_made.py`. Ignored by default: it needs the set, made first, and measures, it judges nothing. +//! +//! `scripts/meetings_made.py `, then +//! `KITOKEY_SEARCH_SET= cargo test --release --test search_speed -- --ignored --nocapture`. + +use std::time::{Duration, Instant}; + +use kitokey_shell::{search, sessions}; + +#[test] +#[ignore = "a measure, on a set made by scripts/meetings_made.py"] +fn the_search_on_a_set_of_meetings_timed() { + let set = std::env::var("KITOKEY_SEARCH_SET").expect("KITOKEY_SEARCH_SET names the set"); + let set = std::path::Path::new(&set); + let mut listing: Vec = (0..10) + .map(|_| { + let started = Instant::now(); + sessions::list(set, None); + started.elapsed() + }) + .collect(); + listing.sort(); + println!("SPEED the list alone: median {:.1} ms", listing[5].as_secs_f64() * 1e3); + for word in ["devis", "budget", "zzqx"] { + let mut took: Vec = Vec::new(); + let mut found = (0, 0, 0); + for _ in 0..10 { + let started = Instant::now(); + let listed = sessions::list(set, None); + let hits = search::found(&listed, word, &|| true).expect("never replaced"); + took.push(started.elapsed()); + found = (hits.titles.len(), hits.minutes.len(), hits.transcripts.len()); + } + took.sort(); + println!( + "SPEED {word}: median {:.1} ms, min {:.1} ms, max {:.1} ms; found titles {}, summaries {}, transcripts {}", + took[5].as_secs_f64() * 1e3, + took[0].as_secs_f64() * 1e3, + took[9].as_secs_f64() * 1e3, + found.0, + found.1, + found.2 + ); + } +} + +#[test] +fn the_meetings_made_are_read_whole_by_the_shell_and_hold_their_placed_words() { + // The set measures what the shell reads: every transcript must be one it reads whole — each segment as + // `transcript/v1` has it, `me` on `local`, `others` on `remote` —, or the search skips lines and is timed on less + // than an hour (2026-12-01: `them`, and tracks drawn apart from speakers, left 3 lines in 4 unread). + let set = tempfile::tempdir().unwrap(); + let script = concat!(env!("CARGO_MANIFEST_DIR"), "/scripts/meetings_made.py"); + let Ok(made) = std::process::Command::new("python3") + .args(["-I", script]) + .arg(set.path()) + .args(["--count", "8", "--minutes", "5"]) + .output() + else { + assert!(std::env::var_os("CI").is_none(), "python3 is not there on this CI runner"); + eprintln!("python3 is not there: the meetings made are not checked"); + return; + }; + assert!(made.status.success(), "{}", String::from_utf8_lossy(&made.stderr)); + let listed = sessions::list(set.path(), None); + assert_eq!(listed.len(), 8); + for session in &listed { + let written = std::fs::read_to_string(session.folder.join("transcript.jsonl")).unwrap(); + let segments = written.lines().filter(|line| line.contains(r#""type": "segment""#)).count(); + let kitokey_shell::meeting::Read::Present(read) = kitokey_shell::meeting::transcript(&session.folder) else { + panic!("{} not read", session.folder.display()); + }; + assert!(segments > 40, "five minutes of lines: {segments}"); + assert_eq!(read.segments.len(), segments, "every line read, {}", session.folder.display()); + } + let devis = search::found(&listed, "devis", &|| true).unwrap(); + assert_eq!(devis.transcripts.len(), 1, "« devis » in the 8th meeting's transcript: {devis:?}"); + assert_eq!(search::found(&listed, "budget", &|| true).unwrap().minutes.len(), 8); +}