oscplayer in python with more features

This commit is contained in:
Philipp Kramer 2022-05-05 17:00:31 +02:00
parent 669aeca055
commit 1a0f664806
3 changed files with 404 additions and 3 deletions

View file

@ -6,9 +6,9 @@ time,heartrate,random
1.0,83.910385,0.23544657
1.25,83.910385,0.9030523
1.5,83.910385,0.24920326
1.75,83.910385,0.8914295
2.0,83.910385,0.09346372
2.25,83.910385,0.8276468
1.75,,0.8914295
2.0,,0.09346372
2.25,,0.8276468
2.5,88.35135,0.99510956
2.75,88.35135,0.51485765
3.0,88.35135,0.6635224

1 time heartrate random
6 1.0 83.910385 0.23544657
7 1.25 83.910385 0.9030523
8 1.5 83.910385 0.24920326
9 1.75 83.910385 0.8914295
10 2.0 83.910385 0.09346372
11 2.25 83.910385 0.8276468
12 2.5 88.35135 0.99510956
13 2.75 88.35135 0.51485765
14 3.0 88.35135 0.6635224

View file

@ -0,0 +1,276 @@
time,value
0,78
1,78
2,78
3,78
4,78
5,50
6,74
7,73
8,52
9,51
10,51
11,79
12,51
13,51
14,79
15,51
16,51
17,72
18,79
19,66
20,81
21,66
22,73
23,66
24,82
25,73
26,66
27,82
28,66
29,80
30,66
31,66
32,66
33,52
34,80
35,52
36,80
37,52
38,70
39,62
40,62
41,62
42,69
43,68
44,66
45,76
46,76
47,76
48,66
49,66
50,62
51,75
52,62
53,62
54,68
55,73
56,73
57,73
58,68
59,73
60,73
61,63
62,72
63,63
64,63
65,68
66,68
67,63
68,69
69,69
70,72
71,72
72,68
73,63
74,74
75,63
76,74
77,69
78,70
79,70
80,61
81,74
82,61
83,61
84,74
85,68
86,74
87,68
88,72
89,61
90,74
91,61
92,61
93,75
94,61
95,61
96,61
97,73
98,75
99,64
100,75
101,64
102,74
103,64
104,64
105,68
106,74
107,74
108,64
109,66
110,64
111,65
112,64
113,65
114,65
115,65
116,64
117,67
118,64
119,68
120,68
121,68
122,68
123,64
124,69
125,78
126,78
127,64
128,70
129,64
130,64
131,69
132,77
133,77
134,69
135,70
136,70
137,66
138,70
139,66
140,70
141,69
142,74
143,66
144,66
145,68
146,66
147,75
148,74
149,66
150,66
151,68
152,67
153,67
154,75
155,68
156,75
157,81
158,63
159,63
160,82
161,70
162,80
163,79
164,70
165,70
166,63
167,78
168,63
169,63
170,74
171,72
172,72
173,53
174,71
175,74
176,53
177,74
178,74
179,61
180,75
181,75
182,75
183,72
184,72
185,75
186,72
187,68
188,61
189,61
190,61
191,71
192,71
193,61
194,76
195,76
196,61
197,66
198,70
199,70
200,76
201,70
202,61
203,70
204,64
205,71
206,71
207,61
208,72
209,73
210,73
211,75
212,69
213,61
214,75
215,74
216,61
217,61
218,61
219,61
220,74
221,61
222,74
223,74
224,61
225,73
226,61
227,61
228,61
229,61
230,73
231,72
232,61
233,61
234,61
235,61
236,67
237,67
238,62
239,62
240,66
241,62
242,70
243,66
244,70
245,62
246,71
247,71
248,62
249,70
250,70
251,68
252,62
253,62
254,62
255,62
256,57
257,57
258,72
259,72
260,72
261,62
262,70
263,70
264,69
265,64
266,62
267,68
268,62
269,67
270,62
271,65
272,74
273,62
274,74
1 time value
2 0 78
3 1 78
4 2 78
5 3 78
6 4 78
7 5 50
8 6 74
9 7 73
10 8 52
11 9 51
12 10 51
13 11 79
14 12 51
15 13 51
16 14 79
17 15 51
18 16 51
19 17 72
20 18 79
21 19 66
22 20 81
23 21 66
24 22 73
25 23 66
26 24 82
27 25 73
28 26 66
29 27 82
30 28 66
31 29 80
32 30 66
33 31 66
34 32 66
35 33 52
36 34 80
37 35 52
38 36 80
39 37 52
40 38 70
41 39 62
42 40 62
43 41 62
44 42 69
45 43 68
46 44 66
47 45 76
48 46 76
49 47 76
50 48 66
51 49 66
52 50 62
53 51 75
54 52 62
55 53 62
56 54 68
57 55 73
58 56 73
59 57 73
60 58 68
61 59 73
62 60 73
63 61 63
64 62 72
65 63 63
66 64 63
67 65 68
68 66 68
69 67 63
70 68 69
71 69 69
72 70 72
73 71 72
74 72 68
75 73 63
76 74 74
77 75 63
78 76 74
79 77 69
80 78 70
81 79 70
82 80 61
83 81 74
84 82 61
85 83 61
86 84 74
87 85 68
88 86 74
89 87 68
90 88 72
91 89 61
92 90 74
93 91 61
94 92 61
95 93 75
96 94 61
97 95 61
98 96 61
99 97 73
100 98 75
101 99 64
102 100 75
103 101 64
104 102 74
105 103 64
106 104 64
107 105 68
108 106 74
109 107 74
110 108 64
111 109 66
112 110 64
113 111 65
114 112 64
115 113 65
116 114 65
117 115 65
118 116 64
119 117 67
120 118 64
121 119 68
122 120 68
123 121 68
124 122 68
125 123 64
126 124 69
127 125 78
128 126 78
129 127 64
130 128 70
131 129 64
132 130 64
133 131 69
134 132 77
135 133 77
136 134 69
137 135 70
138 136 70
139 137 66
140 138 70
141 139 66
142 140 70
143 141 69
144 142 74
145 143 66
146 144 66
147 145 68
148 146 66
149 147 75
150 148 74
151 149 66
152 150 66
153 151 68
154 152 67
155 153 67
156 154 75
157 155 68
158 156 75
159 157 81
160 158 63
161 159 63
162 160 82
163 161 70
164 162 80
165 163 79
166 164 70
167 165 70
168 166 63
169 167 78
170 168 63
171 169 63
172 170 74
173 171 72
174 172 72
175 173 53
176 174 71
177 175 74
178 176 53
179 177 74
180 178 74
181 179 61
182 180 75
183 181 75
184 182 75
185 183 72
186 184 72
187 185 75
188 186 72
189 187 68
190 188 61
191 189 61
192 190 61
193 191 71
194 192 71
195 193 61
196 194 76
197 195 76
198 196 61
199 197 66
200 198 70
201 199 70
202 200 76
203 201 70
204 202 61
205 203 70
206 204 64
207 205 71
208 206 71
209 207 61
210 208 72
211 209 73
212 210 73
213 211 75
214 212 69
215 213 61
216 214 75
217 215 74
218 216 61
219 217 61
220 218 61
221 219 61
222 220 74
223 221 61
224 222 74
225 223 74
226 224 61
227 225 73
228 226 61
229 227 61
230 228 61
231 229 61
232 230 73
233 231 72
234 232 61
235 233 61
236 234 61
237 235 61
238 236 67
239 237 67
240 238 62
241 239 62
242 240 66
243 241 62
244 242 70
245 243 66
246 244 70
247 245 62
248 246 71
249 247 71
250 248 62
251 249 70
252 250 70
253 251 68
254 252 62
255 253 62
256 254 62
257 255 62
258 256 57
259 257 57
260 258 72
261 259 72
262 260 72
263 261 62
264 262 70
265 263 70
266 264 69
267 265 64
268 266 62
269 267 68
270 268 62
271 269 67
272 270 62
273 271 65
274 272 74
275 273 62
276 274 74

