Пример #1
0
    def __init__(self, **kwargs):
        super(Plot, self).__init__(**kwargs)
        self.graph = Graph(xlabel="x",
                           ylabel="y",
                           x_ticks_minor=5,
                           x_ticks_major=25,
                           y_ticks_major=1,
                           y_grid_label=True,
                           x_grid_label=True,
                           x_grid=True,
                           y_grid=True,
                           xmin=-0,
                           xmax=100,
                           ymin=-1,
                           ymax=1,
                           draw_border=False)
        # graph.size = (1200, 400)
        # self.graph.pos = self.center

        self.plot = MeshLinePlot(color=[1, 1, 1, 1])
        self.plot.points = [(x, sin(x / 10.)) for x in range(0, 101)]
        self.plot2 = MeshLinePlot(color=[1, 0, 0, 1])
        self.plot2.points = [(x, cos(x / 10.)) for x in range(0, 101)]
        self.add_widget(self.graph)

        self.graph.add_plot(self.plot)
        self.graph.add_plot(self.plot2)
Пример #2
0
    def init(self, octoprint):
        self.octoprint = octoprint
        # use kivy garden's graph widget
        graph = Graph(
            xlabel='',
            ylabel='°C',
            x_ticks_minor=5,
            x_ticks_major=25,
            y_ticks_minor=0,
            y_ticks_major=50,
            y_grid_label=True,
            x_grid_label=False,
            padding=5,
            y_grid=True,
            xmax=len(self.hotend_temps),
            ymax=230,
            _with_stencilbuffer=False,  # or it does not work in ScreenManager
            label_options={'color': rgb('000000')})
        self.hotend_plot = MeshLinePlot(color=[1, 0, 0, 1])
        self.bed_plot = MeshLinePlot(color=[0, 0, 1, 1])
        graph.add_plot(self.hotend_plot)
        graph.add_plot(self.bed_plot)

        self.ids.plot.add_widget(graph)
        self.graph = graph
        self.update_plot()

        self.status = "Ready."
Пример #3
0
    def graph_create(self):
        global graph1
        graph1 = Graph(
            label_options={'color': rgb('001933'), 'bold': True},
            background_color=rgb('f8f8f2'),
            tick_color=rgb('001933'),
            border_color=rgb('808080'),
            xlabel='X',
            ylabel='Y',
            y_grid_label=True,
            x_grid_label=True,
            padding=5,
            x_ticks_major=5,
            y_ticks_major=0.2,
            x_grid=True,
            y_grid=True,
            xmin=-0,
            xmax=30,
            ymin=-1,
            ymax=1)

        k = np.random.normal()
        global plot1
        plot1 = MeshLinePlot(color=[0, 0, 0.75, 1])
        y = (0.5 - 0.2)/30*np.linspace(0, max_year-1, max_year) + 0.2*np.ones(max_year) + np.random.normal(0, 0.05, max_year)
        plot1.points = [(x, y[x]) for x in range(0, 30)]
        graph1.add_plot(plot1)
        self.add_widget(graph1)
        return graph1
Пример #4
0
    def init(self):
        # use kivy garden's graph widget
        graph = Graph(
            xlabel='t',
            ylabel='HFR',
            x_ticks_minor=5,
            x_ticks_major=10,
            y_ticks_minor=1,
            y_ticks_major=5,
            y_grid_label=True,
            x_grid_label=False,
            padding=0,
            y_grid=False,
            x_grid=False,
            xmin=0,
            ymin=0,
            xmax=100,
            ymax=30,
            _with_stencilbuffer=False,  # or it does not work in ScreenManager
            label_options={'color': rgb('808080')})
        y = (float(i) for i in range(50))
        x = (float(i) for i in range(50))
        plot = MeshLinePlot(color=rgb('1100aa'))
        pts = list(zip(x, y))
        plot.points = pts
        graph.add_plot(plot)

        self.ids.plot.add_widget(graph)

        self.plot = plot
        self.graph = graph
Пример #5
0
class PsiScreen(Screen):
    graph = Graph(xlabel=' ',
                  ylabel='',
                  x_ticks_minor=5,
                  x_ticks_major=0,
                  y_ticks_major=10,
                  y_ticks_minor=2,
                  y_grid_label=True,
                  x_grid_label=False,
                  padding=5,
                  x_grid=True,
                  y_grid=True,
                  xmin=-0,
                  xmax=50,
                  ymin=0,
                  ymax=100,
                  label_options={
                      'color': [0, 1, 1, 1],
                      'bold': False
                  },
                  border_color=[0, 1, 1, .1],
                  tick_color=[1, 1, 1, 1])
    plot = LinePlot(color=[1, 0, 0, 1], line_width=1.5)
    plot.points = [(0, 0)]
    graph.add_plot(plot)
    clock = Clock

    def __init__(self, *args, **kwargs):
        super(PsiScreen, self).__init__(*args, **kwargs)
        self.ids["flt"].add_widget(self.graph)
Пример #6
0
    def __init__(self, x=[], cox=[]):
        """
        Paramètres
        ----------
        x : list
            Tableau des distances à l'électrode.
        cox : list
            Tableau de la concentration.
        """
        self.x = x
        self.cox = cox

        theme_cls = App.get_running_app().theme_cls
        graph_theme={}
        if App.get_running_app().theme == 'default':
            graph_theme = {
                    'label_options': {
                        'color': [0, 0, 0, 1],  # color of tick labels and titles
                        'bold': False,
                        'markup': True},
                    'background_color': [1, 1, 1, 1],  # back ground color of canvas
                    'tick_color': [0, 0, 0, 1],  # ticks and grid
                    'border_color': [0, 0, 0, 1]}  # border drawn around each graph
        elif App.get_running_app().theme ==  'material-design':
            graph_theme = {
                    'label_options': {
                        'color': get_color_from_hex(colors[theme_cls.primary_palette][theme_cls.primary_hue]),#[0, 0, 0, 1],  # color of tick labels and titles
                        'bold': False,
                        'markup': True},
                    'background_color': get_color_from_hex(colors[theme_cls.theme_style]["Background"]),#[1, 1, 1, 1],  # back ground color of canvas
                    'tick_color': get_color_from_hex(colors[theme_cls.accent_palette][theme_cls.accent_hue]),#[0, 0, 0, 1],  # ticks and grid
                    'border_color': get_color_from_hex(colors[theme_cls.accent_palette][theme_cls.accent_hue])}#[0, 0, 0, 1]}  # border drawn around each graph
                
        self.graph = Graph(title = 'Courbe C[sub]ox[/sub]',
                           xlabel='x',
                           ylabel='C[sub]ox[/sub] / C[sup]*[/sup] [sub]ox[/sub]',
                           x_ticks_minor=5,
                           x_ticks_major=5,
                           y_ticks_major=1,
                           y_ticks_minor=4,
                           y_grid_label=True,
                           x_grid_label=True,
                           padding=5,
                           x_grid=False,
                           y_grid=False, 
                           xmin=float(0),
                           xmax=float(0.05), 
                           ymin=float(0),
                           ymax=float(1),
                           precision="%#.4g",
                           **graph_theme)
        
        self.coxplot = SmoothLinePlot(color=[0, 0, 1, 1])
        self.coxplot.label = "Concentration"

        self.graph.add_plot(self.coxplot)
        
        self._trigger = Clock.create_trigger(self.update_ticks)
        self.graph._plot_area.bind(pos=self._trigger)
    def __init__(self):
        self.graph_theme = {
            'label_options': {
                'color': rgb('444444'),  # color of tick labels and titles
                'bold': True
            },
            'background_color': rgb('b8b7bb'),  # back ground color of canvas
            'tick_color': rgb('808080'),  # ticks and grid
            'border_color': rgb('808080')
        }  # border drawn around each graph
        self.graph_canvas = BoxLayout(orientation='vertical', padding=5)
        self.graph_rain = Graph(ylabel="rainfall(mm/s)",
                                y_grid_label=True,
                                x_grid_label=True,
                                xmin=0,
                                xmax=10,
                                ymin=0,
                                ymax=5000,
                                x_ticks_major=5,
                                y_ticks_major=2500,
                                x_ticks_minor=1,
                                y_ticks_minor=100,
                                x_grid=True,
                                y_grid=True,
                                padding=5,
                                **self.graph_theme)

        self.graph_temp = Graph(ylabel="temperature (C)",
                                y_grid_label=True,
                                x_grid_label=True,
                                xmin=0,
                                xmax=10,
                                ymin=0,
                                ymax=50,
                                x_ticks_major=5,
                                y_ticks_major=25,
                                x_ticks_minor=1,
                                y_ticks_minor=5,
                                x_grid=True,
                                y_grid=True,
                                padding=5,
                                **self.graph_theme)

        self.plot_rain = MeshLinePlot(color=[0, 0, 1, 1])
        self.plot_temp = MeshLinePlot(color=[1, 0, 0, 1])
