-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkgraph.py
154 lines (128 loc) · 4.46 KB
/
mkgraph.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/local/bin/python3
# See the bottom for instructions how to use
saveToFile = True
import sys
import matplotlib
if saveToFile:
matplotlib.use('Agg') # to generate png output, must be before importing matplotlib.pyplot
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import numpy as np
import math
import csv
import os
import sys
import pprint
import statistics
import scipy.stats as scistats
def loadCSV(csvfile):
# need to use a correct character encoding.... latin-1 does it
with open(csvfile, encoding='latin-1') as file:
content = csv.DictReader(file, delimiter=',')
rows = []
for row in content: rows.append(row)
return rows
#data_set1 = loadCSV("./data_set1.csv")
#data_set2 = loadCSV("./data.csv")
def mkTimeProgressionGraph(filename):
basename = filename.rsplit('.')[0]
dataset = data_set1 = loadCSV(filename)
plt.ylabel('intensity', fontsize=12)
plt.xlabel('time', fontsize=12)
plt.grid(b=True, axis='y')
plt.plot([ int(r['t']) for r in dataset ],
[ float(r['hope']) for r in dataset ],
label = 'hope' , )
plt.plot([ int(r['t']) for r in dataset ],
[ float(r['fear']) for r in dataset ],
label = 'fear' )
plt.plot([ int(r['t']) for r in dataset ],
[ float(r['joy']) for r in dataset ],
label = 'joy' )
plt.plot([ int(r['t']) for r in dataset ],
[ float(r['satisfaction']) for r in dataset ],
label = 'satisfaction' )
plt.rcParams.update({'font.size': 12})
#fig.suptitle("Emotion time progression")
plt.title("Emotion over time in a simulated gameplay", fontsize=14)
plt.legend()
if saveToFile : plt.savefig('emoOverTime_' + basename + '.png')
else : plt.show()
def mkHeatMap(filename,width,height):
basename = filename.rsplit('.')[0]
dataset = data_set1 = loadCSV(filename)
scale = 1
#width = 15
#height = 28
white = 30
map = np.zeros((scale*height,scale*width))
for x in range(0,scale*height):
for y in range(0,scale*width):
map[x][y] = white
for r in dataset:
xx = round(scale*float(r['x']))
yy = round(scale*float(r['y']))
# rotate +90 degree
x = scale*height - yy
y = xx
hope = float(r['hope'])
joy = float(r['joy'])
satisfaction = float(r['satisfaction'])
combined = 10*(hope + 1.1*joy + 1.5*satisfaction)
if map[(x,y)]==white:
map[(x,y)] = combined
else:
map[(x,y)] = max(map[(x,y)],combined)
ax = plt.gca()
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
plt.imshow(map, cmap='hot', origin='lower', interpolation='nearest')
plt.title("Positive emotion heat map")
#plt.legend()
if saveToFile : plt.savefig('emoHeatmap_1' + basename + '.png')
else : plt.show()
def mkColdMap(filename,width,height):
basename = filename.rsplit('.')[0]
dataset = data_set1 = loadCSV(filename)
scale = 1
white = 10
map = np.zeros((scale*height,scale*width))
for x in range(0,scale*height):
for y in range(0,scale*width):
map[x][y] = white
for r in dataset:
xx = round(scale*float(r['x']))
yy = round(scale*float(r['y']))
# rotate +90 degree
x = scale*height - yy
y = xx
fear = 12*float(r['fear'])
if map[(x,y)]== white:
map[(x,y)] = fear
else:
map[(x,y)] = max(map[(x,y)],fear)
ax = plt.gca()
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
plt.imshow(map, cmap='hot', origin='lower', interpolation='nearest')
plt.title("Negative emotion heat map")
#plt.legend()
if saveToFile : plt.savefig('emoColdmap_1' + basename + '.png')
else : plt.show()
# Available data-sets:
# data_xxx_setup1.csv : a playthrough over a small LR level with fire
# data_xxx_setup2.csv : a playthrough over the same LR level, with a bit more
# fire, and some difference in the placing of the fire
#
# To build the graph depicting how emotions develop over time: (uncomment)
#
mkTimeProgressionGraph('data_goalQuestCompleted.csv')
plt.clf()
mkHeatMap('data_goalQuestCompleted.csv',int(sys.argv[1]),int(sys.argv[2]))
plt.clf()
mkColdMap('data_goalQuestCompleted.csv',int(sys.argv[1]),int(sys.argv[2]))
#points graphics
plt.clf()
mkTimeProgressionGraph('data_goalGetMuchPoints.csv')
plt.clf()
print("graphs are saved in the project directory")