From 3141fea0c5d463cbaf85153e0afa161204f2990a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Thu, 7 Jun 2018 16:18:50 +0200 Subject: [PATCH] fix: Session related issues. --- bgpranking/querying.py | 21 ++++++++++++++------- website/web/__init__.py | 4 ++-- website/web/static/linegraph.js | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/bgpranking/querying.py b/bgpranking/querying.py index f9fc6d6..4751cca 100644 --- a/bgpranking/querying.py +++ b/bgpranking/querying.py @@ -62,9 +62,10 @@ class Querying(): d = self.__normalize_date(date) if source: key = f'{d}|{source}|{asn}|{ipversion}' + return self.ranking.get(key) else: key = f'{d}|asns|{ipversion}' - return self.ranking.zscore(key, asn) + return self.ranking.zscore(key, asn) def get_sources(self, date: Dates=datetime.date.today()): '''Get the sources availables for a specific day (default: today).''' @@ -78,7 +79,7 @@ class Querying(): return descriptions return descriptions[sorted(descriptions.keys(), reverse=True)[0]] - def get_prefix_ips(self, asn: int, prefix: str, date: Dates=datetime.date.today(), source: str=''): + def get_prefix_ips(self, asn: int, prefix: str, date: Dates=datetime.date.today(), source: str='', ipversion: str='v4'): if source: sources = [source] else: @@ -91,13 +92,19 @@ class Querying(): [prefix_ips[ip].append(source) for ip in ips] return prefix_ips - def get_asn_history(self, asn: int, period: int=100, source: str='', ipversion: str='v4'): + def get_asn_history(self, asn: int, period: int=100, source: str='', ipversion: str='v4', date: Dates=datetime.date.today()): to_return = [] - today = datetime.date.today() + + if isinstance(date, str): + date = parse(date).date() + if date + timedelta(days=period / 3) > datetime.date.today(): + # the period to display will be around the date passed at least 2/3 before the date, at most 1/3 after + date = datetime.date.today() + for i in range(period): - date = today - timedelta(days=i) - rank = self.asn_rank(asn, date, source, ipversion) + d = date - timedelta(days=i) + rank = self.asn_rank(asn, d, source, ipversion) if rank is None: rank = 0 - to_return.insert(0, (date.isoformat(), rank)) + to_return.insert(0, (d.isoformat(), rank)) return to_return diff --git a/website/web/__init__.py b/website/web/__init__.py index fa1acee..8e3ee5b 100644 --- a/website/web/__init__.py +++ b/website/web/__init__.py @@ -64,6 +64,7 @@ def index(): def asn_details(): load_session() q = Querying() + sources = q.get_sources(date=session['date']) ranks = q.asn_details(**session) prefix = get_request_parameter('prefix') if prefix: @@ -72,12 +73,11 @@ def asn_details(): prefix_ips.sort(key=lambda entry: len(entry[1]), reverse=True) else: prefix_ips = [] - return render_template('asn.html', ranks=ranks, prefix_ips=prefix_ips, **session) + return render_template('asn.html', sources=sources, ranks=ranks, prefix_ips=prefix_ips, **session) @app.route('/asn_history', methods=['GET', 'POST']) def asn_history(): load_session() - session.pop('date', None) q = Querying() return json.dumps(q.get_asn_history(**session)) diff --git a/website/web/static/linegraph.js b/website/web/static/linegraph.js index 7614f96..2904520 100644 --- a/website/web/static/linegraph.js +++ b/website/web/static/linegraph.js @@ -60,7 +60,7 @@ function xAxis() { function yAxis() { var tickCount = 20, - tickSize = 3, + tickSize = 1, tickPadding = 1, ticks = y.ticks(tickCount), tickFormat = y.tickFormat(tickCount);