forked from StianF/ecomarathon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sim.py
executable file
·65 lines (53 loc) · 1.2 KB
/
sim.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
#!/usr/bin/python
import socket
import sys
import random
import time
S_PORT = 45988 #Port used to connect to the relayserver
#S_ADDR = "81.167.78.33" #Server address
S_ADDR = "127.0.0.1" #Server address
s = None
for res in socket.getaddrinfo(S_ADDR, S_PORT, socket.AF_UNSPEC, socket.SOCK_STREAM, 0):
af, socktype, proto, canonname, sa = res
try:
s = socket.socket(af, socktype, proto)
except socket.error as msg:
s = None
continue
try:
s.connect(sa)
except socket.error as msg:
s.close()
s = None
continue
break
if s == None:
sys.exit(1)
gd = []
fd = open("out.txt")
for line in fd:
gd.append(line)
while(1):
for G in gd:
time.sleep(1)
data = ""
data += "V,"
for i in range(46):
data += "%.2f" % ((random.random()%20)*0.08) + ","
data += "S," + "%.2f" % ((random.random()%20)*0.45) + ","
data += "T,"
for i in range(12):
data += "%.2f" % ((200+random.random()%300)*0.1) + ","
data += "P,"
for i in range(3):
r = random.random() % 100
if r == 0:
data += "err,"
else:
data += "%.2f" % (r) + ","
data += "O,"
for i in range(5):
data += "%.2f" % ((random.random()%24)) + ","
data += "G," + G + "\n"
print(data)
s.send(bytes(data,'UTF-8'))