From b69d8c78e7a1a35b64aef87013d426fba0e18151 Mon Sep 17 00:00:00 2001 From: crflynn Date: Sat, 29 Sep 2018 20:32:25 -0400 Subject: [PATCH] use lines in lieu of fill for proportional downloads --- .gitignore | 3 +++ pypistats/plots/data_base.json | 38 ++++++++++++++++++++++++++++++++++ pypistats/plots/plot_base.json | 2 +- pypistats/views/general.py | 31 +++++++-------------------- 4 files changed, 50 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 8f0b580..3487d93 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ dump.rdb .elasticbeanstalk !.elasticbeanstalk/*.cfg.yml !.elasticbeanstalk/*.global.yml + +# intellij +.idea/ \ No newline at end of file diff --git a/pypistats/plots/data_base.json b/pypistats/plots/data_base.json index 36c2793..6ae56b4 100644 --- a/pypistats/plots/data_base.json +++ b/pypistats/plots/data_base.json @@ -32,6 +32,44 @@ ] }, "percentages":{ + "data":[ + { + "x":[ + "2017-05-01", + "2017-05-02", + "2017-05-03" + ], + "y":[ + "2", + "5", + "4" + ], + "text":[ + "2", + "5", + "4" + ], + "name":"Proportional downloads", + "hoverinfo": "x+text+name", + "type":"scatter", + "mode":"lines+markers", + "connectgaps":true, + "marker":{ + "symbol":"circle", + "line":{ + "color":"#444", + "width":1 + } + }, + "line":{ + "shape":"linear", + "smoothing":1, + "width":2 + } + } + ] + }, + "percentages_fill":{ "data":[ { "x":[ diff --git a/pypistats/plots/plot_base.json b/pypistats/plots/plot_base.json index 80033e6..391342b 100644 --- a/pypistats/plots/plot_base.json +++ b/pypistats/plots/plot_base.json @@ -131,7 +131,7 @@ "gridwidth":2, "autotick":false, "showline":true, - "title":"Proportional Downloads", + "title":"Download Proportion", "ticksuffix":"%", "tickmode":"auto", "linecolor":"rgba(148, 148, 148, 1)", diff --git a/pypistats/views/general.py b/pypistats/views/general.py index d7e7307..68d4db3 100644 --- a/pypistats/views/general.py +++ b/pypistats/views/general.py @@ -151,8 +151,12 @@ def package(package): base["name"] = category.title() data.append(base) plot["data"] = data - plot["layout"]["title"] = \ - f"Downloads of {package} package - {model['name'].title().replace('_', ' ')}" # noqa + if model["metric"] == "percentages": + plot["layout"]["title"] = \ + f"Daily Download Proportions of {package} package - {model['name'].title().replace('_', ' ')}" # noqa + else: + plot["layout"]["title"] = \ + f"Daily Download Quantity of {package} package - {model['name'].title().replace('_', ' ')}" # noqa plots.append(plot) return render_template( "package.html", @@ -216,6 +220,7 @@ def get_download_data(records): data[category]["y"].append(0) return data + def get_proportion_data(records): """Organize the data for the fill plots.""" data = defaultdict(lambda: {"x": [], "y": [], "text": []}) @@ -224,7 +229,6 @@ def get_proportion_data(records): all_categories = [] prev_date = records[0].date - date_csum = 0 for record in records: if record.category not in all_categories: @@ -241,33 +245,14 @@ def get_proportion_data(records): for category in all_categories: data[category]["x"].append(str(record.date)) value = date_categories[category] / total - date_csum += value - data[category]["y"].append(date_csum) + data[category]["y"].append(value) data[category]["text"].append("{0:.2f}%".format(value) + " = {:,}".format(date_categories[category])) - # # Fill missing intermediate dates with zeros - # days_between = (record.date - prev_date).days - # date_list = [prev_date + datetime.timedelta(days=x) for x in range(1, days_between)] - # - # for date in date_list: - # for category in all_categories: - # data[category]["x"].append(str(date)) - # data[category]["y"].append(0) - date_categories = defaultdict(lambda: 0) prev_date = record.date - date_csum = 0 # Track categories for this date date_categories[record.category] = record.downloads - else: - # Fill missing intermediate dates with zeros - total = sum(date_categories.values()) / 100 - for category in all_categories: - data[category]["x"].append(str(record.date)) - date_csum += date_categories[category] - data[category]["y"].append(date_csum) - data[category]["text"].append("{0:.2f}%".format(date_categories[category] / total) + " = {:,}".format(date_categories[category])) return data