Changeset 34438

Show
Ignore:
Timestamp:
04.10.2020 23:47:43 (3 weeks ago)
Author:
davidb
Message:

Next step of coding development; using OrderedDict? to store the values by key, but still in order they appear in the CSV file

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/model-sites-dev/mars/collect/deam/MERGE-CSV-FEATURES-AND-AV-FILES.py

    r34436 r34438  
    55from collections import OrderedDict 
    66 
    7 # result = OrderedDict() 
    8  
    97def csv_features_to_dict(csv_filename): 
    10     # csv_features_file = open('etc/deam-essentia-features-collated.csv') 
    118    csv_features_file = open(csv_filename) 
    129    csv_features_reader = csv.reader(csv_features_file, delimiter=',', quotechar='"') 
     
    2118            row.pop(0) 
    2219            header_row = row 
    23         #        print(f'Column names are {", ".join(row)}') 
    2420        else: 
    2521            full_file_id = row[0] 
     
    4743 
    4844    csv_file = open(csv_filename) 
    49     csv_reader = csv.reader(csv_features_file, delimiter=',') 
     45    csv_reader = csv.reader(csv_file, delimiter=',') 
    5046 
    5147    csv_gt_dict = {} 
     
    5652    for row in csv_reader: 
    5753        if line_count == 0: 
     54            row.pop(0) 
    5855            header_row = row 
    59         #        print(f'Column names are {", ".join(row)}') 
    6056        else: 
    61             song_id = row[0] 
     57            song_id = int(row[0]) 
     58            row.pop(0) 
    6259 
    63             #        print(f'\tsong-id: {song_id}') 
    64             csv_gt_dict[song_id] = row 
     60            row_ordered_dict = OrderedDict() 
     61 
     62            for i in range(0, len(row)): 
     63                field = header_row[i]; 
     64                value = row[i]; 
     65 
     66                row_ordered_dict[field] = value 
     67                 
     68            csv_gt_dict[song_id] = row_ordered_dict 
    6569 
    6670        line_count += 1 
     
    7175csv_features_dict = csv_features_to_dict('etc/deam-essentia-features-collated.csv') 
    7276 
    73 #for song_id_key in csv_features_dict: 
    74 #    print(song_id_key + "\n" + str(csv_features_dict[song_id_key]))  
     77print("Essentia Features (sample of first 3 ids):") 
     78i = 1 
     79for song_id_key, ordered_feature_vals in sorted(csv_features_dict.items()):  
     80#    print(str(song_id_key) + "\n" + str(ordered_feature_vals)) 
     81    if i >= 3: 
     82        break 
     83    i = i + 1 
    7584 
    7685 
    77 for song_id_key, ordered_feature_vals in sorted(csv_features_dict.items()):  
    78     print(str(song_id_key) + "\n" + str(ordered_feature_vals)) 
    79  
    80  
    81 groundtruth_dir = 'prepare/annotations/annotations\ averaged\ per\ song/dynamic\ \(per\ second\ annotations\)' 
     86groundtruth_dir = 'prepare/annotations/annotations averaged per song/dynamic (per second annotations)' 
    8287arousal_csv_filename = groundtruth_dir + '/arousal.csv' 
    83 valance_csv_filename = groundtruth_dir + '/valance.csv' 
     88valence_csv_filename = groundtruth_dir + '/valence.csv' 
    8489 
    8590 
    8691arousal_groundtruth_dict = csv_groundtruth_to_dict(arousal_csv_filename) 
    87 valance_groundtruth_dict = csv_groundtruth_to_dict(valance_csv_filename) 
     92valence_groundtruth_dict = csv_groundtruth_to_dict(valence_csv_filename) 
    8893 
    89 #print(f'Processed {line_count} lines.') 
     94print("Arousal Ground-truth (sample of first 3 ids):") 
     95i = 1 
     96for song_id_key, ordered_feature_vals in sorted(arousal_groundtruth_dict.items()):  
     97    print(str(song_id_key) + "\n" + str(ordered_feature_vals)) 
     98    if i >= 3: 
     99        break 
     100    i = i + 1