-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
120 lines (87 loc) · 3.15 KB
/
data.py
File metadata and controls
120 lines (87 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 26 18:45:09 2020
@author: rebeccaadaimi
"""
import numpy as np
from utils import *
class Data:
def __init__(self):
self.participants = []
def num_people(self):
return len(self.participants)
def add_participant(self, participant):
self.participants.append(participant)
def data(self, excluded_participants=None):
if excluded_participants is None:
excluded_participants = []
audio, labels = [],[]
for participant in [participant for participant in self.participants if
participant not in excluded_participants]:
p_audio, p_labels = participant.data()
audio.append(p_audio)
labels.append(p_labels)
return audio, labels
def dataset(self, excluded_participants=None):
audio, labels = self.data(excluded_participants)
return Dataset(audio, labels)
class Participant:
def __init__(self, name):
self.name = name
self.activities = []
self.session1 = []
self.session2 = []
def add_activity(self, activity):
self.activities.append(activity)
def data(self):
audio, labels = [], []
for i in range(len(self.activities)):
a_audio, a_labels = self.activities[i].data()
audio.extend(a_audio)
labels.extend(a_labels)
return audio, labels
def session_data(self):
self.session1 = Session()
self.session2 = Session()
for i in range(len(self.activities)):
a_audio, a_labels = self.activities[i].data()
if len(a_labels) < 1:
continue
self.session1.add_activity(a_audio[:-1], a_labels[:-1])
if len(a_labels) > 1:
self.session2.add_activity(a_audio[-1:], a_labels[-1:])
return self.session1, self.session2
class Session:
def __init__(self):
self.activities = []
def add_activity(self, audio, label):
if len(label) > 1:
for i in range(len(audio)):
self.activities.append(Interaction(audio[i], label[i]))
elif len(label) == 1:
self.activities.append(Interaction(audio[0], label[0]))
def data(self):
audio, labels = [], []
for i in range(len(self.activities)):
i_audio, i_labels = self.activities[i].audio, self.activities[i].label
audio.append(i_audio)
labels.append(i_labels)
return audio, labels
class Activity:
def __init__(self, activity):
self.activity = activity
self.interactions = []
def add_interaction(self, audio, label):
self.interactions.append(Interaction(audio, label))
def data(self):
audio, labels = [], []
for i in range(len(self.interactions)):
i_audio, i_labels = self.interactions[i].audio, self.interactions[i].label
audio.append(i_audio)
labels.append(i_labels)
return audio, labels
class Interaction:
def __init__(self, audio, label):
self.audio = audio
self.label = label