Skip to content

Commit ae62f8e

Browse files
authored
Merge pull request #12 from Zipstack/csv-bug-fix
Fix!: Remove JSON parsing error and update detailed report formatting
2 parents 073a375 + dc50cf2 commit ae62f8e

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

main.py

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,14 @@ def calculate_cost_and_tokens(result):
222222

223223
# Exract error message from the result JSON
224224
def extract_error_message(result):
225-
result_data = json.loads(result)
226225
# Check for error in extraction_result
227-
extraction_result = result_data.get("extraction_result", [])
226+
extraction_result = result.get("extraction_result", [])
228227
if extraction_result and isinstance(extraction_result, list):
229228
for item in extraction_result:
230229
if "error" in item and item["error"]:
231230
return item["error"]
232231
# Fallback to the parent error
233-
return result_data.get("error", "No error message found")
232+
return result.get("error", "No error message found")
234233

235234
# Print final summary with count of each status and average time using a single SQL query
236235
def print_summary():
@@ -275,34 +274,49 @@ def print_report():
275274
if report_data:
276275
# Tabulate the data with column headers
277276
headers = [
278-
textwrap.fill(header, width=20)
279-
for header in [
280-
"File Name",
281-
"Execution Status",
282-
"Time Elapsed (seconds)",
283-
"Total Embedding Cost",
284-
"Total Embedding Tokens",
285-
"Total LLM Cost",
286-
"Total LLM Tokens",
287-
"Error Message"
288-
]
277+
"File Name",
278+
"Execution Status",
279+
"Time Elapsed (seconds)",
280+
"Total Embedding Cost",
281+
"Total Embedding Tokens",
282+
"Total LLM Cost",
283+
"Total LLM Tokens",
284+
"Error Message"
289285
]
290-
286+
287+
column_widths = {
288+
"File Name": 30,
289+
"Execution Status": 20,
290+
"Time Elapsed (seconds)": 20,
291+
"Total Embedding Cost": 20,
292+
"Total Embedding Tokens": 20,
293+
"Total LLM Cost": 20,
294+
"Total LLM Tokens": 20,
295+
"Error Message": 30,
296+
}
291297

292298
formatted_data = []
293-
# Wrap text in each column to a specific width (e.g., 30 characters for file names and 20 for others) and return None if the value is NULL
299+
# Format and wrap each row's data to match column widths
294300
for row in report_data:
295-
formatted_row = [
296-
"None" if cell is None else
297-
textwrap.fill(str(cell), width=30) if isinstance(cell, str) else
298-
cell if idx == 2 else f"{cell:.8f}" if isinstance(cell, float) else cell
299-
for idx, cell in enumerate(row)
300-
]
301-
formatted_data.append(formatted_row)
302-
301+
formatted_row = []
302+
for idx, cell in enumerate(row):
303+
header = headers[idx]
304+
width = column_widths[header]
305+
cell_value = "None" if cell is None else str(cell)
306+
if header == "Error Message" and len(cell_value) > 50:
307+
# Truncate long error messages
308+
cell_value = textwrap.fill(cell_value[:100], width=width) + "..."
309+
else:
310+
cell_value = textwrap.fill(cell_value, width=width)
311+
formatted_row.append(cell_value)
312+
formatted_data.append(formatted_row)
313+
314+
# Print the table
303315
print(tabulate(formatted_data, headers=headers, tablefmt="pretty"))
304316
else:
305317
print("No records found in the database.")
318+
319+
print("\nNote: For more detailed error messages, use the CSV report argument.")
306320

307321
def export_report_to_csv(output_path):
308322
conn = sqlite3.connect(DB_NAME)
@@ -621,4 +635,4 @@ def main():
621635

622636

623637
if __name__ == "__main__":
624-
main()
638+
main()

0 commit comments

Comments
 (0)