Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
slafi committed Oct 24, 2019
1 parent 5efd1a1 commit dca4d3c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
trecorder.start()

# Start viewer if required
if(appConfig.no_viewer):
if(not appConfig.no_viewer):
viewer = viewer.Viewer(appConfig, window_title='Sensors data')
viewer.start()
else:
Expand All @@ -74,7 +74,7 @@
trecorder.join()

# stop viewer if already started
if(appConfig.no_viewer):
if(not appConfig.no_viewer):
viewer.stop()
viewer.join()

Expand Down
2 changes: 0 additions & 2 deletions common/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ def __init__(self, q, appconfig):
:param q: the telemetry data queue
:param appconfig: the application configuration object
:param interval: the time interval at which telemetry data is stored
:param batch_size: the maximum number of telemetry records stored at once
"""

Thread.__init__(self)
Expand Down
2 changes: 1 addition & 1 deletion core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AppConfig():
connection string)
:param topic: MQTT topic
:param database_filename: the SQlite database filename
:param table_name: the data table name
:param table_name: the data table name where the telemetry data is stored
:param time_window: the time interval for telemetry display
:param recorder_batch_size: the maximum number of telemetry records
saved at once (used by the Recorder)
Expand Down
3 changes: 1 addition & 2 deletions core/config_template.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"secret" : "",
"mac_address" : "",
"topic" : "",
"database" : "voltazero_database.db",
"db_mode" : "create",
"database" : "voltazero_database.db",
"table_name" : "data",
"recorder_batch_size" : 100,
"recorder_interval": 15,
Expand Down
37 changes: 23 additions & 14 deletions core/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
# Initialize logger for the module
logger = logging.getLogger('voltazero_monitor')

# Use WXAgg backend for matplot because Tkinter is not thread-safe
# Uncomment if you want to use WXAgg backend for matplotlib
# because Tkinter is inherently not thread-safe
# import matplotlib
# matplotlib.use('WXAgg')

# Specify the plotting style
Expand All @@ -33,18 +35,18 @@ def plt_maximize():
See: https://stackoverflow.com/a/54708671
"""

backend = plt.get_backend()
backend = plt.get_backend().lower()
cfm = plt.get_current_fig_manager()

if backend == "wxAgg":
if backend == "wxagg":
cfm.frame.Maximize(True)
elif backend == "TkAgg":
elif backend == "tkagg":
pos = str(system()).lower()
if pos == "win32" or pos == 'windows':
cfm.window.state('zoomed') # This works on windows only
else:
cfm.resize(*cfm.window.maxsize())
elif backend == 'QT4Agg':
elif backend == 'qt4agg':
cfm.window.showMaximized()
elif callable(getattr(cfm, "full_screen_toggle", None)):
if not getattr(cfm, "flag_is_max", None):
Expand Down Expand Up @@ -165,7 +167,7 @@ def run(self):
self.enabled = False

except Exception as e:
logger.error(f"An exception has occured [{str(e)}]")
logger.error(f"Exception: {str(e)}")


def draw(self):
Expand All @@ -185,20 +187,28 @@ def draw(self):
marker="o")
self.axs[i].set_xlim(min_x_lim, max_x_lim)

plt.savefig(f'img/new/image_{datetime.datetime.timestamp(datetime.datetime.now())}.png')
plt.show(block=False)
plt.pause(0.0001)
# Uncomment if plot update's screenshot is required
# plt.savefig(f'img/new/image_{datetime.datetime.timestamp(datetime.datetime.now())}.png')

# Show plot without blocking the running process
plt.show(block=False)
plt.pause(0.0001)
else:
logger.info('No data to plot!')

"""for i in range(6):
if len(self.axs[i].lines) > 0:
self.axs[i].lines.remove(self.axs[i].lines[0])
self.axs[i].plot([], [], color='royalblue', marker="o")"""


def init_viewer(self):

"""Initializes the plot window and figure"""

# Turn on matplotlib interactive mode
plt.ion()
# Turn on matplotlib interactive mode if necessary
# plt.ion()

# Creates just a figure and only one subplot
self.fig, self.axs = plt.subplots(6, sharex=True)
Expand Down Expand Up @@ -261,13 +271,12 @@ def fetch_and_format_data(self):
th.append(item.th if not (item.th is None) else np.nan)
ir.append(item.ir if not (item.ir is None) else np.nan)
ls.append(item.ls if not (item.ls is None) else np.nan)
bz.append(item.bz if not (item.bz is None) else np.nan)
#print(f"{item}")
bz.append(item.bz if not (item.bz is None) else np.nan)

self.columns = [timestamps, t0, t1, th, ir, ls, bz]

return len(data)

except Exception as e:
logger.error(f"An exception has occured [{str(e)}]")
logger.error(f"Exception: {str(e)}")
return -1

0 comments on commit dca4d3c

Please sign in to comment.