]> us-delaporte.pagekite.me Git - dotfiles.git/blob - data/issues.ipynb
Todolist tweaks
[dotfiles.git] / data / issues.ipynb
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": null,
6 "metadata": {},
7 "outputs": [],
8 "source": [
9 "import platform\n",
10 "import matplotlib.pyplot as plt\n",
11 "print(platform.python_version())"
12 ]
13 },
14 {
15 "cell_type": "markdown",
16 "metadata": {},
17 "source": []
18 },
19 {
20 "cell_type": "markdown",
21 "metadata": {},
22 "source": [
23 "# Todo List\n",
24 "\n",
25 "- [x] add calculated year to the metadata\n",
26 "- [ ] make one chart per year\n",
27 "- [x] make sure all the data files are getting loaded"
28 ]
29 },
30 {
31 "cell_type": "code",
32 "execution_count": null,
33 "metadata": {},
34 "outputs": [],
35 "source": [
36 "# Get ye data\n",
37 "import glob\n",
38 "import os\n",
39 "\n",
40 "data_files = glob.glob(os.path.expanduser('~\\\\Data\\\\*.json'))\n",
41 "\n",
42 "for file in data_files:\n",
43 "\tprint(f\"{file}\", os.path.getsize(file))\n",
44 "\n"
45 ]
46 },
47 {
48 "cell_type": "code",
49 "execution_count": null,
50 "metadata": {},
51 "outputs": [],
52 "source": [
53 "import pandas as pd\n",
54 "\n",
55 "data_frames = []\n",
56 "for file in data_files:\n",
57 "\n",
58 "\tf = open(file, encoding='utf-8')\n",
59 "\tdf_temp = pd.read_json(f)\n",
60 "\tdata_frames.append(df_temp)\n",
61 "\n",
62 "df = pd.concat(data_frames, ignore_index=True)"
63 ]
64 },
65 {
66 "cell_type": "code",
67 "execution_count": null,
68 "metadata": {},
69 "outputs": [],
70 "source": [
71 "import numpy as np\n",
72 "df['count'] = np.zeros(len(df))\n",
73 "\n"
74 ]
75 },
76 {
77 "cell_type": "markdown",
78 "metadata": {},
79 "source": [
80 "#### Pie Chart"
81 ]
82 },
83 {
84 "cell_type": "code",
85 "execution_count": null,
86 "metadata": {},
87 "outputs": [],
88 "source": [
89 "\n",
90 "dfp = df\n",
91 "# dfp['mile'] = [m.get('title') if m else None for m in dfp.milestone]\n",
92 "dfp['mile'] = [m.get('title') if hasattr(m, 'get') else None for m in dfp['milestone']]\n"
93 ]
94 },
95 {
96 "cell_type": "code",
97 "execution_count": null,
98 "metadata": {},
99 "outputs": [],
100 "source": [
101 "closed_dates = pd.to_datetime(df['closedAt'], format='ISO8601')\n",
102 "dfp['year'] = closed_dates.dt.year\n",
103 "\n",
104 "dfp.drop(columns=['closedAt','milestone', 'url'], inplace=True)\n",
105 "print(dfp)"
106 ]
107 },
108 {
109 "cell_type": "code",
110 "execution_count": null,
111 "metadata": {},
112 "outputs": [],
113 "source": [
114 "\n",
115 "mile_counts = dfp.groupby('mile')['title'].nunique()\n",
116 "dfp['count'] = dfp['mile'].map(mile_counts)\n",
117 "# dfp.drop(columns=['title'], inplace=True)\n",
118 "dfp['mile'] = df['mile'].drop_duplicates()\n",
119 "dfp.dropna(inplace=True)\n",
120 "dfp = dfp[dfp['count'] > 5]\n",
121 "print(dfp)"
122 ]
123 },
124 {
125 "cell_type": "code",
126 "execution_count": null,
127 "metadata": {},
128 "outputs": [],
129 "source": [
130 "mile_counts = df.groupby('mile')['count'].sum()\n",
131 "mile_counts = mile_counts.loc[lambda x: x > 5]\n",
132 "\n",
133 "\n",
134 "print(mile_counts)"
135 ]
136 },
137 {
138 "cell_type": "code",
139 "execution_count": null,
140 "metadata": {},
141 "outputs": [],
142 "source": [
143 "\n",
144 "plt.pie(mile_counts, labels=mile_counts.index, autopct='%0.1f%%')\n",
145 "plt.title(f\"Tasks by Milestone\")\n",
146 "plt.axis('equal')\n",
147 "plt.show()"
148 ]
149 },
150 {
151 "cell_type": "code",
152 "execution_count": null,
153 "metadata": {},
154 "outputs": [],
155 "source": [
156 "type(mile_counts)"
157 ]
158 },
159 {
160 "cell_type": "markdown",
161 "metadata": {},
162 "source": [
163 "#### Plot of closed issues by month and milestone for one project\n"
164 ]
165 },
166 {
167 "cell_type": "code",
168 "execution_count": null,
169 "metadata": {},
170 "outputs": [],
171 "source": [
172 "closed_months = pd.to_datetime(df['closedAt'], format='ISO8601')\n",
173 "df['closed_month'] = closed_months.dt.month\n",
174 "df.drop(columns=['closedAt'], inplace=True)"
175 ]
176 },
177 {
178 "cell_type": "code",
179 "execution_count": null,
180 "metadata": {},
181 "outputs": [],
182 "source": [
183 "df['mile'] = [d.get('title') if d else None for d in df.milestone]"
184 ]
185 },
186 {
187 "cell_type": "code",
188 "execution_count": null,
189 "metadata": {},
190 "outputs": [],
191 "source": [
192 "\n",
193 "dfg = df.groupby(['mile', 'closed_month']).count().reset_index()\n",
194 "dfg.drop(columns=['milestone', 'title', 'url'], inplace=True)\n"
195 ]
196 },
197 {
198 "cell_type": "code",
199 "execution_count": null,
200 "metadata": {},
201 "outputs": [],
202 "source": [
203 "exclude_from_chart = [\n",
204 "\t'Job Aid Ideas']\n",
205 "\n",
206 "for ex in exclude_from_chart:\n",
207 "\tdfg = dfg[dfg['mile'] != ex]\n"
208 ]
209 },
210 {
211 "cell_type": "code",
212 "execution_count": null,
213 "metadata": {},
214 "outputs": [],
215 "source": [
216 "import seaborn as sns\n",
217 "import matplotlib.pyplot as plt\n",
218 "sns.set_theme()"
219 ]
220 },
221 {
222 "cell_type": "code",
223 "execution_count": null,
224 "metadata": {},
225 "outputs": [],
226 "source": [
227 "plt.figure(figsize=(10, 6))\n",
228 "sns.pie(x='closed_month', y='count', hue='mile', data=dfg)\n",
229 "plt.pie(dfg, )\n",
230 "plt.xlabel('Closed Month')\n",
231 "plt.ylabel('ClosedAt')\n",
232 "plt.title('Stacked Line Chart: Milestone Effort by Issue Close Date')\n",
233 "plt.xticks(rotation=45)\n",
234 "plt.legend(title='Mile', loc='upper left')\n",
235 "plt.show()"
236 ]
237 }
238 ],
239 "metadata": {
240 "kernelspec": {
241 "display_name": "Python 3",
242 "language": "python",
243 "name": "python3"
244 },
245 "language_info": {
246 "codemirror_mode": {
247 "name": "ipython",
248 "version": 3
249 },
250 "file_extension": ".py",
251 "mimetype": "text/x-python",
252 "name": "python",
253 "nbconvert_exporter": "python",
254 "pygments_lexer": "ipython3",
255 "version": "3.12.2"
256 }
257 },
258 "nbformat": 4,
259 "nbformat_minor": 2
260 }