little chart-bugfix

git-svn-id: file:///home/jan/tmp/wetterstation/trunk@211 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
losinshi 2007-01-08 20:26:06 +00:00
parent 6accab764c
commit 5ae7688a87
3 changed files with 30 additions and 18 deletions

View File

@ -26,7 +26,8 @@
#define DEFAULT_PG_PASS "" /* Postgres-Passwort */ #define DEFAULT_PG_PASS "" /* Postgres-Passwort */
#define DEFAULT_PG_DATABASE "localbase" /* Postgres-Datenbank */ #define DEFAULT_PG_DATABASE "localbase" /* Postgres-Datenbank */
#define DEFAULT_PG_TIMEOUT "20" /* Postgres-Timeout */ #define DEFAULT_PG_TIMEOUT "20" /* Postgres-Timeout */
#define DEFAULT_CONFIG_FILE "/etc/weatherstation/chart.conf" /* Standart-Configdatei */ //#define DEFAULT_CONFIG_FILE "/etc/weatherstation/chart.conf" /* Standart-Configdatei */
#define DEFAULT_CONFIG_FILE "/home/jan/wettertest/chart/chart.conf" /* Standart-Configdatei */
/* Image-Default-Werte ----------------------------------------------- */ /* Image-Default-Werte ----------------------------------------------- */

View File

@ -6,7 +6,7 @@ manual_table_name auss2_data
table_field temp table_field temp
#table_field press #table_field press
gen_interval 1 gen_interval 1
show_interval 30d show_interval 10d
label_interval 3d label_interval 3d
fixed_timepoint no fixed_timepoint no
timepoint 2006-12-17-13-00 timepoint 2006-12-17-13-00

View File

