New feature in Chart:
Now you can define a 'time-fixpoint' in the past and the Image will generatet everytime,when ((now-fixpoint) % interval) ~ 0. so you can say: generate it every day at 12.00. git-svn-id: file:///home/jan/tmp/wetterstation/trunk@203 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
parent
4eb5123888
commit
c73f7f56ed
|
|
@ -36,6 +36,7 @@
|
||||||
#define DEFAULT_GEN_INTERVAL "15m"
|
#define DEFAULT_GEN_INTERVAL "15m"
|
||||||
#define DEFAULT_SHOW_INTERVAL "2d"
|
#define DEFAULT_SHOW_INTERVAL "2d"
|
||||||
#define DEFAULT_LABEL_INTERVAL "2h"
|
#define DEFAULT_LABEL_INTERVAL "2h"
|
||||||
|
#define DEFAULT_FIX_TIMEPOINT "no"
|
||||||
#define DEFAULT_LABEL_SUM "no"
|
#define DEFAULT_LABEL_SUM "no"
|
||||||
#define DEFAULT_ZERO_MIN "no"
|
#define DEFAULT_ZERO_MIN "no"
|
||||||
#define DEFAULT_AS_BARS "no"
|
#define DEFAULT_AS_BARS "no"
|
||||||
|
|
@ -86,6 +87,7 @@
|
||||||
#define FALSE 0
|
#define FALSE 0
|
||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
#define IMG_FONT "/usr/share/fonts/truetype/freefont/FreeSans.ttf"
|
#define IMG_FONT "/usr/share/fonts/truetype/freefont/FreeSans.ttf"
|
||||||
|
#define CRON_INTERVAL 15 //Minuten
|
||||||
|
|
||||||
|
|
||||||
/* Debug --------------------------------------------------------------- */
|
/* Debug --------------------------------------------------------------- */
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,9 @@ gen_interval 1 # gibt an, in welchem Interval das Bild generiert werden soll
|
||||||
show_interval 10d # gibt an, welcher Interval angezeigt werden soll
|
show_interval 10d # gibt an, welcher Interval angezeigt werden soll
|
||||||
label_interval 1d # gibt an, Welche zeitspanne (ab generierungszeitraum) angezeigt werden soll
|
label_interval 1d # gibt an, Welche zeitspanne (ab generierungszeitraum) angezeigt werden soll
|
||||||
|
|
||||||
|
fixed_timepoint yes
|
||||||
|
timepoint 2006-12-17-13-00
|
||||||
|
|
||||||
# Hoehe und Breite des Bildes
|
# Hoehe und Breite des Bildes
|
||||||
width 800
|
width 800
|
||||||
height 300
|
height 300
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,11 @@ manual_table no
|
||||||
manual_table_name auss2_data
|
manual_table_name auss2_data
|
||||||
table_field temp
|
table_field temp
|
||||||
#table_field press
|
#table_field press
|
||||||
gen_interval 1
|
gen_interval 10
|
||||||
show_interval 10d
|
show_interval 10d
|
||||||
label_interval 1d
|
label_interval 1d
|
||||||
|
fixed_timepoint yes
|
||||||
|
timepoint 2006-12-17-13-00
|
||||||
width 800
|
width 800
|
||||||
height 300
|
height 300
|
||||||
ensor_id 1
|
ensor_id 1
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,8 @@ typedef struct image_cfg {
|
||||||
long gen_interval; /* Generierungsinterval */
|
long gen_interval; /* Generierungsinterval */
|
||||||
long show_interval; /* Anzeigeinterval */
|
long show_interval; /* Anzeigeinterval */
|
||||||
long label_interval; /* Label - Interval */
|
long label_interval; /* Label - Interval */
|
||||||
|
long fix_timepoint; /* Zu festem Zeitpunkt generieren */
|
||||||
|
long timepoint; /* Startzeitpunkt */
|
||||||
int label_sum; /* Sollen Werte aufsummiert statt gemittelt werden */
|
int label_sum; /* Sollen Werte aufsummiert statt gemittelt werden */
|
||||||
int width; /* Breite */
|
int width; /* Breite */
|
||||||
int height; /* Hoehe */
|
int height; /* Hoehe */
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
#include "image_common.h"
|
#include "image_common.h"
|
||||||
|
|
@ -35,7 +36,7 @@ static int read_time(const char *, void *);
|
||||||
static int read_color(const char *, void *);
|
static int read_color(const char *, void *);
|
||||||
static int read_double(const char *, void *);
|
static int read_double(const char *, void *);
|
||||||
static int read_fmt_str(const char *, void *);
|
static int read_fmt_str(const char *, void *);
|
||||||
|
static int read_date(const char *, void *);
|
||||||
|
|
||||||
|
|
||||||
/* Zuordnung zwischen Schluesselwoertern in der Config, Der Funktion, die diese auswertet
|
/* Zuordnung zwischen Schluesselwoertern in der Config, Der Funktion, die diese auswertet
|
||||||
|
|
@ -51,6 +52,8 @@ static const config_keyword keywords[] = {
|
||||||
{"gen_interval", read_time, &(img_cfg.gen_interval), DEFAULT_GEN_INTERVAL},
|
{"gen_interval", read_time, &(img_cfg.gen_interval), DEFAULT_GEN_INTERVAL},
|
||||||
{"show_interval", read_time, &(img_cfg.show_interval), DEFAULT_SHOW_INTERVAL},
|
{"show_interval", read_time, &(img_cfg.show_interval), DEFAULT_SHOW_INTERVAL},
|
||||||
{"label_interval", read_time, &(img_cfg.label_interval), DEFAULT_LABEL_INTERVAL},
|
{"label_interval", read_time, &(img_cfg.label_interval), DEFAULT_LABEL_INTERVAL},
|
||||||
|
{"fixed_timepoint", read_yn, &(img_cfg.fix_timepoint), DEFAULT_FIX_TIMEPOINT},
|
||||||
|
{"timepoint", read_date, &(img_cfg.timepoint), ""},
|
||||||
{"label_sum", read_yn, &(img_cfg.label_sum), DEFAULT_LABEL_SUM},
|
{"label_sum", read_yn, &(img_cfg.label_sum), DEFAULT_LABEL_SUM},
|
||||||
{"width", read_int, &(img_cfg.width), DEFAULT_WIDTH},
|
{"width", read_int, &(img_cfg.width), DEFAULT_WIDTH},
|
||||||
{"height", read_int, &(img_cfg.height), DEFAULT_HEIGHT},
|
{"height", read_int, &(img_cfg.height), DEFAULT_HEIGHT},
|
||||||
|
|
@ -130,7 +133,8 @@ static int read_color(const char *line, void *arg){
|
||||||
char *buff = malloc(sizeof(char)*3);
|
char *buff = malloc(sizeof(char)*3);
|
||||||
|
|
||||||
if(strlen(line) == 11){ /* Wenn String auch wirkle 11 Zeichen lang */
|
if(strlen(line) == 11){ /* Wenn String auch wirkle 11 Zeichen lang */
|
||||||
if (strchr(line, ':') != NULL){ /* und min. 1 : vorkommt */
|
if (strchr(line, ':') != NULL){ /* und min. 1 : vorkommt */
|
||||||
|
strcpy(buff, "00\0");
|
||||||
tmp = malloc(sizeof(img_color_t)); /* Neues Farbelement allocieren */
|
tmp = malloc(sizeof(img_color_t)); /* Neues Farbelement allocieren */
|
||||||
tmp->r = strtol(strncpy(buff, line, 2), NULL, 16); /* r */
|
tmp->r = strtol(strncpy(buff, line, 2), NULL, 16); /* r */
|
||||||
tmp->g = strtol(strncpy(buff, line+3, 2), NULL, 16); /* g */
|
tmp->g = strtol(strncpy(buff, line+3, 2), NULL, 16); /* g */
|
||||||
|
|
@ -191,6 +195,47 @@ static int read_time(const char *line, void *arg){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Liest das Datum, an dem die Bilder-generierung
|
||||||
|
* 'festgemacht' werden soll.
|
||||||
|
* Format: yyyy-mm-dd-hh-mm */
|
||||||
|
static int read_date(const char *line, void *arg){
|
||||||
|
struct tm timestruct;
|
||||||
|
long *dest = arg;
|
||||||
|
char *buff = malloc(sizeof(char)*5);
|
||||||
|
time_t temp = 0;
|
||||||
|
|
||||||
|
if(line == NULL){
|
||||||
|
*dest = 0;
|
||||||
|
free(buff);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(strlen(line) != 16){
|
||||||
|
DEBUGOUT2(" Invalid Date-String '%s'!\n", line);
|
||||||
|
*dest = 0;
|
||||||
|
free(buff);
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
timestruct.tm_sec = 0;
|
||||||
|
timestruct.tm_isdst = -1;
|
||||||
|
strcpy(buff, "0000\0");
|
||||||
|
timestruct.tm_year = (atol(strncpy(buff, line, 4)) - 1901);
|
||||||
|
strcpy(buff, "00\0");
|
||||||
|
timestruct.tm_mon = atol(strncpy(buff, line+5, 2));
|
||||||
|
timestruct.tm_mday = atol(strncpy(buff, line+8, 2));
|
||||||
|
timestruct.tm_hour = atol(strncpy(buff, line+11, 2));
|
||||||
|
timestruct.tm_min = atol(strncpy(buff, line+14, 2));
|
||||||
|
|
||||||
|
temp = mktime(×truct);
|
||||||
|
|
||||||
|
DEBUGOUT2(" Datum gelesen: %s\n", ctime(&temp));
|
||||||
|
}
|
||||||
|
|
||||||
|
*dest = temp;
|
||||||
|
|
||||||
|
free(buff);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Liest ein Bild-Configfile */
|
/* Liest ein Bild-Configfile */
|
||||||
int get_image_cfg(char *file){
|
int get_image_cfg(char *file){
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include "../definitions.h"
|
#include "../definitions.h"
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
|
|
@ -42,7 +43,8 @@ image_cfg_t img_cfg;
|
||||||
/* Funktionsdefinitionen */
|
/* Funktionsdefinitionen */
|
||||||
static void regenerate_image();
|
static void regenerate_image();
|
||||||
static int check_file_interval();
|
static int check_file_interval();
|
||||||
|
static int check_time_with_stat();
|
||||||
|
static int check_time_with_fixpoint();
|
||||||
|
|
||||||
|
|
||||||
/* Handelt ein Bild */
|
/* Handelt ein Bild */
|
||||||
|
|
@ -94,10 +96,6 @@ void process_image_cfg(char *image_cfg_file){
|
||||||
* neu zu erstellen */
|
* neu zu erstellen */
|
||||||
static int check_file_interval(){
|
static int check_file_interval(){
|
||||||
|
|
||||||
struct stat stat_buff;
|
|
||||||
time_t now;
|
|
||||||
long diff_sek;
|
|
||||||
|
|
||||||
/* Pruefen ob Bild vorhanden */
|
/* Pruefen ob Bild vorhanden */
|
||||||
if(access(img_cfg.file_name, F_OK) == -1){
|
if(access(img_cfg.file_name, F_OK) == -1){
|
||||||
DEBUGOUT2("Datei '%s' existiert nicht\n", img_cfg.file_name);
|
DEBUGOUT2("Datei '%s' existiert nicht\n", img_cfg.file_name);
|
||||||
|
|
@ -105,6 +103,20 @@ static int check_file_interval(){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(img_cfg.fix_timepoint){
|
||||||
|
return check_time_with_fixpoint();
|
||||||
|
} else {
|
||||||
|
return check_time_with_stat();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static int check_time_with_stat(){
|
||||||
|
|
||||||
|
struct stat stat_buff;
|
||||||
|
time_t now;
|
||||||
|
long diff_sek;
|
||||||
|
|
||||||
/* Pruefen ob Bild zu alt */
|
/* Pruefen ob Bild zu alt */
|
||||||
if ((stat(img_cfg.file_name, &stat_buff)) != -1){
|
if ((stat(img_cfg.file_name, &stat_buff)) != -1){
|
||||||
|
|
||||||
|
|
@ -124,8 +136,34 @@ static int check_file_interval(){
|
||||||
}
|
}
|
||||||
DEBUGOUT1("Datei ist aktuell genug!\n");
|
DEBUGOUT1("Datei ist aktuell genug!\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int check_time_with_fixpoint(){
|
||||||
|
|
||||||
|
time_t now;
|
||||||
|
int max_diff = (CRON_INTERVAL -1) * 60;
|
||||||
|
int exact_val = 0;
|
||||||
|
int diff = 0;
|
||||||
|
|
||||||
|
now = time(NULL);
|
||||||
|
|
||||||
|
exact_val = (floor( ((double)difftime(now, img_cfg.timepoint)) / ((double)img_cfg.gen_interval) ) * img_cfg.gen_interval) + img_cfg.timepoint;
|
||||||
|
diff = difftime(now, exact_val);
|
||||||
|
|
||||||
|
if(diff < max_diff){
|
||||||
|
DEBUGOUT3("Bild wird generiert, denn es ist kurz (%d sec) nach %s\n", diff, ctime(&exact_val));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
DEBUGOUT1("Bild ist aktuell genug\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Bild (neu-) generieren */
|
/* Bild (neu-) generieren */
|
||||||
static void regenerate_image(){
|
static void regenerate_image(){
|
||||||
FILE *fd = fopen(img_cfg.file_name, "wb"); /* Datei oeffnen */
|
FILE *fd = fopen(img_cfg.file_name, "wb"); /* Datei oeffnen */
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,9 @@
|
||||||
|
weatherstation (1.0.5-1) stable; urgency=low
|
||||||
|
|
||||||
|
* New feature added in chart-program: building graphs on a 'fixpoint'
|
||||||
|
|
||||||
|
-- Jan Losinski <losinski@wh2.tu-dresden.de> Thu, 2 Nov 2006 09:38:14 +0100
|
||||||
|
|
||||||
weatherstation (1.0.4-2) stable; urgency=low
|
weatherstation (1.0.4-2) stable; urgency=low
|
||||||
|
|
||||||
* third try to fix negative tempatatures (seems to be correct!)
|
* third try to fix negative tempatatures (seems to be correct!)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue