-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage_stats.py
86 lines (72 loc) · 1.96 KB
/
package_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"""Compute graphs and statistics of packages purchased and used
"""
import altair as alt
import infra.dask
import infra.pd
import infra.platform
def make_plot():
transactions = infra.pd.read_parquet("data/clean/transactions_DIV_none_INDEX_timestamp.parquet")
purchases = transactions.loc[transactions["kind"] == "purchase"]
purchases = purchases.groupby("amount_bytes")["timestamp"].count()
purchases = purchases.reset_index().rename({"timestamp": "count"}, axis="columns")
purchases["amount_MB"] = purchases["amount_bytes"] * 1.0/1000**2
purchases["total_GB"] = purchases["amount_MB"] * purchases["count"] * 1.0/1000
print(purchases)
bars = alt.Chart(purchases).mark_bar().encode(
x=alt.X(
'count',
title="Count",
),
y=alt.Y(
'amount_MB',
type="ordinal",
title="Package Type (MB)",
),
color=alt.Color(
'amount_MB:N',
legend=None,
)
)
text = bars.mark_text(
align="left",
baseline="middle",
xOffset=5,
).encode(
text="count:Q",
color=alt.value("black"),
)
bars = text + bars
bars.properties(
width=500,
height=75,
).save(
"renders/package_counts.png",
scale_factor=2,
)
alt.Chart(purchases).mark_bar().encode(
x=alt.X(
'total_GB',
title="Total GB Purchased",
),
y=alt.Y(
'amount_MB',
type="ordinal",
title="Package Type (MB)",
),
color=alt.Color(
'amount_MB:N',
legend=None,
)
).properties(
width=500,
height=75,
).save(
"renders/package_bytes.png",
scale_factor=2,
)
if __name__ == "__main__":
platform = infra.platform.read_config()
if platform.altair_support:
print("Running vis tasks")
make_plot()
print("Done!")