Skip to content

Commit

Permalink
ci/eval: fix stats table
Browse files Browse the repository at this point in the history
  • Loading branch information
paparodeo committed Dec 9, 2024
1 parent d95b9cc commit 1d51c73
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions ci/eval/stats.sql
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
CREATE VIEW before AS FROM read_json('data/before-stats.json', map_inference_threshold=-1);
CREATE VIEW after AS FROM read_json('data/after-stats.json', map_inference_threshold=-1);

CREATE MACRO aggregate(tbl) AS TABLE SELECT sum(COLUMNS(*)) FROM query_table(tbl);
CREATE MACRO aggregate(tbl) AS TABLE
SELECT sum(COLUMNS(*)) FROM query_table(tbl);

CREATE MACRO arrow(i) AS
CREATE MACRO trimFract(x) AS
CASE
WHEN i > 0 THEN format('↗ {:t,}', i::int)
WHEN i < 0 THEN format('↘ {:t,}', -i::int)
WHEN x = round(x) THEN format('{:,}', x::bigint)
ELSE format('{:,.2f}', round(x, 2))
END;

CREATE MACRO arrow(x) AS
CASE
WHEN x > 0 THEN format('↗ {}', trimFract(x))
WHEN x < 0 THEN format('↘ {}', trimFract(-x))
ELSE ''
END;

CREATE MACRO pct(x) AS
CASE
WHEN round(x * 100, 2) = 0 then ''
ELSE format('{:.2f}', round(x * 100, 2))
END;

CREATE TABLE stats AS
SELECT
name AS stat,
format('{:,}', b.value) AS before,
format('{:,}', a.value) AS after,
b.value.trimFract() AS before,
a.value.trimFract() AS after,
(a.value - b.value).arrow() AS "Δ",
((1 - b.value/a.value) * 100)::DECIMAL(15,2) AS "Δ%",
(a.value/b.value - 1).pct() AS "Δ%",
FROM (UNPIVOT (from aggregate(before)) ON *) as b
JOIN (UNPIVOT (from aggregate(after)) ON *) as a USING(name);

Expand Down

0 comments on commit 1d51c73

Please sign in to comment.