Пример #8
0
    def __init__(self, n, S, C, t, I):
        """
        Paramètres
        ----------
        n : int
            Nombre d'électrons échangés au cours de la réaction.
        S : float
            Surface d'échange.
        C : float
            Concentration de l'espèce.
        t : list
            Tableau de valeurs des temps expérimentaux.
        I : list
            Tableau de valeurs des intensités mesurées expérimentalement.
        """
        super(GraphLinearRegression, self).__init__(t, I)
        self.n = n
        self.S = S
        self.C = C

        graph_theme = {
            'label_options': {
                'color': [0, 0, 0, 1],  # color of tick labels and titles
                'bold': False
            },
            'background_color': [1, 1, 1, 1],  # back ground color of canvas
            'tick_color': [0, 0, 0, 1],  # ticks and grid
            'border_color': [0, 0, 0, 1]
        }  # border drawn around each graph

        self.graph = Graph(title='Courbes de Regression lineaire',
                           xlabel='log Temps (s)',
                           ylabel='log Intensité (A)',
                           x_ticks_minor=5,
                           x_ticks_major=5,
                           y_ticks_major=0.2,
                           y_ticks_minor=4,
                           y_grid_label=True,
                           x_grid_label=True,
                           padding=5,
                           x_grid=False,
                           y_grid=False,
                           precision="%#.4g",
                           **graph_theme)

        self.logexpplot = SmoothLinePlot(color=[1, 0, 0, 1])
        self.logexpplot.label = "Expérimentale"

        self.linlogexpplot = SmoothLinePlot(color=[1, 0, 1, 1])

        self.graph.legend = True

        self.graph.add_plot(self.logexpplot)
        self.graph.add_plot(self.linlogexpplot)

        self._trigger = Clock.create_trigger(self.update_ticks)
        self.graph._plot_area.bind(pos=self._trigger)
	def build(self):
		self.title = "HP4156C Parameter Analyser"
		## Main screen has a title and two accordions
		root = BoxLayout(orientation='vertical')
		## Add a title header to the window
		graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5, x_ticks_major=25, y_ticks_major=1,y_grid_label=True, x_grid_label=True, padding=5, x_grid=True, y_grid=True, xmin=-0, xmax=100, ymin=-1, ymax=1)
		plot = MeshLinePlot(color=[1, 0, 0, 1])
		plot.points = [(x, sin(x / 10.)) for x in range(0, 101)]
		graph.add_plot(plot)
		root.add_widget(graph)        
		return root
Пример #10
0
    def __init__(self, t=[], I=[]):
        """
        Paramètres
        ----------
        t : list
            Tableau de valeurs de temps.
        I : list
            Tableau de valeurs d'intensité.
        """
        super(CottrellGraph, self).__init__(t, I)

        graph_theme = {
            'label_options': {
                'color': [0, 0, 0, 1],  # color of tick labels and titles
                'bold': False
            },
            'background_color': [1, 1, 1, 1],  # back ground color of canvas
            'tick_color': [0, 0, 0, 1],  # ticks and grid
            'border_color': [0, 0, 0, 1]
        }  # border drawn around each graph

        self.graph = Graph(title='Courbes de Cottrell',
                           xlabel='Temps (s)',
                           ylabel='Intensité (A)',
                           x_ticks_minor=5,
                           x_ticks_major=5,
                           y_ticks_major=0.2,
                           y_ticks_minor=4,
                           y_grid_label=self.ticks_labels,
                           x_grid_label=self.ticks_labels,
                           padding=5,
                           x_grid=False,
                           y_grid=False,
                           xmin=float(self.tleft),
                           xmax=float(self.tright),
                           ymin=float(self.Ibottom),
                           ymax=float(self.Itop),
                           legend=self.legend,
                           precision="%#.4g",
                           **graph_theme)

        self.thplot = SmoothLinePlot(color=[0, 0, 1, 1])
        self.thplot.label = "Théorique"

        self.expplot = SmoothLinePlot(color=[1, 0, 0, 1])
        self.expplot.label = "Expérimentale"

        self.bind(legend=self.graph.setter('legend'))
        self.bind(ticks_labels=self.graph.setter('y_grid_label'))
        self.bind(ticks_labels=self.graph.setter('x_grid_label'))

        self._trigger = Clock.create_trigger(self.update_ticks)
        self.graph.bind(size=self._trigger)
        self.graph._plot_area.bind(pos=self._trigger)
Пример #11
0
 def __init__(self):
     self._plot = MeshLinePlot(color=self.PLOT_LINE_COLOR)
     self._graph = Graph(xlabel=self.X_LABEL, ylabel=self.Y_LABEL,
                         x_ticks_minor=5,
                         y_ticks_major=10, y_ticks_minor=2, y_grid=True,
                         y_grid_label=True, x_grid_label=True, padding=10,
                         xmin=0, ymin=0, ymax=self.Y_MAX_VAL,
                         xmax=self.HISTORY_MAX)
     self.level = None
     self.stats = App.get_running_app().stats
     self.display_level(self.DEFAULT_LEVEL)
     self._graph.add_plot(self._plot)
Пример #12
0
    def create_kivy_plot(self,
                         series=np.array(range(12)),
                         label_y='Average Response Time'):
        if self.graph_figure:
            self.destroy()

        series_len = len(series)
        if series_len == 0:
            return False
        max_y = max(series)
        min_y = min(series)
        #arg_max_y = series.index(max_y) # use this to label max and min...
        #arg_min_y = series.index(min_y) # with their resp time stamp
        ticks_y = round(max_y / 10., 2)

        graph_theme = {
            'label_options': {
                'color': rgb('444444'),  # color of tick labels and titles
                'bold': True
            },
            'background_color': rgb('000000'),  # back ground color of canvas
            'tick_color': rgb('444444'),  # ticks and grid
            'border_color': rgb('444444')
        }  # border drawn around each graph

        self.graph_figure = Graph(xlabel='Last {} games'.format(series_len),
                                  ylabel=label_y,
                                  x_ticks_minor=5,
                                  x_ticks_major=5,
                                  y_ticks_major=ticks_y,
                                  y_grid_label=True,
                                  x_grid_label=True,
                                  padding=10,
                                  x_grid=False,
                                  y_grid=True,
                                  xmin=0,
                                  xmax=series_len,
                                  ymin=0,
                                  ymax=int(1.2 * max_y + 1),
                                  _with_stencilbuffer=False,
                                  **graph_theme)
        plot = SmoothLinePlot(color=next(self.colors))  #mode='line_strip',
        plot.points = [(x, series[x - 1]) for x in range(1, len(series) + 1)]
        self.graph_figure.add_plot(plot)

        self.add_widget(self.graph_figure)
