Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions migrations/seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
)
records.append(record)

for idx, category in enumerate(["2", "3"]):
for idx, category in enumerate(["null", "2", "3"]):
record = PythonMajorDownloadCount(
date=date,
package=package,
Expand All @@ -74,7 +74,9 @@
)
records.append(record)

for idx, category in enumerate(["2.7", "3.4", "3.5", "3.6", "3.7", "3.8"]):
for idx, category in enumerate(
["null", "2.7", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
):
record = PythonMinorDownloadCount(
date=date,
package=package,
Expand All @@ -83,7 +85,7 @@
)
records.append(record)

for idx, category in enumerate(["windows", "linux", "darwin"]):
for idx, category in enumerate(["null", "windows", "linux", "darwin"]):
record = SystemDownloadCount(
date=date,
package=package,
Expand Down
26 changes: 21 additions & 5 deletions pypistats/views/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,15 @@ def package_page(package):
else:
metrics = ["downloads", "percentages"]

if model == PythonMinorDownloadCount:
category_key = python_minor_key
else:
category_key = None

for metric in metrics:
model_data.append({"metric": metric, "name": model.__tablename__, "data": data_function[metric](records)})
model_data.append(
{"metric": metric, "name": model.__tablename__, "data": data_function[metric](records, category_key)}
)

# Build the plots
plots = []
Expand Down Expand Up @@ -191,7 +198,16 @@ def package_page(package):
return render_template("package.html", package=package, plots=plots, metadata=metadata, recent=recent, user=g.user)


def get_download_data(records):
def python_minor_key(version):
try:
key = [""] + [int(p) for p in version.split(".")]
except ValueError:
key = [version]

return key


def get_download_data(records, category_key=None):
"""Organize the data for the absolute plots."""
data = defaultdict(lambda: {"x": [], "y": []})

Expand All @@ -204,7 +220,7 @@ def get_download_data(records):
if record.category not in all_categories:
all_categories.append(record.category)

all_categories = sorted(all_categories)
all_categories = sorted(all_categories, key=category_key)
for category in all_categories:
data[category] # set the dict value (keeps it ordered)

Expand Down Expand Up @@ -244,7 +260,7 @@ def get_download_data(records):
return data


def get_proportion_data(records):
def get_proportion_data(records, category_key=None):
"""Organize the data for the fill plots."""
data = defaultdict(lambda: {"x": [], "y": [], "text": []})

Expand All @@ -257,7 +273,7 @@ def get_proportion_data(records):
if record.category not in all_categories:
all_categories.append(record.category)

all_categories = sorted(all_categories)
all_categories = sorted(all_categories, key=category_key)
for category in all_categories:
data[category] # set the dict value (keeps it ordered)

Expand Down