@@ -244,9 +244,13 @@ def cal_static(self) -> None:
244
244
self .filename = filename
245
245
super ()._load_ipynb () # self.notebook_content
246
246
247
- python_version = self .notebook_content ["metadata" ]["language_info" ][
248
- "version"
249
- ]
247
+ try :
248
+ python_version = self .notebook_content ["metadata" ]["language_info" ][
249
+ "version"
250
+ ]
251
+ except :
252
+ python_version = "Unkown"
253
+
250
254
markdown_count = sum (
251
255
1
252
256
for cell in self .notebook_content ["cells" ]
@@ -264,10 +268,15 @@ def cal_static(self) -> None:
264
268
self ._increment_count (code_count , self .static ["code_counts" ])
265
269
self ._increment_count (total_count , self .static ["total_counts" ])
266
270
271
+ self .static = self .sort_dict_by_keys (self .static )
272
+
267
273
@staticmethod
268
274
def _increment_count (key : str , count_dict : dict ) -> None :
269
275
"""Increment count for a key in the given dictionary."""
270
- count_dict [str (key )] = count_dict .get (str (key ), 0 ) + 1
276
+ count_dict [key ] = count_dict .get (key , 0 ) + 1
277
+
278
+ def sort_dict_by_keys (self , input_dict ):
279
+ return {key : dict (sorted (value .items ())) for key , value in input_dict .items ()}
271
280
272
281
def plot_static_data (self , category : str ) -> None :
273
282
if category not in self .static :
@@ -284,7 +293,7 @@ def plot_static_data(self, category: str) -> None:
284
293
285
294
# Customize the chart
286
295
plt .title (f"Counts for { category } " )
287
- plt .xlabel ("Keys " )
296
+ plt .xlabel ("The number of cells " )
288
297
plt .ylabel ("Counts" )
289
298
plt .xticks (rotation = 45 , ha = "right" )
290
299
plt .grid (axis = "y" , linestyle = "--" , alpha = 0.7 )
0 commit comments