-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_script.py
101 lines (71 loc) · 2.6 KB
/
main_script.py
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
import json
from datetime import datetime
from time import sleep
from drives import Drive
from affective_appraisal import Appraisal, Behaviour
def read_data(datafile):
with open(datafile, "r") as file:
vectors = json.load(file)
timestamps = sorted([dt for dt in vectors.keys()])
return vectors, timestamps
def create_objects():
social = Drive()
stimuli = Drive()
fatigue = Drive()
behaviours = Behaviour()
appraisal = Appraisal()
return social, stimuli, fatigue, behaviours, appraisal
def update_regimes(social, stimuli, fatigue, activations = None):
if activations is not None:
social.update_activation(activations["Social"])
social.set_current_regime()
stimuli.update_activation(activations["Stimuli"])
stimuli.set_current_regime()
fatigue.update_activation(activations["Fatigue"])
fatigue.set_current_regime()
regimes = {
"Social": social.regime,
"Stimuli": stimuli.regime,
"Fatigue": fatigue.regime
}
return regimes
def get_average_emotions(person):
emotions = {}
if "text" in person.keys():
for key, value in person["face"]["emotions"].items():
emotions[key] = (person["text"]["emotions"][key] + value)/2
else:
emotions = person["face"]["emotions"]
return emotions
def print_info(social, stimuli, fatigue, behaviours, appraisal, full = True):
if not full:
print("Emotion: {0}\nBehaviour: {1}".format(appraisal.emotion, behaviours.behaviour))
print("==============")
else:
#print("Social drive:\n", social)
#print("Stimuli drive:\n", stimuli)
#print("Fatigue drive:\n", fatigue)
print("Appraisal:\n", appraisal)
#print("Behaviour:\n", behaviours)
# print("==============")
# print("Emotion: {0}\nBehaviour: {1}".format(appraisal.emotion, behaviours.behaviour))
print("==============")
def main():
vectors, timestamps = read_data("scenario_neutral_happy.json") #scenario_happy_sad
social, stimuli, fatigue, behaviours, appraisal = create_objects()
regimes = update_regimes(social, stimuli, fatigue)
for t in timestamps:
activations, attention = behaviours.generate_behaviour(regimes)
if attention == "person":
emotions = get_average_emotions(vectors[t][attention])
appraisal.update(emotions)
appraisal.generate_emotion()
elif attention == "object":
print("Object interaction not ready yet.")
else: #attention == None
print("Robin needs rest.")
sleep(3)
regimes = update_regimes(social, stimuli, fatigue, activations)
print_info(social, stimuli, fatigue, behaviours, appraisal, full = False)
if __name__ == '__main__':
main()