Add weekly/monthly views for events and tool data summaries

New views:
- vwudcevents_monthly: Monthly event counts by machine/type
- vwudctooldata_weekly: Weekly tool data trends by machine/tool
- vwudctooldata_monthly: Monthly tool data trends by machine/tool

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
cproudlock
2025-12-16 10:13:49 -05:00
parent 0d0e589ea4
commit a5b4013949

View File

@@ -263,6 +263,43 @@ SELECT
FROM udcevents_daily FROM udcevents_daily
GROUP BY YEARWEEK(summarydate, 1), machinenumber, eventtype; GROUP BY YEARWEEK(summarydate, 1), machinenumber, eventtype;
-- Monthly event trends from daily summaries
CREATE OR REPLACE VIEW vwudcevents_monthly AS
SELECT
DATE_FORMAT(summarydate, '%Y-%m') as yearmonth,
machinenumber,
eventtype,
SUM(event_count) as event_count
FROM udcevents_daily
GROUP BY DATE_FORMAT(summarydate, '%Y-%m'), machinenumber, eventtype;
-- Weekly tool data trends from daily summaries
CREATE OR REPLACE VIEW vwudctooldata_weekly AS
SELECT
YEARWEEK(summarydate, 1) as yearweek,
MIN(summarydate) as week_start,
machinenumber,
toolnumber,
SUM(measurement_count) as measurement_count,
SUM(oot_count) as oot_count,
ROUND(AVG(avg_deviation), 6) as avg_deviation,
MAX(max_deviation) as max_deviation
FROM udctooldata_daily
GROUP BY YEARWEEK(summarydate, 1), machinenumber, toolnumber;
-- Monthly tool data trends from daily summaries
CREATE OR REPLACE VIEW vwudctooldata_monthly AS
SELECT
DATE_FORMAT(summarydate, '%Y-%m') as yearmonth,
machinenumber,
toolnumber,
SUM(measurement_count) as measurement_count,
SUM(oot_count) as oot_count,
ROUND(AVG(avg_deviation), 6) as avg_deviation,
MAX(max_deviation) as max_deviation
FROM udctooldata_daily
GROUP BY DATE_FORMAT(summarydate, '%Y-%m'), machinenumber, toolnumber;
-- ============================================================================ -- ============================================================================
-- Usage Instructions -- Usage Instructions
-- ============================================================================ -- ============================================================================