@ -37,11 +37,12 @@
/* Variablen */ /* Variablen */
static pix_list_ptr min = NULL; /* Pointer auf min - Element */ static pix_list_ptr min = NULL; /* Pointer auf min - Element */
static pix_list_ptr max = NULL; /* Pointer auf Max - Element */ static pix_list_ptr max = NULL; /* Pointer auf Max - Element */
double padd_val = 0; /* Wert, der oben und unten auf das 'reale' Max u. min aufgerechnet wird, damit die Linie nicht 'anstoesst' */ double graph_min = 0; /* graphen-maximum */
double real_min = 0; /* Realer Max - Wert */ double graph_max = 0; /* graphen-minimum */
double real_max = 0; /* Realer Min - Wert */
static long base_time; /* Zeit an der 0-Koordinate (lt. Datenbank!) */ static long base_time; /* Zeit an der 0-Koordinate (lt. Datenbank!) */
int max_diff = 0; /* Maximaler Abstand, den 2 Werte haben duerfen, ohne das die Linie unterbrochen wird */ int max_diff = 0; /* Maximaler Abstand, den 2 Werte haben duerfen, ohne das die Linie unterbrochen wird */
int real_min = 0;
int real_max = 0;
/* Funktionsdefinitionen */ /* Funktionsdefinitionen */
@ -67,6 +68,7 @@ label_list_ptr get_y_label_list(int c_hight, int padding){
int i; int i;
int new_val = 0; int new_val = 0;
char * buff = NULL; char * buff = NULL;
double padd_val = 0; /* Wert, der oben und unten auf das 'reale' Max u. min aufgerechnet wird, damit die Linie nicht 'anstoesst' */
label_list_ptr ptr = NULL; label_list_ptr ptr = NULL;
label_list_ptr new_ptr = NULL; label_list_ptr new_ptr = NULL;
@ -94,11 +96,11 @@ label_list_ptr get_y_label_list(int c_hight, int padding){
factor = ( ((double)c_hight - (2 * padding)) / ((double)diff) ); factor = ( ((double)c_hight - (2 * padding)) / ((double)diff) );
padd_val = (1 / factor) * ((double)padding); padd_val = (1 / factor) * ((double)padding);
real_min = min_val - padd_val; graph_min = min_val - padd_val;
real_max = max_val + padd_val; graph_max = max_val + padd_val;
real_diff = real_max - real_min; real_diff = graph_max - graph_min;
DEBUGOUT5(" Realer Max. Wert: %3.3f, Realer Min. Wert: %3.3f Differenz: %3.3f (inkl. Koeffizient: %3.3f)\n", real_max, real_min, real_diff, img_cfg.val_koeff); DEBUGOUT5(" Realer Max. Wert: %3.3f, Realer Min. Wert: %3.3f Differenz: %3.3f (inkl. Koeffizient: %3.3f)\n", graph_max, graph_min, real_diff, img_cfg.val_koeff);
/* Interval der Labels berechnen */ /* Interval der Labels berechnen */
@ -112,7 +114,7 @@ label_list_ptr get_y_label_list(int c_hight, int padding){
DEBUGOUT2(" Interval: %f \n", interval); DEBUGOUT2(" Interval: %f \n", interval);
/* An Labels auf die 0 'eichen' */ /* An Labels auf die 0 'eichen' */
temp = ceil(real_min); temp = ceil(graph_min);
while (fmod(((double)temp), ((double)interval)) != 0){ while (fmod(((double)temp), ((double)interval)) != 0){
temp++; temp++;
} }
@ -121,7 +123,7 @@ label_list_ptr get_y_label_list(int c_hight, int padding){
* daher den Zaehler um eins erhoehen und wenn dabei ueber * daher den Zaehler um eins erhoehen und wenn dabei ueber
* den Bereich hinaus, dann wieder eins runter */ * den Bereich hinaus, dann wieder eins runter */
num++; num++;
if ((temp + ((num - 1) * interval)) > (real_max - 1)) if ((temp + ((num - 1) * interval)) > (graph_max - 0.5))
num--; num--;
/* Puffer fuer die Labels */ /* Puffer fuer die Labels */
@ -142,7 +144,7 @@ label_list_ptr get_y_label_list(int c_hight, int padding){
/* Neues Label - Element */ /* Neues Label - Element */
new_ptr = malloc(sizeof(label_list_t)); new_ptr = malloc(sizeof(label_list_t));
new_ptr->pos = floor( (real_max - ((double)new_val) ) * factor); new_ptr->pos = floor( (graph_max - ((double)new_val) ) * factor);
new_ptr->value = new_val; new_ptr->value = new_val;
new_ptr->text = strdup(buff); new_ptr->text = strdup(buff);
new_ptr->next = NULL; new_ptr->next = NULL;
@ -219,9 +221,9 @@ label_list_ptr get_x_label_list(int c_width){
/* Skaliert die X-Koordinaten der Punkte im angegebenem Bereich /* Skaliert die X-Koordinaten der Punkte im angegebenem Bereich
* ausfuehrliche Beschreibung im header-file */ * ausfuehrliche Beschreibung im header-file */
int scale_y_coords(pix_list_ptr ptr, int c_height){ int scale_y_coords(pix_list_ptr ptr, int c_height){
double range = (((real_max - real_min) / img_cfg.val_koeff ) + 1) ; /* Anzahl von 0,1-Schritten */ double range = (((graph_max - graph_min) / img_cfg.val_koeff ) + 1) ; /* Anzahl von 0,1-Schritten */
double pix_per_scale = ((double)c_height) / ((double)range); /* Pixel pro 0,1 */ double pix_per_scale = ((double)c_height) / ((double)range); /* Pixel pro 0,1 */
int zero_line = floor( ((double)((real_max / img_cfg.val_koeff) + 1)) * pix_per_scale); /* Nullinie */ int zero_line = floor( ((double)((graph_max / img_cfg.val_koeff) + 1)) * pix_per_scale); /* Nullinie */
pix_list_ptr temp = ptr; /* Temporaerer Pointer zum durchgehen der Liste */ pix_list_ptr temp = ptr; /* Temporaerer Pointer zum durchgehen der Liste */
DEBUGOUT1("\nBerechne y-Koordinaten:\n"); DEBUGOUT1("\nBerechne y-Koordinaten:\n");
@ -242,7 +244,7 @@ int scale_y_coords(pix_list_ptr ptr, int c_height){
DEBUGOUT2(" Nullinie bei: %d\n", zero_line); DEBUGOUT2(" Nullinie bei: %d\n", zero_line);
/* Wenn Nullinie zu sehen, dann die Position zurueckgeben */ /* Wenn Nullinie zu sehen, dann die Position zurueckgeben */
if ((real_max - real_min + 1) >= real_max){ if ((graph_max - graph_min + 1) >= graph_max){
return zero_line; return zero_line;
} else { } else {
return -1; return -1;
@ -255,7 +257,7 @@ pix_list_ptr get_max_elem(){
return min; return min;
} }
double get_max_val(){ double get_max_val(){
return real_max - padd_val; return real_max * 0.1 ;
} }
@ -265,7 +267,7 @@ pix_list_ptr get_min_elem(){
return max; return max;
} }
double get_min_val(){ double get_min_val(){
return real_min + padd_val; return real_min * 0.1 ;
} }
@ -305,6 +307,7 @@ pix_list_ptr get_pix_list(int c_width){
int pix_coord; /* x - Koordinate, an die der Wert gehoert */ int pix_coord; /* x - Koordinate, an die der Wert gehoert */
int i, s, t, u; /* Laufvariable zum durchlaufen des Datenbank-resuls */ int i, s, t, u; /* Laufvariable zum durchlaufen des Datenbank-resuls */
long timestamp; long timestamp;
int temp_value;
pix_list_ptr list_ptr = NULL; /* Zeiger auf den Anfang der Wertliste */ pix_list_ptr list_ptr = NULL; /* Zeiger auf den Anfang der Wertliste */
pix_list_ptr temp_ptr = NULL; /* Zeiger zum durchlaufen der Wertliste */ pix_list_ptr temp_ptr = NULL; /* Zeiger zum durchlaufen der Wertliste */
@ -341,6 +344,7 @@ pix_list_ptr get_pix_list(int c_width){
for (i = 0; i < PQntuples(res); i++){ for (i = 0; i < PQntuples(res); i++){
timestamp = atol(PQgetvalue(res, i, time_field)); timestamp = atol(PQgetvalue(res, i, time_field));
time_temp = timestamp - base_time; time_temp = timestamp - base_time;
temp_value = atoi( PQgetvalue(res, i, val_field) );
/* Wenn Balken gezeichnet werden sollen */ /* Wenn Balken gezeichnet werden sollen */
if(img_cfg.bars){ if(img_cfg.bars){
@ -348,6 +352,13 @@ pix_list_ptr get_pix_list(int c_width){
if(time_temp < 1) if(time_temp < 1)
time_temp++; time_temp++;
time_temp = floor( ((double)time_temp) / ((double)img_cfg.label_interval) ) * img_cfg.label_interval; time_temp = floor( ((double)time_temp) / ((double)img_cfg.label_interval) ) * img_cfg.label_interval;
} else {
if(temp_value > real_max){
real_max = temp_value;
}
if (temp_value < real_min){
real_min = temp_value;
}
} }
/* Koordinate berechnen */ /* Koordinate berechnen */
@ -426,7 +437,7 @@ pix_list_ptr get_pix_list(int c_width){
} }
/* Speichert einen geholten Wert ab */ /* Speichert einen geholten Wert ab */
static pix_list_ptr add_pix_value(pix_list_ptr ptr, int coord, int value, int max_diff){ static inline pix_list_ptr add_pix_value(pix_list_ptr ptr, int coord, int value, int max_diff){
int old_coord; int old_coord;
/* Erstes Element */ /* Erstes Element */