
--ACInModels BatteryTypes ChargeConfigs OutputConfigs S
drop view if exists hrv1;
create view hrv1 as 
select dt, hr.ACInModelId, ACInModel, hr.BatteryTypeId, BatteryType, hr.ChargeConfigId, ChargeConfig, hr.OutputConfigId, OutputConfig 
from hr
  left join ACInModels          a ON hr.ACInModelId         =  a.ACInModelId
  left join BatteryTypes        b ON hr.BatteryTypeId       =  b.BatteryTypeId
  left join ChargeConfigs       c ON  hr.ChargeConfigId      =  c.ChargeConfigId
  left join OutputConfigs       o ON  hr.OutputConfigId      =  o.OutputConfigId
;
--fixit: rename the column SystemStatus in table ir to SystemStatusId to match the key column in table SystemStatuses
drop view if exists irv1;
create view irv1 as
select dt, ir.SystemStatusId, SystemStatus  from ir  
left join SystemStatuses   s ON  ir.systemStatusId  =  s.SystemStatusId
;

--drop view if exists period13hrs;
--CREATE VIEW if not exists periodhrs13 as select * from ir where dt >= (select datetime(max(dt), '-13 hour') from ir) order by dt;
drop view if exists period25hrs;
CREATE VIEW if not exists period25hrs as select * from ir where dt >= (select datetime(max(dt), '-25 hour') from ir) order by dt;
--CREATE VIEW if not exists period25hrs as select * from ram.ir UNION select * from ssd.ir where dt >= (select datetime(max(dt), '-25 hour') from ram.ir) order by dt;
drop view if exists period49hrs;
CREATE VIEW if not exists period49hrs as select * from ir where dt >= (select datetime(max(dt), '-49 hour') from ir) order by dt;
--CREATE VIEW if not exists period49hrs as select * from ram.ir UNION select * from ssd.ir where dt >= (select datetime(max(dt), '-49 hour') from ram.ir) order by dt;
drop view if exists period97hrs;
CREATE VIEW if not exists period97hrs as select * from ir where dt >= (select datetime(max(dt), '-97 hour') from ir) order by dt;
--CREATE VIEW if not exists period97hrs as select * from ram.ir UNION select * from ssd.ir where dt >= (select datetime(max(dt), '-97 hour') from ram.ir) order by dt;
--
drop view if exists period193hrs;
CREATE VIEW if not exists period193hrs as select * from ir where dt >= (select datetime(max(dt), '-193 hour') from ir) order by dt;

drop view if exists interval10min;
CREATE VIEW if not exists interval10min as select * from ir where substr(datetime(dt),16,1) = '0' order by dt;

drop view if exists interval12min;
CREATE VIEW if not exists interval12min as select * from ir where substr(datetime(dt),16,1) = '0' order by dt;
