From f1b360a9a751d5dc6cddebe62c0bdf590ab840ee Mon Sep 17 00:00:00 2001 From: Tomasz Brzezina Date: Fri, 17 Oct 2014 11:35:50 +0200 Subject: [PATCH 1/7] Changes for multiple cm160 devices - not working now, because of segfault --- src/cm160.c | 68 +++++++++++++++++++++++-------- src/cm160.h | 3 +- src/db.c | 59 +++++++++++++-------------- src/db.h | 2 +- src/sql_cmd.h | 106 ++++++++++++++++++++++++++++++++++-------------- src/usb_utils.c | 44 ++++++++++---------- src/usb_utils.h | 2 +- 7 files changed, 178 insertions(+), 106 deletions(-) diff --git a/src/cm160.c b/src/cm160.c index 1987478..756daa4 100644 --- a/src/cm160.c +++ b/src/cm160.c @@ -20,6 +20,8 @@ */ #include +#include +#include #include #include #include @@ -54,7 +56,7 @@ static char WAIT_MSG[11] = { #define UART_ENABLE 0x0001 #define UART_DISABLE 0x0000 -struct cm160_device g_devices[MAX_DEVICES]; +struct cm160_device g_devices[]; static unsigned char history[HISTORY_SIZE][11]; static void process_live_data(struct record_data *rec) @@ -70,8 +72,9 @@ static void process_live_data(struct record_data *rec) } else _watts = w; - - FILE *fp = fopen(".live", "w"); + char filename[255]; + sprintf(filename,".%d.live",rec->addr); + FILE *fp = fopen(filename, "w"); if(fp && rec->hour!=255) // to avoid writing strange values (i.e. date 2255, hour 255:255) that sometimes I got { fprintf(fp, "%02d/%02d/%04d %02d:%02d - %.02f kW\n", @@ -83,7 +86,7 @@ static void process_live_data(struct record_data *rec) static void decode_frame(unsigned char *frame, struct record_data *rec) { int volt = 230; // TODO: use the value from energy_param table (supply_voltage) - rec->addr = 0; // TODO: don't use an harcoded addr value for the device... + rec->addr = g_devices[0].serial_no; rec->year = frame[1]+2000; rec->month = frame[2]; rec->day = frame[3]; @@ -314,31 +317,60 @@ static int handle_device(int dev_id) int main(int argc, char **argv) { + int opt = 0; + char serial[255]=""; + char *serialPtr; + int index; + serialPtr = serial; int dev_cnt; - if(argc>1 && (strcmp(argv[1], "-d")==0) ) - demonize(argv[0]); - while(1) - { + while ((opt = getopt(argc,argv, "ds:")) != -1) { + switch(opt) { + case 's': + strcpy(serialPtr,optarg); + break; + case 'd': + demonize(argv[0]); + break; + case '?': + if (optopt == 's') { + fprintf(stderr, "Option -%c requires an argument.\n", optopt); + } else if (isprint(optopt)) { + fprintf(stderr, "Unknown option '-%c'.\n", optopt); + } else { + printf("\nUnknown option character '\\x%x'.\n:", optopt); + } + break; + default: + abort(); + } + } + for (index = optind; index < argc; index++) + printf ("Non-option argument %s\n", argv[index]); + + while(1) { db_open(); dev_cnt = 0; receive_history = true; frame_id = 0; printf("Wait for cm160 device to be connected\n"); - while((dev_cnt = scan_usb()) == 0) + while((dev_cnt = scan_usb(serialPtr)) == 0) sleep(2); - printf("Found %d compatible device%s\n", dev_cnt, dev_cnt>1?"s":""); + if (dev_cnt>1) { + printf("Found %d compatible devices.\nUse -s option.\n", dev_cnt); + break; + } else { + printf("Found 1 compatible device.\nStarting....\n"); + if(!(g_devices[0].hdev = usb_open(g_devices[0].usb_dev))) { + fprintf(stderr, "failed to open device\n"); + db_close(); + break; + } - // Only 1 device supported - if(!(g_devices[0].hdev = usb_open(g_devices[0].usb_dev))) - { - fprintf(stderr, "failed to open device\n"); + handle_device(0); + usb_close(g_devices[0].hdev); db_close(); - break; } - handle_device(0); - usb_close(g_devices[0].hdev); - db_close(); } return 0; diff --git a/src/cm160.h b/src/cm160.h index 36dd1a0..221b817 100644 --- a/src/cm160.h +++ b/src/cm160.h @@ -22,11 +22,10 @@ #ifndef __CM160_H__ #define __CM160_H__ -#define MAX_DEVICES 1 // Only one device supported now - struct cm160_device { struct usb_device *usb_dev; usb_dev_handle *hdev; + int serial_no; int epin; // IN end point address int epout; // OUT end point address }; diff --git a/src/db.c b/src/db.c index d6c9ccb..7eb262a 100644 --- a/src/db.c +++ b/src/db.c @@ -85,7 +85,7 @@ int db_open(void) if(ret == SQLITE_OK) { - sqlite3_create_function(db, "update_stat_db", 5, SQLITE_UTF8, NULL, + sqlite3_create_function(db, "update_stat_db", 6, SQLITE_UTF8, NULL, &update_stat, NULL, NULL); SQL_EXEC(db, CREATE_UPDATE_STAT_TRIGGER, "Create update_stat trigger"); @@ -159,7 +159,9 @@ int db_insert_hist(struct record_data *rec) do { retry = false; + printf("debug4\n"); ret = sqlite3_exec(db, sql, NULL, NULL, &errmsg); + printf("debug5\n"); if(ret == SQLITE_BUSY) { sqlite3_free(errmsg); @@ -168,7 +170,7 @@ int db_insert_hist(struct record_data *rec) } else if(ret != SQLITE_OK) { - printf("db_insert_hist error: %s\n", errmsg); + printf("db_insert_hist Error: %s\n", errmsg); sqlite3_free(errmsg); } } @@ -179,54 +181,51 @@ int db_insert_hist(struct record_data *rec) void update_stat(sqlite3_context *context, int argc, sqlite3_value **argv) { - if(argc != 5) + if(argc != 6) return; - int y = sqlite3_value_int(argv[0]); - int m = sqlite3_value_int(argv[1]); - int d = sqlite3_value_int(argv[2]); - int h = sqlite3_value_int(argv[3]); - double kwh = sqlite3_value_double(argv[4]); + int addr = sqlite3_value_int(argv[0]); + int y = sqlite3_value_int(argv[1]); + int m = sqlite3_value_int(argv[2]); + int d = sqlite3_value_int(argv[3]); + int h = sqlite3_value_int(argv[4]); + double kwh = sqlite3_value_double(argv[5]); // printf("update_stat callback called %d/%d/%d @%dh: %f kwh\n", y, m, d, h, kwh); - update_stat_db(y, m, d, h, kwh); + update_stat_db(addr, y, m, d, h, kwh); } -int update_stat_db(int y, int m, int d, int h, double kwh) +int update_stat_db(int addr, int y, int m, int d, int h, double kwh) { - int addr = 0; // TODO - char sql[512]; - double day_conso = 0; - double night_conso = 0; - + char sql[1024]; + int i = 0; + double hour_conso[24]; + for(i=0;i<25;i++) { + hour_conso[i]=0; + } if(!db || !stat_db) { fprintf(stderr, "Error: db_insert_hist dbs not opened!\n"); return -1; } + hour_conso[h] += kwh; - if(get_day_of_week(y, m, d) < 5 && is_full_tariff(h)) // TODO: use tariffs from db - day_conso += kwh; - else - night_conso += kwh; - - // update energy_hour_stat - sprintf(sql, UPDATE_STAT_HOUR, kwh, day_conso, night_conso, y, m, d, h, - addr, y, m, d, h, kwh, day_conso, night_conso); + // update energy_hour_stat + sprintf(sql, UPDATE_STAT_HOUR, kwh, hour_conso[0],hour_conso[1],hour_conso[2],hour_conso[3],hour_conso[4],hour_conso[5],hour_conso[6],hour_conso[7],hour_conso[8],hour_conso[9],hour_conso[10],hour_conso[11],hour_conso[12],hour_conso[13],hour_conso[14],hour_conso[15],hour_conso[16],hour_conso[17],hour_conso[18],hour_conso[19],hour_conso[20],hour_conso[21],hour_conso[22],hour_conso[23], y, m, d, h, addr, + addr, y, m, d, h, kwh, hour_conso[0],hour_conso[1],hour_conso[2],hour_conso[3],hour_conso[4],hour_conso[5],hour_conso[6],hour_conso[7],hour_conso[8],hour_conso[9],hour_conso[10],hour_conso[11],hour_conso[12],hour_conso[13],hour_conso[14],hour_conso[15],hour_conso[16],hour_conso[17],hour_conso[18],hour_conso[19],hour_conso[20],hour_conso[21],hour_conso[22],hour_conso[23]); SQL_EXEC(stat_db, sql, "Update stat_hour DB"); - // update energy_day_stat - sprintf(sql, UPDATE_STAT_DAY, kwh, day_conso, night_conso, y, m, d, - addr, y, m, d, kwh, day_conso, night_conso); + sprintf(sql, UPDATE_STAT_DAY, kwh, hour_conso[0],hour_conso[1],hour_conso[2],hour_conso[3],hour_conso[4],hour_conso[5],hour_conso[6],hour_conso[7],hour_conso[8],hour_conso[9],hour_conso[10],hour_conso[11],hour_conso[12],hour_conso[13],hour_conso[14],hour_conso[15],hour_conso[16],hour_conso[17],hour_conso[18],hour_conso[19],hour_conso[20],hour_conso[21],hour_conso[22],hour_conso[23], y, m, d, addr, + addr, y, m, d, kwh, hour_conso[0],hour_conso[1],hour_conso[2],hour_conso[3],hour_conso[4],hour_conso[5],hour_conso[6],hour_conso[7],hour_conso[8],hour_conso[9],hour_conso[10],hour_conso[11],hour_conso[12],hour_conso[13],hour_conso[14],hour_conso[15],hour_conso[16],hour_conso[17],hour_conso[18],hour_conso[19],hour_conso[20],hour_conso[21],hour_conso[22],hour_conso[23]); SQL_EXEC(stat_db, sql, "Update stat_day DB"); // update energy_month_stat - sprintf(sql, UPDATE_STAT_MONTH, kwh, day_conso, night_conso, y, m, - addr, y, m, kwh, day_conso, night_conso); + sprintf(sql, UPDATE_STAT_MONTH, kwh, hour_conso[0],hour_conso[1],hour_conso[2],hour_conso[3],hour_conso[4],hour_conso[5],hour_conso[6],hour_conso[7],hour_conso[8],hour_conso[9],hour_conso[10],hour_conso[11],hour_conso[12],hour_conso[13],hour_conso[14],hour_conso[15],hour_conso[16],hour_conso[17],hour_conso[18],hour_conso[19],hour_conso[20],hour_conso[21],hour_conso[22],hour_conso[23], y, m, addr, + addr, y, m, kwh, hour_conso[0],hour_conso[1],hour_conso[2],hour_conso[3],hour_conso[4],hour_conso[5],hour_conso[6],hour_conso[7],hour_conso[8],hour_conso[9],hour_conso[10],hour_conso[11],hour_conso[12],hour_conso[13],hour_conso[14],hour_conso[15],hour_conso[16],hour_conso[17],hour_conso[18],hour_conso[19],hour_conso[20],hour_conso[21],hour_conso[22],hour_conso[23]); SQL_EXEC(stat_db, sql, "Update stat_month DB"); // update energy_year_stat - sprintf(sql, UPDATE_STAT_YEAR, kwh, day_conso, night_conso, y, - addr, y, kwh, day_conso, night_conso); + sprintf(sql, UPDATE_STAT_YEAR, kwh, hour_conso[0],hour_conso[1],hour_conso[2],hour_conso[3],hour_conso[4],hour_conso[5],hour_conso[6],hour_conso[7],hour_conso[8],hour_conso[9],hour_conso[10],hour_conso[11],hour_conso[12],hour_conso[13],hour_conso[14],hour_conso[15],hour_conso[16],hour_conso[17],hour_conso[18],hour_conso[19],hour_conso[20],hour_conso[21],hour_conso[22],hour_conso[23], y, addr, + addr, y, kwh, hour_conso[0],hour_conso[1],hour_conso[2],hour_conso[3],hour_conso[4],hour_conso[5],hour_conso[6],hour_conso[7],hour_conso[8],hour_conso[9],hour_conso[10],hour_conso[11],hour_conso[12],hour_conso[13],hour_conso[14],hour_conso[15],hour_conso[16],hour_conso[17],hour_conso[18],hour_conso[19],hour_conso[20],hour_conso[21],hour_conso[22],hour_conso[23]); SQL_EXEC(stat_db, sql, "Update stat_year DB"); return SQLITE_OK; diff --git a/src/db.h b/src/db.h index afee0c4..1850ec6 100644 --- a/src/db.h +++ b/src/db.h @@ -47,6 +47,6 @@ int db_insert_hist(struct record_data *rec); int db_update_status(void); void update_stat(sqlite3_context *context, int argc, sqlite3_value **argv); -int update_stat_db(int y, int m, int d, int h, double kwh); +int update_stat_db(int addr, int y, int m, int d, int h, double kwh); #endif // __DB_H__ diff --git a/src/sql_cmd.h b/src/sql_cmd.h index 49054c2..0ceb183 100644 --- a/src/sql_cmd.h +++ b/src/sql_cmd.h @@ -64,7 +64,7 @@ #define CREATE_UPDATE_STAT_TRIGGER "CREATE TRIGGER IF NOT EXISTS updatestat_cb "\ "AFTER INSERT ON energy_history" \ - " BEGIN SELECT update_stat_db(NEW.year," \ + " BEGIN SELECT update_stat_db(NEW.addr, NEW.year," \ " NEW.month, NEW.day, NEW.hour," \ " NEW.ch1_kw_avg/1000);" \ " END;" @@ -78,26 +78,70 @@ #define CREATE_YEAR_STAT "CREATE TABLE energy_year_stat(" \ "addr INT, year INT, kwh_total INT," \ - " kwh_week_total INT, kwh_weekend_total INT," \ + " kwh_0_total INT, kwh_1_total INT," \ + " kwh_2_total INT, kwh_3_total INT," \ + " kwh_4_total INT, kwh_5_total INT," \ + " kwh_6_total INT, kwh_7_total INT," \ + " kwh_8_total INT, kwh_9_total INT," \ + " kwh_10_total INT, kwh_11_total INT," \ + " kwh_12_total INT, kwh_13_total INT," \ + " kwh_14_total INT, kwh_15_total INT," \ + " kwh_16_total INT, kwh_17_total INT," \ + " kwh_18_total INT, kwh_19_total INT," \ + " kwh_20_total INT, kwh_21_total INT," \ + " kwh_22_total INT, kwh_23_total INT," \ " record_count INT, status INT," \ " PRIMARY KEY(addr, year));" #define CREATE_MONTH_STAT "CREATE TABLE energy_month_stat(" \ "addr INT, year INT, month INT, kwh_total INT,"\ - " kwh_week_total INT, kwh_weekend_total INT," \ + " kwh_0_total INT, kwh_1_total INT," \ + " kwh_2_total INT, kwh_3_total INT," \ + " kwh_4_total INT, kwh_5_total INT," \ + " kwh_6_total INT, kwh_7_total INT," \ + " kwh_8_total INT, kwh_9_total INT," \ + " kwh_10_total INT, kwh_11_total INT," \ + " kwh_12_total INT, kwh_13_total INT," \ + " kwh_14_total INT, kwh_15_total INT," \ + " kwh_16_total INT, kwh_17_total INT," \ + " kwh_18_total INT, kwh_19_total INT," \ + " kwh_20_total INT, kwh_21_total INT," \ + " kwh_22_total INT, kwh_23_total INT," \ " record_count INT, status INT," \ " PRIMARY KEY(addr, year, month));" #define CREATE_DAY_STAT "CREATE TABLE energy_day_stat(" \ - "addr INT, year INT, month INT, day INT, " \ - "kwh_total INT, kwh_week_total INT, " \ - "kwh_weekend_total INT, record_count INT, status INT, " \ + "addr INT, year INT, month INT, day INT, kwh_total INT," \ + " kwh_0_total INT, kwh_1_total INT," \ + " kwh_2_total INT, kwh_3_total INT," \ + " kwh_4_total INT, kwh_5_total INT," \ + " kwh_6_total INT, kwh_7_total INT," \ + " kwh_8_total INT, kwh_9_total INT," \ + " kwh_10_total INT, kwh_11_total INT," \ + " kwh_12_total INT, kwh_13_total INT," \ + " kwh_14_total INT, kwh_15_total INT," \ + " kwh_16_total INT, kwh_17_total INT," \ + " kwh_18_total INT, kwh_19_total INT," \ + " kwh_20_total INT, kwh_21_total INT," \ + " kwh_22_total INT, kwh_23_total INT," \ + " record_count INT, status INT," \ " PRIMARY KEY(addr, year, month, day));" #define CREATE_HOUR_STAT "CREATE TABLE energy_hour_stat(" \ - "addr INT, year INT, month INT, day INT, hour INT, " \ - "kwh_total INT, kwh_week_total INT, " \ - "kwh_weekend_total INT, record_count INT, status INT, " \ + "addr INT, year INT, month INT, day INT, hour INT, kwh_total INT," \ + " kwh_0_total INT, kwh_1_total INT," \ + " kwh_2_total INT, kwh_3_total INT," \ + " kwh_4_total INT, kwh_5_total INT," \ + " kwh_6_total INT, kwh_7_total INT," \ + " kwh_8_total INT, kwh_9_total INT," \ + " kwh_10_total INT, kwh_11_total INT," \ + " kwh_12_total INT, kwh_13_total INT," \ + " kwh_14_total INT, kwh_15_total INT," \ + " kwh_16_total INT, kwh_17_total INT," \ + " kwh_18_total INT, kwh_19_total INT," \ + " kwh_20_total INT, kwh_21_total INT," \ + " kwh_22_total INT, kwh_23_total INT," \ + " record_count INT, status INT," \ " PRIMARY KEY(addr, year, month, day, hour));" #define ATTACH_IMPORT_DB "ATTACH DATABASE '%s' AS import_db" @@ -153,43 +197,43 @@ " VALUES (%d, %d, %d, %d, %d, %d," \ " %f, %f, %d, %d, %f, %f, %f, %f);" -#define UPDATE_STAT_HOUR "INSERT OR REPLACE INTO energy_hour_stat" \ - " SELECT addr, year, month, day, hour, kwh_total + %f," \ - " kwh_week_total + %f, kwh_weekend_total + %f," \ - " record_count + 1 AS c, status FROM energy_hour_stat" \ - " WHERE year=%d AND month=%d AND day=%d AND hour=%d" \ - " UNION " \ - " SELECT %d, %d, %d, %d, %d, %f, %f, %f, 1 as r, 0" \ - " ORDER BY r DESC" \ +#define UPDATE_STAT_HOUR "INSERT OR REPLACE INTO energy_hour_stat" \ + " SELECT addr, year, month, day, hour, kwh_total + %f," \ + " kwh_0_total + %f, kwh_1_total + %f, kwh_2_total + %f, kwh_3_total + %f, kwh_4_total + %f, kwh_5_total + %f, kwh_6_total + %f, kwh_7_total + %f, kwh_8_total + %f, kwh_9_total + %f, kwh_10_total + %f, kwh_11_total + %f, kwh_12_total + %f, kwh_13_total + %f, kwh_14_total + %f, kwh_15_total + %f, kwh_16_total + %f, kwh_17_total + %f, kwh_18_total + %f, kwh_19_total + %f, kwh_20_total + %f, kwh_21_total + %f, kwh_22_total + %f, kwh_23_total + %f," \ + " record_count + 1 AS c, status FROM energy_hour_stat" \ + " WHERE year=%d AND month=%d AND day=%d AND hour=%d AND addr=%d"\ + " UNION " \ + " SELECT %d, %d, %d, %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, 1 as r, 0" \ + " ORDER BY r DESC" \ " LIMIT 1;" -#define UPDATE_STAT_DAY "INSERT OR REPLACE INTO energy_day_stat" \ - " SELECT addr, year, month, day, kwh_total + %f," \ - " kwh_week_total + %f, kwh_weekend_total + %f," \ - " record_count + 1 AS c, status FROM energy_day_stat" \ - " WHERE year = %d AND month = %d AND day = %d" \ - " UNION " \ - " SELECT %d, %d, %d, %d, %f, %f, %f, 1 as r, 0" \ - " ORDER BY r DESC" \ +#define UPDATE_STAT_DAY "INSERT OR REPLACE INTO energy_day_stat" \ + " SELECT addr, year, month, day, kwh_total + %f," \ + " kwh_0_total + %f, kwh_1_total + %f, kwh_2_total + %f, kwh_3_total + %f, kwh_4_total + %f, kwh_5_total + %f, kwh_6_total + %f, kwh_7_total + %f, kwh_8_total + %f, kwh_9_total + %f, kwh_10_total + %f, kwh_11_total + %f, kwh_12_total + %f, kwh_13_total + %f, kwh_14_total + %f, kwh_15_total + %f, kwh_16_total + %f, kwh_17_total + %f, kwh_18_total + %f, kwh_19_total + %f, kwh_20_total + %f, kwh_21_total + %f, kwh_22_total + %f, kwh_23_total + %f," \ + " record_count + 1 AS c, status FROM energy_day_stat" \ + " WHERE year = %d AND month = %d AND day = %d AND addr=%d"\ + " UNION " \ + " SELECT %d, %d, %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, 1 as r, 0" \ + " ORDER BY r DESC" \ " LIMIT 1;" #define UPDATE_STAT_MONTH "INSERT OR REPLACE INTO energy_month_stat" \ " SELECT addr, year, month, kwh_total + %f," \ - " kwh_week_total + %f, kwh_weekend_total + %f," \ + " kwh_0_total + %f, kwh_1_total + %f, kwh_2_total + %f, kwh_3_total + %f, kwh_4_total + %f, kwh_5_total + %f, kwh_6_total + %f, kwh_7_total + %f, kwh_8_total + %f, kwh_9_total + %f, kwh_10_total + %f, kwh_11_total + %f, kwh_12_total + %f, kwh_13_total + %f, kwh_14_total + %f, kwh_15_total + %f, kwh_16_total + %f, kwh_17_total + %f, kwh_18_total + %f, kwh_19_total + %f, kwh_20_total + %f, kwh_21_total + %f, kwh_22_total + %f, kwh_23_total + %f," \ " record_count + 1 AS c, status FROM energy_month_stat"\ - " WHERE year = %d AND month = %d" \ + " WHERE year = %d AND month = %d AND addr=%d" \ " UNION " \ - " SELECT %d, %d, %d, %f, %f, %f, 1 as r, 0" \ + " SELECT %d, %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, 1 as r, 0" \ " ORDER BY r DESC" \ " LIMIT 1;" #define UPDATE_STAT_YEAR "INSERT OR REPLACE INTO energy_year_stat" \ " SELECT addr, year, kwh_total + %f," \ - " kwh_week_total + %f, kwh_weekend_total + %f," \ + " kwh_0_total + %f, kwh_1_total + %f, kwh_2_total + %f, kwh_3_total + %f, kwh_4_total + %f, kwh_5_total + %f, kwh_6_total + %f, kwh_7_total + %f, kwh_8_total + %f, kwh_9_total + %f, kwh_10_total + %f, kwh_11_total + %f, kwh_12_total + %f, kwh_13_total + %f, kwh_14_total + %f, kwh_15_total + %f, kwh_16_total + %f, kwh_17_total + %f, kwh_18_total + %f, kwh_19_total + %f, kwh_20_total + %f, kwh_21_total + %f, kwh_22_total + %f, kwh_23_total + %f," \ " record_count + 1 AS c, status FROM energy_year_stat" \ - " WHERE year = %d" \ + " WHERE year = %d AND addr=%d" \ " UNION " \ - " SELECT %d, %d, %f, %f, %f, 1 as r, 0" \ + " SELECT %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, 1 as r, 0" \ " ORDER BY r DESC" \ " LIMIT 1;" diff --git a/src/usb_utils.c b/src/usb_utils.c index 51ab2c9..12ebfe3 100644 --- a/src/usb_utils.c +++ b/src/usb_utils.c @@ -23,42 +23,40 @@ #include #include "cm160.h" -#define OWL_VENDOR_ID 0x0fde -#define CM160_DEV_ID 0xca05 +#define OWL_VENDOR_ID 0x0fde +#define CM160_DEV_ID 0xca05 -extern struct cm160_device g_devices[MAX_DEVICES]; +extern struct cm160_device g_devices[]; -static int scan_device(struct usb_device *dev, int *dev_cnt) -{ - if(dev->descriptor.idVendor == OWL_VENDOR_ID && - dev->descriptor.idProduct == CM160_DEV_ID) - { - printf("Found compatible device #%d: %04x:%04x (%s)\n", - *dev_cnt, dev->descriptor.idVendor, - dev->descriptor.idProduct, dev->filename); - g_devices[*dev_cnt].usb_dev = dev; - (*dev_cnt)++; +static int scan_device(struct usb_device *dev, int *dev_cnt, char *serial) { + if(dev->descriptor.idVendor == OWL_VENDOR_ID && dev->descriptor.idProduct == CM160_DEV_ID) { + char devserial[255]; + usb_dev_handle *hdlr; + hdlr = usb_open(dev); + usb_get_string_simple(hdlr, 3, devserial, 255); + if (serial[0]=='\0' || strcmp(serial, devserial) == 0) { + printf("Found compatible device #%d: %04x:%04x serial:%s (%s)\n", + *dev_cnt, dev->descriptor.idVendor, + dev->descriptor.idProduct, devserial, dev->filename); + g_devices[*dev_cnt].usb_dev = dev; + g_devices[*dev_cnt].serial_no =(int)strtol(serial,NULL,16); + (*dev_cnt)++; + } } - return 0; } -int scan_usb() -{ +int scan_usb(char *serial) { int dev_cnt = 0; usb_init(); usb_find_busses(); usb_find_devices(); - struct usb_bus *bus = NULL; struct usb_device *dev = NULL; - for(bus = usb_get_busses(); bus; bus = bus->next) - { - for(dev = bus->devices; dev; dev=dev->next) - { - scan_device(dev, &dev_cnt); - if(dev_cnt==MAX_DEVICES) return dev_cnt; + for(bus = usb_get_busses(); bus; bus = bus->next) { + for(dev = bus->devices; dev; dev=dev->next) { + scan_device(dev, &dev_cnt, serial); } } diff --git a/src/usb_utils.h b/src/usb_utils.h index f611ae6..fb2a544 100644 --- a/src/usb_utils.h +++ b/src/usb_utils.h @@ -22,6 +22,6 @@ #ifndef __USB_UTILS__ #define __USB_UTILS__ -int scan_usb(); +int scan_usb(char *serial); #endif // __USB_UTILS__ From 48bbe039e08a856dbdbc90321001793e7bc01ff2 Mon Sep 17 00:00:00 2001 From: Tomasz Brzezina Date: Fri, 17 Oct 2014 11:41:33 +0200 Subject: [PATCH 2/7] changes in view --- www/index.php | 19 ++------ www/live.php | 102 ++++++++++++++++++++++++------------------- www/live_data_id.php | 9 ++++ 3 files changed, 69 insertions(+), 61 deletions(-) create mode 100644 www/live_data_id.php diff --git a/www/index.php b/www/index.php index a11ca61..d9ec52f 100644 --- a/www/index.php +++ b/www/index.php @@ -1,6 +1,6 @@ - +. Electricity consumption @@ -11,23 +11,10 @@ 'Janvier', - 2 => 'Fevrier', - 3 => 'Mars', - 4 => 'Avril', - 5 => 'Mai', - 6 => 'Juin', - 7 => 'Juillet', - 8 => 'Aout', - 9 => 'Septembre', - 10 => 'Octobre', - 11 => 'Novembre', - 12 => 'Decembre', - ); - return $months[$nb]; + return strftime("%B", mktime(0,0,0,$nb)); } diff --git a/www/live.php b/www/live.php index 64b1a9e..d2e33ab 100644 --- a/www/live.php +++ b/www/live.php @@ -23,74 +23,82 @@ function build_live_graph() var graph = $("#live_graph"); var data = []; totalPoints = 300; var marks = []; - var min, max; - function getData() + var min = []; + var max = []; + function getData(addr) { - if(typeof getData.counter == 'undefined' ) - getData.counter = 0; - if(typeof getData.prev_time == 'undefined' ) - getData.prev_time = '00:00'; - + if(typeof counter == 'undefined' ) + counter = 0; + if(typeof prev_time == 'undefined' ) + prev_time = '00:00'; + if(typeof data[addr] == 'undefined' ) + data[addr]=[]; // init data with -1 - if(data.length == 0) + if(data[addr].length == 0) { for(var i = 0; i < totalPoints; ++i) - data.push(-1); + data[addr].push(-1); } // remove the oldest value - if(data.length >= totalPoints) - data = data.slice(1); + if(data[addr].length >= totalPoints) + data[addr] = data[addr].slice(1); // add the new one function onNewData(new_data) { - getData.counter++; + counter++; // string format: 'dd/MM/yyyy hh:mm - xxxx kW' var time = new_data.split(' - ')[0]; time = time.split(' ')[1]; var kw = new_data.split(' - ')[1]; kw = kw.split(' ')[0]; var v = parseFloat(kw); - data.push(v); - if(time != getData.prev_time) + data[addr].push(v); + if(time > prev_time) { var mark = []; mark['pos'] = totalPoints; mark['text'] = time; marks.push(mark); - getData.prev_time = time; + prev_time = time; } } $.ajax({ - url: "live_data.php", + url: "live_data_id.php?addr="+addr, method: 'GET', dataType: 'text', success: onNewData }); // compute min and max - max = Math.max.apply(null, data); - min = max; - for (var i = totalPoints-1; i >= 0; i--) - { - if (data[i] < min && data[i] > 0) { - min = data[i]; + for (key in data) { + max[key] = Math.max.apply(null, data[key]); + min[key] = max[key]; + + for (var i = totalPoints-1; i >= 0; i--) + { + if (data[key][i] < min[key] && data[key][i] > 0) { + min[key] = data[key][i]; + } } } - $('.min').remove(); - if(min>0) - { - var off = 3; - graph.append('
min:' + min + '
'); - } - - $('.max').remove(); - if(max>0 && max != min) - { - var off = 15; - graph.append('
max:' + max + '
'); + var index=0; + for (key in data) { + var off = 3+index*30; + if(min[key]>0) { + $('#min'+key).remove(); + + graph.append('
min:' + min[key] + '
'); + } + if(max[key]>0 && max[key] != min[key]) + { + $('#max'+key).remove(); + var off = 15+index*30; + graph.append('
max:' + max[key] + '
'); + } + index++; } // update marks var num_marks = marks.length; @@ -102,8 +110,8 @@ function onNewData(new_data) // zip the generated y values with the x values var res = []; - for(var i = 0; i < data.length; ++i) - res.push([i, data[i]]) + for(var i = 0; i < data[addr].length; ++i) + res.push([i, data[addr][i]]) return res; } @@ -115,13 +123,15 @@ function markings() { var mark = marks[i]; if(marks[i].pos >= 0) - markings.push({ color: '#888', lineWidth: 0.5, xaxis: { from: marks[i].pos, to: marks[i].pos } }); - - if(min >= 0) - markings.push({ color: '#88F', lineWidth: 0.5, yaxis: { from: min, to: min } }); - if(max >= 0 && max != min) - markings.push({ color: '#F88', lineWidth: 0.5, yaxis: { from: max, to: max } }); - } + markings.push({ color: '#888', lineWidth: 0.5, xaxis: { from: marks[i].pos, to: marks[i].pos } }); + } + for(key in data) { + if(min[key] >= 0) + markings.push({ color: '#88F', lineWidth: 0.5, yaxis: { from: min[key], to: min[key] } }); + if(max[key] >= 0 && max != min[key]) + markings.push({ color: '#F88', lineWidth: 0.5, yaxis: { from: max[key], to: max[key] } }); + } + return markings; } // Add ticks with the time value @@ -171,10 +181,11 @@ function xaxis_ticks() yaxis: { min: 0 }, grid: { markings: markings } }; - var plot = $.plot(graph, [ getData() ], options); + var plot = $.plot(graph, [ getData(2360670),getData(2354602)], options); function update() { - plot.setData([ getData() ]); + plot.setData([ getData(2360670),getData(2354602)]); + //alert(getData(2360670)+getData(2354602)); plot.setupGrid(); plot.draw(); @@ -185,6 +196,7 @@ function update() { } build_live_graph(); + diff --git a/www/live_data_id.php b/www/live_data_id.php new file mode 100644 index 0000000..2524826 --- /dev/null +++ b/www/live_data_id.php @@ -0,0 +1,9 @@ + From b7eb370f33d59f6452c6cd185d4e3ae6ed6297de Mon Sep 17 00:00:00 2001 From: Tomasz Brzezina Date: Fri, 17 Oct 2014 11:42:15 +0200 Subject: [PATCH 3/7] I18n - names --- www/jsdatepick-calendar/jsDatePick.full.1.3.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/www/jsdatepick-calendar/jsDatePick.full.1.3.js b/www/jsdatepick-calendar/jsDatePick.full.1.3.js index 9107ce9..a580e38 100755 --- a/www/jsdatepick-calendar/jsDatePick.full.1.3.js +++ b/www/jsdatepick-calendar/jsDatePick.full.1.3.js @@ -56,8 +56,20 @@ */ // The language array - change these values to your language to better fit your needs! g_l = []; -g_l["MONTHS"] = ["January","February","March","April","May","June","July","August","September","October","November","December"]; -g_l["DAYS_3"] = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]; +g_l["MONTHS"]= []; +g_l["DAYS_3"]= []; +var formatter = new Intl.DateTimeFormat("pl", { month: "long" }); +for(i=1;i<13;i++) { + g_l["MONTHS"].push(formatter.format(new Date(2000,i,1))); +} +//g_l["MONTHS"] = ["January","February","March","April","May","June","July","August","September","Paździer","November","December"]; + +var formatter = new Intl.DateTimeFormat("pl", { weekday: "short" }); + +for(i=1;i<8;i++) { + g_l["DAYS_3"].push(formatter.format(new Date(2000,9,i))); +} +//g_l["DAYS_3"] = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]; g_l["MONTH_FWD"] = "Move a month forward"; g_l["MONTH_BCK"] = "Move a month backward"; g_l["YEAR_FWD"] = "Move a year forward"; From 0154c7b4964d1efaae43501900d1618b5438ea5d Mon Sep 17 00:00:00 2001 From: Tomasz Brzezina Date: Fri, 17 Oct 2014 12:30:19 +0200 Subject: [PATCH 4/7] FOUND BUG! The length of sql was to short! 2048 is better than 1024! --- src/db.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/db.c b/src/db.c index 7eb262a..6877074 100644 --- a/src/db.c +++ b/src/db.c @@ -159,9 +159,7 @@ int db_insert_hist(struct record_data *rec) do { retry = false; - printf("debug4\n"); ret = sqlite3_exec(db, sql, NULL, NULL, &errmsg); - printf("debug5\n"); if(ret == SQLITE_BUSY) { sqlite3_free(errmsg); @@ -196,7 +194,7 @@ void update_stat(sqlite3_context *context, int argc, sqlite3_value **argv) int update_stat_db(int addr, int y, int m, int d, int h, double kwh) { - char sql[1024]; + char sql[2048]; int i = 0; double hour_conso[24]; for(i=0;i<25;i++) { From 0e108f08abbda3b6dc13cb8c75160a869e465130 Mon Sep 17 00:00:00 2001 From: Tomasz Brzezina Date: Sat, 18 Oct 2014 10:57:01 +0200 Subject: [PATCH 5/7] changes that shows charts --- src/db.c | 38 +++++------------ src/sql_cmd.h | 107 +++------------------------------------------- www/index.php | 116 +++++++++++++++++++++++++++++++------------------- 3 files changed, 90 insertions(+), 171 deletions(-) diff --git a/src/db.c b/src/db.c index 6877074..650d09f 100644 --- a/src/db.c +++ b/src/db.c @@ -66,9 +66,6 @@ static int create_stat_db() printf("%s doesn't exist -> create it.\n", EAGLE_OWL_STAT_DB); sqlite3_open_v2(EAGLE_OWL_STAT_DB, &stat_db, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, NULL); - SQL_EXEC(stat_db, CREATE_YEAR_STAT, "Create energy_year_stat table"); - SQL_EXEC(stat_db, CREATE_MONTH_STAT, "Create energy_month_stat table"); - SQL_EXEC(stat_db, CREATE_DAY_STAT, "Create energy_year_day table"); SQL_EXEC(stat_db, CREATE_HOUR_STAT, "Create energy_year_hour table"); return ret; @@ -192,39 +189,27 @@ void update_stat(sqlite3_context *context, int argc, sqlite3_value **argv) update_stat_db(addr, y, m, d, h, kwh); } +int dayofweek(int y, int m, int d) { /* 0 = Sunday */ + static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; + y -= m < 3; + return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7; +} + int update_stat_db(int addr, int y, int m, int d, int h, double kwh) { char sql[2048]; int i = 0; - double hour_conso[24]; - for(i=0;i<25;i++) { - hour_conso[i]=0; - } + int dow; if(!db || !stat_db) { fprintf(stderr, "Error: db_insert_hist dbs not opened!\n"); return -1; } - hour_conso[h] += kwh; - + dow = dayofweek(y,m,d); // update energy_hour_stat - sprintf(sql, UPDATE_STAT_HOUR, kwh, hour_conso[0],hour_conso[1],hour_conso[2],hour_conso[3],hour_conso[4],hour_conso[5],hour_conso[6],hour_conso[7],hour_conso[8],hour_conso[9],hour_conso[10],hour_conso[11],hour_conso[12],hour_conso[13],hour_conso[14],hour_conso[15],hour_conso[16],hour_conso[17],hour_conso[18],hour_conso[19],hour_conso[20],hour_conso[21],hour_conso[22],hour_conso[23], y, m, d, h, addr, - addr, y, m, d, h, kwh, hour_conso[0],hour_conso[1],hour_conso[2],hour_conso[3],hour_conso[4],hour_conso[5],hour_conso[6],hour_conso[7],hour_conso[8],hour_conso[9],hour_conso[10],hour_conso[11],hour_conso[12],hour_conso[13],hour_conso[14],hour_conso[15],hour_conso[16],hour_conso[17],hour_conso[18],hour_conso[19],hour_conso[20],hour_conso[21],hour_conso[22],hour_conso[23]); + sprintf(sql, UPDATE_STAT_HOUR, kwh, y, m, d, h, addr, + addr, y, m, d, h, dow, kwh); SQL_EXEC(stat_db, sql, "Update stat_hour DB"); - // update energy_day_stat - sprintf(sql, UPDATE_STAT_DAY, kwh, hour_conso[0],hour_conso[1],hour_conso[2],hour_conso[3],hour_conso[4],hour_conso[5],hour_conso[6],hour_conso[7],hour_conso[8],hour_conso[9],hour_conso[10],hour_conso[11],hour_conso[12],hour_conso[13],hour_conso[14],hour_conso[15],hour_conso[16],hour_conso[17],hour_conso[18],hour_conso[19],hour_conso[20],hour_conso[21],hour_conso[22],hour_conso[23], y, m, d, addr, - addr, y, m, d, kwh, hour_conso[0],hour_conso[1],hour_conso[2],hour_conso[3],hour_conso[4],hour_conso[5],hour_conso[6],hour_conso[7],hour_conso[8],hour_conso[9],hour_conso[10],hour_conso[11],hour_conso[12],hour_conso[13],hour_conso[14],hour_conso[15],hour_conso[16],hour_conso[17],hour_conso[18],hour_conso[19],hour_conso[20],hour_conso[21],hour_conso[22],hour_conso[23]); - SQL_EXEC(stat_db, sql, "Update stat_day DB"); - - // update energy_month_stat - sprintf(sql, UPDATE_STAT_MONTH, kwh, hour_conso[0],hour_conso[1],hour_conso[2],hour_conso[3],hour_conso[4],hour_conso[5],hour_conso[6],hour_conso[7],hour_conso[8],hour_conso[9],hour_conso[10],hour_conso[11],hour_conso[12],hour_conso[13],hour_conso[14],hour_conso[15],hour_conso[16],hour_conso[17],hour_conso[18],hour_conso[19],hour_conso[20],hour_conso[21],hour_conso[22],hour_conso[23], y, m, addr, - addr, y, m, kwh, hour_conso[0],hour_conso[1],hour_conso[2],hour_conso[3],hour_conso[4],hour_conso[5],hour_conso[6],hour_conso[7],hour_conso[8],hour_conso[9],hour_conso[10],hour_conso[11],hour_conso[12],hour_conso[13],hour_conso[14],hour_conso[15],hour_conso[16],hour_conso[17],hour_conso[18],hour_conso[19],hour_conso[20],hour_conso[21],hour_conso[22],hour_conso[23]); - SQL_EXEC(stat_db, sql, "Update stat_month DB"); - - // update energy_year_stat - sprintf(sql, UPDATE_STAT_YEAR, kwh, hour_conso[0],hour_conso[1],hour_conso[2],hour_conso[3],hour_conso[4],hour_conso[5],hour_conso[6],hour_conso[7],hour_conso[8],hour_conso[9],hour_conso[10],hour_conso[11],hour_conso[12],hour_conso[13],hour_conso[14],hour_conso[15],hour_conso[16],hour_conso[17],hour_conso[18],hour_conso[19],hour_conso[20],hour_conso[21],hour_conso[22],hour_conso[23], y, addr, - addr, y, kwh, hour_conso[0],hour_conso[1],hour_conso[2],hour_conso[3],hour_conso[4],hour_conso[5],hour_conso[6],hour_conso[7],hour_conso[8],hour_conso[9],hour_conso[10],hour_conso[11],hour_conso[12],hour_conso[13],hour_conso[14],hour_conso[15],hour_conso[16],hour_conso[17],hour_conso[18],hour_conso[19],hour_conso[20],hour_conso[21],hour_conso[22],hour_conso[23]); - SQL_EXEC(stat_db, sql, "Update stat_year DB"); return SQLITE_OK; } @@ -247,9 +232,6 @@ int db_update_status(void) sprintf(sql, "UPDATE energy_hour_stat SET status = 1 WHERE record_count = %d", 60); SQL_EXEC(stat_db, sql, "Update energy_hour_stat status"); - sprintf(sql, "UPDATE energy_day_stat SET status = 1 WHERE record_count = %d", 60*24); - SQL_EXEC(stat_db, sql, "Update energy_day_stat status"); - return SQLITE_OK; } diff --git a/src/sql_cmd.h b/src/sql_cmd.h index 0ceb183..09c07ac 100644 --- a/src/sql_cmd.h +++ b/src/sql_cmd.h @@ -72,76 +72,14 @@ #define DELETE_UPDATE_STAT_TRIGGER "DROP TRIGGER IF EXISTS updatestat_cb;" // record_count: number of minutes records that have been used to compute the stat -// e.g: for a full day_stat: record_count should be 24*60 (24 hours of 60 minutes) +// e.g: for a full hour_stat: record_count should be 60 (60 minutes) // status: 0: the stat is complete (record_count is the max value) // 1: the stat is incomplete (record_count is lower than the max value) -#define CREATE_YEAR_STAT "CREATE TABLE energy_year_stat(" \ - "addr INT, year INT, kwh_total INT," \ - " kwh_0_total INT, kwh_1_total INT," \ - " kwh_2_total INT, kwh_3_total INT," \ - " kwh_4_total INT, kwh_5_total INT," \ - " kwh_6_total INT, kwh_7_total INT," \ - " kwh_8_total INT, kwh_9_total INT," \ - " kwh_10_total INT, kwh_11_total INT," \ - " kwh_12_total INT, kwh_13_total INT," \ - " kwh_14_total INT, kwh_15_total INT," \ - " kwh_16_total INT, kwh_17_total INT," \ - " kwh_18_total INT, kwh_19_total INT," \ - " kwh_20_total INT, kwh_21_total INT," \ - " kwh_22_total INT, kwh_23_total INT," \ - " record_count INT, status INT," \ - " PRIMARY KEY(addr, year));" - -#define CREATE_MONTH_STAT "CREATE TABLE energy_month_stat(" \ - "addr INT, year INT, month INT, kwh_total INT,"\ - " kwh_0_total INT, kwh_1_total INT," \ - " kwh_2_total INT, kwh_3_total INT," \ - " kwh_4_total INT, kwh_5_total INT," \ - " kwh_6_total INT, kwh_7_total INT," \ - " kwh_8_total INT, kwh_9_total INT," \ - " kwh_10_total INT, kwh_11_total INT," \ - " kwh_12_total INT, kwh_13_total INT," \ - " kwh_14_total INT, kwh_15_total INT," \ - " kwh_16_total INT, kwh_17_total INT," \ - " kwh_18_total INT, kwh_19_total INT," \ - " kwh_20_total INT, kwh_21_total INT," \ - " kwh_22_total INT, kwh_23_total INT," \ - " record_count INT, status INT," \ - " PRIMARY KEY(addr, year, month));" - -#define CREATE_DAY_STAT "CREATE TABLE energy_day_stat(" \ - "addr INT, year INT, month INT, day INT, kwh_total INT," \ - " kwh_0_total INT, kwh_1_total INT," \ - " kwh_2_total INT, kwh_3_total INT," \ - " kwh_4_total INT, kwh_5_total INT," \ - " kwh_6_total INT, kwh_7_total INT," \ - " kwh_8_total INT, kwh_9_total INT," \ - " kwh_10_total INT, kwh_11_total INT," \ - " kwh_12_total INT, kwh_13_total INT," \ - " kwh_14_total INT, kwh_15_total INT," \ - " kwh_16_total INT, kwh_17_total INT," \ - " kwh_18_total INT, kwh_19_total INT," \ - " kwh_20_total INT, kwh_21_total INT," \ - " kwh_22_total INT, kwh_23_total INT," \ - " record_count INT, status INT," \ - " PRIMARY KEY(addr, year, month, day));" - -#define CREATE_HOUR_STAT "CREATE TABLE energy_hour_stat(" \ - "addr INT, year INT, month INT, day INT, hour INT, kwh_total INT," \ - " kwh_0_total INT, kwh_1_total INT," \ - " kwh_2_total INT, kwh_3_total INT," \ - " kwh_4_total INT, kwh_5_total INT," \ - " kwh_6_total INT, kwh_7_total INT," \ - " kwh_8_total INT, kwh_9_total INT," \ - " kwh_10_total INT, kwh_11_total INT," \ - " kwh_12_total INT, kwh_13_total INT," \ - " kwh_14_total INT, kwh_15_total INT," \ - " kwh_16_total INT, kwh_17_total INT," \ - " kwh_18_total INT, kwh_19_total INT," \ - " kwh_20_total INT, kwh_21_total INT," \ - " kwh_22_total INT, kwh_23_total INT," \ - " record_count INT, status INT," \ +#define CREATE_HOUR_STAT "CREATE TABLE energy_hour_stat(" \ + "addr INT, year INT, month INT, day INT," \ + " hour INT, dow INT, kwh_total INT," \ + " record_count INT, status INT," \ " PRIMARY KEY(addr, year, month, day, hour));" #define ATTACH_IMPORT_DB "ATTACH DATABASE '%s' AS import_db" @@ -198,43 +136,12 @@ " %f, %f, %d, %d, %f, %f, %f, %f);" #define UPDATE_STAT_HOUR "INSERT OR REPLACE INTO energy_hour_stat" \ - " SELECT addr, year, month, day, hour, kwh_total + %f," \ - " kwh_0_total + %f, kwh_1_total + %f, kwh_2_total + %f, kwh_3_total + %f, kwh_4_total + %f, kwh_5_total + %f, kwh_6_total + %f, kwh_7_total + %f, kwh_8_total + %f, kwh_9_total + %f, kwh_10_total + %f, kwh_11_total + %f, kwh_12_total + %f, kwh_13_total + %f, kwh_14_total + %f, kwh_15_total + %f, kwh_16_total + %f, kwh_17_total + %f, kwh_18_total + %f, kwh_19_total + %f, kwh_20_total + %f, kwh_21_total + %f, kwh_22_total + %f, kwh_23_total + %f," \ + " SELECT addr, year, month, day, hour, dow, kwh_total + %f," \ " record_count + 1 AS c, status FROM energy_hour_stat" \ " WHERE year=%d AND month=%d AND day=%d AND hour=%d AND addr=%d"\ " UNION " \ - " SELECT %d, %d, %d, %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, 1 as r, 0" \ + " SELECT %d, %d, %d, %d, %d, %d, %f, 1 as r, 0" \ " ORDER BY r DESC" \ " LIMIT 1;" -#define UPDATE_STAT_DAY "INSERT OR REPLACE INTO energy_day_stat" \ - " SELECT addr, year, month, day, kwh_total + %f," \ - " kwh_0_total + %f, kwh_1_total + %f, kwh_2_total + %f, kwh_3_total + %f, kwh_4_total + %f, kwh_5_total + %f, kwh_6_total + %f, kwh_7_total + %f, kwh_8_total + %f, kwh_9_total + %f, kwh_10_total + %f, kwh_11_total + %f, kwh_12_total + %f, kwh_13_total + %f, kwh_14_total + %f, kwh_15_total + %f, kwh_16_total + %f, kwh_17_total + %f, kwh_18_total + %f, kwh_19_total + %f, kwh_20_total + %f, kwh_21_total + %f, kwh_22_total + %f, kwh_23_total + %f," \ - " record_count + 1 AS c, status FROM energy_day_stat" \ - " WHERE year = %d AND month = %d AND day = %d AND addr=%d"\ - " UNION " \ - " SELECT %d, %d, %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, 1 as r, 0" \ - " ORDER BY r DESC" \ - " LIMIT 1;" - -#define UPDATE_STAT_MONTH "INSERT OR REPLACE INTO energy_month_stat" \ - " SELECT addr, year, month, kwh_total + %f," \ - " kwh_0_total + %f, kwh_1_total + %f, kwh_2_total + %f, kwh_3_total + %f, kwh_4_total + %f, kwh_5_total + %f, kwh_6_total + %f, kwh_7_total + %f, kwh_8_total + %f, kwh_9_total + %f, kwh_10_total + %f, kwh_11_total + %f, kwh_12_total + %f, kwh_13_total + %f, kwh_14_total + %f, kwh_15_total + %f, kwh_16_total + %f, kwh_17_total + %f, kwh_18_total + %f, kwh_19_total + %f, kwh_20_total + %f, kwh_21_total + %f, kwh_22_total + %f, kwh_23_total + %f," \ - " record_count + 1 AS c, status FROM energy_month_stat"\ - " WHERE year = %d AND month = %d AND addr=%d" \ - " UNION " \ - " SELECT %d, %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, 1 as r, 0" \ - " ORDER BY r DESC" \ - " LIMIT 1;" - -#define UPDATE_STAT_YEAR "INSERT OR REPLACE INTO energy_year_stat" \ - " SELECT addr, year, kwh_total + %f," \ - " kwh_0_total + %f, kwh_1_total + %f, kwh_2_total + %f, kwh_3_total + %f, kwh_4_total + %f, kwh_5_total + %f, kwh_6_total + %f, kwh_7_total + %f, kwh_8_total + %f, kwh_9_total + %f, kwh_10_total + %f, kwh_11_total + %f, kwh_12_total + %f, kwh_13_total + %f, kwh_14_total + %f, kwh_15_total + %f, kwh_16_total + %f, kwh_17_total + %f, kwh_18_total + %f, kwh_19_total + %f, kwh_20_total + %f, kwh_21_total + %f, kwh_22_total + %f, kwh_23_total + %f," \ - " record_count + 1 AS c, status FROM energy_year_stat" \ - " WHERE year = %d AND addr=%d" \ - " UNION " \ - " SELECT %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, 1 as r, 0" \ - " ORDER BY r DESC" \ - " LIMIT 1;" - #endif//__EAGLEOWL_SQL_H__ diff --git a/www/index.php b/www/index.php index d9ec52f..7aa4dbb 100644 --- a/www/index.php +++ b/www/index.php @@ -12,6 +12,20 @@ 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 0, 23 => 0); + $tariffs['G12'][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 1, 14 => 1, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 1, 23 => 1); + if ($i==0 || $i==6) { + $tariffs['G12w'][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 1, 14 => 1, 15 => 1, 16 => 1, 17 => 1, 18 => 1, 19 => 1, 20 => 1, 21 => 1, 22 => 1, 23 => 0); + } else { + $tariffs['G12w'][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 1, 14 => 1, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 1, 23 => 1); + } +} +if (isset($_GET['tariff'])) { + $tariff=$_GET['tariff']; +} else { + $tariff="G12w"; +} function month_to_string($nb) { return strftime("%B", mktime(0,0,0,$nb)); @@ -53,8 +67,7 @@ function var_to_js($jsname,$a) return $ret; } -function get_data($db, $year=0, $month=0, $day=0) -{ +function get_data($db, $year=0, $month=0, $day=0, $addr=0) { $i = 0; $unit = "year"; if($year) @@ -73,6 +86,9 @@ function get_data($db, $year=0, $month=0, $day=0) if($month) $req.= "AND month = \"$month\" "; if($day) $req.= "AND day = \"$day\" "; } + if ($addr) { + $req.="AND addr = \"$addr\" "; + } $req.= "GROUP BY year"; if($year) $req.= ", month"; if($month) $req.= ", day"; @@ -94,80 +110,89 @@ function get_data($db, $year=0, $month=0, $day=0) return $arr; } -function get_stat_data($db, $year=0, $month=0, $day=0) -{ +function get_stat_data($db, $year=0, $month=0, $day=0, $addr=0) { + global $tariffs,$tariff; $i = 0; $unit = "year"; - $table = "energy_year_stat"; + $table = "energy_hour_stat"; if($year){ $unit = "month"; - $table = "energy_month_stat"; } if($month){ $unit = "day"; - $table = "energy_day_stat"; } if($day){ $unit = "hour"; - $table = "energy_hour_stat"; } - $req = "SELECT "; - $req.= "$unit, "; - $req2 = "kwh_total, kwh_week_total, kwh_weekend_total FROM ".$table." "; + $req = "SELECT year, month, day, hour, dow, SUM(kwh_total) FROM energy_hour_stat "; if($unit <> "year"){ $req2.= "WHERE "; if($year) $req2.= "year = \"$year\" "; if($month) $req2.= "AND month = \"$month\" "; + if($addr) $req2.= "AND addr = \"$addr\" "; if($day){ - $req2.= "AND day = \"$day\" "; - $req2.="UNION SELECT hour+24, ".$req2."+1 AND hour=0 "; - } + $req2.= "AND day = \"$day\" "; + // $req2.="UNION SELECT hour+24, ".$req2."+1 AND hour=0 "; + } + if ($addr) + $reg2.= "AND addr = \"$addr\" "; } - - $req.= $req2."ORDER BY $unit;"; - + $req.= $req2."GROUP BY".($addr ? " addr," : "")." year, month, day, hour, dow ORDER BY year, month, day, hour;"; // echo "
$req

