9 jupytext_version: 1.11.1
11 display_name: Python 3 (ipykernel)
22 import matplotlib as mpl
23 import matplotlib.pyplot as plt
28 with open('../advent-of-code22.cabal') as f:
29 build_depends = [l for l in f.readlines() if 'build-depends' in l]
34 cabal_file = open('../advent-of-code22.cabal').read()
35 executables = cabal_file.split('executable')[2:]
41 e.strip().split('build-depends: ')[1].split(',')
46 parts = line.strip().split('build-depends: ')
47 name = parts[0].split()[0]
49 depends = [p.strip() for p in parts[1].split('\n')[0].split(',') if 'base' not in p]
56 modules = {e: ms for e, ms in [extract(e) for e in executables] if e.endswith(tuple(str(i) for i in range(10)))}
61 all_modules = set(m for p in modules for m in modules[p])
62 modules_df = pd.DataFrame.from_dict({p: {m: m in modules[p] for m in sorted(all_modules)} for p in modules}, orient='index').sort_index()
67 print(modules_df.sum().sort_values(ascending=False).to_markdown())
71 sorted_modules = modules_df.sum().sort_values(ascending=False).index.values
76 modules_sorted_cols = modules_df[sorted_modules]
81 modules_scatter = modules_df.stack().reset_index()
82 modules_scatter.columns = ['program', 'module', 'present']
83 modules_scatter = modules_scatter[modules_scatter.present]
88 modules_scatter.plot.scatter(x='program', y='module', s=80, rot=45, figsize=(10, 6))
92 cmap = mpl.colors.ListedColormap(['white', 'blue'])
94 fig, ax = plt.subplots(figsize=(10, 10))
95 ax.imshow(modules_df.to_numpy().T, cmap=cmap)
96 plt.xticks(range(modules_df.index.size), labels=modules_df.index.values, rotation=90);
97 plt.yticks(range(modules_df.columns.size), labels=modules_df.columns.values);
99 ax.xaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.5))
100 ax.yaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.5))
101 ax.grid(which='minor', axis='both', linestyle='-', color='silver', linewidth=1.5);
102 plt.savefig('packages.png');
106 cmap = mpl.colors.ListedColormap(['white', 'blue'])
108 fig, ax = plt.subplots(figsize=(10, 10))
109 ax.imshow(modules_sorted_cols.to_numpy().T, cmap=cmap)
110 plt.xticks(range(modules_sorted_cols.index.size), labels=modules_sorted_cols.index.values, rotation=90);
111 plt.yticks(range(modules_sorted_cols.columns.size), labels=modules_sorted_cols.columns.values);
113 ax.xaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.5))
114 ax.yaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.5))
115 ax.grid(which='minor', axis='both', linestyle='-', color='silver', linewidth=1.5);
116 plt.savefig('packages_sorted.png');
120 mains = list(sorted(f for f in glob.glob('../advent*/Main.hs')))
129 lines = f.readlines()
130 import_lines = [l for l in lines if l.strip().startswith('import') if 'Debug.Trace' not in l]
132 for i in import_lines:
133 words = i.strip().split()
135 imports.append((words[2], True))
137 imports.append((words[1], False))
138 main_imports[m.split('/')[1]] = imports
144 import_counts = collections.Counter(l for ls in main_imports.values() for l in ls)
145 import_counts.most_common()
149 main_imports_unqualified = {m: set(i[0] for i in main_imports[m]) for m in main_imports}
150 main_imports_unqualified
154 import_counts_unqualified = collections.Counter(l for ls in main_imports_unqualified.values() for l in ls)
155 import_counts_unqualified.most_common()
159 all_imports = set(m for p in main_imports_unqualified for m in main_imports_unqualified[p])
160 imports_df = pd.DataFrame.from_dict(
161 {p: {m: m in main_imports_unqualified[p]
162 for m in sorted(all_imports)}
163 for p in main_imports_unqualified},
164 orient='index').sort_index()
169 print(imports_df.sum().sort_values(ascending=False).to_markdown())
173 imports_scatter = imports_df.stack().reset_index()
174 imports_scatter.columns = ['program', 'module', 'present']
175 imports_scatter = imports_scatter[imports_scatter.present]
180 imports_scatter.plot.scatter(x='program', y='module', s=80, rot=45, figsize=(10, 10))
184 imports_df.columns.size
188 sorted_imports = imports_df.sum().sort_values(ascending=False).index.values
193 imports_sorted_cols = imports_df[sorted_imports]
198 cmap = mpl.colors.ListedColormap(['white', 'blue'])
200 fig, ax = plt.subplots(figsize=(10, 10))
201 ax.imshow(imports_df.to_numpy().T, cmap=cmap)
202 plt.xticks(range(imports_df.index.size), labels=imports_df.index.values, rotation=90);
203 plt.yticks(range(imports_df.columns.size), labels=imports_df.columns.values);
205 ax.xaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.5))
206 ax.yaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.5))
207 ax.grid(which='minor', axis='both', linestyle='-', color='silver', linewidth=1.5);
208 plt.savefig('imports.png');
212 cmap = mpl.colors.ListedColormap(['white', 'blue'])
214 fig, ax = plt.subplots(figsize=(10, 10))
215 ax.imshow(imports_sorted_cols.to_numpy().T, cmap=cmap)
216 plt.xticks(range(imports_sorted_cols.index.size), labels=imports_sorted_cols.index.values, rotation=90);
217 plt.yticks(range(imports_sorted_cols.columns.size), labels=imports_sorted_cols.columns.values);
219 ax.xaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.5))
220 ax.yaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.5))
221 ax.grid(which='minor', axis='both', linestyle='-', color='silver', linewidth=1.5);
222 plt.savefig('imports_sorted.png');
226 import matplotlib as mpl