chg: [domains] add crawler status stats by domain type pie chart

dev
terrtia 2024-02-28 14:19:47 +01:00
parent 142ac83472
commit d5e830c591
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
3 changed files with 28 additions and 1 deletions

View File

@ -931,6 +931,13 @@ def get_crawlers_stats_by_month(domain_type, date=None):
stats.append(get_crawlers_stats_by_day(date, domain_type))
return stats
def get_crawlers_stats_up_down_by_month(domain_type, date=None):
stats = {'down': 0, 'up': 0}
for date in Date.get_month_dates(date=date):
day = get_crawlers_stats_by_day(date, domain_type)
stats['down'] += day.get('down', 0)
stats['up'] += day.get('up', 0)
return stats
def get_crawlers_stats(domain_type=None):
stats = {}

View File

@ -316,6 +316,19 @@ def crawlers_last_domains_month_json():
stats = crawlers.get_crawlers_stats_by_month(domain_type)
return jsonify(stats)
@crawler_splash.route('/crawlers/last/domains/status/month/json')
@login_required
@login_read_only
def crawlers_last_domains_status_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
stats = crawlers.get_crawlers_stats_up_down_by_month(domain_type)
data = []
for key in stats:
data.append({'name': key, 'value': stats[key]})
return jsonify(data)
#### Domains ####

View File

@ -17,6 +17,7 @@
<script src="{{ url_for('static', filename='js/jquery.daterangepicker.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/d3.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/d3/barchart_stack.js') }}"></script>
<script src="{{ url_for('static', filename='js/d3/pie_chart.js') }}"></script>
<style>
.domain_name {
@ -91,8 +92,8 @@
</div>
<h3>Month Stats:</h3>
<div id="pie_chart_month"></div>
<div id="barchart_type_month"></div>
<div class="text-center" id="pie_chart_month"></div>
</div>
@ -142,6 +143,12 @@ $(document).ready(function(){
}
);
$.getJSON("{{ url_for('crawler_splash.crawlers_last_domains_status_month_json') }}?type={{type}}",
function (data) {
pie_chart("pie_chart_month", data, {});
}
);
$.getJSON("{{ url_for('crawler_splash.crawlers_last_domains_month_json') }}?type={{type}}",
function (data) {
let div_width = $("#barchart_type_month").width();