Пример #13
0
    def mostrar_histograma(self):
        """
        Mostra o histograma da imagem.
        """
        histograma = self.imagem_core.get_histograma()

        graph = Graph(xlabel='Tom de Cinza',
                      ylabel='Quantidade de tons',
                      padding=5,
                      xmin=0,
                      xmax=max(histograma.keys()),
                      ymin=0,
                      ymax=max(histograma.values()))
        plot = MeshLinePlot()
        plot.points = histograma.items()
        graph.add_plot(plot)
        self.widgets_dinamicos.append(graph)
        self.add_widget(graph)
Пример #14
0
    def build_graph(self, tree):
        # example of a custom theme
        graph_theme = {
            'label_options': {
                'color':
                (0.27, 0.27, 0.27, 1),  # color of tick labels and titles
                'bold': True
            },
            'background_color':
            (0.97, 0.97, 0.95, 1),  # back ground color of canvas
            'tick_color': (0.5, 0.5, 0.5, 1),  # ticks and grid
            'border_color':
            (0.5, 0.5, 0.5, 1)  # border drawn around each graph
        }

        self.graph = Graph(xlabel='Seconde',
                           ylabel='Apples',
                           x_ticks_minor=0.5,
                           x_ticks_major=1,
                           y_ticks_minor=1,
                           y_ticks_major=10,
                           y_grid_label=True,
                           x_grid_label=True,
                           padding=5,
                           xlog=False,
                           ylog=False,
                           x_grid=True,
                           y_grid=True,
                           xmin=-3,
                           xmax=0,
                           ymin=-30,
                           ymax=30,
                           **graph_theme)

        self.dpoints = []
        for nom, couleur in tree:
            self.dpoints.append((nom, MeshLinePlot(color=couleur)))
        for dpoints in self.dpoints:
            self.graph.add_plot(dpoints[1])

        #self.lpoints = [[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]
        self.lpoints = []

        return self.graph
Пример #15
0
 def build(self):
     super().__init__()
     self.graph = Graph(xlabel='X',
                        ylabel='Y',
                        x_ticks_minor=5,
                        x_ticks_major=25,
                        y_ticks_major=1,
                        y_grid_label=True,
                        x_grid_label=True,
                        padding=5,
                        x_grid=True,
                        y_grid=True,
                        xmin=-0,
                        xmax=100,
                        ymin=-1,
                        ymax=1)
     self.plot = MeshLinePlot(color=[1, 0, 0, 1])
     self.plot.points = [(x, sin(x / 10.)) for x in range(0, 101)]
     self.graph.add_plot(self.plot)
     return self.graph
Пример #16
0
    def __init__(self, **kwargs):
        super(case, self).__init__(**kwargs)
        box = FloatLayout()
        graph = Graph(xlabel='X',
                      ylabel='Y',
                      x_ticks_minor=5,
                      x_ticks_major=25,
                      y_ticks_major=1,
                      y_grid_label=True,
                      x_grid_label=True,
                      padding=5,
                      x_grid=True,
                      y_grid=True,
                      xmin=-0,
                      xmax=20,
                      ymin=0,
                      ymax=10)
        plot = LinePlot()
        # plot.points = [(x, sin(x / 10.)) for x in range(0, 101)]

        # data = np.array([[0,0], [1,1],[2,2]])

        data = collections.deque(maxlen=20)
        time = collections.deque(maxlen=20)

        d = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
        t = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

        data.append(d)
        time.append(t)

        toplot = np.vstack((time, data)).T

        print toplot

        plot.points = tuple(map(tuple, toplot))

        graph.add_plot(plot)
        box.add_widget(graph)

        self.add_widget(box)
Пример #17
0
    def initGraph(self):
        self.graph = Graph(xlabel='TDOAs',
                           ylabel='Y',
                           x_ticks_minor=10,
                           x_ticks_major=10,
                           y_ticks_major=0.5,
                           x_grid_label=False,
                           padding=5,
                           x_grid=False,
                           y_grid=False,
                           xmin=0,
                           xmax=self.numTDOAs,
                           ymin=-0.5,
                           ymax=1.5)
        self.gaussianplot = MeshLinePlot(
            color=[1, 0, 0, 1])  # 사용자가 선택하는 target TDOA 정규 분포
        self.calculated_plot = MeshLinePlot(
            color=[0, 1, 0, 1])  # gccPHAT으로 분석된 TDOA plot

        self.graph.add_plot(self.gaussianplot)
        self.add_widget(self.graph)
Пример #18
0
 def __init__(self, n=3, xmin=0, xmax=10, ymin=-1, ymax=1, xlabel='Time'):
     """
     n: number of graphs
     xmin: minimum x
     xmax: maximum x
     ymin: minimum y
     ymax: maximum y
     xlabel: label for x axis (time of freq)
     """
     super(Grapher, self).__init__(orientation='vertical')
     self.graph = []
     self.plots = []
     if xlabel == 'Time':
         self.plots.append(MeshLinePlot(color=[1, 0, 0, 1]))
         self.plots.append(MeshLinePlot(color=[0, 1, 0, 1]))
         self.plots.append(MeshLinePlot(color=[0, 0, 1, 1]))
     else:
         self.plots.append(MeshStemPlot(color=[1, 0, 0, 1]))
         self.plots.append(MeshStemPlot(color=[0, 1, 0, 1]))
         self.plots.append(MeshStemPlot(color=[0, 0, 1, 1]))
     self.reset_plots()
     for i in range(n):
         self.graph.append(
             Graph(xlabel=xlabel,
                   ylabel='Amp',
                   x_ticks_minor=5,
                   x_ticks_major=25,
                   y_ticks_major=1,
                   y_grid_label=True,
                   x_grid_label=True,
                   padding=5,
                   x_grid=True,
                   y_grid=True,
                   xmin=xmin,
                   xmax=xmax,
                   ymin=ymin,
                   ymax=ymax))
         self.graph[i].add_plot(self.plots[i])
         self.add_widget(self.graph[i])
Пример #19
0
 def __init__(self, **kwargs):
     self.grid = True or kwargs['grid']
     self.color = kwargs['color']
     self.name = kwargs['name'].upper()
     self.label = kwargs['name']
     self.parent = kwargs['parent']
     self.gtype = kwargs['gtype']
     self.graph = Graph(ylabel=self.label,
                        x_ticks_minor=1,
                        x_ticks_major=5,
                        y_ticks_major=20,
                        x_grid_label=True,
                        y_grid_label=True,
                        padding=5,
                        x_grid=self.grid,
                        y_grid=self.grid,
                        xmin=0,
                        xmax=50,
                        ymin=0,
                        ymax=20)
     self.plot = SmoothLinePlot(color=self.color)
     self.plot.points = []
     self.graph.add_plot(self.plot)
