garten

diff weather.c @ 17:5e6c9260913a

lots of cleanups and small fixes
author meillo@marmaro.de
date Wed, 23 Jul 2008 17:14:38 +0200
parents 8db6497d6065
children 5937504619f2
line diff
     1.1 --- a/weather.c	Wed Jul 23 16:49:10 2008 +0200
     1.2 +++ b/weather.c	Wed Jul 23 17:14:38 2008 +0200
     1.3 @@ -26,8 +26,8 @@
     1.4  float mean_hum[12] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
     1.5  
     1.6  
     1.7 +/* generates random number between -limit and +limit */
     1.8  float rand_limit(float limit) {
     1.9 -	/* generates random number between -limit and +limit */
    1.10  	int r;
    1.11  
    1.12  	r = rand() / ( ((float) RAND_MAX + 1) / (2*limit) );
    1.13 @@ -45,8 +45,9 @@
    1.14  			" select temp, sun, rain, wind, hum from weather "
    1.15  			" order by tick desc "
    1.16  			" limit %d "
    1.17 -			, nlast);
    1.18 -	db_query(query);
    1.19 +			, nlast
    1.20 +			);
    1.21 +	stmt = db_query(query);
    1.22  	for (i = 0; i < nlast && sqlite3_step(stmt) == SQLITE_ROW; i++) {
    1.23  		lastw[i].temp = sqlite3_column_double(stmt, 0);
    1.24  		lastw[i].sun = sqlite3_column_double(stmt, 1);
    1.25 @@ -55,19 +56,6 @@
    1.26  		lastw[i].hum = sqlite3_column_double(stmt, 4);
    1.27  	}
    1.28  	sqlite3_finalize(stmt);
    1.29 -
    1.30 -	/*
    1.31 -	result = mysql_store_result(conn);
    1.32 -	for (i = 0; i < nlast && (row = mysql_fetch_row(result)); i++) {
    1.33 -		lastw[i].temp = atof(row[0]);
    1.34 -		lastw[i].sun = atof(row[1]);
    1.35 -		lastw[i].rain = atof(row[2]);
    1.36 -		lastw[i].wind = atof(row[3]);
    1.37 -		lastw[i].hum = atof(row[4]);
    1.38 -	}
    1.39 -	mysql_free_result(result);
    1.40 -	*/
    1.41 -
    1.42  }
    1.43  
    1.44  
    1.45 @@ -86,10 +74,10 @@
    1.46  			" insert into weather "
    1.47  			" (tick, temp, sun, rain, wind, hum) "
    1.48  			" values ('%d', '%f', '%f', '%f', '%f', '%f') "
    1.49 -			, gametime, w->temp, w->sun, w->rain, w->wind, w->hum);
    1.50 -	/* puts(query); */
    1.51 +			, gametime, w->temp, w->sun, w->rain, w->wind, w->hum
    1.52 +			);
    1.53  	if (!db_update(query)) {
    1.54 -		printf("error: weather insertion failed: %s\n", sqlite3_errmsg(db));
    1.55 +		db_error("weather insertion");
    1.56  	}
    1.57  }
    1.58