advance on tests; almost there...
[talweg.git] / data / scripts / augment_meteo.R
index 19efe99..11649f3 100644 (file)
@@ -1,27 +1,18 @@
 meteo_df = read.csv("meteo.csv")
 
+#inspiration
+#http://stackoverflow.com/questions/8214303/conditional-replacement-of-values-in-a-data-frame
+
 meteo_df$Season = 0
 meteo_df$Week = 0
 meteo_df$Pollution = -1
 
-#Need to load and aggregate PM10 by days
-pm10_df = read.csv("pm10_mesures.csv")
+#Need to load and aggregate PM10 by days: use getData() from package
+data = getData(..., predict_at=0) #TODO:
 
-line_number = 1 #line number in pm10 file
-for (i in 1:(nrow(meteo_df)))
+for (i in 1:nrow(meteo_df))
 {
-       pm10s = c()
-       repeat {
-       {
-               pm10s = c(pm10s, pm10_df[line_number,2])
-               line_number = line_number + 1
-       };
-       if (line_number >= nrow(pm10_df)+1
-               || strsplit(as.character(pm10_df[line_number,1])," ")[[1]][2] == '0:15')
-       {
-               break
-       }}
-       pm10_level = mean(pm10s, na.rm=TRUE)
+       pm10_level = data$getLevel(i)
        #Fill Pollution column: -1 if no info, 0 to 2 for pollution level
        if (!is.nan(pm10_level))
        {
@@ -41,8 +32,5 @@ for (i in 1:(nrow(meteo_df)))
        meteo_df$Week[i] = ifelse(current_datetime$wday %in% c(6,0), 0, 1)
 }
 
-#see also:
-#http://stackoverflow.com/questions/8214303/conditional-replacement-of-values-in-a-data-frame
-
 #Finally write new data
 write.csv(meteo_df, file="meteo_extra.csv", row.names=FALSE)