Advertisement
Guest User

Untitled

a guest
Jul 19th, 2024
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. import os
  2. import json
  3.  
  4. # This must be run in the "results" folder.
  5.  
  6. def get_summary_files():
  7.     return [f for f in os.listdir() if 'summary' in f.lower() and f.endswith('.json')]
  8.  
  9. def extract_json_content(file_path):
  10.     with open(file_path, 'r') as file:
  11.         return json.load(file)
  12.  
  13. def process_summaries():
  14.     total_correct = 0
  15.     total_wrong = 0
  16.     categories = {}
  17.    
  18.     for file in get_summary_files():
  19.         data = extract_json_content(file)
  20.         category = list(data.keys())[0]  # Assuming the first key is the category
  21.         total = data['total']
  22.        
  23.         categories[category] = {
  24.             'correct': total['corr'],
  25.             'wrong': total['wrong'],
  26.             'accuracy': total['acc']
  27.         }
  28.        
  29.         total_correct += total['corr']
  30.         total_wrong += total['wrong']
  31.    
  32.     return categories, total_correct, total_wrong
  33.  
  34. def main():
  35.     categories, total_correct, total_wrong = process_summaries()
  36.    
  37.     print("Results by category:")
  38.     for category, results in categories.items():
  39.         print(f"{category.capitalize()}:")
  40.         print(f"  Correct: {results['correct']}")
  41.         print(f"  Wrong: {results['wrong']}")
  42.         print(f"  Accuracy: {results['accuracy']:.2%}")
  43.         print()
  44.    
  45.     total_questions = 12032  # As per the given table
  46.     total_answered = total_correct + total_wrong
  47.     failed = total_questions - total_answered
  48.    
  49.     print(f"Total correct: {total_correct}")
  50.     print(f"Total wrong: {total_wrong}")
  51.     print(f"Total answered: {total_answered}")
  52.     print(f"Failed to answer: {failed}")
  53.     print(f"Overall accuracy: {total_correct / total_answered:.2%}")
  54.  
  55. if __name__ == "__main__":
  56.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement