def __init__(self, parent):
        super(WattrAnimatedGraphDialog, self).__init__(parent)

        self.graph_panel = WattrGraphPanel(self)
        self.GetSizer().Prepend(self.graph_panel,
                                1,
                                wx.LEFT | wx.TOP | wx.GROW,
                                border=1)

        self.min_x = WattrControlBox(self, "X Min", 0)
        self.max_x = WattrControlBox(self, "X Max", 100)
        self.min_y = WattrControlBox(self, "Y Min", 0)
        self.max_y = WattrControlBox(self, "Y Max", 100)

        self.controls_sizer.Add(self.min_x)
        self.controls_sizer.Add(self.max_x)
        self.controls_sizer.Add(self.min_y)
        self.controls_sizer.Add(self.max_y)
        self.controls_sizer.Fit(self)
        self.Fit()

        self.data = []

        self.redraw_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.on_redraw_timer, self.redraw_timer)
        self.dismiss_alert.Bind(wx.EVT_BUTTON, self.hide_alert)
        self.pause_button.Bind(wx.EVT_BUTTON, self.on_pause_button)
        self.pause_button.Bind(wx.EVT_UPDATE_UI, self.on_update_pause_button)
        self.show_grid.Bind(wx.EVT_CHECKBOX, self.on_show_grid)
        self.paused = False
Beispiel #2
0
 def __init__(self, parent, listener=None):
     super(HistogramController, self).__init__(parent, listener)
     self.histogram_panel = WattrGraphPanel(self.get_view())
     self.plot = self.histogram_panel.add_plot()
     sizer = self.get_view().GetSizer()
     sizer.Add(self.histogram_panel,
               1,
               wx.LEFT | wx.TOP | wx.GROW,
               border=1)
     self.get_view().Fit()
Beispiel #3
0
class GraphController(object):

    def __init__(self, parent):
        super(GraphController, self).__init__()
        self.panel = WattrGraphPanel(parent)
        self.panel.import_csv.Bind(wx.EVT_BUTTON, self.on_import_csv)

    def get_view(self):
        return self.panel
    
    def graph(self, x=[1,2,3], y=[1,2,3]):
        self.panel.plot_data(x, y, linewidth=2.0)
        self.panel.Show()

    def on_import_csv(self, event):
        openFileDialog = wx.FileDialog(self.panel, "Open", "", "", 
                                       "CSV files (*.csv)|*.csv", 
                                       wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
        openFileDialog.ShowModal()
        path = openFileDialog.GetPath()
        openFileDialog.Destroy()

        with open(path, 'rb') as csv_input:
            graphdata = csv.DictReader(csv_input, fieldnames= ('time', 'frequency',))
            graphdata.next()
            x = []
            y = []
            for row in graphdata:
                x.append(float(row['time']))
                y.append(float(row['frequency']))
        self.panel.set_title("Frequency vs Time")
        self.panel.set_label_x("Time (s)")
        self.panel.set_label_y("Frequency (Hz)")
        self.graph(x, y)
Beispiel #4
0
 def __init__(self, parent, listener=None):
     super(HistogramController, self).__init__(parent, listener)
     self.histogram_panel = WattrGraphPanel(self.get_view())
     self.plot = self.histogram_panel.add_plot()
     sizer = self.get_view().GetSizer()
     sizer.Add(self.histogram_panel, 1, wx.LEFT|wx.TOP|wx.GROW, border=1)
     self.get_view().Fit()
Beispiel #5
0
class HistogramController(BaseController):

    view_class = WattrHistogramDialog

    def __init__(self, parent, listener=None):
        super(HistogramController, self).__init__(parent, listener)
        self.histogram_panel = WattrGraphPanel(self.get_view())
        self.plot = self.histogram_panel.add_plot()
        sizer = self.get_view().GetSizer()
        sizer.Add(self.histogram_panel,
                  1,
                  wx.LEFT | wx.TOP | wx.GROW,
                  border=1)
        self.get_view().Fit()

    def plot_hist(self, data, title, x, y):
        self.plot.hist(data)
        self.plot.set_title(title)
        self.plot.set_xlabel(x)
        self.plot.set_ylabel(y)
        self.histogram_panel.figure.tight_layout()
        self.get_view().Fit()

    def on_close(self, evt):
        self.get_view().EndModal(0)
    def __init__(self, parent):
        super(WattrAnimatedGraphDialog, self).__init__(parent)
        
        self.graph_panel = WattrGraphPanel(self)
        self.GetSizer().Prepend(self.graph_panel, 1, wx.LEFT | wx.TOP | wx.GROW, border = 1)

        self.min_x = WattrControlBox(self, "X Min", 0)
        self.max_x = WattrControlBox(self, "X Max", 100)
        self.min_y = WattrControlBox(self, "Y Min", 0)
        self.max_y = WattrControlBox(self, "Y Max", 100)

        self.controls_sizer.Add(self.min_x) 
        self.controls_sizer.Add(self.max_x) 
        self.controls_sizer.Add(self.min_y) 
        self.controls_sizer.Add(self.max_y) 
        self.controls_sizer.Fit(self)
        self.Fit()
        
        self.data = []

        self.redraw_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.on_redraw_timer, self.redraw_timer)
        self.dismiss_alert.Bind(wx.EVT_BUTTON, self.hide_alert)
        self.pause_button.Bind(wx.EVT_BUTTON, self.on_pause_button)
        self.pause_button.Bind(wx.EVT_UPDATE_UI, self.on_update_pause_button)
        self.show_grid.Bind(wx.EVT_CHECKBOX, self.on_show_grid)
        self.paused = False
