Fixes suggested by ekim

pull/370/head
Christopher Usher 1 year ago
parent eae430d5f3
commit e66540087a

@ -273,6 +273,9 @@
args:: [], args:: [],
}, },
// template for donation data urls
donation_url_template:: "https://example.com/DB{}/DB{}.json",
// Extra options to pass via environment variables, // Extra options to pass via environment variables,
// eg. log level, disabling stack sampling. // eg. log level, disabling stack sampling.
env:: { env:: {
@ -575,7 +578,7 @@
[if $.enabled.graphs then "graphs"]: { [if $.enabled.graphs then "graphs"]: {
image: $.get_image("graphs"), image: $.get_image("graphs"),
restart: "always", restart: "always",
command: ["--base-dir", "/mnt/graphs"], command: [$.donation_url_template, "--base-dir", "/mnt/graphs"],
volumes: ["%s:/mnt" % $.segments_path], volumes: ["%s:/mnt" % $.segments_path],
environment: $.env, environment: $.env,
}, },

@ -11,10 +11,11 @@ import bokeh.plotting
import bokeh.models import bokeh.models
import bokeh.palettes import bokeh.palettes
import bokeh.settings import bokeh.settings
import numpy as np
import requests import requests
import numpy as np
def parse_json(json_donations, start_date, end_hour=np.inf, every_five=True): def parse_json(json_donations, start_date, end_hour=np.inf, every_five=True):
@ -41,7 +42,7 @@ def parse_json(json_donations, start_date, end_hour=np.inf, every_five=True):
else: else:
return trimmed_bustimes, trimmed_donations return trimmed_bustimes, trimmed_donations
def load_previous_donations(start_end_times, timeout): def load_previous_donations(start_end_times, donation_url_template, timeout):
all_years = {} all_years = {}
for year in start_end_times: for year in start_end_times:
@ -50,8 +51,9 @@ def load_previous_donations(start_end_times, timeout):
current_year = year current_year = year
continue continue
logging.info('Loading year {}'.format(year))
url = 'https://vst.ninja/DB{}/graphs/jsons/DB{}.json'.format(year, year) url = donation_url_template.format(year, year)
logging.info('Loading {}'.format(url))
year_json = requests.get(url, timeout=timeout).json() year_json = requests.get(url, timeout=timeout).json()
all_years[year] = parse_json(year_json, start, end, year >= 5) all_years[year] = parse_json(year_json, start, end, year >= 5)
@ -97,8 +99,8 @@ def all_years_donations_graph(start_end_times, all_years, current_year, current_
logging.info('{} Saved'.format(output_path)) logging.info('{} Saved'.format(output_path))
@argh.arg('--base-dir', help='Directory where segments are stored. Default is current working directory.') @argh.arg('--base-dir', help='Directory where graphs are output. Default is current working directory.')
def main(base_dir='.'): def main(donation_url_template, base_dir='.'):
stopping = gevent.event.Event() stopping = gevent.event.Event()
@ -113,14 +115,14 @@ def main(base_dir='.'):
start_end_times = json.load(open(start_end_path)) start_end_times = json.load(open(start_end_path))
start_end_times = {int(year):start_end_times[year] for year in start_end_times} start_end_times = {int(year):start_end_times[year] for year in start_end_times}
all_years, current_year = load_previous_donations(start_end_times, timeout) all_years, current_year = load_previous_donations(start_end_times, donation_url_template, timeout)
current_url = 'http://example.com/{}/{}'.format(current_year, current_year) current_url = donation_url_template.format(current_year, current_year)
while not stopping.is_set(): while not stopping.is_set():
try: try:
logging.info('Loading current data') logging.info('Loading {}'.format(current_url))
current_json = requests.get(current_url, timeout=timeout).json() current_json = requests.get(current_url, timeout=timeout).json()
all_years_donations_graph(start_end_times, all_years, current_year, current_json, base_dir) all_years_donations_graph(start_end_times, all_years, current_year, current_json, base_dir)
@ -131,15 +133,3 @@ def main(base_dir='.'):
stopping.wait(delay) stopping.wait(delay)
# logging.info('Starting Graph Generator')
# generator = GraphGenerator(current_url, start_time, previous_years:)
# manager = gevent.spawn(generator.run)
# def stop():
# manager.stop()
# gevent.signal_handler(signal.SIGTERM, stop)
# stop()
# logging.info('Gracefully stopped')

@ -8,6 +8,7 @@ setup(
'argh', 'argh',
'bokeh', 'bokeh',
'gevent', 'gevent',
'numpy',
'requests' 'requests'
], ],
) )

Loading…
Cancel
Save