From a6e990db68445815b761d59994c6420a84b0ccfa Mon Sep 17 00:00:00 2001 From: Christopher Usher Date: Mon, 13 Nov 2023 17:39:47 -0800 Subject: [PATCH] Donation graph now works in a container --- docker-compose.jsonnet | 9 +++++++++ graphs/graphs/__main__.py | 1 - graphs/graphs/main.py | 19 ++++++++++++------- old_build | 4 ++-- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/docker-compose.jsonnet b/docker-compose.jsonnet index afb0b72..a85eaa4 100644 --- a/docker-compose.jsonnet +++ b/docker-compose.jsonnet @@ -32,6 +32,7 @@ tootbot: false, twitchbot: false, bus_analyzer: false, + graphs: false, }, // Twitch channels to capture. The first one will be used as the default channel in the editor. @@ -571,6 +572,14 @@ environment: $.env, }, + [if $.enabled.graphs then "graphs"]: { + image: $.get_image("graphs"), + restart: "always", + command: ["--base-dir", "/mnt/graphs"], + volumes: ["%s:/mnt" % $.segments_path], + environment: $.env, + }, + local bot_service(name, config, args, subcommand=null) = { image: $.get_image("zulip_bots"), restart: "always", diff --git a/graphs/graphs/__main__.py b/graphs/graphs/__main__.py index 27210eb..8076c62 100644 --- a/graphs/graphs/__main__.py +++ b/graphs/graphs/__main__.py @@ -2,7 +2,6 @@ import gevent.monkey gevent.monkey.patch_all() import logging -import os import argh diff --git a/graphs/graphs/main.py b/graphs/graphs/main.py index 481efab..430abca 100644 --- a/graphs/graphs/main.py +++ b/graphs/graphs/main.py @@ -4,12 +4,14 @@ gevent.monkey.patch_all() import datetime import logging import json +import os -import requests - +import argh import bokeh.plotting import bokeh.models import bokeh.palettes +import requests + import numpy as np @@ -54,15 +56,16 @@ def load_previous_donations(start_end_times, timeout): return all_years, current_year -def main(): +@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 - start_end_file = 'start_end_times.json' logging.info('Loading start and end times') - start_end_times = json.load(open(start_end_file)) + 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) @@ -106,8 +109,10 @@ def main(): p.legend.location = "top_left" p.legend.click_policy="hide" - logging.info('Saving plot') - bokeh.plotting.save(p, filename='dbfh_donations.html', title='DBfH Donations') + output_path = os.path.join(base_dir, 'all_years_donations.html') + 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)) except Exception: logging.exception('Plotting failed. Retrying') diff --git a/old_build b/old_build index 8ba9be2..0fc3669 100755 --- a/old_build +++ b/old_build @@ -11,13 +11,13 @@ cd "$(dirname "$(realpath "$0")")" # Pass PUSH=true to also push the resulting images, or PUSH=latest to push them as :latest tag # The different images we can build -COMPONENTS=(downloader restreamer backfiller thrimshim cutter sheetsync nginx postgres segment_coverage graphs) +COMPONENTS=(downloader restreamer backfiller thrimshim cutter sheetsync nginx postgres segment_coverage playlist_manager chat_archiver graphs) # Define push if not already defined PUSH=${PUSH:-} # Base is the repository namespace information, not including the wubloader-component part. -BASE="quay.io/ekimekim" +BASE="ghcr.io/dbvideostriketeam" # The docker image tag, derived from the git commit + whether working tree is clean TAG=$(./get-build-tag)