"; $db->busyTimeout (10000); + echo "
".$req;
   $result = $db->query($req);
   $arr = array();
   while ($res = $result->fetchArray())
   {
-    if($unit == "month")
-      $arr[$i] = array( 0 => month_to_string($res[0]), 
-                        1 => $res[1],
-                        2 => $res[2],
-                        3 => $res[3] );
-    else
-      $arr[$i] = array( 0 => "$res[0]",
-                        1 => $res[1],
-                        2 => $res[2],
-                        3 => $res[3] );
-                        
-    $i++;
-  }
-  return $arr;
+  //print_r($res);
+  //  echo "o godzinie ".$res[3]." w ".$res[4]." jest taryfa nr ".$tariffs[$tariff][$res[4]][$res[3]]."
"; + switch($unit) { + case 'year': + $index = $res[0]; + $arr[$index][0] = "$res[0]"; + break; + case 'month': + $index = $res[1]; + $arr[$index][0] = month_to_string($res[1]); + break; + case 'day': + $index = $res[2]; + $arr[$index][0] = "$res[2]"; + break; + case 'hour': + $index = $res[3]; + $arr[$index][0] = "$res[3]"; + break; + default: + } + $arr[$index][1] += $res[5]; + $arr[$index][2] +=0; + $arr[$index][3] +=0; + $arr[$index][4] +=0; + $arr[$index][$tariffs[$tariff][$res[4]][$res[3]]+2] += $res[5]; + + return array_values($arr); } -function get_weekend_data($db, $year=0, $month=0, $day=0) -{ +function get_weekend_data($db, $year=0, $month=0, $day=0, $addr=0) { $i = 0; - if($year) - { + if($year) { $table = "energy_year_stat"; if($month) $table = "energy_month_stat"; if($day) $table = "energy_day_stat"; - $req = "SELECT kwh_week_total, kwh_weekend_total FROM ".$table; + $req = "SELECT 10 AS kwh_week_total, 20 AS kwh_weekend_total FROM ".$table; $req.= " WHERE "; if($year) $req.= "year = \"$year\" "; if($month) $req.= "AND month = \"$month\" "; if($day) $req.= "AND day = \"$day\" "; } else - $req = "SELECT sum(kwh_week_total), sum(kwh_weekend_total) FROM energy_year_stat"; + $req = "SELECT 15 AS kwh_week_total, 25 AS kwh_weekend_total FROM energy_year_stat"; $req.= ";"; @@ -223,21 +248,25 @@ function get_weekend_data($db, $year=0, $month=0, $day=0) $graph_type = 'bar'; // graph type : bar, line or pie $title = "Total"; $axis_x_name = ''; +if(isset($_GET['addr'])) { + $addr = intval($_GET['addr']); + +} if(isset($_GET['year'])) { - $year = $_GET['year']; + $year = intval($_GET['year']); $title = "$year"; $axis_x_name = 'month'; } if(isset($_GET['month'])) { - $month = $_GET['month']; + $month = intval($_GET['month']); $title = month_to_string($month)." $year"; $axis_x_name = 'day'; } if(isset($_GET['day'])) { - $day = $_GET['day']; + $day = intval($_GET['day']); $graph_type = 'line'; $title = "$day ".month_to_string($month)." $year"; $axis_x_name = 'hour'; @@ -245,12 +274,13 @@ function get_weekend_data($db, $year=0, $month=0, $day=0) if($stat_db) { - $data = get_stat_data($stat_db, $year, $month, $day); - $wedata = get_weekend_data($stat_db, $year, $month, $day); + $data = get_stat_data($stat_db, $year, $month, $day, $addr); + print_r($data); +// $wedata = get_weekend_data($stat_db, $year, $month, $day, $addr); } else { - $data = get_data($db, $year, $month, $day); + $data = get_data($db, $year, $month, $day, $addr); } // Following lines are to select a valid date in the calendar From 7c13529df373671b4f1d1eacb0e1ad8df7148d3a Mon Sep 17 00:00:00 2001 From: Tomasz Brzezina Date: Sat, 18 Oct 2014 13:06:50 +0200 Subject: [PATCH 6/7] cleaning --- www/index.php | 154 +++++++++++++++++++--------------------------- www/live_data.php | 8 --- 2 files changed, 64 insertions(+), 98 deletions(-) delete mode 100644 www/live_data.php diff --git a/www/index.php b/www/index.php index 7aa4dbb..6d059c3 100644 --- a/www/index.php +++ b/www/index.php @@ -70,29 +70,29 @@ function var_to_js($jsname,$a) function get_data($db, $year=0, $month=0, $day=0, $addr=0) { $i = 0; $unit = "year"; - if($year) + if ($year) $unit = "month"; - if($month) + if ($month) $unit = "day"; - if($day) + if ($day) $unit = "hour"; $req = "SELECT "; $req.= "$unit, "; $req.= "SUM(ch1_kw_avg / 1000) FROM energy_history "; - if($unit <> "year"){ + if ($unit <> "year"){ $req.= "WHERE "; - if($year) $req.= "year = \"$year\" "; - if($month) $req.= "AND month = \"$month\" "; - if($day) $req.= "AND day = \"$day\" "; + if ($year) $req.= "year = \"$year\" "; + if ($month) $req.= "AND month = \"$month\" "; + if ($day) $req.= "AND day = \"$day\" "; } if ($addr) { $req.="AND addr = \"$addr\" "; } $req.= "GROUP BY year"; - if($year) $req.= ", month"; - if($month) $req.= ", day"; - if($day) $req.= ", hour"; + if ($year) $req.= ", month"; + if ($month) $req.= ", day"; + if ($day) $req.= ", hour"; $req.= ";"; // echo "
$req