Пример #20
0
    def __init__(self, **kwargs):
        super(RootWidget, self).__init__(**kwargs)

        graph = Graph(xlabel='X',
                      ylabel='Y',
                      x_ticks_minor=5,
                      x_ticks_major=25,
                      y_ticks_major=1,
                      y_grid_label=True,
                      x_grid_label=True,
                      padding=5,
                      x_grid=True,
                      y_grid=True,
                      xmin=-0,
                      xmax=100,
                      ymin=-1,
                      ymax=1)

        graph.background_color = 0, 0, 1, 1  # blue color

        plot = MeshLinePlot(color=[1, 0, 0, 1])
        plot.points = [(x, sin(x / 10.)) for x in range(0, 101)]
        graph.add_plot(plot)
        self.add_widget(graph)
Пример #21
0
Файл: dash.py Проект: x4rMa/Dash
class Performance(StackLayout):
    """
    This class contains the graphing application for the Kivy Dashboard
    Application. It accepts a buffer string from a socket connection
    established elsewhere in the software, then parses the data to be
    inserted into a graph"""
    graph = Graph(xlabel='Time', ylabel='', x_ticks_minor=5,
        x_ticks_major=100, y_ticks_major=12,
        y_grid_label=True, x_grid_label=True, padding=5,
        x_grid=True, y_grid=True, xmin=-0, xmax=300, ymin=0, ymax=120, size_hint=(1,.9))

    ## creates graph object to be accessed by updateUI function

    plot1 = MeshLinePlot(color=[1, 0, 0, 1])
    plot2 = MeshLinePlot(color=[0, 1, 0, 1])
    plot3 = MeshLinePlot(color=[0, 0, 1, 1])

    last_data = '0,0,0,0'
    ## creates the initial plot objects for the garden.graph function
    ## with defining color

    RPMbtn = ToggleButton(text='RPM', size_hint=(.33,.1))
    ENGbtn = ToggleButton(text='Engine Load', size_hint=(.33,.1))
    COTbtn = ToggleButton(text='Coolant Temp', size_hint=(.33,.1))

    RPMstate = 0
    ENGstate = 0
    COTstate = 0

    RPMlist = []
    while(len(RPMlist)<300):
        RPMlist.append(0)   
    
    ENGlist = []
    while(len(ENGlist)<300):
        ENGlist.append(0)

    COTlist = []
    while(len(COTlist)<300):
        COTlist.append(0)
    ## Creates three lists, of length 300, all initialized to zero
    ## The graph will build from this list, and if it is not initialized to
    ## zero beforehand, it will get an indexing error
    
    def __init__(self, **kwargs):
        """Creates the layout and widget tree for performance class"""
        super(Performance, self).__init__(**kwargs)
        self.add_widget(self.RPMbtn)
        self.add_widget(self.ENGbtn)
        self.add_widget(self.COTbtn)
        self.add_widget(self.graph)

        self.RPMbtn.bind(on_press = self.RPMplot)
        self.ENGbtn.bind(on_press = self.ENGplot)
        self.COTbtn.bind(on_press = self.COTplot)

        Clock.schedule_interval(self.updateUI, 1.0/10.0)
        ## pings the updateUI function ten times a second, giving
        ## the graph a framerate of 10fps

    def RPMplot(self, RPMbtn):
        """sets the state for the RPM button widget"""
        if (self.RPMstate == 0):
            self.RPMstate = 1
        else:
            self.RPMstate = 0
            
    def ENGplot(self, ENGbtn):
        """sets the state for the Engine Load button widget"""
        if (self.ENGstate == 0):
            self.ENGstate = 1
        else:
            self.ENGstate = 0
            
    def COTplot(self, COTbtn):
        """sets the state for the Coolant Temp button widget"""
        if (self.COTstate == 0):
            self.COTstate = 1
        else:
            self.COTstate = 0
        
    
    def updateUI(self, dt):
        """Updates the parameters of the graph.

        This function will remove redundant plots on the graph
        then receive new data from bluetooth socket.
        The data is broken up and placed on the graph
        depending on the state of the button widgets
        """
        try:
            self.graph.remove_plot(plot1)
        except:
            pass
        try:
            self.graph.remove_plot(plot2)
        except:
            pass
        try:
            self.graph.remove_plot(plot3)
        except:
            pass
        ## tries to remove the previously added plots to the graph
        ## this prevents ghosting on the graph itself
        
        # try:
        #     data = client_sock.recv(1024)

        #     if (len(data) < 1):
        #         data = self.last_data
        #     else:
        #         print data

        #     self.last_data = data

        ## Receive data as a string into 'data'. If the
        ## socket produces no information, as the vehicle will
        ## typically vary on how long between data is sent
        ## the data will either get '0,0,0,0' indicating no data
        ## has been sent yet, or it will use the last good data received
            
        # except IOError, NameError:
        #     data = last_data
            
        # if (client_sock == False):
        #     print "Socket Connection Lost"
            
        # values = data.split(',')

        ## data is split into
        
        self.RPMlist.insert(0, random.randint(60,80))
        if(len(self.RPMlist)>300):
             self.RPMlist = self.RPMlist[:300]
        
        self.ENGlist.insert(0, random.randint(20,40))
        if(len(self.ENGlist)>300):
             self.ENGlist = self.ENGlist[:300]
        
        self.COTlist.insert(0, random.randint(1,30))
        if(len(self.COTlist)>300):
             self.COTlist = self.COTlist[:300]
        
        # Used for testing random numbers in the graph
        
        
        # self.RPMlist.insert(0, int(values[1])/100)
        # if(len(self.RPMlist)>300):
        #     self.RPMlist = self.RPMlist[:300]

        # self.ENGlist.insert(0, int(values[2]))
        # if(len(self.ENGlist)>300):
        #     self.ENGlist = self.ENGlist[:300]

        # self.COTlist.insert(0, int(values[3]))
        # if(len(self.COTlist)>300):
        #     self.COTlist = self.COTlist[:300]

        ## The values (data) are inserted into their respective
        ## performance metric lists
        
		self.RPMbtn.text = str('RPM: ' + str(self.RPMlist[0]))
		self.ENGbtn.text = str('Engine Load: ' + str(self.ENGlist[0]))
		self.COTbtn.text = str('Coolant Temp: ' + str(self.COTlist[0]))
		
		## Used to place random numbers in graph for testing

        # self.RPMbtn.text = str('RPM: ' + values[1])
        # self.ENGbtn.text = str('Engine Load: ' + values[2])
        # self.COTbtn.text = str('Coolant Temp: ' + values[3])

        ## Updates the buttons on screen to the correct values

        self.RPMlist.reverse()
        self.ENGlist.reverse()
        self.COTlist.reverse()

        ## Reverses each list so that the graph is displayed as scrolling from
        ## the right, rather than the left

        if(self.RPMstate == 1):
            self.plot1.points = ((x, self.RPMlist[x]) for x in xrange(0,300))
            self.graph.add_plot(self.plot1)
        
        if(self.ENGstate == 1):
            self.plot2.points = ((x, self.ENGlist[x]) for x in xrange(0,300))
            self.graph.add_plot(self.plot2)
    
        if(self.COTstate == 1):
            self.plot3.points = ((x, self.COTlist[x]) for x in xrange(0,300))
            self.graph.add_plot(self.plot3)

        ## The App checks the state of the buttons, and updates the graph
        ## if the buttons are toggled
        
        self.RPMlist.reverse()
        self.ENGlist.reverse()
        self.COTlist.reverse()
