|
|
|
@ -10,6 +10,7 @@ import argh
|
|
|
|
|
import bokeh.plotting
|
|
|
|
|
import bokeh.models
|
|
|
|
|
import bokeh.palettes
|
|
|
|
|
import bokeh.settings
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -56,29 +57,9 @@ def load_previous_donations(start_end_times, timeout):
|
|
|
|
|
|
|
|
|
|
return all_years, current_year
|
|
|
|
|
|
|
|
|
|
@argh.arg('--base-dir', help='Directory where segments are stored. Default is current working directory.')
|
|
|
|
|
def main(base_dir='.'):
|
|
|
|
|
|
|
|
|
|
stopping = gevent.event.Event()
|
|
|
|
|
|
|
|
|
|
delay = 60 * 1
|
|
|
|
|
timeout = 15
|
|
|
|
|
logging.info('Loading start and end times')
|
|
|
|
|
start_end_path = os.path.join(base_dir, 'start_end_times.json')
|
|
|
|
|
start_end_times = json.load(open(start_end_path))
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
current_url = 'http://example.com/{}/{}'.format(current_year, current_year)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while not stopping.is_set():
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
logging.info('Loading current data')
|
|
|
|
|
current_json = requests.get(current_url, timeout=timeout).json()
|
|
|
|
|
def all_years_donations_graph(start_end_times, all_years, current_year, current_json, base_dir):
|
|
|
|
|
|
|
|
|
|
logging.info('Generating all years donation graph')
|
|
|
|
|
p = bokeh.plotting.figure(x_axis_label='Bus Time', y_axis_label='Donations', x_range=(0, 60 * 60 * 172),
|
|
|
|
|
width=1280, height=720, active_scroll='wheel_zoom',
|
|
|
|
|
tools='pan,wheel_zoom,box_zoom,reset')
|
|
|
|
@ -110,9 +91,41 @@ def main(base_dir='.'):
|
|
|
|
|
p.legend.click_policy="hide"
|
|
|
|
|
|
|
|
|
|
output_path = os.path.join(base_dir, 'all_years_donations.html')
|
|
|
|
|
bokeh.settings.settings.py_log_level = 'warn'
|
|
|
|
|
bokeh.plotting.output_file(filename=output_path, title='DBfH All Years Donations')
|
|
|
|
|
bokeh.plotting.save(p, filename=output_path)
|
|
|
|
|
logging.info('{} Saved'.format(output_path))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@argh.arg('--base-dir', help='Directory where segments are stored. Default is current working directory.')
|
|
|
|
|
def main(base_dir='.'):
|
|
|
|
|
|
|
|
|
|
stopping = gevent.event.Event()
|
|
|
|
|
|
|
|
|
|
logging.getLogger('bokeh').setLevel(logging.WARNING)
|
|
|
|
|
|
|
|
|
|
delay = 60 * 1
|
|
|
|
|
timeout = 15
|
|
|
|
|
|
|
|
|
|
# First load data required
|
|
|
|
|
logging.info('Loading start and end times')
|
|
|
|
|
start_end_path = os.path.join(base_dir, 'start_end_times.json')
|
|
|
|
|
start_end_times = json.load(open(start_end_path))
|
|
|
|
|
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)
|
|
|
|
|
current_url = 'http://example.com/{}/{}'.format(current_year, current_year)
|
|
|
|
|
|
|
|
|
|
while not stopping.is_set():
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
logging.info('Loading current data')
|
|
|
|
|
current_json = requests.get(current_url, timeout=timeout).json()
|
|
|
|
|
|
|
|
|
|
all_years_donations_graph(start_end_times, all_years, current_year, current_json, base_dir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
logging.exception('Plotting failed. Retrying')
|
|
|
|
|
|
|
|
|
|