on the way to R6 class + remove truncated days (simplifications)
[talweg.git] / data / scripts / augment_meteo.R
index 19efe99..c762fe8 100644 (file)
@@ -1,27 +1,21 @@
 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
+ts_data = system.file("extdata","pm10_mesures_H_loc.csv",package="talweg")
+exo_data = system.file("extdata","meteo_extra_noNAs.csv",package="talweg")
+data = getData(ts_data, exo_data, input_tz = "Europe/Paris",
+       working_tz="Europe/Paris", predict_at=0)
 
-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 +35,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)