Пример #22
0
 def create_basic_graph(self, y_label, y_min, y_max, size_hint, pos_hint, x_grid_label=True, xlabel='frames'):
     return Graph(size_hint=size_hint, pos_hint=pos_hint,
         xlabel=xlabel, ylabel=y_label, x_ticks_minor=3,
         x_ticks_major=50, y_ticks_major=100,
         y_grid_label=False, x_grid_label=x_grid_label, padding=5,
         x_grid=False, y_grid=False, xmin=0, xmax=100, ymin=y_min, ymax=y_max)
    def __init__(self, **kwargs):
        super(Screen, self).__init__(**kwargs)

        self.allowed_receive_database = True

        self.error = Image(
            source='Img/error.png',
            allow_stretch=False,
            keep_ratio=True,
            pos_hint={"center_x": 0.095, "center_y": 0.64},
            size_hint=(0.11, 0.11))

        self.wait = Image(
            source='Img/wait.png',
            allow_stretch=False,
            keep_ratio=True,
            pos_hint={"center_x": 0.095, "center_y": 0.64},
            size_hint=(0.11, 0.11))

        graph_theme = {
            'label_options': {
                'color': rgb('444444'),  # color of tick labels and titles
                'bold': True},
            'background_color': rgb('f8f8f2'),  # back ground color of canvas
            'tick_color': rgb('808080'),  # ticks and grid
            'border_color': rgb('808080')}  # border drawn around each graph

        self.graph1 = Graph(
            xlabel='Time [s]',
            ylabel='Value',
            x_ticks_minor=5,
            x_ticks_major=5,
            y_ticks_minor=1,
            y_ticks_major=10,
            y_grid_label=True,
            x_grid_label=True,
            padding=5,
            xlog=False,
            ylog=False,
            x_grid=False,
            y_grid=False,
            xmin=0,
            xmax=30,
            ymin=0,
            ymax=100,
            pos_hint={'center_x': 0.5, 'center_y': 0.5},
            _with_stencilbuffer=False,
            **graph_theme)

        self.graph2 = Graph(
            xlabel='Time [s]',
            ylabel='Value',
            x_ticks_minor=5,
            x_ticks_major=5,
            y_ticks_minor=1,
            y_ticks_major=1,
            y_grid_label=True,
            x_grid_label=True,
            padding=5,
            xlog=False,
            ylog=False,
            x_grid=False,
            y_grid=False,
            xmin=0,
            xmax=30,
            ymin=-5,
            ymax=5,
            pos_hint={'center_x': 0.5, 'center_y': 0.5},
            _with_stencilbuffer=False,
            **graph_theme)

        self.plot1 = LinePlot(line_width=2, color=[1, 0, 0, 1])
        self.plot1.points = [(i, j*10/3) for i, j in enumerate(range(31))]
        self.graph1.add_plot(self.plot1)
        self.ids.panel1.add_widget(self.graph1)

        self.plot2 = LinePlot(line_width=2, color=[1, 0, 0, 1])
        self.plot2.points = [(i, j/3 - 5) for i, j in enumerate(range(31))]
        self.graph2.add_plot(self.plot2)
        self.ids.panel2.add_widget(self.graph2)
Пример #24
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.app_ = App.get_running_app()
        # Get the dates clicked
        self.model_ = self.app_.calendar_.dates_.model_
        # Information to be added
        self.body = self.model_.printSelectedResults()

        # Layout arrangementw
        self.orientation = 'vertical'
        # Elevators information
        self.layout_comp = BoxLayout(orientation='horizontal',
                                     size_hint=(1, 1))
        self.layout_map = BoxLayout(orientation='horizontal', size_hint=(1, 1))

        self.img_comp_1 = Image(source='component_1.png',
                                keep_ratio=False,
                                size_hint=(1, 1),
                                allow_stretch=False,
                                mipmap=True)
        self.img_comp_2 = Image(source='component_2.png',
                                keep_ratio=False,
                                size_hint=(1, 1),
                                allow_stretch=False,
                                mipmap=True)
        self.layout_comp.add_widget(self.img_comp_1)
        self.layout_comp.add_widget(self.img_comp_2)

        self.img_map_1 = Image(source='map_kunshan.png',
                               keep_ratio=False,
                               size_hint=(1, 1),
                               allow_stretch=True)
        self.img_map_2 = Image(source='map_sh.png',
                               keep_ratio=False,
                               size_hint=(1, 1),
                               allow_stretch=True)
        self.layout_map.add_widget(self.img_map_1)
        self.layout_map.add_widget(
            Label(size_hint=(0.1, 1),
                  text='昆\n山\n地\n区\n电\n梯\n分\n布\n图',
                  font_name=font_name,
                  font_size='20sp',
                  color=(0, 0, 0, 1)))
        self.layout_map.add_widget(self.img_map_2)
        self.layout_map.add_widget(
            Label(size_hint=(0.1, 1),
                  text='上\n海\n地\n区\n电\n梯\n分\n布\n图',
                  font_name=font_name,
                  font_size='20sp',
                  color=(0, 0, 0, 1)))

        self.layout_fig = BoxLayout(orientation='vertical', size_hint=(1, 0.7))
        #self.layout_fig.add_widget(self.layout_comp)
        self.layout_fig.add_widget(self.layout_map)
        self.add_widget(self.layout_fig)

        #self.layout_scroll_lb=Label(text=self.body,size_hint=(1,None))
        #self.layout_scroll_lb.height=self.layout_scroll_lb.texture_size[1]
        #self.layout_scroll=ScrollableLabel(text=self.body)
        #self.layout_scroll.add_widget(self.layout_scroll_lb)

        #self.layout1_title=Label(text='以下电梯预测将在30天内发生故障:\n'+self.body,font_name=font_name)
        #self.layout1_title.size=self.layout1_title.texture_size
        #self.layout1.add_widget(self.layout1_title)
        #self.layout1.add_widget(self.layout_scroll)
        # Plots
        self.graph_theme = {
            'label_options': {
                'color': (0, 0, 0, 1),  # color of tick labels and titles
                'bold': True
            },
            'tick_color': (0, 0, 0, 1)
        }  # ticks and grid

        self.graph = Graph(xlabel='Current time',
                           ylabel='Maintenance date',
                           x_ticks_major=5,
                           y_ticks_major=5,
                           y_grid_label=True,
                           x_grid_label=True,
                           padding=5,
                           x_grid=True,
                           y_grid=True,
                           xmin=-0,
                           xmax=31,
                           ymin=-0,
                           ymax=31,
                           **self.graph_theme)

        self.plot = MeshLinePlot(color=[1, 0, 0, 1])
        self.best_maint_dates = joblib.load('mon_best_int_np.asv')
        self.best_maint_dates = self.best_maint_dates[self.model_.month - 1]
        self.plot.points = [(x + 1, x + 1 + self.best_maint_dates[x])
                            for x in range(len(self.best_maint_dates))]
        self.graph.add_plot(self.plot)

        self.layout_graph = BoxLayout(orientation='vertical',
                                      size_hint=(0.7, 1))
        self.layout_graph.add_widget(
            Label(text='本月最优维保日期随时间变化图',
                  font_name=font_name,
                  size_hint=(1, 0.1),
                  font_size='16sp',
                  color=(0, 0, 0, 1)))
        self.layout_graph.add_widget(self.graph)

        # Note for user
        self.layout_info = BoxLayout(orientation='vertical',
                                     size_hint=(0.3, 1))
        self.layout_info.add_widget(
            Label(
                text=
                '待预防性维护电梯信息:\n设备编号\n设备所在区域类型\n故障信息\n所在城市\n电梯运行速度\n设备型号\n距离上一次维修天数',
                font_name=font_name,
                pos_hint={
                    'x': 0.5,
                    'center_y': .5
                },
                font_size='16sp',
                color=(0, 0, 0, 1)))

        self.layout_note = BoxLayout(orientation='vertical',
                                     size_hint=(0.5, 0.8))
        self.layout_note.add_widget(
            Button(on_press=self.on_press,
                   text='输出\n电梯\n信息',
                   font_name=font_name,
                   pos_hint={
                       'x': .5,
                       'y': 1
                   },
                   size_hint=(0.4, 0.2),
                   font_size='20sp',
                   color=(0, 0, 0, 1),
                   background_color=color_shadow_blue))

        self.layout_graph_note = BoxLayout(orientation='horizontal',
                                           size_hint=(1, 0.5))
        self.layout_graph_note.add_widget(self.layout_graph)
        self.layout_graph_note.add_widget(self.layout_info)
        self.layout_graph_note.add_widget(self.layout_note)

        self.add_widget(self.layout_graph_note)

        self.layout2 = BoxLayout(orientation='horizontal', size_hint=(1, .15))
        self.add_widget(self.layout2)
        self.layout2.add_widget(
            Label(text="请按 'ESC'键或点击窗外以关闭窗口",
                  font_name=font_name,
                  font_size='20sp',
                  color=(1, 0, 0, 1)))
