Skip to content

Commit

Permalink
chg: [crawler stats] add previous month stats by domain type
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrtia committed May 15, 2024
1 parent 21642fe commit 4eb1b01
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bin/packages/Date.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
11 changes: 11 additions & 0 deletions var/www/blueprints/crawler_splash.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions var/www/templates/crawler/crawler_splash/last_crawled.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ <h3>Month Stats:</h3>
<div id="barchart_type_month"></div>
<div class="text-center" id="pie_chart_month"></div>

<h3>Previous Month Stats:</h3>
<div id="barchart_type_month"></div>
<div class="text-center" id="barchart_type_previous_month"></div>

</div>

</div>
Expand Down Expand Up @@ -156,6 +160,13 @@ <h3>Month Stats:</h3>
}
);

$.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(){
Expand Down

0 comments on commit 4eb1b01

Please sign in to comment.