"; @@ -101,7 +101,7 @@ function get_data($db, $year=0, $month=0, $day=0, $addr=0) { $arr = array(); while ($res = $result->fetchArray()) { - if($unit == "month") + if ($unit == "month") $arr[$i] = array( 0 => month_to_string($res[0]), 1 => $res[1] ); else $arr[$i] = array( 0 => "$res[0]", 1 => $res[1] ); @@ -115,23 +115,23 @@ function get_stat_data($db, $year=0, $month=0, $day=0, $addr=0) { $i = 0; $unit = "year"; $table = "energy_hour_stat"; - if($year){ + if ($year){ $unit = "month"; } - if($month){ + if ($month){ $unit = "day"; } - if($day){ + if ($day){ $unit = "hour"; } $req = "SELECT year, month, day, hour, dow, SUM(kwh_total) FROM energy_hour_stat "; - if($unit <> "year"){ + if ($unit <> "year"){ $req2.= "WHERE "; - if($year) $req2.= "year = \"$year\" "; - if($month) $req2.= "AND month = \"$month\" "; - if($addr) $req2.= "AND addr = \"$addr\" "; - if($day){ + if ($year) $req2.= "year = \"$year\" "; + if ($month) $req2.= "AND month = \"$month\" "; + if ($addr) $req2.= "AND addr = \"$addr\" "; + if ($day){ $req2.= "AND day = \"$day\" "; // $req2.="UNION SELECT hour+24, ".$req2."+1 AND hour=0 "; } @@ -141,13 +141,9 @@ function get_stat_data($db, $year=0, $month=0, $day=0, $addr=0) { $req.= $req2."GROUP BY".($addr ? " addr," : "")." year, month, day, hour, dow ORDER BY year, month, day, hour;"; // echo "
$req

"; $db->busyTimeout (10000); - echo "
".$req;
   $result = $db->query($req);
   $arr = array();
-  while ($res = $result->fetchArray())
-  {
-  //print_r($res);
-  //  echo "o godzinie ".$res[3]." w ".$res[4]." jest taryfa nr ".$tariffs[$tariff][$res[4]][$res[3]]."
"; + while ($res = $result->fetchArray()) { switch($unit) { case 'year': $index = $res[0]; @@ -172,40 +168,19 @@ function get_stat_data($db, $year=0, $month=0, $day=0, $addr=0) { $arr[$index][3] +=0; $arr[$index][4] +=0; $arr[$index][$tariffs[$tariff][$res[4]][$res[3]]+2] += $res[5]; - - return array_values($arr); -} - -function get_weekend_data($db, $year=0, $month=0, $day=0, $addr=0) { - $i = 0; - if($year) { - $table = "energy_year_stat"; - if($month) - $table = "energy_month_stat"; - if($day) - $table = "energy_day_stat"; - - $req = "SELECT 10 AS kwh_week_total, 20 AS kwh_weekend_total FROM ".$table; - $req.= " WHERE "; - if($year) $req.= "year = \"$year\" "; - if($month) $req.= "AND month = \"$month\" "; - if($day) $req.= "AND day = \"$day\" "; } - else - $req = "SELECT 15 AS kwh_week_total, 25 AS kwh_weekend_total FROM energy_year_stat"; + foreach($arr as $key=>$item) { + $val1+=$item[2]; + $val2+=$item[3]; + $val3+=$item[4]; + } + $arr2[0] = array( 0 => 'Rate 1', 1 => $val1); + $arr2[1] = array( 0 => 'Rate 2', 1 => $val2); + $arr2[2] = array( 0 => 'Rate 3', 1 => $val3); - $req.= ";"; - -// echo "
$req

"; - $result = $db->query($req); - $arr = array(); - $res = $result->fetchArray(); -// { - $arr[0] = array( 0 => 'normal', 1 => $res[0]); - $arr[1] = array( 0 => 'night & weekend', 1 => $res[1]); -// $i++; -// } - return $arr; + $all['bar']=array_values($arr); + $all['pie']=$arr2; + return $all; } $config = parse_ini_file('/etc/eagleowl.conf', true); @@ -215,21 +190,21 @@ function get_weekend_data($db, $year=0, $month=0, $day=0, $addr=0) { $main_db = "eagleowl.db"; $stat_db = "eagleowl_stat.db"; -if(isset($config['install_path'])) +if (isset($config['install_path'])) $root_path = $config['install_path']; -if(isset($config['db_subdir'])) +if (isset($config['db_subdir'])) $db_subdir = $config['db_subdir']; -if(isset($config['main_db_name'])) +if (isset($config['main_db_name'])) $main_db = $config['main_db_name']; -if(isset($config['stat_db_name'])) +if (isset($config['stat_db_name'])) $stat_db = $config['stat_db_name']; -if($root_path === "" || !is_dir($root_path)) +if ($root_path === "" || !is_dir($root_path)) { echo"invalid path \"$root_path\": set the correct install_path in /etc/eaglowl.conf"; exit(); } -if(!is_dir($root_path."/".$db_subdir)) +if (!is_dir($root_path."/".$db_subdir)) { echo "invalid path \"$root_path/$db_subdir\": "; echo "set the correct install_path and db_subdir in /etc/eaglowl.conf"; @@ -248,45 +223,42 @@ function get_weekend_data($db, $year=0, $month=0, $day=0, $addr=0) { $graph_type = 'bar'; // graph type : bar, line or pie $title = "Total"; $axis_x_name = ''; -if(isset($_GET['addr'])) { +if (isset($_GET['addr'])) { $addr = intval($_GET['addr']); } -if(isset($_GET['year'])) +if (isset($_GET['year'])) { $year = intval($_GET['year']); $title = "$year"; $axis_x_name = 'month'; } -if(isset($_GET['month'])) -{ +if (isset($_GET['month'])) { $month = intval($_GET['month']); $title = month_to_string($month)." $year"; $axis_x_name = 'day'; } -if(isset($_GET['day'])) -{ +if (isset($_GET['day'])) { $day = intval($_GET['day']); $graph_type = 'line'; $title = "$day ".month_to_string($month)." $year"; $axis_x_name = 'hour'; } -if($stat_db) -{ - $data = get_stat_data($stat_db, $year, $month, $day, $addr); - print_r($data); -// $wedata = get_weekend_data($stat_db, $year, $month, $day, $addr); -} -else -{ +if ($stat_db) { + $all = get_stat_data($stat_db, $year, $month, $day, $addr); +// echo "
";
+//  print_r($all);
+  $data = $all['bar'];
+  $wedata = $all['pie'];
+} else {
   $data = get_data($db, $year, $month, $day, $addr);
 }
 
 // Following lines are to select a valid date in the calendar
-if(!$year) $year = date('Y');
-if(!$month) $month = date('m');
-//if(!$day) $day = date('d');
+if (!$year) $year = date('Y');
+if (!$month) $month = date('m');
+//if (!$day) $day = date('d');
 ?>
 
 ";
-  if($wedata)
+  if ($wedata)
     echo "
"; } diff --git a/www/live_data.php b/www/live_data.php deleted file mode 100644 index 9b619f0..0000000 --- a/www/live_data.php +++ /dev/null @@ -1,8 +0,0 @@ - From 7973710307f7e73957c1a7da234524582ffb48e2 Mon Sep 17 00:00:00 2001 From: Tomasz Brzezina Date: Thu, 23 Oct 2014 23:27:02 +0200 Subject: [PATCH 7/7] split tariffs and prices into subfiles --- www/index.php | 27 +++---- .../jsDatePick.full.1.3.js | 2 +- www/listValidDays.php | 2 +- www/prices.php | 17 +++++ www/tariffs.php | 75 +++++++++++++++++++ 5 files changed, 105 insertions(+), 18 deletions(-) create mode 100644 www/prices.php create mode 100644 www/tariffs.php diff --git a/www/index.php b/www/index.php index 6d059c3..0d44fc0 100644 --- a/www/index.php +++ b/www/index.php @@ -12,15 +12,8 @@ 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 0, 23 => 0); - $tariffs['G12'][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 1, 14 => 1, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 1, 23 => 1); - if ($i==0 || $i==6) { - $tariffs['G12w'][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 1, 14 => 1, 15 => 1, 16 => 1, 17 => 1, 18 => 1, 19 => 1, 20 => 1, 21 => 1, 22 => 1, 23 => 0); - } else { - $tariffs['G12w'][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 1, 14 => 1, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 1, 23 => 1); - } -} +require "prices.php"; +require "tariffs.php"; if (isset($_GET['tariff'])) { $tariff=$_GET['tariff']; } else { @@ -111,7 +104,7 @@ function get_data($db, $year=0, $month=0, $day=0, $addr=0) { } function get_stat_data($db, $year=0, $month=0, $day=0, $addr=0) { - global $tariffs,$tariff; + global $tariffs,$tariff,$prices; $i = 0; $unit = "year"; $table = "energy_hour_stat"; @@ -167,19 +160,20 @@ function get_stat_data($db, $year=0, $month=0, $day=0, $addr=0) { $arr[$index][2] +=0; $arr[$index][3] +=0; $arr[$index][4] +=0; - $arr[$index][$tariffs[$tariff][$res[4]][$res[3]]+2] += $res[5]; + $arr[$index][$tariffs[$tariff][$res[1]][$res[4]][$res[3]]+2] += $res[5]; } foreach($arr as $key=>$item) { $val1+=$item[2]; $val2+=$item[3]; $val3+=$item[4]; } - $arr2[0] = array( 0 => 'Rate 1', 1 => $val1); - $arr2[1] = array( 0 => 'Rate 2', 1 => $val2); - $arr2[2] = array( 0 => 'Rate 3', 1 => $val3); + $arr2[0] = array( 0 => round($prices[$tariff][0]*$val1/1000,2)." zł", 1 => $val1); + $arr2[1] = array( 0 => round($prices[$tariff][1]*$val2/1000,2)." zł", 1 => $val2); + $arr2[2] = array( 0 => round($prices[$tariff][2]*$val3/1000,2)." zł", 1 => $val3); $all['bar']=array_values($arr); $all['pie']=$arr2; + $all['pietitle']=round($prices[$tariff][0]*$val1/1000,2)+ round($prices[$tariff][1]*$val2/1000,2)+round($prices[$tariff][2]*$val3/1000,2)." zł"; return $all; } @@ -251,6 +245,7 @@ function get_stat_data($db, $year=0, $month=0, $day=0, $addr=0) { // print_r($all); $data = $all['bar']; $wedata = $all['pie']; + $pietitle = $all['pietitle']; } else { $data = get_data($db, $year, $month, $day, $addr); } @@ -340,7 +335,7 @@ function draw_we_chart(title, axis_x_name) myChart.setLegend('#88FF88', 'Rate 2'); myChart.setLegend('#8888FF', 'Rate 3'); myChart.setPieRadius(95); - myChart.setShowXValues(false); + myChart.setShowXValues(true); myChart.setLegendShow(true); myChart.setLegendFontFamily('Times New Roman'); myChart.setLegendFontSize(10); @@ -400,7 +395,7 @@ function draw_we_chart(title, axis_x_name) else{ echo "
"; if ($wedata) - echo "
"; + echo "
"; } ?> diff --git a/www/jsdatepick-calendar/jsDatePick.full.1.3.js b/www/jsdatepick-calendar/jsDatePick.full.1.3.js index a580e38..b3509ba 100755 --- a/www/jsdatepick-calendar/jsDatePick.full.1.3.js +++ b/www/jsdatepick-calendar/jsDatePick.full.1.3.js @@ -59,7 +59,7 @@ g_l = []; g_l["MONTHS"]= []; g_l["DAYS_3"]= []; var formatter = new Intl.DateTimeFormat("pl", { month: "long" }); -for(i=1;i<13;i++) { +for(i=0;i<12;i++) { g_l["MONTHS"].push(formatter.format(new Date(2000,i,1))); } //g_l["MONTHS"] = ["January","February","March","April","May","June","July","August","September","Paździer","November","December"]; diff --git a/www/listValidDays.php b/www/listValidDays.php index 451c753..104cbb8 100644 --- a/www/listValidDays.php +++ b/www/listValidDays.php @@ -36,7 +36,7 @@ $stat_db = $root_path."/".$db_subdir."/".$stat_db; $db = new SQLite3($stat_db); - $req = "SELECT day, status FROM energy_day_stat WHERE year = $year and month = $month;"; + $req = "SELECT day, status FROM energy_hour_stat WHERE year = $year and month = $month GROUP BY year,month, day ;"; $db->busyTimeout (10000); $result = $db->query($req); while ($res = $result->fetchArray()) diff --git a/www/prices.php b/www/prices.php new file mode 100644 index 0000000..80f56bf --- /dev/null +++ b/www/prices.php @@ -0,0 +1,17 @@ + 338.90); +$prices['A23']=array(0 => 402.90, 1 => 383.80, 2=> 247.90); +$prices['B21']=array(0 => 311.90); +$prices['B11']=array(0 => 311.90); +$prices['B21']=array(0 => 311.90); +$prices['B22']=array(0 => 369.70, 1 => 279.40); +$prices['B23']=array(0 => 402.90, 1 => 383.80, 2 => 247.90); +$prices['C21']=array(0 => 335.80); +$prices['C22a']=array(0 => 393.40, 1 => 299.90); +$prices['C22b']=array(0 => 375.70, 1 => 252.80); +$prices['C23']=array(0 => 433.80, 1 => 426.60, 2 => 267.30); +$prices['C11']=array(0 => 338.90); +$prices['C12a']=array(0 => 416.40, 1 =>295.60); +$prices['C12b']=array(0 => 426.70, 1 =>246.40); +$prices['C13']=array(0 => 438.40, 1 => 422.00, 2 => 266.70); +?> diff --git a/www/tariffs.php b/www/tariffs.php new file mode 100644 index 0000000..426ff12 --- /dev/null +++ b/www/tariffs.php @@ -0,0 +1,75 @@ + 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 0, 23 => 0); + $tariffs['B11'][$j][$i] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 0, 23 => 0); + $tariffs['B21'][$j][$i] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 0, 23 => 0); + $tariffs['C11'][$j][$i] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 0, 23 => 0); + $tariffs['C21'][$j][$i] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 0, 23 => 0); + + $tariffs['C12b'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 1, 14 => 1, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 1, 23 => 1); + $tariffs['C22b'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 1, 22 => 1, 23 => 1); + + $tariffs['G11'][$j][$i] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 0, 14 => 0, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 0, 23 => 0); + $tariffs['G12'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 0, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 1, 14 => 1, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 1, 23 => 1); + $tariffs['G12w'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 0, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0, 13 => 1, 14 => 1, 15 => 0, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 0, 22 => 1, 23 => 1); + switch ($j) { + case 1: + case 2: + case 11: + case 12: + $tariffs['B22'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 0, 9 => 0, 10 => 0, 11 => 1, 12 => 1, 13 => 1, 14 => 1, 15 => 1, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 1, 22 => 1, 23 => 1); + $tariffs['C12a'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 0, 9 => 0, 10 => 0, 11 => 1, 12 => 1, 13 => 1, 14 => 1, 15 => 1, 16 => 1, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 1, 22 => 1, 23 => 1); + $tariffs['C22a'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 0, 9 => 0, 10 => 0, 11 => 1, 12 => 1, 13 => 1, 14 => 1, 15 => 1, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 1, 22 => 1, 23 => 1); + $tariffs['A23'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + $tariffs['B23'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + $tariffs['C13'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + $tariffs['C23'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + $tariffs['G13'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + break; + case 3: + case 10: + $tariffs['B22'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 0, 9 => 0, 10 => 0, 11 => 1, 12 => 1, 13 => 1, 14 => 1, 15 => 1, 16 => 1, 17 => 1, 18 => 0, 19 => 0, 20 => 0, 21 => 1, 22 => 1, 23 => 1); + $tariffs['C12a'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 0, 9 => 0, 10 => 0, 11 => 1, 12 => 1, 13 => 1, 14 => 1, 15 => 1, 16 => 1, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 1, 22 => 1, 23 => 1); + $tariffs['C22a'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 0, 9 => 0, 10 => 0, 11 => 1, 12 => 1, 13 => 1, 14 => 1, 15 => 1, 16 => 1, 17 => 1, 18 => 0, 19 => 0, 20 => 0, 21 => 1, 22 => 1, 23 => 1); + $tariffs['A23'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + $tariffs['B23'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + $tariffs['C13'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + $tariffs['C23'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + $tariffs['G13'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 0, 17 => 0, 18 => 0, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + break; + case 4: + case 9: + $tariffs['B22'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 0, 9 => 0, 10 => 0, 11 => 1, 12 => 1, 13 => 1, 14 => 1, 15 => 1, 16 => 1, 17 => 1, 18 => 1, 19 => 0, 20 => 0, 21 => 1, 22 => 1, 23 => 1); + $tariffs['C12a'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 0, 9 => 0, 10 => 0, 11 => 1, 12 => 1, 13 => 1, 14 => 1, 15 => 1, 16 => 1, 17 => 1, 18 => 1, 19 => 1, 20 => 0, 21 => 1, 22 => 1, 23 => 1); + $tariffs['C22a'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 0, 9 => 0, 10 => 0, 11 => 1, 12 => 1, 13 => 1, 14 => 1, 15 => 1, 16 => 1, 17 => 1, 18 => 1, 19 => 0, 20 => 0, 21 => 1, 22 => 1, 23 => 1); + $tariffs['A23'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 2, 17 => 2, 18 => 2, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + $tariffs['B23'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 2, 17 => 2, 18 => 2, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + $tariffs['C13'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 2, 17 => 2, 18 => 2, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + $tariffs['C23'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 2, 17 => 2, 18 => 2, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + $tariffs['G13'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 2, 17 => 2, 18 => 2, 19 => 0, 20 => 0, 21 => 0, 22 => 2, 23 => 2); + break; + case 5: + case 6: + case 7: + case 8: + $tariffs['B22'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 0, 9 => 0, 10 => 0, 11 => 1, 12 => 1, 13 => 1, 14 => 1, 15 => 1, 16 => 1, 17 => 1, 18 => 1, 19 => 1, 20 => 0, 21 => 1, 22 => 1, 23 => 1); + $tariffs['C12a'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 0, 9 => 0, 10 => 0, 11 => 1, 12 => 1, 13 => 1, 14 => 1, 15 => 1, 16 => 1, 17 => 1, 18 => 1, 19 => 1, 20 => 0, 21 => 1, 22 => 1, 23 => 1); + $tariffs['C22a'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 0, 9 => 0, 10 => 0, 11 => 1, 12 => 1, 13 => 1, 14 => 1, 15 => 1, 16 => 1, 17 => 1, 18 => 1, 19 => 1, 20 => 0, 21 => 1, 22 => 1, 23 => 1); + $tariffs['A23'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 2, 17 => 2, 18 => 2, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + $tariffs['B23'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 2, 17 => 2, 18 => 2, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + $tariffs['C13'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 2, 17 => 2, 18 => 2, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + $tariffs['C23'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 2, 17 => 2, 18 => 2, 19 => 0, 20 => 0, 21 => 2, 22 => 2, 23 => 2); + $tariffs['G13'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 2, 14 => 2, 15 => 2, 16 => 2, 17 => 2, 18 => 2, 19 => 0, 20 => 0, 21 => 0, 22 => 2, 23 => 2); + break; + } + if ($i==0 || $i==6) { + $tariffs['G12w'][$j][$i] = array(0 => 1, 1 => 1, 2 => 1, 3 => 1, 4 => 1, 5 => 1, 6 => 1, 7 => 1, 8 => 1, 9 => 1, 10 => 1, 11 => 1, 12 => 1, 13 => 1, 14 => 1, 15 => 1, 16 => 1, 17 => 1, 18 => 1, 19 => 1, 20 => 1, 21 => 1, 22 => 1, 23 => 1); + $tariffs['A23'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 2, 8 => 2, 9 => 2, 10 => 2, 11 => 2, 12 => 2, 13 => 2, 14 => 2, 15 => 2, 16 => 2, 17 => 2, 18 => 2, 19 => 2, 20 => 2, 21 => 2, 22 => 2, 23 => 2); + $tariffs['B23'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 2, 8 => 2, 9 => 2, 10 => 2, 11 => 2, 12 => 2, 13 => 2, 14 => 2, 15 => 2, 16 => 2, 17 => 2, 18 => 2, 19 => 2, 20 => 2, 21 => 2, 22 => 2, 23 => 2); + $tariffs['C13'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 2, 8 => 2, 9 => 2, 10 => 2, 11 => 2, 12 => 2, 13 => 2, 14 => 2, 15 => 2, 16 => 2, 17 => 2, 18 => 2, 19 => 2, 20 => 2, 21 => 2, 22 => 2, 23 => 2); + $tariffs['C23'][$j][$i] = array(0 => 2, 1 => 2, 2 => 2, 3 => 2, 4 => 2, 5 => 2, 6 => 2, 7 => 2, 8 => 2, 9 => 2, 10 => 2, 11 => 2, 12 => 2, 13 => 2, 14 => 2, 15 => 2, 16 => 2, 17 => 2, 18 => 2, 19 => 2, 20 => 2, 21 => 2, 22 => 2, 23 => 2); + } + } +} +?>