Newer
Older
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import sqlalchemy\n",
"import pandas as pd\n",
"import numpy as np\n",
"from pathlib import Path\n",
"import cudf"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"hive_dir = '/data/rc/gpfs-policy/data/gpfs-hive/data-project/'\n",
"db = Path('/data/rc/gpfs-policy/data/gpfs-hive/db/data-project.db')\n",
"engine = sqlalchemy.create_engine(f\"sqlite:///{db}\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_sql(\"SELECT * FROM churn WHERE prior_log_dt >= '2024-11-14'\",engine)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"df['total_churn'] = df['created'] + df['deleted'] + df['modified']\n",
"df[['log_dt','prior_log_dt']] = df[['log_dt','prior_log_dt']].apply(lambda x: pd.to_datetime(x))\n",
"df['tld'] = df['tld'].astype('category')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"tld_agg = df.groupby('tld',observed=True)['total_churn'].sum().sort_values(ascending=False)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"no_churn = tld_agg.loc[tld_agg.eq(0)].index"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"cdf = cudf.read_parquet(hive_dir,filters = [('tld','in',no_churn.to_list()),('acq','==','2025-01-15')],columns=['tld','size','kballoc'],categorical_partitions=True)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"cdf['tld'] = cdf['tld'].astype('category')"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"inactive_storage = cdf.groupby('tld',observed=True)[['size','kballoc']].sum()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"inactive_storage['kballoc'].divide(1024**3).sum()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Plotting"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"active = df.loc[~df['tld'].isin(no_churn.to_list())].copy()\n",
"active['tld'] = active['tld'].cat.remove_unused_categories()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# order by total churn over the whole time period\n",
"order = active.groupby('tld',observed=True)['total_churn'].sum().sort_values(ascending=False).index.as_ordered()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"# order by daily activity, percentage of days in the time period where at least one change was made\n",
"order = active.groupby('tld',observed=True)['total_churn'].apply(lambda x: x.ne(0).sum()).sort_values(ascending=False).index.as_ordered()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"import plotly.graph_objects as go"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig = go.Figure(\n",
" data = go.Heatmap(\n",
" z = np.log10(active['total_churn']),\n",
" y = active['log_dt'],\n",
" x = active['tld'],\n",
" xgap=1,\n",
" colorscale='thermal',\n",
" colorbar=dict(\n",
" tickvals=np.arange(0,9),\n",
" ticktext=[str(10**d) for d in np.arange(0,9)],\n",
" tickfont=dict(\n",
" size = 14\n",
" ),\n",
" title=dict(\n",
" text='Churn (files altered)',\n",
" font=dict(\n",
" size = 16\n",
" )\n",
" )\n",
" ),\n",
" hovertemplate='Dir: %{x}<br>Date: %{y}<br>Churn: %{customdata}<extra></extra>',\n",
" customdata=active['total_churn']\n",
" )\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 163,
"metadata": {},
"outputs": [],
"source": [
"fig = fig.update_layout(\n",
" template = 'plotly_white',\n",
" height = 1000,\n",
" width = 2000,\n",
" title_text = 'Time Course of Total Churn For Project Directories Over 2 Months',\n",
" title_x = 0.5,\n",
" title_xanchor = 'center',\n",
" title_font_size = 30,\n",
"\n",
" xaxis = dict(\n",
" title = dict(\n",
" text = 'Directory Name',\n",
" font_size = 20\n",
" ),\n",
" gridwidth = 2,\n",
" showgrid = True,\n",
" gridcolor='black'\n",
" ),\n",
" \n",
" yaxis = dict(\n",
" showgrid = False,\n",
" title = dict(\n",
" text = 'Policy Run Date',\n",
" font_size = 20\n",
" ),\n",
" gridcolor = 'black',\n",
" ),\n",
" \n",
" coloraxis_colorbar=dict(\n",
" title=\"Raw Values\", # Change the title of the z-axis\n",
" titlefont=dict(size=20) # Increase the font size\n",
" ),\n",
"\n",
" margin=dict(t=100, b=20, l=40, r=40)\n",
")\n",
"\n",
"fig = fig.update_xaxes(\n",
" categoryorder='array',\n",
" categoryarray=order,\n",
" tickfont={'size':14},\n",
" ticklabelshift = 3,\n",
" tickson = 'boundaries',\n",
" gridwidth=2\n",
")\n",
"\n",
"fig = fig.update_yaxes(\n",
" tickfont={'size':16},\n",
" tickformat = \"%Y-%m-%d\",\n",
" tick0 = '2024-11-15',\n",
" ticklabelstep=2,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.11"
}
},
"nbformat": 4,
"nbformat_minor": 2
}