Пример #25
0
class PowerMeterControl(TabbedPanel):
    fpower = StringProperty('0.0')
    power = NumericProperty(0.0)
    max_power = NumericProperty(0.0)
    voltage = NumericProperty(0)
    tick_color = ListProperty([0, 1, 0, 1])
    wavelength = BoundedNumericProperty(780.0,
                                        min=340.0,
                                        max=1180,
                                        errorhandler=lambda x: 1180
                                        if x > 1180 else 340)
    connected = BooleanProperty(False)
    logo = 'CQTtools_inverted.png'
    graph = Graph()

    plot = ObjectProperty(None)

    powermeter = None

    pm_range = 4

    iteration = 0

    dt = 0.25

    def update(self, dt):
        #adding by ChiHuan in v1.0. Averaging the reading.
        v = []
        average_v = 0
        for i in range(0, 50):
            v.append(float(self.powermeter.get_voltage()))
            average_v = np.mean(v)
        #self.voltage = float(self.powermeter.get_voltage())
        self.voltage = float(average_v)
        self.power = self.amp2power(self.voltage, self.wavelength,
                                    int(self.pm_range))
        self.fpower = self.formated_power()  #
        #self.power_max()
        self.plot.points.append((self.iteration * dt, self.power * 1000))
        #print self.plot.points
        self.iteration += 1 * dt
        if self.iteration > 150:
            self.iteration = 0
            self.plot.points = []
            self.ids.graph1.remove_plot(self.plot)

    def update_range(self, value):
        self.pm_range = value
        if self.connected == True:
            self.pm_range = value
            self.powermeter.set_range(int(self.pm_range))
            print self.pm_range
            return self.pm_range

    def connect_to_powermeter(self, connection):
        if not self.connected:
            if platform == 'android':  #to get access to serial port on android
                os.system(
                    "su -c chmod 777 " + connection
                )  #has to run as child otherwise will not work with all su binarys
            self.data = self._read_cal_file()
            self.powermeter = pm.pmcommunication(connection)
            Clock.schedule_interval(self.update, self.dt)
            self.connected = True
            self.update_range(self.pm_range)
            plot = MeshLinePlot(color=[0, 1, 0, 1])
            self.ids.graph1.add_plot(plot)
            self.plot = plot
            return self.powermeter

    def serial_ports_android(self):
        #Lists serial ports
        ports = glob.glob('/dev/ttyACM*')
        return ports
        """this section of the code deals with converting between the voltage value and the
    optical power at the wavelength of interest"""

    resistors = [1e6, 110e3, 10e3, 1e3,
                 20]  #sense resistors adjust to what is on the board

    file_name = 's5106_interpolated.cal'  #detector calibration file

    def _read_cal_file(self):  # read in calibration file for sensor
        f = open(self.file_name, 'r')
        x = json.load(f)
        f.close()
        return x

    def volt2amp(self, voltage, range_number):
        self.amp = voltage / self.resistors[range_number]
        return self.amp

    def amp2power(self, voltage, wavelength, range_number):
        amp = self.volt2amp(voltage, range_number - 1)
        xdata = self.data[0]
        ydata = self.data[1]
        i = xdata.index(int(wavelength))
        responsivity = ydata[i]
        power = amp / float(responsivity)
        return power

    def formated_power(self):
        power = self.amp2power(self.voltage, self.wavelength,
                               int(self.pm_range))
        fpower = power * 1000
        if 1 < fpower < 500:
            fpower = round(fpower, 2)
            out = str(fpower) + 'mW'
        elif 0.001 < fpower < 1:
            fpower = round(fpower * 1000, 2)
            out = str(fpower) + 'uW'
        elif 10e-6 < fpower < 0.001:
            fpower = round(fpower * 1e6, 2)
            out = str(fpower) + 'nW'
        elif fpower < 10e-6:
            out = 'Low'
        else:
            out = 'High'
        return out

    def power_max(self):
        if self.max_power < self.power:
            self.max_power = self.power
        return self.max_power
