In [11]:
import platform
import datetime as datetime
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from utils import query, mask_print_session, load_cached_json
if not platform.python_version().startswith('3'):
raise Exception('Please execute with Python 3.x')
%pylab inline
Data is queried from OpenTSDB, which is hosed on http://il075:9999 (only reachable within the SRFG network).
Documentation about the REST query can be found on http://opentsdb.net/docs/build/html/api_http/query/index.html.
SensorID | Unit | Description |
---|---|---|
fila.distance | mm | mength of filament |
file.skidrate | 1/m | skids per meter |
fila.skidcount | 1 | absolute number of skids |
temp | C° | temperature of sorounding |
temp.bed.current | C° | temperature of bottom plateau |
temp.nozzle.currentC° | C° | temperature of nozzle |
airquality | VOC | quality of air http://www.velux.de/produkte/lueftungsloesungen-belueftung/raumluftfuehler |
head.pos.z | mm | z-coordinate of printerhead |
extrusion | mm3 | volume of used filament |
In [12]:
# df = query(host='http://il075:9999/api/query',
# start=datetime.date(year=2016, month=12, day=23),
# end=datetime.date(year=2016, month=12, day=24),
# metric=['avg:fila.distance',
# 'avg:fila.skidrate',
# 'avg:fila.skidcount',
# 'avg:temp',
# 'avg:temp.bed.current',
# 'avg:temp.nozzle.current',
# 'avg:airquality',
# 'avg:head.pos.z',
# 'avg:extrusion'])
df = load_cached_json()
df.head()
Out[12]:
In [13]:
ax = df.plot(figsize=(12, 8))
ax.set_xlabel("23 December 2016")
ax.set_ylabel("*")
plt.show()
In [14]:
from pandas.tools.plotting import scatter_matrix
ax = scatter_matrix(df, alpha=0.2, figsize=(24, 24), diagonal='kde')
plt.savefig('./scatter_plot.png')
plt.show()
In [15]:
# create session mask and ids
fila_distance = df['fila.distance']
fila_run_id = mask_print_session(fila_distance)
# plot print sessions ids
diff_data = fila_distance.to_frame()
diff_data['fila.run.id'] = fila_run_id * 100 # make it visible in plot
ax = diff_data.plot(figsize=(12, 8), ylim=[-10, 1200], style=['o','rx'], markersize=1,
# xlim=[datetime.datetime(year=2016, month=12, day=23, hour=9, minute=55),
# datetime.datetime(year=2016, month=12, day=23, hour=10, minute=55)]
)
ax.set_xlabel("23 December 2016")
ax.set_ylabel("Distance in mm")
plt.title('Masked Printing Session')
plt.show()
# add to main dataframe
df['fila.run.id'] = fila_run_id
In [16]:
temp_mean = np.nan * np.ones(shape=len(fila_distance))
num_prints = int(df['fila.run.id'].max())
for session_id in range(1, num_prints+1):
temp = df['temp.nozzle.current']
ixs = np.array(df['fila.run.id'] == session_id, dtype=bool)
temp_mean[ixs] = temp[ixs].mean()
print('Mean temp for print {} is {:.2f} C°'.format(session_id, temp[ixs].mean()))
temp_mean = pd.Series(index=fila_distance.index, data=temp_mean)
df['temp.nozzle.current'].plot(style='x', figsize=(12, 8))
ax = temp_mean.plot(style='r', figsize=(12, 8))
ax.set_xlabel("23 December 2016")
ax.set_ylabel("Temperature in C°")
plt.title('Mean Temperature for each Print')
plt.show()
# add to main dataframe
df['temp.nozzle.mean'] = temp_mean
In [17]:
# store as csv
df.to_csv('printer_data_23_12_2016.csv', date_format='%s')