1 | #!/usr/bin/env python
|
---|
2 |
|
---|
3 | import csv
|
---|
4 | import re
|
---|
5 | from collections import OrderedDict
|
---|
6 |
|
---|
7 | def csv_features_to_dict(csv_filename):
|
---|
8 | csv_features_file = open(csv_filename)
|
---|
9 | csv_features_reader = csv.reader(csv_features_file, delimiter=',', quotechar='"')
|
---|
10 |
|
---|
11 | csv_features_dict = {}
|
---|
12 |
|
---|
13 | line_count = 0
|
---|
14 | header_row = None
|
---|
15 |
|
---|
16 | for row in csv_features_reader:
|
---|
17 | if line_count == 0:
|
---|
18 | row.pop(0)
|
---|
19 | header_row = row
|
---|
20 | else:
|
---|
21 | full_file_id = row[0]
|
---|
22 |
|
---|
23 | pat = re.compile('^import/(\\d+).json$')
|
---|
24 | mat = pat.match(full_file_id)
|
---|
25 | song_id = int(mat.group(1))
|
---|
26 |
|
---|
27 | row.pop(0)
|
---|
28 | row_ordered_dict = OrderedDict()
|
---|
29 |
|
---|
30 | for i in range(0, len(header_row)):
|
---|
31 | field = header_row[i];
|
---|
32 | value = row[i];
|
---|
33 |
|
---|
34 | row_ordered_dict[field] = value
|
---|
35 |
|
---|
36 | csv_features_dict[song_id] = row_ordered_dict
|
---|
37 |
|
---|
38 | line_count += 1
|
---|
39 |
|
---|
40 | return csv_features_dict
|
---|
41 |
|
---|
42 | def csv_groundtruth_to_dict(csv_filename):
|
---|
43 |
|
---|
44 | csv_file = open(csv_filename)
|
---|
45 | csv_reader = csv.reader(csv_file, delimiter=',')
|
---|
46 |
|
---|
47 | csv_gt_dict = {}
|
---|
48 |
|
---|
49 | line_count = 0
|
---|
50 | header_row = None
|
---|
51 |
|
---|
52 | for row in csv_reader:
|
---|
53 | if line_count == 0:
|
---|
54 | row.pop(0)
|
---|
55 | header_row = row
|
---|
56 | else:
|
---|
57 | song_id = int(row[0])
|
---|
58 | row.pop(0)
|
---|
59 |
|
---|
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
|
---|
69 |
|
---|
70 | line_count += 1
|
---|
71 |
|
---|
72 | return csv_gt_dict
|
---|
73 |
|
---|
74 |
|
---|
75 | csv_features_dict = csv_features_to_dict('etc/deam-essentia-features-collated.csv')
|
---|
76 |
|
---|
77 | print("Essentia Features (sample of first 3 ids):")
|
---|
78 | i = 1
|
---|
79 | for 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
|
---|
84 |
|
---|
85 |
|
---|
86 | groundtruth_dir = 'prepare/annotations/annotations averaged per song/dynamic (per second annotations)'
|
---|
87 | arousal_csv_filename = groundtruth_dir + '/arousal.csv'
|
---|
88 | valence_csv_filename = groundtruth_dir + '/valence.csv'
|
---|
89 |
|
---|
90 |
|
---|
91 | arousal_groundtruth_dict = csv_groundtruth_to_dict(arousal_csv_filename)
|
---|
92 | valence_groundtruth_dict = csv_groundtruth_to_dict(valence_csv_filename)
|
---|
93 |
|
---|
94 | print("Arousal Ground-truth (sample of first 3 ids):")
|
---|
95 | i = 1
|
---|
96 | for 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
|
---|