Commit fb38344869da4fb838e462b912336973296bbecc
1 parent
d1c44c51
Exists in
master
and in
2 other branches
Implement the cache warmup.
Showing
5 changed files
with
37 additions
and
11 deletions
Show diff stats
CHANGELOG.md
... | ... | @@ -10,13 +10,16 @@ |
10 | 10 | An heliospheric propagation 1D MHD model for solar wind prediction at planets, probes and comets. |
11 | 11 | |
12 | 12 | |
13 | - | |
14 | -## 1.0.0-rc5 | |
13 | +## 1.0.0-rc6 | |
15 | 14 | |
16 | 15 | - [ ] Rework the images of Rosetta and Juno |
17 | -- [ ] Cache warmup (generate for today's default interval) `/cache/warmup` | |
18 | -- [ ] Improve the generated CDF for SAMP | |
19 | 16 | - [ ] Enable p67 |
17 | + | |
18 | + | |
19 | +## 1.0.0-rc5 | |
20 | + | |
21 | +- [x] Cache warmup (generate for today's default interval) `/cache/warmup` | |
22 | +- [x] Improve the generated CDF for SAMP | |
20 | 23 | - [x] Enable Earth |
21 | 24 | - [x] Enable more precise configuration of each models' parameters |
22 | 25 | ... | ... |
config.yml
web/run.py
... | ... | @@ -14,6 +14,7 @@ from math import sqrt |
14 | 14 | from os import environ, remove as removefile |
15 | 15 | from os.path import isfile, join, abspath, dirname |
16 | 16 | |
17 | +from dateutil.relativedelta import relativedelta | |
17 | 18 | from flask import Flask |
18 | 19 | from flask import request |
19 | 20 | from flask import url_for, send_from_directory, abort as abort_flask |
... | ... | @@ -322,6 +323,11 @@ def check_target_config(slug): |
322 | 323 | get_target_config(slug) |
323 | 324 | |
324 | 325 | |
326 | +def get_active_targets(): | |
327 | + all_targets = config['targets'] | |
328 | + return [t for t in all_targets if not ('locked' in t and t['locked'])] | |
329 | + | |
330 | + | |
325 | 331 | def retrieve_amda_netcdf(orbiter, what, started_at, stopped_at): |
326 | 332 | """ |
327 | 333 | Handles remote querying Myriam's API, downloading, extracting and caching |
... | ... | @@ -1089,16 +1095,29 @@ def cache_warmup(): |
1089 | 1095 | Linked to SpaceWeather#edit in swapp.ls to get the default time interval. |
1090 | 1096 | If you edit this code you'll need to edit the other as well and vice versa. |
1091 | 1097 | """ |
1092 | - # relativedelta(years=3) | |
1093 | - # startted_at = datetime.datetime.now() - relativedelta(years=3) | |
1094 | - return "To Do" | |
1098 | + before = relativedelta(years=1) | |
1099 | + after = relativedelta(weeks=3) | |
1100 | + today = datetime.datetime.now().replace(hour=0, minute=0, second=0) | |
1101 | + started_at = today - before | |
1102 | + stopped_at = today + after | |
1103 | + sta = started_at.strftime(FILE_DATE_FMT) | |
1104 | + sto = stopped_at.strftime(FILE_DATE_FMT) | |
1105 | + | |
1106 | + targets = get_active_targets() | |
1107 | + for target in targets: | |
1108 | + download_target_csv(target['slug'], sta, sto) | |
1109 | + targets_slugs = [target['slug'] for target in targets] | |
1110 | + targets_slugs.sort() | |
1111 | + download_targets_cdf('-'.join(targets_slugs), sta, sto) | |
1112 | + | |
1113 | + return "Done" | |
1095 | 1114 | |
1096 | 1115 | |
1097 | 1116 | @app.route("/log") |
1098 | 1117 | def log_show(): |
1099 | 1118 | with open(LOG_FILE, 'r') as f: |
1100 | 1119 | contents = f.read() |
1101 | - return contents | |
1120 | + return "<pre>" + contents + "</pre>" | |
1102 | 1121 | |
1103 | 1122 | |
1104 | 1123 | @app.route("/log/clear") | ... | ... |
web/static/js/swapp.js
... | ... | @@ -46,9 +46,10 @@ |
46 | 46 | stopped_at = moment().add(3, 'week').hours(0).minutes(0).seconds(0); |
47 | 47 | this.setStartAndStop(started_at, stopped_at); |
48 | 48 | this.loadAndCreatePlots(started_at, stopped_at); |
49 | - return window.addEventListener('resize', function(){ | |
49 | + window.addEventListener('resize', function(){ | |
50 | 50 | return this$.resize(); |
51 | 51 | }); |
52 | + return this; | |
52 | 53 | }; |
53 | 54 | SpaceWeather.prototype.buildDataUrlForTarget = function(target_slug, started_at, stopped_at){ |
54 | 55 | var url; | ... | ... |
web/static/js/swapp.ls
... | ... | @@ -72,14 +72,15 @@ https://gitlab.irap.omp.eu/CDPP/SPACEWEATHERONLINE |
72 | 72 | This ain't in the constructor because it might return a Promise later on. |
73 | 73 | (for the loader, for example) |
74 | 74 | """ |
75 | - # Default time interval is from two weeks ago to one week ahead. | |
75 | + # Default time interval is from one year ago to three weeks ahead. | |
76 | 76 | # We set the h/m/s to zero to benefit from a daily cache. |
77 | + # If you edit these values you need to change the cache warmup too (run.py) | |
77 | 78 | started_at = moment().subtract(1, 'year').hours(0).minutes(0).seconds(0) |
78 | 79 | stopped_at = moment().add(3, 'week').hours(0).minutes(0).seconds(0) |
79 | 80 | @setStartAndStop(started_at, stopped_at) |
80 | 81 | @loadAndCreatePlots(started_at, stopped_at) |
81 | - | |
82 | 82 | window.addEventListener 'resize', ~> @resize() |
83 | + this | |
83 | 84 | |
84 | 85 | buildDataUrlForTarget: (target_slug, started_at, stopped_at) -> |
85 | 86 | url = @configuration['api']['data_for_interval'] | ... | ... |