.open ramdisk/aiox.db

drop table if exists temp.calkwhs; create table temp.calkwhs as select max(dt) dt from ir  group by date(dt) ;
select rowid, * from temp.calkwhs;

drop table if exists temp.irdb; create table temp.irdb as  select date(dt)dt, Epv1_total solar, Ebat_dischrTotal as discharged, Epv1_total + Eac_chrTotal as charged, Eac_chrTotal + Eac_dischrTotal as grid, Eop_dischrTotal as load from ir, temp.calkwhs using(dt) order by dt ;
select rowid, * from temp.irdb;

--daily
select b.dt, round(b.solar-a.solar,1)solar, round(b.discharged-a.discharged,1)discharged, round(b.charged-a.charged,1)charged, round(b.grid-a.grid,1)grid, round(b.load-a.load,1)load from temp.irdb b, temp.irdb a   where a.dt = date(b.dt,'-1 day') order by b.dt  ;


