Compare commits

..

3 commits

Author SHA1 Message Date
b490bd7f7a added logs to gitignore 2026-06-04 14:41:45 +02:00
246c2cf322 removed testing logs 2026-06-04 14:41:13 +02:00
5a6663c369 Implemented logging 2026-06-04 14:40:54 +02:00
4 changed files with 19 additions and 8 deletions

2
.gitignore vendored
View file

@ -240,4 +240,4 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear # and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/ .idea/
log*.txt

9
logger.py Normal file
View file

@ -0,0 +1,9 @@
import time
def logwriter(val, logpath, warn):
with open(logpath, "a") as logfile:
if not warn:
logfile.write("{}: Value was {}\n".format(time.time(), val))
else:
logfile.write("{}: WARNING! Value was {}, too high\n".format(time.time(), val))

View file

@ -1,6 +0,0 @@
import time
def log(val):
with open(log.txt) as logfile:
logfile.write("{}: Value was {}".format(time.time(), val))

View file

@ -2,10 +2,14 @@ import send_test_data
import json import json
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
from logger import logwriter
import time
data_store = [] data_store = []
data_buffer = [] data_buffer = []
times = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] times = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
logpath = "log{}.txt".format(time.time())
logs = True
try: try:
for data in send_test_data.data_test_forever(): for data in send_test_data.data_test_forever():
@ -15,11 +19,13 @@ try:
# draw graph # draw graph
fig, ax = plt.subplots() fig, ax = plt.subplots()
if currentdata["V"] > 150: if currentdata["V"] > 160:
ax.set_facecolor('red') ax.set_facecolor('red')
ax.plot(times[:len(data_buffer)], data_buffer, 'k') ax.plot(times[:len(data_buffer)], data_buffer, 'k')
warn = True
else: else:
ax.plot(times[:len(data_buffer)], data_buffer) ax.plot(times[:len(data_buffer)], data_buffer)
warn = False
ax.set_xlabel('Time [100 ms]') ax.set_xlabel('Time [100 ms]')
ax.set_ylabel('Value randomness') ax.set_ylabel('Value randomness')
ax.set_title('Value randomness over time') ax.set_title('Value randomness over time')
@ -27,5 +33,7 @@ try:
plt.yticks(np.arange(0, 257, 32)) plt.yticks(np.arange(0, 257, 32))
plt.show() plt.show()
plt.close() plt.close()
if logs:
logwriter(currentdata["V"], logpath, warn)
except KeyboardInterrupt: except KeyboardInterrupt:
exit(0) exit(0)