Beispiel #7
0
class GraphController(object):
    def __init__(self, parent):
        super(GraphController, self).__init__()
        self.panel = WattrGraphPanel(parent)
        self.panel.import_csv.Bind(wx.EVT_BUTTON, self.on_import_csv)

    def get_view(self):
        return self.panel

    def graph(self, x=[1, 2, 3], y=[1, 2, 3]):
        self.panel.plot_data(x, y, linewidth=2.0)
        self.panel.Show()

    def on_import_csv(self, event):
        openFileDialog = wx.FileDialog(self.panel, "Open", "", "",
                                       "CSV files (*.csv)|*.csv",
                                       wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
        openFileDialog.ShowModal()
        path = openFileDialog.GetPath()
        openFileDialog.Destroy()

        with open(path, 'rb') as csv_input:
            graphdata = csv.DictReader(csv_input,
                                       fieldnames=(
                                           'time',
                                           'frequency',
                                       ))
            graphdata.next()
            x = []
            y = []
            for row in graphdata:
                x.append(float(row['time']))
                y.append(float(row['frequency']))
        self.panel.set_title("Frequency vs Time")
        self.panel.set_label_x("Time (s)")
        self.panel.set_label_y("Frequency (Hz)")
        self.graph(x, y)
Beispiel #8
0
class HistogramController(BaseController):

    view_class = WattrHistogramDialog

    def __init__(self, parent, listener=None):
        super(HistogramController, self).__init__(parent, listener)
        self.histogram_panel = WattrGraphPanel(self.get_view())
        self.plot = self.histogram_panel.add_plot()
        sizer = self.get_view().GetSizer()
        sizer.Add(self.histogram_panel, 1, wx.LEFT|wx.TOP|wx.GROW, border=1)
        self.get_view().Fit()

    def plot_hist(self, data, title, x, y):
        self.plot.hist(data)
        self.plot.set_title(title)
        self.plot.set_xlabel(x)
        self.plot.set_ylabel(y)
        self.histogram_panel.figure.tight_layout()
        self.get_view().Fit()

    def on_close(self, evt):
        self.get_view().EndModal(0)
Beispiel #9
0
 def __init__(self, parent):
     super(GraphController, self).__init__()
     self.panel = WattrGraphPanel(parent)
     self.panel.import_csv.Bind(wx.EVT_BUTTON, self.on_import_csv)
Beispiel #10
0
 def __init__(self, parent):
     super(GraphController, self).__init__()
     self.panel = WattrGraphPanel(parent)
     self.panel.import_csv.Bind(wx.EVT_BUTTON, self.on_import_csv)
class WattrAnimatedGraphDialog(WattrGUI.AnimatedGraphDialog):

    DEFAULT_X_MAX = 50
    DEFAULT_WIN_LENGTH = 50

    def __init__(self, parent):
        super(WattrAnimatedGraphDialog, self).__init__(parent)
        
        self.graph_panel = WattrGraphPanel(self)
        self.GetSizer().Prepend(self.graph_panel, 1, wx.LEFT | wx.TOP | wx.GROW, border = 1)

        self.min_x = WattrControlBox(self, "X Min", 0)
        self.max_x = WattrControlBox(self, "X Max", 100)
        self.min_y = WattrControlBox(self, "Y Min", 0)
        self.max_y = WattrControlBox(self, "Y Max", 100)

        self.controls_sizer.Add(self.min_x) 
        self.controls_sizer.Add(self.max_x) 
        self.controls_sizer.Add(self.min_y) 
        self.controls_sizer.Add(self.max_y) 
        self.controls_sizer.Fit(self)
        self.Fit()
        
        self.data = []

        self.redraw_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.on_redraw_timer, self.redraw_timer)
        self.dismiss_alert.Bind(wx.EVT_BUTTON, self.hide_alert)
        self.pause_button.Bind(wx.EVT_BUTTON, self.on_pause_button)
        self.pause_button.Bind(wx.EVT_UPDATE_UI, self.on_update_pause_button)
        self.show_grid.Bind(wx.EVT_CHECKBOX, self.on_show_grid)
        self.paused = False

    def show_alert(self, text):
        self.alert_text.SetLabel(text)
        self.alert_panel.Show()
        self.Layout()

    def hide_alert(self, evt=None):
        self.alert_panel.Hide()
        self.Layout()

    def on_show_grid(self, evt):
        self.draw_plot()

    def on_pause_button(self, evt):
        self.paused = not self.paused

    def on_update_pause_button(self, evt):
        text = "Resume" if self.paused else "Pause"
        self.pause_button.SetLabel(text)

    def init_plot(self, rtype, y, title):
        self.rtype = rtype
        self.axes = self.graph_panel.add_plot()
        self.axes.set_title(title)
        self.axes.set_ylabel(y)
        self.axes.set_axis_bgcolor('black')
        self.plot_data = self.axes.plot(self.data,
            linewidth=1,
            color=(1,1,0),
        )[0]
        return
        def format_date(x, pos=None):
            if x <= 0:
                return "0"
            return num2date(x).strftime("%H:%M:%S")
        self.axes.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))

    def draw_plot(self):
        cols = zip(*self.data[-2000:])
        if not cols:
            print "No Data"
            return
        x_data = cols[0]
        y_data = cols[1]

        if self.rtype == READING.VOLTAGE:
            if max(y_data) > 126:
                self.show_alert("Spike Detected!")
            if min(y_data) < 114:
                self.show_alert("Sag Detected!")

        if self.max_x.is_auto():
           xmax = x_data[-1] #if len(x_data) > self.DEFAULT_X_MAX else datetime.datetime.now()
        else:
            xmax = datetime.datetime.now() + datetime.timedelta(seconds=int(self.max_x.manual_value()))

        if self.min_x.is_auto():
            xmin = xmax - datetime.timedelta(seconds=50)
        else:
            xmin = datetime.datetime.now() + datetime.timedelta(seconds=int(self.min_x.manual_value()))

        if self.min_y.is_auto():
            ymin = round(min(y_data), 0) -1
        else:
            ymin = int(self.min_y.manual_value())

        if self.max_y.is_auto():
            ymax = round(max(y_data), 0) + 1
        else:
            ymax = int(self.max_y.manual_value())

        self.axes.set_xbound(lower=xmin, upper=xmax)
        self.axes.set_ybound(lower=ymin, upper=ymax)
        self.axes.relim()
        if self.show_grid.IsChecked():
            self.axes.grid(True, color='gray')
        else:
            self.axes.grid(False)
        self.plot_data.set_data(x_data, y_data)
        self.graph_panel.figure.autofmt_xdate()
        self.Layout()

    def on_redraw_timer(self, evt):
        if not self.paused:
            while True:
                value = self.data_source.next_reading(self.rtype)
                if value:
                    self.data.append(value)
                else:
                    break
        self.draw_plot()

    def start(self, data_source):
        self.data_source = data_source
        self.redraw_timer.Start(100)

    def stop(self):
        self.redraw_timer.Stop()