Пример #26
0
class Chart(MDBoxLayout):
    volume_graph = ObjectProperty(defaultvalue=Graph(xlabel='Time (s)',
                                                     ylabel='Volume (ml)',
                                                     x_ticks_minor=1,
                                                     x_ticks_major=1,
                                                     y_ticks_major=1,
                                                     y_grid_label=True,
                                                     x_grid_label=True,
                                                     padding=5,
                                                     xmin=0,
                                                     xmax=50,
                                                     ymin=VOLUME_Y_LIMITS[0],
                                                     ymax=VOLUME_Y_LIMITS[1]))
    pressure_graph = ObjectProperty(
        defaultvalue=Graph(xlabel='Time (s)',
                           ylabel='Pressure (cm H20)',
                           x_ticks_minor=1,
                           x_ticks_major=1,
                           y_ticks_major=1,
                           y_grid_label=True,
                           x_grid_label=True,
                           padding=5,
                           xmin=0,
                           xmax=50,
                           ymin=PRESSURE_Y_LIMITS[0],
                           ymax=PRESSURE_Y_LIMITS[1]))
    flow_graph = ObjectProperty(defaultvalue=Graph(xlabel='Time (s)',
                                                   ylabel='Flow (l/min)',
                                                   x_ticks_minor=1,
                                                   x_ticks_major=1,
                                                   y_ticks_major=1,
                                                   y_grid_label=True,
                                                   x_grid_label=True,
                                                   padding=5,
                                                   xmin=0,
                                                   xmax=50,
                                                   ymin=FLOW_Y_LIMITS[0],
                                                   ymax=FLOW_Y_LIMITS[1]))

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.orientation = 'vertical'
        self.plot_pressure = LinePlot(color=[1, 0, 0, 1], line_width=2)
        self.plot_flow = LinePlot(color=[1, 0, 0, 1], line_width=2)
        self.plot_volume = LinePlot(color=[1, 0, 0, 1], line_width=2)
        self.data = {'time': [], 'pressure': [], 'flow': [], 'volume': []}
        threading.Thread(target=self.generate_data, daemon=True).start()
        self.start()

    def start(self):
        self.pressure_graph.add_plot(self.plot_pressure)
        self.flow_graph.add_plot(self.plot_flow)
        self.volume_graph.add_plot(self.plot_volume)
        self.add_widget(self.pressure_graph)
        self.add_widget(self.flow_graph)
        self.add_widget(self.volume_graph)
        # Clock.schedule_interval(self.get_value, 0.05)
        threading.Thread(target=self.get_value, args=(0.05, ),
                         daemon=True).start()

    def stop(self):
        Clock.unschedule(self.get_value)

    def get_value(self, delay=.05):
        while True:
            self.update_axis()
            self.plot_pressure.points = [
                (x, self.data['pressure'][i])
                for i, x in enumerate(self.data['time'])
            ]
            self.plot_flow.points = [(x, self.data['flow'][i])
                                     for i, x in enumerate(self.data['time'])]
            self.plot_volume.points = [(x, self.data['volume'][i])
                                       for i, x in enumerate(self.data['time'])
                                       ]

            # Make the program sleep before resuming the iteration
            time.sleep(delay)

    def update_axis(self, *args):
        # Modifying the x-axis
        if len(self.data['time']) == NUMBER_OF_POINTS:
            self.pressure_graph.xmin = self.data['time'][0]
            self.pressure_graph.xmax = self.data['time'][-1]
            self.flow_graph.xmin = self.data['time'][0]
            self.flow_graph.xmax = self.data['time'][-1]
            self.volume_graph.xmin = self.data['time'][0]
            self.volume_graph.xmax = self.data['time'][-1]

        # Modifying the y-axis
        if max(self.data['pressure']) >= PRESSURE_Y_LIMITS[1]:
            self.pressure_graph.ymax = max(self.data['pressure']) + 1
        if max(self.data['flow']) >= FLOW_Y_LIMITS[1]:
            self.flow_graph.ymax = max(self.data['flow']) + 1
        if max(self.data['volume']) >= VOLUME_Y_LIMITS[1]:
            self.volume_graph.ymax = max(self.data['volume']) + 1

    def generate_data(self):
        x = -10
        while True:
            if ((x - (x % 10)) / 10) % 2 == 0:
                current_pressure_value = self.triangular_wave(t=x,
                                                              period=2,
                                                              scale=1,
                                                              duty_cycle=.5)
                current_flow_value = self.triangular_wave(t=x,
                                                          period=2,
                                                          scale=1,
                                                          duty_cycle=.2)
                current_volume_value = self.triangular_wave(t=x,
                                                            period=2,
                                                            scale=4,
                                                            duty_cycle=.6)
            else:
                current_pressure_value = self.triangular_wave(t=x,
                                                              period=2,
                                                              scale=1,
                                                              duty_cycle=.5)
                current_flow_value = self.triangular_wave(t=x,
                                                          period=2,
                                                          scale=2,
                                                          duty_cycle=.2)
                current_volume_value = self.triangular_wave(t=x,
                                                            period=2,
                                                            scale=1,
                                                            duty_cycle=.6)
            if len(self.data['time']) == NUMBER_OF_POINTS:
                for data in self.data:  # deleting the first elements to keep the number of elements constant
                    del self.data[data][0]

            self.data['pressure'].append(current_pressure_value)
            self.data['flow'].append(current_flow_value)
            self.data['volume'].append(current_volume_value)
            self.data['time'].append(x)

            x += .2  # Incrementing the horizontal axis or the time axis
            time.sleep(.1)

    @staticmethod
    def triangular_wave(t, period, scale=1, duty_cycle=.5):
        actual_time = t % period
        if actual_time <= duty_cycle * period:
            return scale * actual_time
        else:
            return 0
Пример #27
0
class Chart(MDBoxLayout):
    volume_graph = Graph(xlabel='time',
                         ylabel='volume',
                         x_ticks_minor=1,
                         x_ticks_major=5,
                         y_ticks_major=1,
                         y_grid_label=True,
                         x_grid_label=True,
                         padding=5,
                         x_grid=True,
                         y_grid=True,
                         xmin=0,
                         xmax=50,
                         ymin=-1,
                         ymax=1)
    pressure_graph = Graph(xlabel='time',
                           ylabel='pressure',
                           x_ticks_minor=1,
                           x_ticks_major=5,
                           y_ticks_major=1,
                           y_grid_label=True,
                           x_grid_label=True,
                           padding=5,
                           x_grid=True,
                           y_grid=True,
                           xmin=0,
                           xmax=50,
                           ymin=-1,
                           ymax=1)
    flow_graph = Graph(xlabel='time',
                       ylabel='flow',
                       x_ticks_minor=1,
                       x_ticks_major=5,
                       y_ticks_major=1,
                       y_grid_label=True,
                       x_grid_label=True,
                       padding=5,
                       x_grid=True,
                       y_grid=True,
                       xmin=0,
                       xmax=50,
                       ymin=-1,
                       ymax=1)

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.orientation = 'vertical'
        self.plot_pressure = LinePlot(color=[1, 0, 0, 1], line_width=2)
        self.plot_flow = LinePlot(color=[1, 0, 0, 1], line_width=2)
        self.plot_volume = LinePlot(color=[1, 0, 0, 1], line_width=2)
        self.data = {'time': [], 'pressure': [], 'flow': [], 'volume': []}
        threading.Thread(target=self.generate_data, daemon=True).start()
        self.start()

    def start(self):
        self.pressure_graph.add_plot(self.plot_pressure)
        self.flow_graph.add_plot(self.plot_flow)
        self.volume_graph.add_plot(self.plot_volume)
        self.add_widget(self.pressure_graph)
        self.add_widget(self.flow_graph)
        self.add_widget(self.volume_graph)
        Clock.schedule_interval(self.get_value, 0.05)

    def stop(self):
        Clock.unschedule(self.get_value)

    def get_value(self, dt):
        self.update_axis()
        self.plot_pressure.points = [(x, self.data['pressure'][i])
                                     for i, x in enumerate(self.data['time'])]
        self.plot_flow.points = [(x, self.data['flow'][i])
                                 for i, x in enumerate(self.data['time'])]
        self.plot_volume.points = [(x, self.data['volume'][i])
                                   for i, x in enumerate(self.data['time'])]

    def update_axis(self, *args):
        if len(self.data['time']) == NUMBEROFPOINTS:
            self.pressure_graph.xmin = self.data['time'][0]
            self.pressure_graph.xmax = self.data['time'][-1]
            self.flow_graph.xmin = self.data['time'][0]
            self.flow_graph.xmax = self.data['time'][-1]
            self.volume_graph.xmin = self.data['time'][0]
            self.volume_graph.xmax = self.data['time'][-1]

    def generate_data(self):
        x = -10
        while True:
            current_pressure_value = math.cos(x)
            current_flow_value = math.sin(x)
            current_volume_value = -math.cos(x)
            if len(self.data['time']) == NUMBEROFPOINTS:
                for data in self.data:  # deleting the first elements to keep the number of elements constant
                    del self.data[data][0]

            self.data['pressure'].append(current_pressure_value)
            self.data['flow'].append(current_flow_value)
            self.data['volume'].append(current_volume_value)
            self.data['time'].append(x)

            x += 1  # Incrementing the horizontal axis or the time axis
            time.sleep(.1)
    def __init__(self,
                 data_file,
                 measure_collections_f,
                 additional_interval,
                 restart=True,
                 **kwargs):
        super(VisualizationApp, self).__init__(**kwargs)

        self.restart = restart
        self.data_file = data_file
        self.additional_interval = additional_interval
        self.camera_folder = data_file + '_images_Camera\\'
        self.camera_files = sorted([
            f for f in os.listdir(self.camera_folder)
            if os.path.isfile(os.path.join(self.camera_folder, f))
            and f.endswith('.jpg')
        ])
        self.ground_truth_file = [
            os.path.join(self.camera_folder, f)
            for f in os.listdir(self.camera_folder)
            if os.path.isfile(os.path.join(self.camera_folder, f))
            and f.startswith('00gt')
        ][0]

        self.image = Image(source=os.path.join(self.camera_folder,
                                               self.camera_files[0]),
                           size=(352, 288),
                           pos=(0, 0))
        #with self.image.canvas as canvas:
        #    Color(1., 0, 0)
        #   Rectangle(size=(1, 10000))

        self.graph = Graph(
            xlabel='Time [s]',
            ylabel='Distance [m]',  #x_ticks_minor=0.5,
            x_ticks_major=2,
            y_ticks_major=1,
            y_grid_label=True,
            x_grid_label=True,
            padding=10,
            x_grid=True,
            y_grid=True,
            xmin=0,
            xmax=0,
            ymin=-1,
            ymax=11)

        last_mc = None
        self.first_timestamp = measure_collections_f[0].first_measure(
        ).timestamp
        for mc in measure_collections_f:
            color = [1, 1, 0, 1]
            if mc.prediction == 'FREE_SPACE':
                color = [1, 0, 1, 1]
            elif mc.prediction == 'PARKING_CAR':
                color = [0, 1, 1, 1]
            elif mc.prediction == 'OVERTAKING_SITUATION':
                color = [0, 0, 1, 1]
            plot = MeshLinePlot(color=color)
            plot.points = [(m.timestamp - self.first_timestamp, m.distance)
                           for m in mc.measures]
            self.graph.add_plot(plot)

            color_actual = [1, 1, 0, 1]
            if mc.get_probable_ground_truth() == GroundTruthClass.FREE_SPACE:
                color_actual = [1, 0, 1, 1]
            elif GroundTruthClass.is_parking_car(
                    mc.get_probable_ground_truth()):
                color_actual = [0, 1, 1, 1]
            elif GroundTruthClass.is_overtaking_situation(
                    mc.get_probable_ground_truth()):
                color_actual = [0, 0, 1, 1]
            plot_actual = MeshLinePlot(color=color_actual)
            plot_actual.points = [(m.timestamp - self.first_timestamp,
                                   m.distance - 0.1) for m in mc.measures]
            self.graph.add_plot(plot_actual)

            if last_mc is not None:
                plot_next = MeshLinePlot(color=[1, 1, 1, 1])
                plot_next.points = [
                    (last_mc.last_measure().timestamp - self.first_timestamp,
                     last_mc.last_measure().distance),
                    (mc.first_measure().timestamp - self.first_timestamp,
                     mc.first_measure().distance)
                ]
                self.graph.add_plot(plot_next)

            last_mc = mc

        # plot = MeshLinePlot(color=[1, 1, 1, 1])
        # plot.points = [(m.timestamp - self.first_timestamp, m.distance) for m in self.measurements]
        # self.graph.add_plot(plot)

        self._keyboard = Window.request_keyboard(self._keyboard_closed, self)
        self._keyboard.bind(on_key_down=self._on_keyboard_down)

        self.running = True
        self.cur_index = -1
        self.show_next_image(0)
