mirror of
https://github.com/LukeHagar/pypistats.dev.git
synced 2025-12-06 04:21:09 +00:00
use lines in lieu of fill for proportional downloads
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -22,3 +22,6 @@ dump.rdb
|
|||||||
.elasticbeanstalk
|
.elasticbeanstalk
|
||||||
!.elasticbeanstalk/*.cfg.yml
|
!.elasticbeanstalk/*.cfg.yml
|
||||||
!.elasticbeanstalk/*.global.yml
|
!.elasticbeanstalk/*.global.yml
|
||||||
|
|
||||||
|
# intellij
|
||||||
|
.idea/
|
||||||
@@ -32,6 +32,44 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"percentages":{
|
"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":[
|
"data":[
|
||||||
{
|
{
|
||||||
"x":[
|
"x":[
|
||||||
|
|||||||
@@ -131,7 +131,7 @@
|
|||||||
"gridwidth":2,
|
"gridwidth":2,
|
||||||
"autotick":false,
|
"autotick":false,
|
||||||
"showline":true,
|
"showline":true,
|
||||||
"title":"Proportional Downloads",
|
"title":"Download Proportion",
|
||||||
"ticksuffix":"%",
|
"ticksuffix":"%",
|
||||||
"tickmode":"auto",
|
"tickmode":"auto",
|
||||||
"linecolor":"rgba(148, 148, 148, 1)",
|
"linecolor":"rgba(148, 148, 148, 1)",
|
||||||
|
|||||||
@@ -151,8 +151,12 @@ def package(package):
|
|||||||
base["name"] = category.title()
|
base["name"] = category.title()
|
||||||
data.append(base)
|
data.append(base)
|
||||||
plot["data"] = data
|
plot["data"] = data
|
||||||
plot["layout"]["title"] = \
|
if model["metric"] == "percentages":
|
||||||
f"Downloads of {package} package - {model['name'].title().replace('_', ' ')}" # noqa
|
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)
|
plots.append(plot)
|
||||||
return render_template(
|
return render_template(
|
||||||
"package.html",
|
"package.html",
|
||||||
@@ -216,6 +220,7 @@ def get_download_data(records):
|
|||||||
data[category]["y"].append(0)
|
data[category]["y"].append(0)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def get_proportion_data(records):
|
def get_proportion_data(records):
|
||||||
"""Organize the data for the fill plots."""
|
"""Organize the data for the fill plots."""
|
||||||
data = defaultdict(lambda: {"x": [], "y": [], "text": []})
|
data = defaultdict(lambda: {"x": [], "y": [], "text": []})
|
||||||
@@ -224,7 +229,6 @@ def get_proportion_data(records):
|
|||||||
all_categories = []
|
all_categories = []
|
||||||
|
|
||||||
prev_date = records[0].date
|
prev_date = records[0].date
|
||||||
date_csum = 0
|
|
||||||
|
|
||||||
for record in records:
|
for record in records:
|
||||||
if record.category not in all_categories:
|
if record.category not in all_categories:
|
||||||
@@ -241,33 +245,14 @@ def get_proportion_data(records):
|
|||||||
for category in all_categories:
|
for category in all_categories:
|
||||||
data[category]["x"].append(str(record.date))
|
data[category]["x"].append(str(record.date))
|
||||||
value = date_categories[category] / total
|
value = date_categories[category] / total
|
||||||
date_csum += value
|
data[category]["y"].append(value)
|
||||||
data[category]["y"].append(date_csum)
|
|
||||||
data[category]["text"].append("{0:.2f}%".format(value) + " = {:,}".format(date_categories[category]))
|
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)
|
date_categories = defaultdict(lambda: 0)
|
||||||
prev_date = record.date
|
prev_date = record.date
|
||||||
date_csum = 0
|
|
||||||
|
|
||||||
# Track categories for this date
|
# Track categories for this date
|
||||||
date_categories[record.category] = record.downloads
|
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
|
return data
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user