Last active
          August 28, 2018 07:38 
        
      - 
      
- 
        Save tai271828/c51d0970cafe41bc3031b4b182f31fc7 to your computer and use it in GitHub Desktop. 
    Dump duration information from a submission.json
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/env python3 | |
| # | |
| # Usage: | |
| # ./this-script <your-submission-json> [your-output-csv] | |
| # | |
| # | |
| import csv | |
| import sys | |
| import json | |
| import datetime | |
| try: | |
| input_filename = sys.argv[1] | |
| except IndexError: | |
| print("Please input submission in json format.") | |
| sys.exit(1) | |
| id_duration_all = [] | |
| total_duration = [] | |
| with open(input_filename, "r") as submission: | |
| data = json.load(submission) | |
| data_results = data["results"] | |
| for entry in data_results: | |
| total_duration.append(entry["duration"]) | |
| duration_rsec = int("{0:.0f}".format(round(entry["duration"], 0))) | |
| duration_hms = str(datetime.timedelta(seconds=duration_rsec)) | |
| id_duration = [entry["id"], duration_hms] | |
| id_duration_all.append(id_duration) | |
| try: | |
| output_filename = sys.argv[2] | |
| except IndexError: | |
| output_filename = "duration.csv" | |
| with open(output_filename, "w") as output_file: | |
| output_writer = csv.writer(output_file) | |
| for entry in id_duration_all: | |
| output_writer.writerow(entry) | |
| total_sec = sum(total_duration) | |
| total_rsec = int("{0:.0f}".format(round(total_sec, 0))) | |
| total_hms = str(datetime.timedelta(seconds=total_rsec)) | |
| print("Total duration is {}".format(total_hms)) | |
| print("done.") | |
thanks for the comments <3 <3 enjoy the duration!
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
hi this is cool!