Newer
Older
John-Paul Robinson
committed
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
{
"cells": [
{
"cell_type": "markdown",
"id": "5fb66d11",
"metadata": {},
"source": [
"# run report on pickled list policy data\n",
"\n",
"The script reads pickled files that match the `glob_pattern` from the `pickledir` derived from `dirname` and runs the report saving it as a csv to the subdir \"`dirname`/reports\" dir by default.\n",
"\n",
"Some progress info is available via the `verbose` flag.\n",
"\n",
"The current report aggrates storage stats by top-level-dir and age (year) of data's last access. The goal of this report is to understand the distribution of lesser used data."
]
},
{
"cell_type": "markdown",
"id": "51c07f66",
"metadata": {},
"source": [
"!conda info --envs"
]
},
{
"cell_type": "markdown",
"id": "15997b7d",
"metadata": {},
"source": [
"!conda list"
]
},
{
"cell_type": "markdown",
"id": "c740ad5f",
"metadata": {},
"source": [
"!pip list -freeze"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5059337b",
"metadata": {},
"outputs": [],
"source": [
"import datetime\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"from urllib.parse import unquote\n",
"import sys\n",
"import os\n",
"import pathlib\n",
"import re\n",
"import dask.dataframe as dd\n",
"import dask"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2beaec9e",
"metadata": {},
"outputs": [],
"source": [
"from dask.diagnostics import ProgressBar"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0d8afdae",
"metadata": {},
"outputs": [],
"source": [
"from dask.distributed import Client"
]
},
{
"cell_type": "markdown",
"id": "81b2e176",
"metadata": {},
"source": [
"Client(scheduler_file='scheduler.json')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "514ecfc1",
"metadata": {},
"outputs": [],
"source": [
"client = Client(scheduler_file='scheduler.json')"
]
},
{
"cell_type": "markdown",
"id": "b17e817d",
"metadata": {},
"source": [
"\n",
"client = Client()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5a2cdaa6",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "5f4c10d1",
"metadata": {},
"source": [
"## input vars"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d9533a4c",
"metadata": {},
"outputs": [],
"source": [
"dirname=\"data/list-policy_projects_2024-05-03\" # directory to fine files to pickle\n",
"glob_pattern = \"*.parquet\" # file name glob pattern to match, can be file name for individual file\n",
"line_regex_filter = \".*\" # regex to match lines of interest in file\n",
"pickledir=f\"{dirname}/parquet\"\n",
"reportdir=f\"{dirname}/reports\"\n",
"tldpath=\"/data/project\"\n",
"\n",
"verbose = True\n",
"limit = 0"
]
},
{
"cell_type": "markdown",
"id": "a28d0f15",
"metadata": {},
"source": [
"## Utilities"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ed367712",
"metadata": {},
"outputs": [],
"source": [
"# get top level dir on which to aggregate\n",
"\n",
"def get_tld(df, dirname):\n",
" '''\n",
" df: dataframe with path column (e.g. from policy run)\n",
" dirname: top level dir (TLD) that contains dirs for report\n",
" \n",
" The function uses the length of dirname to locate the TLD column in the split path.\n",
" '''\n",
" dirpaths = dirname.split(\"/\")\n",
" new=df[\"path\"].str.split(\"/\", n=len(dirpaths)+1, expand=True)\n",
" #df=df.assign(tld=new[len(dirpaths)])\n",
" #df[\"tld\"] = new[len(dirpaths)]\n",
" \n",
" return new[len(dirpaths)]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a057a9ec",
"metadata": {},
"outputs": [],
"source": [
"# get top level dir on which to aggregate\n",
"\n",
"def get_year(df, column):\n",
" '''\n",
" df: dataframe with path column (e.g. from policy run)\n",
" dirname: top level dir (TLD) that contains dirs for report\n",
" \n",
" The function uses the length of dirname to locate the TLD column in the split path.\n",
" '''\n",
" new = df[column].dt.year\n",
" #dirpaths = dirname.split(\"/\")\n",
" #new=df[\"path\"].str.split(\"/\", n=len(dirpaths)+1, expand=True)\n",
" #df=df.assign(tld=new[len(dirpaths)])\n",
" #df[\"tld\"] = new[len(dirpaths)]\n",
" \n",
" return new"
]
},
{
"cell_type": "code",
"execution_count": null,
Loading
Loading full blame...