repeat last data when full set not available

This commit is contained in:
Torsten 2021-07-25 19:47:29 +03:00
parent ad43cdea35
commit 4515881aea
4 changed files with 24 additions and 16 deletions

View File

@ -26,7 +26,7 @@
<div class="ct-chart chart2"></div> <div class="ct-chart chart2"></div>
</div> </div>
<div class="right"> <div class="right">
<h1> Log 1.0.1 </h1> <h1> Log 1.0.2 </h1>
<div id="log"></div> <div id="log"></div>
</div> </div>
<script > <script >

View File

@ -25,6 +25,8 @@ protected:
int week_counter = 0; int week_counter = 0;
int month_counter = 0; int month_counter = 0;
int max_week = 0;
int max_month = 0;
void add_month(int from ) ; void add_month(int from ) ;
void switch_logic(float in , float out); void switch_logic(float in , float out);

View File

@ -61,6 +61,20 @@ void Collector::add(float in , float out)
} }
} }
void Collector::add_week(float in , float out){
switch_logic(in , out);
week_in[week_counter] = in;
week_out[week_counter] = out;
if((week_counter % PER_HOUR) == 0){
add_month( week_counter - PER_HOUR);
}
if(week_counter > max_week) max_week = week_counter ;
week_counter++ ;
if(week_counter >= WEEK) {
week_counter = 0;
}
}
void Collector::switch_logic(float in , float out){ void Collector::switch_logic(float in , float out){
if(out > (in + 1.0) ){ if(out > (in + 1.0) ){
digitalWrite( RELAY_BUILTIN , HIGH); digitalWrite( RELAY_BUILTIN , HIGH);
@ -73,19 +87,6 @@ void Collector::switch_logic(float in , float out){
} }
} }
void Collector::add_week(float in , float out){
switch_logic(in , out);
week_in[week_counter] = in;
week_out[week_counter] = out;
if((week_counter % PER_HOUR) == 0){
add_month( week_counter - PER_HOUR);
}
week_counter++ ;
if(week_counter >= WEEK) {
week_counter = 0;
}
}
void Collector::add_month(int from){ void Collector::add_month(int from){
if( from < 0) return; if( from < 0) return;
if( from + PER_HOUR > WEEK) return ; if( from + PER_HOUR > WEEK) return ;
@ -97,6 +98,7 @@ void Collector::add_month(int from){
} }
month_in[month_counter] = month_i / PER_HOUR; month_in[month_counter] = month_i / PER_HOUR;
month_out[month_counter] = month_o / PER_HOUR ; month_out[month_counter] = month_o / PER_HOUR ;
if( month_counter > max_month) max_month = month_counter ;
month_counter++ ; month_counter++ ;
if(month_counter >= MONTH) { if(month_counter >= MONTH) {
month_counter = 0; month_counter = 0;
@ -106,17 +108,21 @@ void Collector::add_month(int from){
String Collector::week_data(int at){ String Collector::week_data(int at){
if( at < WEEK){ if( at < WEEK){
if( at > max_week ) at = max_week;
return String(week_in[at] , 2) ; return String(week_in[at] , 2) ;
}else{ }else{
return String(week_out[at - WEEK] , 2) ; if( at > (max_week + WEEK) ) at = max_week + WEEK;
return String(week_out[at - WEEK] , 2) ;
} }
} }
String Collector::month_data(int at){ String Collector::month_data(int at){
if( at < MONTH){ if( at < MONTH){
if(at > max_month) at = max_month ;
return String(month_in[at] , 2) ; return String(month_in[at] , 2) ;
}else{ }else{
if(at > (max_month + MONTH)) at = max_month + MONTH ;
return String(month_out[at - MONTH] , 2) ; return String(month_out[at - MONTH] , 2) ;
} }
} }

View File

@ -4,7 +4,7 @@
#include <FS.h> #include <FS.h>
static String FAN_VERSION = "1.0.1" ; static String FAN_VERSION = "1.0.2" ;
String getContentType(String filename){ String getContentType(String filename){
if(filename.indexOf(".htm") > 0) return "text/html"; if(filename.indexOf(".htm") > 0) return "text/html";