From 0fcdac97208facd593523f1e19290e2679269a04 Mon Sep 17 00:00:00 2001 From: losinshi Date: Wed, 13 Sep 2006 07:31:05 +0000 Subject: [PATCH] chart: min / max - generating git-svn-id: file:///home/jan/tmp/wetterstation/trunk@83 dd492736-c11a-0410-ad51-8c26713eaf7f --- cronjob/chart/image_file/image_data.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cronjob/chart/image_file/image_data.c b/cronjob/chart/image_file/image_data.c index 512c4f3..6008fd8 100644 --- a/cronjob/chart/image_file/image_data.c +++ b/cronjob/chart/image_file/image_data.c @@ -13,6 +13,9 @@ +static pix_list_ptr min = NULL; +static pix_list_ptr max = NULL; + static pix_list_ptr add_pix_value(pix_list_ptr , int , int ); static char *get_conn_string(); @@ -58,12 +61,27 @@ pix_list_ptr get_pix_list(int c_width){ pix_coord = floor( ((double)time_temp) * seconds_per_pix) ; temp_ptr = add_pix_value(temp_ptr, pix_coord, atoi( PQgetvalue(res, i, val_field) ) ); - if(list_ptr == NULL){ + if (list_ptr == NULL) list_ptr = temp_ptr; + + /* Min / Max ermitteln */ + if (min != NULL){ + if ( (temp_ptr->value_sum / temp_ptr->value_count) < (min->value_sum / min->value_count) ) + min = temp_ptr; + } else { + min = temp_ptr; } + if (max != NULL){ + if ( (temp_ptr->value_sum / temp_ptr->value_count) > (max->value_sum / max->value_count) ) + max = temp_ptr; + } else { + max = temp_ptr; + } } + DEBUGOUT3(" Min: x-pos.: %d, Wert: %d\n", min->x_pix_coord, (min->value_sum / min->value_count) ); + DEBUGOUT3(" Max: x-pos.: %d, Wert: %d\n", max->x_pix_coord, (max->value_sum / max->value_count) ); PQclear(res); PQfinish(conn); free(query);