From: Benjamin Auder Date: Thu, 16 Mar 2017 19:10:51 +0000 (+0100) Subject: add possibility for outpit file, parameterize report.gj X-Git-Url: https://git.auder.net/js/img/%7B%7B%20asset%28%27mixstore/css/user/board.css%27%29%20%7D%7D?a=commitdiff_plain;h=0c1bf707abbc1b60db7f67c67c0cb123b3df85ff;p=talweg.git add possibility for outpit file, parameterize report.gj --- diff --git a/reports/ipynb_generator.py b/reports/ipynb_generator.py index fedfa40..339f96a 100755 --- a/reports/ipynb_generator.py +++ b/reports/ipynb_generator.py @@ -17,7 +17,7 @@ shortname2language = dict( tex='Tex', ) -def read(text, argv=sys.argv[2:]): +def read(text, argv=sys.argv[3:]): lines = text.splitlines() # First read all include statements for i in range(len(lines)): @@ -122,17 +122,18 @@ def write(cells): def driver(): """Compile a document and its variables.""" try: - filename = sys.argv[1] + inputfile = sys.argv[1] with open(filename, 'r') as f: text = f.read() + outputfile = '-' if len(sys.argv) <= 2 else sys.argv[2] except (IndexError, IOError) as e: - print('Usage: %s filename' % (sys.argv[0])) + print('Usage: %s inputfile [outputfile|- [Mako args]]' % (sys.argv[0])) print(e) sys.exit(1) - cells = read(text, argv=sys.argv[2:]) + cells = read(text, argv=sys.argv[3:]) filestr = write(cells) # Assuming file extension .gj (generate Jupyter); TODO: less strict - filename = filename[:-3] + '.ipynb' + outputfile = inputfile[:-3]+'.ipynb' if outputfile == '-' else outputfile with open(filename, 'w') as f: f.write(filestr) diff --git a/reports/report.gj b/reports/report.gj index dc4cbd4..3524e10 100644 --- a/reports/report.gj +++ b/reports/report.gj @@ -26,26 +26,30 @@ library(talweg) ts_data = read.csv(system.file("extdata","pm10_mesures_H_loc_report.csv",package="talweg")) exo_data = read.csv(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=13) +data = getData(ts_data, exo_data, input_tz = "Europe/Paris", working_tz="Europe/Paris", + predict_at=${P}) #predict from P+1 to P+H included indices_ch = seq(as.Date("2015-01-18"),as.Date("2015-01-24"),"days") indices_ep = seq(as.Date("2015-03-15"),as.Date("2015-03-21"),"days") indices_np = seq(as.Date("2015-04-26"),as.Date("2015-05-02"),"days") -H = 17 #predict from 8am to 12pm % for i in range(3): -----

${list_titles[i]}

-----r -p_nn_exo = computeForecast(data, ${list_indices[i]}, "Neighbors", "Neighbors", simtype="exo", horizon=H) -p_nn_mix = computeForecast(data, ${list_indices[i]}, "Neighbors", "Neighbors", simtype="mix", horizon=H) -p_az = computeForecast(data, ${list_indices[i]}, "Average", "Zero", horizon=H) #, memory=183) -p_pz = computeForecast(data, ${list_indices[i]}, "Persistence", "Zero", horizon=H, same_day=TRUE) +p_nn_exo = computeForecast(data, ${list_indices[i]}, "Neighbors", "Neighbors", + horizon=${H}, simtype="exo") +p_nn_mix = computeForecast(data, ${list_indices[i]}, "Neighbors", "Neighbors", + horizon=${H}, simtype="mix") +p_az = computeForecast(data, ${list_indices[i]}, "Average", "Zero", + horizon=${H}) +p_pz = computeForecast(data, ${list_indices[i]}, "Persistence", "Zero", + horizon=${H}, same_day=TRUE) -----r -e_nn_exo = computeError(data, p_nn_exo, H) -e_nn_mix = computeError(data, p_nn_mix, H) -e_az = computeError(data, p_az, H) -e_pz = computeError(data, p_pz, H) +e_nn_exo = computeError(data, p_nn_exo, ${H}) +e_nn_mix = computeError(data, p_nn_mix, ${H}) +e_az = computeError(data, p_az, ${H}) +e_pz = computeError(data, p_pz, ${H}) options(repr.plot.width=9, repr.plot.height=7) plotError(list(e_nn_mix, e_pz, e_az, e_nn_exo), cols=c(1,2,colors()[258], 4))