125
oscplayer/oscplayer.py Normal file
View file

@ -0,0 +1,125 @@
import argparse
import random
import time
from pythonosc import udp_client
import csv
import numpy as np
header=None
rows=None
rowid=0
time_start=0
client=None
lastvalue=[]
minvalues=[]
maxvalues=[]
meanvalues=[]
basetopics=["/3/oscplayer","/oscplayer","/oscplayer"]
def init():
parser = argparse.ArgumentParser()
parser.add_argument("--ip", default="127.0.0.1", help="The ip of the OSC server")
parser.add_argument("--port", type=int, default=7000, help="The port the OSC server is listening on")
args = parser.parse_args()
global client
client = udp_client.SimpleUDPClient(args.ip, args.port)
csvlist=None
with open('heart_cluster_max.csv', newline='') as csvfile:
csvreader = csv.reader(csvfile, delimiter=',', quotechar='|')
csvlist = list(csvreader)
'''for row in csvreader:
if header is None:
header=row
else:
rows.vstack(row)
'''
global header
header=csvlist[0]
global rows
rows=csvlist[1:]
global rowid
rowid=0 #waiting for this row to send
global lastvalue
lastvalue=np.zeros(len(rows)-1)
global minvalues
global maxvalues
global meanvalues
minvalues=[float(min(x)) for x in filterEmpty(rows)]
maxvalues=[float(max(x)) for x in filterEmpty(rows)]
#print(np.mean(np.array((filterEmpty(rows))),axis=1)) #TODO: mittelwert ausrechnen funktioniert noch nicht
#exit()
#meanvalues=[float(np.mean(x)) for x in filterEmpty(rows)]
global time_start
time_start = time.time()
def update(ctime):
global minvalues
global maxvalues
global meanvalues
global rowid
global client
global lastvalue
if rowid>=len(rows): #ended?
return False
if ctime-time_start>=float(rows[rowid][0]):
#print(rows[rowid])
crow=rows[rowid]
for i in range(len(header)-1):
if len(crow[i+1])>0: #value not empty
value=float(crow[i+1])
send=False
if (i==0):
value=int(mapRange(value,minvalues[i],maxvalues[i],1,40))
send=True
if (i==1):
send=True
if (i==2):
send=True
if (i==3):
send=True
if (i==4):
send=True
if send:
print(basetopics[i]+"/"+header[i+1]+": "+ str(value))
client.send_message(basetopics[i]+"/"+header[i+1], value)
lastvalue[i]=value #save last value
rowid+=1
return True
def filterEmpty(rows):
m=[np.array(rows)[:,i+1] for i in range(np.shape(np.array(rows))[1]-1)]
n=[[x if len(x)>0 else None for x in y] for y in m]
n=[list(filter(None, x)) for x in n]
return n
def mapRange(value, inMin, inMax, outMin, outMax):
return outMin + (((value - inMin) / (inMax - inMin)) * (outMax - outMin))
if __name__ == "__main__":
init()
res=True
while res:
res=update(time.time())