From 4eb1b01370a4d6e7da73409d4ddb1d7940e96aec Mon Sep 17 00:00:00 2001 From: terrtia Date: Wed, 15 May 2024 10:03:00 +0200 Subject: [PATCH] chg: [crawler stats] add previous month stats by domain type --- bin/packages/Date.py | 6 ++++++ var/www/blueprints/crawler_splash.py | 11 +++++++++++ .../crawler/crawler_splash/last_crawled.html | 11 +++++++++++ 3 files changed, 28 insertions(+) diff --git a/bin/packages/Date.py b/bin/packages/Date.py index 77d71188..e6c3738b 100644 --- a/bin/packages/Date.py +++ b/bin/packages/Date.py @@ -263,3 +263,9 @@ def sanitise_daterange(date_from, date_to, separator='', date_type='str'): date_from = date_to date_to = res return date_from, date_to + +def get_previous_month_date(): + now = datetime.date.today() + first = now.replace(day=1) + last_month = first - datetime.timedelta(days=1) + return last_month.strftime("%Y%m%d") diff --git a/var/www/blueprints/crawler_splash.py b/var/www/blueprints/crawler_splash.py index 666645cb..15785ebb 100644 --- a/var/www/blueprints/crawler_splash.py +++ b/var/www/blueprints/crawler_splash.py @@ -316,6 +316,17 @@ def crawlers_last_domains_month_json(): stats = crawlers.get_crawlers_stats_by_month(domain_type) return jsonify(stats) +@crawler_splash.route('/crawlers/last/domains/month/previous/json') +@login_required +@login_read_only +def crawlers_last_domains_previous_month_json(): + domain_type = request.args.get('type') + if domain_type not in crawlers.get_crawler_all_types(): + return jsonify({'error': 'Invalid domain type'}), 400 + date = Date.get_previous_month_date() + stats = crawlers.get_crawlers_stats_by_month(domain_type, date=date) + return jsonify(stats) + @crawler_splash.route('/crawlers/last/domains/status/month/json') @login_required @login_read_only diff --git a/var/www/templates/crawler/crawler_splash/last_crawled.html b/var/www/templates/crawler/crawler_splash/last_crawled.html index e26710bf..b553b562 100644 --- a/var/www/templates/crawler/crawler_splash/last_crawled.html +++ b/var/www/templates/crawler/crawler_splash/last_crawled.html @@ -95,6 +95,10 @@
+

Previous Month Stats:

+
+
+ @@ -156,6 +160,13 @@ $(document).ready(function(){ } ); + $.getJSON("{{ url_for('crawler_splash.crawlers_last_domains_previous_month_json') }}?type={{type}}", + function (data) { + let div_width = $("#barchart_type_previous_month").width(); + barchart_stack("barchart_type_previous_month", data, {"width": div_width}); + } + ); + }); function toggle_sidebar(){