Skip to content

Commit 8a8bdc4

Browse files
Merge pull request #11 from LangChain-OpenTutorial/soo-hotfix
🚑 hotfix not cal. static function
2 parents 03ce018 + d315d58 commit 8a8bdc4

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

markdown_generator/mdconverter_class.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,13 @@ def cal_static(self) -> None:
244244
self.filename = filename
245245
super()._load_ipynb() # self.notebook_content
246246

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+
250254
markdown_count = sum(
251255
1
252256
for cell in self.notebook_content["cells"]
@@ -264,10 +268,15 @@ def cal_static(self) -> None:
264268
self._increment_count(code_count, self.static["code_counts"])
265269
self._increment_count(total_count, self.static["total_counts"])
266270

271+
self.static = self.sort_dict_by_keys(self.static)
272+
267273
@staticmethod
268274
def _increment_count(key: str, count_dict: dict) -> None:
269275
"""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()}
271280

272281
def plot_static_data(self, category: str) -> None:
273282
if category not in self.static:
@@ -284,7 +293,7 @@ def plot_static_data(self, category: str) -> None:
284293

285294
# Customize the chart
286295
plt.title(f"Counts for {category}")
287-
plt.xlabel("Keys")
296+
plt.xlabel("The number of cells")
288297
plt.ylabel("Counts")
289298
plt.xticks(rotation=45, ha="right")
290299
plt.grid(axis="y", linestyle="--", alpha=0.7)

0 commit comments

Comments
 (0)