From 329ed6e6b4af09ae6d06976b8a2d40f760246b5e Mon Sep 17 00:00:00 2001 From: losinshi Date: Tue, 12 Sep 2006 23:17:18 +0000 Subject: [PATCH] chart fetchs data git-svn-id: file:///home/jan/tmp/wetterstation/trunk@81 dd492736-c11a-0410-ad51-8c26713eaf7f --- cronjob/chart/image_file/image_data.c | 19 +++++++++---------- cronjob/chart/image_file/testimage.conf | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cronjob/chart/image_file/image_data.c b/cronjob/chart/image_file/image_data.c index e55bef5..c60b440 100644 --- a/cronjob/chart/image_file/image_data.c +++ b/cronjob/chart/image_file/image_data.c @@ -44,7 +44,7 @@ pix_list_ptr get_pix_list(int c_width){ DEBUGOUT1("\nHole Daten...\n"); DEBUGOUT2(" Ein Pixel entspricht %f sekunden\n", seconds_per_pix); - snprintf(query, BUFFSIZE, "SELECT round(date_part('epoch', current_timestamp)) AS now, round(date_part('epoch', timestamp)) AS times, %s AS val FROM %s WHERE timestamp > (current_timestamp - INTERVAL '%d seconds') ORDER BY times DESC", img_cfg.table_field, table, img_cfg.show_interval ); + snprintf(query, BUFFSIZE, "SELECT round(date_part('epoch', current_timestamp)) AS now, round(date_part('epoch', timestamp)) AS times, %s AS val FROM %s WHERE timestamp > (current_timestamp - INTERVAL '%d seconds') ORDER BY times ASC", img_cfg.table_field, table, img_cfg.show_interval ); res = pg_check_exec(conn, query); @@ -64,40 +64,39 @@ pix_list_ptr get_pix_list(int c_width){ } - - - - - - PQclear(res); PQfinish(conn); free(query); free(table); free(conn_string); - return NULL; + return list_ptr; } -static pix_list_ptr add_pix_value(pix_list_ptr ptr, int coord, int value){ - +static pix_list_ptr add_pix_value(pix_list_ptr ptr, int coord, int value){ + if(ptr == NULL){ + DEBUGOUT1("\nLese Daten ein:\n"); ptr = malloc(sizeof(pix_list_t)); ptr->next = NULL; ptr->x_pix_coord = 0; ptr->value_count = 0; ptr->value_sum = 0; + DEBUGOUT1(" Erstes Element generiert...\n"); } if(coord == ptr->x_pix_coord){ ptr->value_sum += value; ptr->value_count++; + DEBUGOUT5(" Zu x-pos. %d %d. Wert (%d) hinzugefügt. Durchschn.: %d\n", ptr->x_pix_coord, ptr->value_count, value, (ptr->value_sum/ptr->value_count) ); } else { ptr->next = malloc(sizeof(pix_list_t)); ptr = ptr->next; + ptr->x_pix_coord = coord; ptr->value_sum = value; ptr->value_count = 1; ptr->next = NULL; + DEBUGOUT3(" An x-pos. %d Wert %d eingefuegt\n", ptr->x_pix_coord, ptr->value_sum); } return ptr; diff --git a/cronjob/chart/image_file/testimage.conf b/cronjob/chart/image_file/testimage.conf index c5a923b..40ad75f 100644 --- a/cronjob/chart/image_file/testimage.conf +++ b/cronjob/chart/image_file/testimage.conf @@ -2,7 +2,7 @@ filename /home/jan/Testbild.png headline Testbild table_field temp gen_interval 15m -show_interval 1h +show_interval 10h label_interval 10m label_sum no width 400