class WattrAnimatedGraphDialog(WattrGUI.AnimatedGraphDialog):

    DEFAULT_X_MAX = 50
    DEFAULT_WIN_LENGTH = 50

    def __init__(self, parent):
        super(WattrAnimatedGraphDialog, self).__init__(parent)

        self.graph_panel = WattrGraphPanel(self)
        self.GetSizer().Prepend(self.graph_panel,
                                1,
                                wx.LEFT | wx.TOP | wx.GROW,
                                border=1)

        self.min_x = WattrControlBox(self, "X Min", 0)
        self.max_x = WattrControlBox(self, "X Max", 100)
        self.min_y = WattrControlBox(self, "Y Min", 0)
        self.max_y = WattrControlBox(self, "Y Max", 100)

        self.controls_sizer.Add(self.min_x)
        self.controls_sizer.Add(self.max_x)
        self.controls_sizer.Add(self.min_y)
        self.controls_sizer.Add(self.max_y)
        self.controls_sizer.Fit(self)
        self.Fit()

        self.data = []

        self.redraw_timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.on_redraw_timer, self.redraw_timer)
        self.dismiss_alert.Bind(wx.EVT_BUTTON, self.hide_alert)
        self.pause_button.Bind(wx.EVT_BUTTON, self.on_pause_button)
        self.pause_button.Bind(wx.EVT_UPDATE_UI, self.on_update_pause_button)
        self.show_grid.Bind(wx.EVT_CHECKBOX, self.on_show_grid)
        self.paused = False

    def show_alert(self, text):
        self.alert_text.SetLabel(text)
        self.alert_panel.Show()
        self.Layout()

    def hide_alert(self, evt=None):
        self.alert_panel.Hide()
        self.Layout()

    def on_show_grid(self, evt):
        self.draw_plot()

    def on_pause_button(self, evt):
        self.paused = not self.paused

    def on_update_pause_button(self, evt):
        text = "Resume" if self.paused else "Pause"
        self.pause_button.SetLabel(text)

    def init_plot(self, rtype, y, title):
        self.rtype = rtype
        self.axes = self.graph_panel.add_plot()
        self.axes.set_title(title)
        self.axes.set_ylabel(y)
        self.axes.set_axis_bgcolor('black')
        self.plot_data = self.axes.plot(
            self.data,
            linewidth=1,
            color=(1, 1, 0),
        )[0]
        return

        def format_date(x, pos=None):
            if x <= 0:
                return "0"
            return num2date(x).strftime("%H:%M:%S")

        self.axes.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))

    def draw_plot(self):
        cols = zip(*self.data[-2000:])
        if not cols:
            print "No Data"
            return
        x_data = cols[0]
        y_data = cols[1]

        if self.rtype == READING.VOLTAGE:
            if max(y_data) > 126:
                self.show_alert("Spike Detected!")
            if min(y_data) < 114:
                self.show_alert("Sag Detected!")

        if self.max_x.is_auto():
            xmax = x_data[
                -1]  #if len(x_data) > self.DEFAULT_X_MAX else datetime.datetime.now()
        else:
            xmax = datetime.datetime.now() + datetime.timedelta(
                seconds=int(self.max_x.manual_value()))

        if self.min_x.is_auto():
            xmin = xmax - datetime.timedelta(seconds=50)
        else:
            xmin = datetime.datetime.now() + datetime.timedelta(
                seconds=int(self.min_x.manual_value()))

        if self.min_y.is_auto():
            ymin = round(min(y_data), 0) - 1
        else:
            ymin = int(self.min_y.manual_value())

        if self.max_y.is_auto():
            ymax = round(max(y_data), 0) + 1
        else:
            ymax = int(self.max_y.manual_value())

        self.axes.set_xbound(lower=xmin, upper=xmax)
        self.axes.set_ybound(lower=ymin, upper=ymax)
        self.axes.relim()
        if self.show_grid.IsChecked():
            self.axes.grid(True, color='gray')
        else:
            self.axes.grid(False)
        self.plot_data.set_data(x_data, y_data)
        self.graph_panel.figure.autofmt_xdate()
        self.Layout()

    def on_redraw_timer(self, evt):
        if not self.paused:
            while True:
                value = self.data_source.next_reading(self.rtype)
                if value:
                    self.data.append(value)
                else:
                    break
        self.draw_plot()

    def start(self, data_source):
        self.data_source = data_source
        self.redraw_timer.Start(100)

    def stop(self):
        self.redraw_timer.Stop()