Пример #29
0
    def __init__(self, **kwargs):
        super(Stats, self).__init__(**kwargs)
        self.flag = 0
        # flag = 1: Daily cost
        # flag = 2: Weekly cost
        # flag = 3: Monthly cost
        # flag = 4: Daily mistakes
        # flag = 5: Weekly mistakes
        # flag = 6: Monthly mistakes
        # flag = 7: Omission Category
        # flag = 8: Commission Category

        self.calculate_day_cost()

        self.graph_theme = {
            'label_options': {
                'color': (182 / 255.0, 174 / 255.0, 183 / 255.0,
                          1),  # color of tick labels and titles
                'bold': False
            },
            'tick_color': (1, 1, 1, 1),  # ticks and grid
            'border_color': (182 / 255.0, 174 / 255.0, 183 / 255.0, 1)
        }  # border drawn around each graph

        # Monthly cost graph
        self.graph1 = Graph(xlabel='Months',
                            ylabel='Costs',
                            size_hint=(0.7, 0.9),
                            pos_hint={
                                'center_x': .5,
                                'center_y': 0.5
                            },
                            x_ticks_major=5,
                            y_ticks_major=10,
                            y_grid_label=True,
                            x_grid_label=True,
                            padding=5,
                            xmin=0,
                            xmax=12,
                            ymin=0,
                            ymax=80,
                            **self.graph_theme)

        # Weekly cost graph
        self.graph2 = Graph(xlabel='Weeks',
                            ylabel='Costs',
                            size_hint=(0.7, 0.9),
                            pos_hint={
                                'center_x': .5,
                                'center_y': 0.5
                            },
                            x_ticks_major=5,
                            y_ticks_major=10,
                            y_grid_label=True,
                            x_grid_label=True,
                            padding=5,
                            xmin=0,
                            xmax=20,
                            ymin=0,
                            ymax=80,
                            **self.graph_theme)

        # Daily cost graph
        self.graph8 = Graph(xlabel='Days',
                            ylabel='Costs',
                            size_hint=(0.7, 0.9),
                            pos_hint={
                                'center_x': .5,
                                'center_y': 0.5
                            },
                            x_ticks_major=5,
                            y_ticks_major=10,
                            y_grid_label=True,
                            x_grid_label=True,
                            padding=5,
                            xmin=0,
                            xmax=150,
                            ymin=0,
                            ymax=80,
                            **self.graph_theme)

        # Monthly mistakes graph
        self.graph5 = Graph(xlabel='Months',
                            ylabel='Mistakes',
                            size_hint=(0.7, 0.9),
                            pos_hint={
                                'center_x': .5,
                                'center_y': 0.5
                            },
                            x_ticks_major=5,
                            y_ticks_major=1,
                            y_grid_label=True,
                            x_grid_label=True,
                            padding=5,
                            xmin=0,
                            xmax=12,
                            ymin=0,
                            ymax=5,
                            **self.graph_theme)

        # Weekly mistakes graph
        self.graph6 = Graph(xlabel='Weeks',
                            ylabel='Mistakes',
                            size_hint=(0.7, 0.9),
                            pos_hint={
                                'center_x': .5,
                                'center_y': 0.5
                            },
                            x_ticks_major=5,
                            y_ticks_major=1,
                            y_grid_label=True,
                            x_grid_label=True,
                            padding=5,
                            xmin=0,
                            xmax=25,
                            ymin=0,
                            ymax=5,
                            **self.graph_theme)

        # Daily mistakes graph
        self.graph7 = Graph(xlabel='Days',
                            ylabel='Mistakes',
                            size_hint=(0.7, 0.9),
                            pos_hint={
                                'center_x': .5,
                                'center_y': 0.5
                            },
                            x_ticks_major=5,
                            y_ticks_major=1,
                            y_grid_label=True,
                            x_grid_label=True,
                            padding=5,
                            xmin=0,
                            xmax=150,
                            ymin=0,
                            ymax=5,
                            **self.graph_theme)
Пример #30
0
from math import sin
from kivy.garden.graph import Graph, MeshLinePlot
graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5,
x_ticks_major=25, y_ticks_major=1,
y_grid_label=True, x_grid_label=True, padding=5,
x_grid=True, y_grid=True, xmin=-0, xmax=100, ymin=-1, ymax=1)
plot = MeshLinePlot(color=[1, 0, 0, 1])
plot.points = [(x, sin(x / 10.)) for x in range(0, 101)]
graph.add_plot(plot)