A Nix-friendly SQLite-enhanced fork of Flitter, a speedrunning split timer for Unix-style terminals
Revisão | 442635013a88c060ff0fd919ce7ae048b4a7b418 (tree) |
---|---|
Hora | 2023-05-26 03:11:22 |
Autor | Corbin <cds@corb...> |
Commiter | Corbin |
Finish hacking on summary tool.
All of the queries seem to report accurate data. Summation of segments
across categories is working; if you run a game that branches into many
categories, then statistics are accumulated across all categories.
@@ -14,6 +14,8 @@ let add_stdev db = | ||
14 | 14 | ~step:(fun w d -> Welford.observe w (Data.to_int_exn d)) |
15 | 15 | ~final:(fun w -> Data.FLOAT (Welford.stddev w)) |
16 | 16 | |
17 | +let duration_of_float f = Duration.to_string (int_of_float f) 3 | |
18 | + | |
17 | 19 | let () = |
18 | 20 | match Sys.get_argv () with |
19 | 21 | | [| _; db_path |] -> |
@@ -33,25 +35,24 @@ let () = | ||
33 | 35 | (Data.to_string_exn row.(1)) |
34 | 36 | (Duration.to_string (Data.to_int_exn row.(3)) 3) |
35 | 37 | (Data.to_int_exn row.(2)) |
36 | - (Duration.to_string | |
37 | - (int_of_float (Data.to_float_exn row.(4))) | |
38 | - 3) | |
39 | - (Duration.to_string | |
40 | - (int_of_float (Data.to_float_exn row.(5))) | |
41 | - 3)))) | |
38 | + (duration_of_float (Data.to_float_exn row.(4))) | |
39 | + (duration_of_float (Data.to_float_exn row.(5)))))) | |
42 | 40 | | [| _; db_path; game; category |] -> |
43 | 41 | Storage.with_db db_path (fun db -> |
44 | 42 | add_stdev db; |
45 | 43 | let vals = [ Data.TEXT game; Data.TEXT category ] in |
46 | 44 | let stmt = |
47 | 45 | prepare db |
48 | - "with path(end, i) as (select starting_at, 0 from routes where \ | |
49 | - game = ?1 and category = ?2 union select ending_at, path.i + 1 \ | |
50 | - from segments, path where game = ?1 and category = ?2 and \ | |
46 | + "with path(start, end, i) as (select segments.starting_at, \ | |
47 | + segments.ending_at, 0 from segments, routes where routes.game = \ | |
48 | + ?1 and routes.category = ?2 and segments.starting_at = \ | |
49 | + routes.starting_at union select starting_at, ending_at, path.i \ | |
50 | + + 1 from segments, path where game = ?1 and category = ?2 and \ | |
51 | 51 | starting_at = path.end) select starting_at, ending_at, \ |
52 | 52 | min(duration), avg(duration), stdev(duration) from path, \ |
53 | - segments where game = ?1 and category = ?2 and ending_at = \ | |
54 | - path.end group by starting_at, ending_at order by path.i;" | |
53 | + segments where game = ?1 and starting_at = path.start and \ | |
54 | + ending_at = path.end group by starting_at, ending_at order by \ | |
55 | + path.i;" | |
55 | 56 | in |
56 | 57 | check_select stmt vals (fun row -> |
57 | 58 | print_string |
@@ -59,12 +60,8 @@ let () = | ||
59 | 60 | (Data.to_string_exn row.(0)) |
60 | 61 | (Data.to_string_exn row.(1)) |
61 | 62 | (Duration.to_string (Data.to_int_exn row.(2)) 3) |
62 | - (Duration.to_string | |
63 | - (int_of_float (Data.to_float_exn row.(3))) | |
64 | - 3) | |
65 | - (Duration.to_string | |
66 | - (int_of_float (Data.to_float_exn row.(4))) | |
67 | - 3)))) | |
63 | + (duration_of_float (Data.to_float_exn row.(3))) | |
64 | + (duration_of_float (Data.to_float_exn row.(4)))))) | |
68 | 65 | | [| _; db_path; game; category; attempt |] -> |
69 | 66 | Storage.with_db db_path (fun db -> |
70 | 67 | let vals = |
@@ -75,13 +72,17 @@ let () = | ||
75 | 72 | ] |
76 | 73 | in |
77 | 74 | let stmt = |
75 | + (* XXX SELECT DISTINCT required because path sometimes repeats i *) | |
78 | 76 | prepare db |
79 | - "with path(end, i) as (select 'New Game', 0 union select \ | |
80 | - ending_at, path.i + 1 from segments, path where game = ?1 and \ | |
81 | - category = ?2 and attempt = ?3 and starting_at = path.end) \ | |
82 | - select starting_at, ending_at, duration from path, segments \ | |
83 | - where game = ?1 and category = ?2 and attempt = ?3 and \ | |
84 | - ending_at = path.end order by path.i;" | |
77 | + "with path(start, end, i) as (select segments.starting_at, \ | |
78 | + segments.ending_at, 0 from segments, routes where routes.game = \ | |
79 | + ?1 and routes.category = ?2 and segments.starting_at = \ | |
80 | + routes.starting_at union select starting_at, ending_at, path.i \ | |
81 | + + 1 from segments, path where game = ?1 and category = ?2 and \ | |
82 | + attempt = ?3 and starting_at = path.end) select distinct \ | |
83 | + starting_at, ending_at, duration from path, segments where game \ | |
84 | + = ?1 and category = ?2 and attempt = ?3 and starting_at = \ | |
85 | + path.start and ending_at = path.end order by path.i;" | |
85 | 86 | in |
86 | 87 | check_select stmt vals (fun row -> |
87 | 88 | print_string |