--splits the days into before and after.
.open ramdisk/aiox.db
.echo on
select load_extension('libsqlitefunctions.so');  --rpi

.mode column

select time(max(dt))t from ir;
-- *************************************************************************
-- *1.All days 
select min(dt), max(dt), max(gridvolt), floor(avg(Ppv1))PV, floor(avg(ACChr_Watt))UTL, floor(avg(OP_Watt - (AC_InWatt - ACChr_Watt))) dc2ac, count() from ir ;
--
-- *1.1  Time-of-Day
select t, date(dt)day, floor(avg(Ppv1))PV, floor(avg(ACChr_Watt))UTL, floor(avg(OP_Watt - (AC_InWatt - ACChr_Watt))) dc2ac, count() from ir, (select time(max(dt))t from ir) as t where time(dt) < t ;
--
-- *1.2  Time-of-Day
select t, date(dt)day, floor(avg(Ppv1))PV, floor(avg(ACChr_Watt))UTL, floor(avg(OP_Watt - (AC_InWatt - ACChr_Watt))) dc2ac, count() from ir, (select time(max(dt))t from ir) as t where time(dt) > t ;

-- *************************************************************************
-- *2. Daily
select date(dt)day, max(gridvolt), floor(avg(Ppv1))PV, floor(avg(ACChr_Watt))UTL, floor(avg(OP_Watt - (AC_InWatt - ACChr_Watt))) dc2ac, count() from ir group by day;
--
-- **2.1 Time-of-Day
select t, date(dt)day, floor(avg(Ppv1))PV, floor(avg(ACChr_Watt))UTL, floor(avg(OP_Watt - (AC_InWatt - ACChr_Watt))) dc2ac, count() from ir, (select time(max(dt))t from ir) as t where time(dt) < t group by day;
--
-- **2.2 Time-of-Day
select t, date(dt)day, floor(avg(Ppv1))PV, floor(avg(ACChr_Watt))UTL, floor(avg(OP_Watt - (AC_InWatt - ACChr_Watt))) dc2ac, count() from ir, (select time(max(dt))t from ir) as t where time(dt) > t group by day;

-- *************************************************************************

