From 412b012ddfb512296830e85b9c006ccba4d1554c Mon Sep 17 00:00:00 2001 From: Terrtia Date: Mon, 16 Jul 2018 16:45:36 +0200 Subject: [PATCH] add: hash line_graph (nb/day) --- .../base64Decoded/Flask_base64Decoded.py | 35 ++++- .../base64Decoded/templates/showHash.html | 120 ++++++++++++++++++ 2 files changed, 151 insertions(+), 4 deletions(-) diff --git a/var/www/modules/base64Decoded/Flask_base64Decoded.py b/var/www/modules/base64Decoded/Flask_base64Decoded.py index 177908f4..8284dd16 100644 --- a/var/www/modules/base64Decoded/Flask_base64Decoded.py +++ b/var/www/modules/base64Decoded/Flask_base64Decoded.py @@ -235,10 +235,6 @@ def showHash(): first_seen=first_seen, last_seen=last_seen, nb_seen_in_all_pastes=nb_seen_in_all_pastes, sparkline_values=sparkline_values) -@base64Decoded.route('/base64Decoded/test_json') -def test_json(): - return jsonify([{'date': "2018-09-09", 'value': 34}, {'date': "2018-09-10", 'value': 56}, {'date': "2018-09-11", 'value': 0}, {'date': "2018-09-12", 'value': 12}]) - @base64Decoded.route('/base64Decoded/hash_by_type_json') def hash_by_type_json(): type = request.args.get('type') @@ -318,6 +314,37 @@ def range_type_json(): return jsonify(range_type) +@base64Decoded.route('/base64Decoded/hash_graph_line_json') +def hash_graph_line_json(): + hash = request.args.get('hash') + date_from = request.args.get('date_from') + date_to = request.args.get('date_to') + + #hash = '9c748d28d78a64aef99e7ba866a433eb635c6d7a' + + if date_from is None or date_to is None: + nb_days_seen_in_pastes = 30 + else: + # # TODO: # FIXME: + nb_days_seen_in_pastes = 30 + + date_range_seen_in_pastes = get_date_range(nb_days_seen_in_pastes) + + #verify input + if r_serv_metadata.hget('metadata_hash:'+hash, 'estimated_type') is not None: + json_seen_in_paste = [] + for date in date_range_seen_in_pastes: + nb_seen_this_day = r_serv_metadata.zscore('base64_date:'+date, hash) + if nb_seen_this_day is None: + nb_seen_this_day = 0 + date = date[0:4] + '-' + date[4:6] + '-' + date[6:8] + json_seen_in_paste.append({ 'date' : date, 'value' : int( nb_seen_this_day )}) + + return jsonify(json_seen_in_paste) + else: + return jsonify() + + @base64Decoded.route('/base64Decoded/hash_graph_node_json') def hash_graph_node_json(): hash = request.args.get('hash') diff --git a/var/www/modules/base64Decoded/templates/showHash.html b/var/www/modules/base64Decoded/templates/showHash.html index 2796d572..e63b8cd1 100644 --- a/var/www/modules/base64Decoded/templates/showHash.html +++ b/var/www/modules/base64Decoded/templates/showHash.html @@ -74,6 +74,16 @@ .graph_panel { padding: unset; } + + .line_graph { + fill: none; + stroke: steelblue; + stroke-width: 2px; + stroke-linejoin: round; + stroke-linecap: round; + stroke-width: 1.5; + /*attr('stroke', '#bcbd22').*/ + } @@ -153,6 +163,17 @@ + +
+
+ Graph +
+
+
+
+
+
+ @@ -166,6 +187,7 @@ sparklines("sparkline", {{ sparkline_values }}) all_graph.node_graph = create_graph('/base64Decoded/hash_graph_node_json?hash={{hash}}'); + all_graph.line_chart = create_line_chart('graph_line', '/base64Decoded/hash_graph_line_json?hash={{hash}}'); all_graph.onResize(); }); @@ -415,6 +437,104 @@ all_graph.onResize = function () { } window.all_graph = all_graph; + + +