EPOCH = datetime(2016, 1, 1, 0, 0) # starting point of date
TS_MULT_us = 1e3
def int2dt(ts, ts_mult=TS_MULT_us):
"""Convert seconds value into datatime struct which can be used for x-axis labeeling"""
return(datetime.utcfromtimestamp(float(ts)/ts_mult))
class CAxisTime(pg.AxisItem):
"""Over riding the tickString method by extending the class"""
# @param[in] values List of time.
# @param[in] scale Not used.
# @param[in] spacing Not used.
def tickStrings(self, values, scale, spacing):
"""Generate the string labeeling of X-axis from the seconds value of Y-axis"""
# sending a list of values in format "HH:MM:SS.SS" generated from Total seconds.
return [(int2dt(value).strftime("%H:%M:%S.%f"))[:-4] for value in values]
class GraphWindow(QMainWindow):
def __init__(self,data,time,data_points, parent= None):
''' initialization of variables'''
QMainWindow.__init__(self,parent)
self.layer = ''
self.layer_info = ''
self.enabled = False
self.gw_comm = GraphWindowCommunication()
self.connection = False
self.layer_set = []
self.layer_set_vector = []
self.data = data
self.time = time
self.dd = True
self.data_points = data_points
self.buffer = deque(maxlen=10)
for x in range (1,10):
self.buffer.appendleft(x)
self.setupGui()
def setupGui(self):
"""Creating GUI plot window"""
frame = QFrame(self)
self.setCentralWidget(frame)
self.grid_layout = QGridLayout(frame)
self.value_display = QLineEdit()
self.stackedWidget = QStackedWidget()
pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')
self.axis = CAxisTime(orientation='bottom')
self.pqg_plot_widget = pg.PlotWidget(title="Altitude (datapoints = "+str(self.data_points)+" )",axisItems={'bottom': self.axis},left="Y-axis (meters)",bottom= "Time ")
self.pqg_plot_item = self.pqg_plot_widget.getPlotItem()
self.pqg_plot_viewbox = self.pqg_plot_widget.getViewBox()
self.pqg_plot_viewbox.setMouseMode(pg.ViewBox.PanMode)
self.pqg_plot_item.showGrid(x = True, y = True, alpha = 0.3)
self.pqg_plot_item.showAxis('bottom',True)
self.pqg_plot_item_data = self.pqg_plot_item.plot(pen=(211,211,211),symbolPen='w',symbolSize=5,symbolBrush=(0,0,255))
self.stackedWidget.addWidget(self.pqg_plot_widget)
self.grid_layout.addWidget(self.value_display)
self.grid_layout.addWidget(self.stackedWidget)
self.value_display.setMinimumWidth(250)
self.pqg_plot_item_data.setData(self.data)
self.setWindowTitle('Altitude')
self.timer = QTimer()
self.timer.timeout.connect(self.update)
self.timer.start(1000)
def update(self):
"""Update every Minute """
self.pqg_plot_item_data.setData(y=list(self.data),x=list(self.time))
self.value_display.setText("Current Altitude = "+str(self.data[-1]))