forked from tvachnad/Neural-Network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loggingServer.py
100 lines (78 loc) · 2.34 KB
/
loggingServer.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
import json
import os, datetime
from flask import Flask, jsonify, render_template, request
app = Flask(__name__)
class logserver:
firefile = ""
potfile = ""
confile = ""
conwfile = ""
def logFiring(self, log):
self.writeLog(self.firefile, log)
return "success"
def logPot(self, log):
self.writeLog(self.potfile, log)
return "success"
def logConnection(self, log):
self.writeLog(self.confile, log)
return "success"
def logConW(self, log):
self.writeLog(self.conwfile, log)
return "success"
def writeLog(self, filename, data):
logfile = open(filename, 'a')
for entry in data:
logfile.write(entry)
del data[:]
logfile.close()
def createNewLogFiles(self):
logpath = os.path.dirname(os.getcwd())
logpath = os.path.normpath(os.path.join(logpath, 'BrainPowerLogs'))
conpath = os.path.normpath(os.path.join(logpath, 'Connections'))
conwpath = os.path.normpath(os.path.join(logpath, 'ConWeights'))
firepath = os.path.normpath(os.path.join(logpath, 'Firing'))
potpath = os.path.normpath(os.path.join(logpath, 'Potential'))
timestampstr = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
self.firefile = os.path.join(firepath, timestampstr)
self.potfile = os.path.join(potpath, timestampstr)
self.confile = os.path.join(conpath, timestampstr)
self.conwfile = os.path.join(conwpath, timestampstr)
lfile = open(self.firefile, 'w')
lfile.close()
lfile = open(self.potfile, 'w')
lfile.close()
lfile = open(self.confile, 'w')
lfile.close()
lfile = open(self.conwfile, 'w')
lfile.close()
def main(self):
app.run(port=8080, debug=True)
logserv = logserver()
@app.route("/")
def index():
return render_template('index.html')
@app.route('/firing', methods=['POST'])
def logFiring():
log = request.get_json()
logserv.logFiring(log)
return "success"
@app.route('/potential', methods=['POST'])
def logPotential():
log = request.get_json()
logserv.logPot(log)
return "success"
@app.route('/connection', methods=['POST'])
def logConnections():
log = request.get_json()
logserv.logConnection(log)
return "success"
@app.route('/conweights', methods=['POST'])
def logWeights():
log = request.get_json()
logserv.logConW(log)
return "success"
@app.route('/createLogs', methods=['POST'])
def createLogFiles():
logserv.createNewLogFiles()
if __name__ == '__main__':
logserv.main()