Beispiel #1
0
 def tabProbabilityTesting(self):
     '''
     tab containing plot of probability distributions from various user-specificed pools of dice
     '''
     self.plotColorMap = [
         [1,0,0,1],
         [0,1,0,1],
         [0,0,1,1],
         [1,1,0,1],
         [1,0,1,1],
         [0,1,1,1],
         [1,1,1,1],
         [0.75,0.75,0.75,1]]
     tabProb = TabbedPanelItem(text = 'Prob. Plots')
     self.statsMainLayout = BoxLayout(orientation = 'vertical')
     self.entryLayout =  BoxLayout(orientation = 'vertical',size_hint = (1,0.45))
     buttonLayout = BoxLayout(size_hint = (1,0.05))
     self.graphLayout = BoxLayout(size_hint = (1,0.5))
     self.graph = Graph(xlabel='Value', ylabel='Counts', 
         x_ticks_minor=1,x_ticks_major=2, y_ticks_minor = 100, y_ticks_major=500,
         y_grid_label=True, x_grid_label=True, padding=5,
         x_grid=True, y_grid=True, xmin=-0, xmax=15, ymin=0,ymax = 5000)
     self.graphLayout.add_widget(self.graph)
     self.plotList = []
     self.statsMainLayout.add_widget(self.entryLayout)
     self.statsMainLayout.add_widget(buttonLayout)
     self.statsMainLayout.add_widget(self.graphLayout)
     self.testList = []
     self.appendNewTest(self.entryLayout,readOnly = True) 
     self.testList.append(self.appendNewTest(self.entryLayout)) 
     buttonList = [['Add New Test','Plot Results','Reset']]
     buttonFunctionList = [[self.fireNewTestButton,self.firePlotButton,self.fireResetTestsButton]]
     self.addButtons(buttonList,buttonFunctionList,buttonLayout)
     tabProb.add_widget(self.statsMainLayout)
     return tabProb    
Beispiel #2
0
    def __init__(self, ticker):
        self.CurrentPrice = 100
        self.ticker = ticker
        self.cryptos = []
        self.yticks = 100

        self.xticks = 10
        self.xmax = 50
        self.chart = Graph(
            xlabel='Time',
            ylabel='Price',
            x_ticks_minor=0,
            x_ticks_major=self.xticks,
            y_ticks_major=self.yticks,
            y_grid_label=True,
            x_grid_label=True,
            padding=5,
            x_grid=True,
            y_grid=True,
            xmin=0,
            xmax=self.xmax,
            ymin=0,
        )

        self.plot = SmoothLinePlot(color=[1, 1, 1, 1])
        self.chart.add_plot(self.plot)
Beispiel #3
0
    def __init__(self, information=None):
        super(Logic, self).__init__()

        if information is None:
            information = dict()

        self.information = information

        self.mi = dict()
        self.nmi = dict()
        self.tmi = dict()
        self.twomi = dict()

        self.graph = Graph(xlabel='X',
                           ylabel='Y',
                           x_ticks_minor=.25,
                           x_ticks_major=1,
                           y_ticks_minor=1,
                           y_ticks_major=1,
                           y_grid_label=True,
                           x_grid_label=True,
                           padding=5,
                           x_grid=True,
                           y_grid=True,
                           xmin=-1,
                           xmax=24,
                           ymin=-1,
                           ymax=1)
        self.red_plot = MeshLinePlot(color=[1, 0, 0, 1])
        self.gre_plot = MeshLinePlot(color=[0, 1, 0, 1])
        self.blu_plot = MeshLinePlot(color=[0, 0, 1, 1])
        self.yel_plot = MeshLinePlot(color=[1, 1, 0, 1])

        self.add_widget(widget=self.graph)
def make_plot(ratings_list, plot_dates, plot_tickers, plot_colors):
    # Prepare the data
    x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

    # make the graph
    graph = Graph(ylabel='Ratings',
                  x_ticks_major=1,
                  y_ticks_minor=1,
                  y_ticks_major=1,
                  y_grid_label=True,
                  x_grid_label=False,
                  padding=5,
                  x_grid=True,
                  y_grid=True,
                  xmin=0,
                  xmax=10,
                  ymin=0,
                  ymax=10)

    if (len(plot_tickers) > 0):
        i = 0
        while (i < len(plot_tickers)):
            plot = MeshLinePlot(color=plot_colors[i])
            plot.points = [(i, j) for i, j in zip(x, ratings_list[i])]

            graph.add_plot(plot)
            i += 1

    return graph
Beispiel #5
0
 def yap(self, za):
     box = self.ids.deneme
     graph_theme = {
         'label_options': {
             'color': rgb('444444'),  # color of tick labels and titles
             'bold': True
         },
         'background_color': rgb('2b2b2b'),  # canvas background color
         'tick_color': rgb('7ba21d'),  # ticks and grid
         'border_color': rgb('000000')
     }  # border drawn around each graph
     self.graph = Graph(
         xlabel='Time (s)',
         ylabel='Temparature (°F)',
         x_ticks_major=10,
         y_ticks_major=10,
         y_grid_label=True,
         x_grid_label=True,
         padding=5,
         #xmin=0,
         #ymin=0,
         **graph_theme)
     box.add_widget(self.graph)
     self.plot = LinePlot(line_width=2, color=[0.48, 0.63, 0.11, 1])
     self.graph.add_plot(self.plot)
     self.salise = 0
     self.saniye = 0
     self.dakika = 0
     self.values = []
Beispiel #6
0
class ScreenRace:

    sogMemory = 30  # seconds
    sogHistory = []

    def __init__(self, gui=None):
        if gui == None:
            print("ScreenRace __init__ with gui == None - need to set it up!")
        else:
            self.gui = gui

        self.th = TimeHelper()

    def setGui(self, gui):
        self.gui = gui

    def setupGui(self):
        self.sogG = Graph(
            ymax=1.0,
            ymin=-1.0,
        )
        self.sogP = MeshLinePlot(color=[1, 1, 0, 1])
        self.sogG.add_plot(self.sogP)
        self.gui.rl.ids.flRace.add_widget(self.sogG)

    def on_settings(self, o=None):
        print("on_settings")

    def update(self, fromWho, vals):
        #print("sogUpdate" ,fromWho, vals)
        self.sogHistory.append(vals['speed'])
    def __init__(self, **kwargs):
        super(GraphPlot, self).__init__(**kwargs)
        self.y_range = 10
        self.x_range = 10
        self.range_multiplier = [2, 2.5, 2]
        self.graph = Graph(xlabel="x",
                           ylabel="y",
                           x_ticks_major=self.x_range / 2,
                           y_ticks_major=self.y_range / 2,
                           y_grid_label=True,
                           x_grid_label=True,
                           x_grid=True,
                           y_grid=True,
                           xmin=-self.x_range,
                           xmax=self.x_range,
                           ymin=-self.y_range,
                           ymax=self.y_range,
                           draw_border=False)
        # graph.size = (1200, 400)
        # self.graph.pos = self.center

        self.plot = MeshLinePlot(color=[1, 1, 1, 1])
        x = -self.x_range
        self.plot.points = []
        while x < self.x_range:
            try:
                self.plot.points.append((x, sin(x)))
            except ZeroDivisionError:
                pass

            x += self.x_range / 100
        self.add_widget(self.graph)

        self.graph.add_plot(self.plot)
def make_plot(plot_price,
              plot_dates,
              tickers_on_plot,
              plot_colors,
              xlabel='Bitcoin'):
    x = list(range(1, (len(plot_price) + 1)))
    y = plot_price
    y_axis_ticks = (max(y) - min(y)) / 5
    plot = None
    graph = Graph(xlabel=xlabel,
                  x_ticks_major=1,
                  y_ticks_major=y_axis_ticks,
                  y_grid_label=True,
                  x_grid_label=True,
                  padding=10,
                  x_grid=False,
                  y_grid=False,
                  xmin=min(x),
                  xmax=max(x),
                  ymin=min(y),
                  ymax=max(y))

    for i in range(0, len(tickers_on_plot)):
        plot = MeshLinePlot(color=plot_colors[i])
        plot.points = [(i, j) for i, j in zip(x, (y))]
        graph.add_plot(plot)
    return graph
Beispiel #9
0
class LiveView(Widget):
    def __init__(self, **kwargs):
        super().__init__()
        self.graph = Graph(x_ticks_minor=4,
                           x_ticks_major=16,
                           y_grid_label=True,
                           x_grid_label=True,
                           padding=5,
                           x_grid=True,
                           y_grid=True,
                           xmin=-0,
                           xmax=SAMPLES,
                           ymin=0,
                           **kwargs)
        self.plot = MeshLinePlot(color=[1, 1, 0, 1])
        self.plot.points = [(x, 0) for x in range(0, SAMPLES + 1)]
        self.graph.add_plot(self.plot)
        self.total_plot = MeshLinePlot(color=[0, 1, 1, 1])
        self.total_plot.points = [(x, 0) for x in range(0, SAMPLES + 1)]
        self.graph.add_plot(self.total_plot)

        self.values = collections.defaultdict(
            lambda: [0 for x in range(0, SAMPLES + 1)])

    def update(self, sender, date, value):
        self.values[sender][date] = value
        total = [self.values[sender][date] for sender in self.values.keys()]

        self.plot.points[date] = (date, value)
        self.total_plot.points[date] = (date, sum(total))
    def update(self):
        self.remove_widget(self.graph)
        self.graph = Graph(xlabel="x",
                           ylabel="y",
                           x_ticks_major=self.x_range / 2,
                           y_ticks_major=self.y_range / 2,
                           y_grid_label=True,
                           x_grid_label=True,
                           x_grid=True,
                           y_grid=True,
                           xmin=-self.x_range,
                           xmax=self.x_range,
                           ymin=-self.y_range,
                           ymax=self.y_range,
                           draw_border=False)
        self.plot = MeshLinePlot(color=[1, 1, 1, 1])
        x = -self.x_range
        self.plot.points = []
        while x < self.x_range:
            try:
                self.plot.points.append((x, sin(x)))
            except ZeroDivisionError:
                pass

            x += self.x_range / 100
        self.add_widget(self.graph)

        self.graph.add_plot(self.plot)
Beispiel #11
0
    def create_graph(self):
        colors = itertools.cycle([
            rgb('7dac9f'), rgb('dc7062'), rgb('66a8d4'), rgb('e5b060')
        ])
        graph_theme = {
            'label_options': {
                'color': (0, 0, 0, 1),
                'bold': False},
            'background_color': (.9, .9, .9, 1),
            'tick_color': rgb('808080'),
            'border_color': rgb('808080')
        }
        graph = Graph(xlabel='',
                      ylabel='Glicemia',
                      font_size=14,
                      x_ticks_minor=0,
                      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_theme)

        #plot = MeshLinePlot(color=[1, 0, 0, 1])
        plot = MeshLinePlot(color=next(colors))
        plot.points = [(x, sin(x/10.)) for x in range(0, 101)]
        graph.add_plot(plot)
        return graph
Beispiel #12
0
    def __init__(self, ticker):
        self.CurrentPrice = 0
        self.dt = 0
        self.ticker = ticker
        self.cryptos = []
        self.yticks = 100
        for dicto in json.loads(
                requests.get(
                    'https://finnhub.io/api/v1/crypto/symbol?exchange=binance&token=bvtss4748v6pijnevmqg'
                ).text):

            self.cryptos.append(dicto['symbol'])

        self.xticks = 10
        self.xmax = 50
        self.chart = Graph(
            xlabel='Time',
            ylabel='Price',
            x_ticks_minor=0,
            x_ticks_major=self.xticks,
            y_ticks_major=self.yticks,
            y_grid_label=True,
            x_grid_label=True,
            padding=5,
            x_grid=True,
            y_grid=True,
            xmin=0,
            xmax=self.xmax,
            ymin=0,
        )

        self.plot = SmoothLinePlot(color=[1, 1, 1, 1])
        self.chart.add_plot(self.plot)
Beispiel #13
0
    def create_graph(self):
        print("Création du graph ...")
        if self.graph:
            self.ids.graph_id.remove_widget(self.graph)

        xmin = self.get_xmin()

        self.graph = Graph(background_color=(0.8, 0.8, 0.8, 1),
                           border_color=(0, 0.1, 0.1, 1),
                           xlabel=self.xlabel,
                           ylabel=self.ylabel,
                           x_ticks_minor=self.x_ticks_minor,
                           x_ticks_major=self.x_ticks_major,
                           y_ticks_major=self.y_ticks_major,
                           x_grid_label=True,
                           y_grid_label=True,
                           padding=10,
                           x_grid=True,
                           y_grid=True,
                           xmin=xmin,
                           xmax=self.xmax,
                           ymin=self.ymin,
                           ymax=self.ymax,
                           tick_color=(1, 0, 1, 1),
                           label_options={'color': (0.2, 0.2, 0.2, 1)})

        self.graph.add_plot(self.curve_x)
        self.graph.add_plot(self.curve_y)
        self.graph.add_plot(self.curve_z)
        self.ids.graph_id.add_widget(self.graph)
Beispiel #14
0
 def setupGui(self):
     self.sogG = Graph(
         ymax=1.0,
         ymin=-1.0,
     )
     self.sogP = MeshLinePlot(color=[1, 1, 0, 1])
     self.sogG.add_plot(self.sogP)
     self.gui.rl.ids.flRace.add_widget(self.sogG)
Beispiel #15
0
 def build(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)
     plot = MeshLinePlot(color=[1, 0, 0, 1])
     plot.points = [(x, sin(x / 10.)) for x in range(0, 101)]
     graph.add_plot(plot)
     return graph
Beispiel #16
0
    def __init__(self, aircraft_config, **kwargs):
        super(AircraftLoadLayout, self).__init__(**kwargs)
        self.cols = 1
        self.cfg = load_aircraft_config(aircraft_config)
        self.loads = create_loads_list(self.cfg)

        acft = self.cfg.aircraft
        self.lbl_info = Label(text="%s (%s)" % (acft.designation, acft.immat))
        self.add_widget(self.lbl_info)

        self.sliders = SlidersLayout(self.cfg, self.loads)
        self.add_widget(self.sliders)

        self.lbl_center_gravity = Label(text="")
        self.add_widget(self.lbl_center_gravity)

        self.graph = Graph(
            xlabel="X",
            ylabel="mass",
            # x_ticks_minor=0.05, x_ticks_major=0.5,
            # y_ticks_major=100, # y_ticks_minor=20,
            y_grid_label=True,
            x_grid_label=True,
            padding=5,
            x_grid=True,
            y_grid=True,
            xmin=0.7,
            xmax=1.1,
            ymin=0,
            ymax=1000,
        )
        self.mesh_line_plot = MeshLinePlot(color=[0, 0, 1, 1])
        self.graph.add_plot(self.mesh_line_plot)

        self.add_widget(self.graph)

        self.btn_toggle = ToggleButton(
            text="lever arm / moment",
            group="xaxis",
        )
        self.btn_toggle.bind(on_press=self.on_touch_move)
        self.add_widget(self.btn_toggle)

        # point = Point(0.8, 400)
        # plot = ScatterPlot(color=(1,0,0,1), pointsize=5)
        self.scatter_plot = ScatterPlot(color=[1, 0, 0, 1], point_size=5)
        # plot.points.append((0.8, 400))
        self.graph.add_plot(self.scatter_plot)

        self.update_label_plot()
Beispiel #17
0
    def rainGraph(self):
        rainY = []
        for i in range(len(self.fileData) - 19, len(self.fileData)):
            rainY.append(str(math.floor((float(self.fileData[i][8])))))
        plot = None
        graph = Graph(size_hint = (0.5,0.8), pos_hint = {'x': .24, 'y': 0}, ylabel='Rain Events', xlabel='Time', x_ticks_major=1, y_ticks_minor=1,
                      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=50, background_color = [1,1,1,.2])

        plot = MeshLinePlot(color=[.5, 0, .5, 1])
        plot.points = [(int(i), int(rainY[i])) for i in range(0, 19)]
        graph.add_plot(plot)

        return graph
Beispiel #18
0
    def __init__(self, **kwargs):
        super(MyGraphs, self).__init__(**kwargs)
        self.cols = 1

        # Graphs init
        self.graph = graph = Graph(xlabel='čas',
                                   ylabel='C',
                                   x_ticks_minor=1,
                                   x_ticks_major=5,
                                   y_ticks_major=10,
                                   y_grid_label=True,
                                   x_grid_label=True,
                                   padding=5,
                                   x_grid=True,
                                   y_grid=True,
                                   xmin=-0,
                                   xmax=10,
                                   ymin=-1,
                                   ymax=1)

        self.backButton = Button(text="Back", size_hint=(1, .1))
        self.backButton.bind(on_touch_down=self.backButtonPressed)

        self.mainLayout = GridLayout(rows=2)
        self.mainLayout.add_widget(graph)
        self.mainLayout.add_widget(self.backButton)
        self.add_widget(self.mainLayout)
Beispiel #19
0
    def humidGraph(self):
        humidY = []

        for i in range(len(self.fileData) - 19, len(self.fileData)):
            humidY.append(str(math.floor((float(self.fileData[i][4])))))

        humidityPlot = None
        humidityGraph = Graph(size_hint = (0.5,0.8), pos_hint = {'x': .24, 'y': 0}, ylabel='% Humidity', xlabel='Time', x_ticks_major=1, y_ticks_minor=1, 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=100, background_color = [1,1,1,.2])

        humidityPlot = MeshLinePlot(color=[.5,0 ,.5, 1])
        humidityPlot.points = [(int(i), int(humidY[i])) for i in range(0, 19)]
        humidityGraph.add_plot(humidityPlot)

        return humidityGraph
Beispiel #20
0
class linechart():
    def __init__(self, ticker):
        self.CurrentPrice = 100
        self.ticker = ticker
        self.cryptos = []
        self.yticks = 100

        self.xticks = 10
        self.xmax = 50
        self.chart = Graph(
            xlabel='Time',
            ylabel='Price',
            x_ticks_minor=0,
            x_ticks_major=self.xticks,
            y_ticks_major=self.yticks,
            y_grid_label=True,
            x_grid_label=True,
            padding=5,
            x_grid=True,
            y_grid=True,
            xmin=0,
            xmax=self.xmax,
            ymin=0,
        )

        self.plot = SmoothLinePlot(color=[1, 1, 1, 1])
        self.chart.add_plot(self.plot)

    def update(self, data):

        #sizing graph adding upper buffer
        self.chart.ymax = round((data['ymax'] + data['ymax'] / 4) / 10) * 10
        self.chart.ymin = round((data['ymin'] - data['ymin'] / 4) / 10) * 10
        #sizing xmax
        self.xmax = len(data['plot'])

        self.plots = data['plot']
        self.CurrentPrice = data['CurrentPrice']

        self.yticks = (self.chart.ymax - self.chart.ymin) / 4
        self.chart.y_ticks_major = self.yticks
        self.plot.points = self.plots
        self.xmax = len(self.plot.points) - 1
        self.chart.xmax = self.xmax

    def Get_graph(self):
        return self.chart
Beispiel #21
0
    def tempGraph(self):

        tempY =[]

        for i in range(len(self.fileData) - 19, len(self.fileData)):
            tempY.append(str(math.floor((float(self.fileData[i][6])))))

        plot = None
        graph = Graph(size_hint = (.5,.8), ylabel='Outside Temperature (C)', xlabel = 'Time', x_ticks_major = 1, y_ticks_minor = 1, 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=-10, ymax=50, pos_hint = {'x': .24, 'y': .2}, background_color = [1,1,1,.2])

        plot = MeshLinePlot(color = [1,1,1,1])

        plot.points = [(int(i), int(tempY[i])) for i in range(0, 19)]
        graph.add_plot(plot)
        return graph
 def default_graph_waveform(self):
     self.graph = Graph(xlabel='t (s) or steps',
                        ylabel='BP (mmHg)',
                        x_ticks_minor=5,
                        x_ticks_major=1.0,
                        y_ticks_major=50,
                        y_grid_label=True,
                        x_grid_label=True,
                        padding=5,
                        x_grid=True,
                        y_grid=True,
                        xmin=-0,
                        xmax=10.0,
                        ymin=0,
                        ymax=240)
     self.plot = MeshLinePlot(color=[1, 1, 1, 1])
     self.plot.points = [(x * 0.02, 5) for x in range(0, 501)]
     self.graph.add_plot(self.plot)
Beispiel #23
0
    def __init__(self, game, screen, **kwargs):
        super(StateInfoBar, self).__init__(game, screen, **kwargs)

        # Right graph
        self.graph1 = graph1 = Graph(xlabel='Game',
                                     ylabel='Reward',
                                     x_ticks_major=self.DEFAULT_X_TICKS_MAJOR,
                                     y_ticks_major=self.DEFAULT_Y_TICKS_MAJOR,
                                     y_grid_label=True,
                                     x_grid_label=True,
                                     padding=5,
                                     x_grid=True,
                                     y_grid=True,
                                     xmin=self.DEFAULT_XMIN,
                                     xmax=self.DEFAULT_XMAX,
                                     ymin=self.DEFAULT_YMIN,
                                     ymax=self.DEFAULT_YMAX)

        self.plot1 = plot1 = MeshLinePlot(color=[1, 0, 0, 1])
        plot1.points = []
        graph1.add_plot(plot1)

        self.ids["graph1"].add_widget(graph1)

        # Left graph
        self.graph2 = graph2 = Graph(xlabel='Generation',
                                     ylabel='MaxFitness',
                                     x_ticks_major=self.DEFAULT_X_TICKS_MAJOR,
                                     y_ticks_major=self.DEFAULT_Y_TICKS_MAJOR,
                                     y_grid_label=True,
                                     x_grid_label=True,
                                     padding=5,
                                     x_grid=True,
                                     y_grid=True,
                                     xmin=self.DEFAULT_XMIN,
                                     xmax=self.DEFAULT_XMAX,
                                     ymin=self.DEFAULT_YMIN,
                                     ymax=self.DEFAULT_YMAX)

        self.plot2 = plot2 = MeshLinePlot(color=[0, 1, 0, 1])
        plot2.points = []
        graph2.add_plot(plot2)

        self.ids["graph2"].add_widget(graph2)
Beispiel #24
0
    def create_graph(self):
        """Création du graph seul et pas d'ajout au widget"""

        print("Appel de la création du graph ..")
        self.unit_x = "minutes"

        # Paramètres du graph en x
        self.xmin = 0
        self.xmax = 1000
        self.x_ticks_major = 3600
        self.x_ticks_minor = 600

        # Paramètres du graph en y
        self.ymin = 0
        self.ymax = self.y_major
        self.ylabel = self.unit_y
        self.y_ticks_major = self.y_major / 10
        self.y_ticks_minor = 0  #5

        # Je crée ou recrée
        self.graph = Graph(background_color=(0.8, 0.8, 0.8, 1),
                           border_color=(0, 0.1, 0.1, 1),
                           xlabel=self.xlabel,
                           ylabel=self.ylabel,
                           x_ticks_minor=self.x_ticks_minor,
                           x_ticks_major=self.x_ticks_major,
                           y_ticks_major=self.y_ticks_major,
                           x_grid_label=True,
                           y_grid_label=True,
                           padding=10,
                           view_pos=(10, -10),
                           x_grid=True,
                           y_grid=True,
                           xmin=self.xmin,
                           xmax=self.xmax,
                           ymin=self.ymin,
                           ymax=self.ymax,
                           tick_color=(1, 0, 1, 1),
                           label_options={'color': (0.2, 0.2, 0.2, 1)})

        self.graph.add_plot(self.curve_plot)
        self.ids.graph_id.add_widget(self.graph)
Beispiel #25
0
def all_graph(Shear_list, length, position, label):
    datapoints = np.arange(0, length, 0.01)
    point_data_list = []
    multiplier = 1
    if label == "Bending moment (kNm)" or label == "Deflection (1/EI)" or 'Axial Stress (kN)':
        multiplier = -1
    ymax = 0
    ymin = 0
    min_y = 0
    max_y = 0
    for i in range(len(datapoints)):
        point_data = 0
        for all in Shear_list:
            point_data += all.calculate(datapoints[i])*multiplier
        if point_data + abs(point_data / 5) > ymax:
            ymax = point_data + abs(point_data / 5)
        elif ymin > point_data - abs(point_data / 5):
            ymin = point_data - abs(point_data / 5)
        point_data_list.append((datapoints[i], point_data))
        if i == 0:
            max_y = point_data
            min_y = point_data
        else:
            max_y = max(point_data, max_y)
            min_y = min(point_data, min_y)
    ymax = int(round(ymax, 0))
    ymin = int(round(ymin, 0))
    max_y = round(max_y, 3)
    min_y = round(min_y, 3)
    if ymax == 0:
        ymax = 1
    if ymin == 0:
        ymin = -1
    graph = Graph(pos_hint=position, size_hint=(0.7, 0.9), xlabel='Position', ylabel=label, x_ticks_minor=5,
                  x_ticks_major=length / 10, x_grid_label=True, y_grid_label=True, y_ticks_major=(ymax-ymin)/5,
                  y_ticks_minor=5, padding=5, x_grid=True, y_grid=True, xmax=length, xmin=0, ymin=ymin, ymax=ymax)
    plot = MeshLinePlot()
    plot.points = point_data_list
    graph.add_plot(plot)
    return graph, [min_y, max_y]
Beispiel #26
0
    def create_graph(self, dates):
        if len(dates) > 0:
            graph = Graph(x_ticks_minor=5,
                          y_ticks_minor=5,
                          x_ticks_major=5,
                          y_ticks_major=5,
                          y_grid_label=True,
                          x_grid_label=True,
                          padding=5,
                          border_color=[0, 0, 0, 0],
                          font_size=8,
                          xmin=0,
                          xmax=calendar.monthrange(dates[0].year,
                                                   dates[0].month)[1],
                          ymin=int(min([x.weight for x in dates]) - 5),
                          ymax=int(max([x.weight for x in dates]) + 5))
        else:
            graph = Graph(x_ticks_minor=5,
                          y_ticks_minor=5,
                          x_ticks_major=5,
                          y_ticks_major=5,
                          y_grid_label=True,
                          x_grid_label=True,
                          padding=5,
                          border_color=[0, 0, 0, 0],
                          font_size=8,
                          xmin=0,
                          ymin=0)

        plot = SmoothLinePlot(color=[1, 105 / 255, 97 / 255, 1])
        plot.points = [(x.day, float(x.weight)) for x in dates]
        graph.add_plot(plot)

        return graph
Beispiel #27
0
    def __init__(self, **kwargs):
        super().__init__()
        self.graph = Graph(x_ticks_minor=4,
                           x_ticks_major=16,
                           y_grid_label=True,
                           x_grid_label=True,
                           padding=5,
                           x_grid=True,
                           y_grid=True,
                           xmin=-0,
                           xmax=SAMPLES,
                           ymin=0,
                           **kwargs)
        self.plot = MeshLinePlot(color=[1, 1, 0, 1])
        self.plot.points = [(x, 0) for x in range(0, SAMPLES + 1)]
        self.graph.add_plot(self.plot)
        self.total_plot = MeshLinePlot(color=[0, 1, 1, 1])
        self.total_plot.points = [(x, 0) for x in range(0, SAMPLES + 1)]
        self.graph.add_plot(self.total_plot)

        self.values = collections.defaultdict(
            lambda: [0 for x in range(0, SAMPLES + 1)])
Beispiel #28
0
    def __init__(self, **kwargs):
        super(StockDetailScreen, self).__init__(**kwargs)

        self.layout = CustomLayout()
        back_img = lm.createImage(source='images/back.png', rel_size=lm.rel_square(rel_width=.1))
        self.layout.add_item(CustomButton(back_img, on_release_func=lambda: back(self.manager), alignment='left'))

        self.stock_name = lm.createLabel(bold= False, rel_size= (1, .1), text_rel_size = (.95, .1), halign='center', valign='middle')
        self.layout.add_item(self.stock_name)

        self.layout.add_widget(Button(text="TRADE", bold=True, font_size=40,
                                        background_color=DARK_GREEN, on_release=self.trade),                                        
                                        rel_size=(.8, .1))

        self.current_price = lm.createLabel(font_size= 50, rel_size= (1, .1))

        self.layout.add_item(self.current_price)
        self.center_image = lm.createImage(source='images/up_arrow.png', rel_size=lm.rel_square(rel_width=.5))
        self.layout.add_item(self.center_image)

        self.stock_symbol = lm.createLabel(font_size= 50, rel_size= (1, .1))
        self.layout.add_item(self.stock_symbol)

        self.num_shares = lm.createLabel(font_size= 28, rel_size= (1, .1))
        self.layout.add_item(self.num_shares)

        self.layout.add_item(lm.createLabel(text = 'Past Week Performace', font_size= 28, rel_size= (1, .1)))

        # graph
        self.graph = Graph(x_ticks_major=1, tick_color = (0,0,0,.5), xlabel='Days',
              y_grid_label=True, x_grid_label=True, precision='%.2f', padding=5,
              x_grid=True, y_grid=True, xmin=-5, xmax=-1, ymin=0, ymax=100,
              border_color = (0,0,0,0), label_options = {'color': (0,0,0,1)})        

        self.plot = [(i-7, .3*i*100) for i in range(7)]

        self.layout.add_widget(self.graph, rel_size=(.90, .3))

        self.add_widget(self.layout.create())
class UIApp(App):
    def init(self):
        self.read_pulse_table()

    def build(self):
        self.savef = None
        self.state = None
        self.baselineHR = 60.0  # baseline HR
        self.Ts = 1.0 / 50.0  # sampling period
        self.modulation = 0.1  # how much to modulate the pressure wave via RR
        self.pressure = Pressure()
        superBox = BoxLayout(orientation='vertical')
        HB = BoxLayout(orientation='horizontal')
        cell1 = BoxLayout(orientation='vertical')
        self.textinputHomePos = FloatInput(text='100')
        cell1h = BoxLayout(orientation='horizontal')
        label = Label(text='Home Pos')
        cell1h.add_widget(label)
        cell1h.add_widget(self.textinputHomePos)

        self.textinputCalibMax = FloatInput(text='1500')
        cell1bh = BoxLayout(orientation='horizontal')
        label = Label(text='Calib Max')
        cell1bh.add_widget(label)
        cell1bh.add_widget(self.textinputCalibMax)

        self.textinputCalibInc = FloatInput(text='25')
        cell1ch = BoxLayout(orientation='horizontal')
        label = Label(text='Calib Inc')
        cell1ch.add_widget(label)
        cell1ch.add_widget(self.textinputCalibInc)

        self.textinputCalibDelay = FloatInput(text='0.1')
        cell1dh = BoxLayout(orientation='horizontal')
        label = Label(text='Calib Delay')
        cell1dh.add_widget(label)
        cell1dh.add_widget(self.textinputCalibDelay)

        self.home_button = Button(text='Home')
        self.home_button.bind(on_press=self.home)
        self.home_button.background_color = default_bgnd
        self.calib_button = Button(text='Calibrate')
        self.calib_button.background_color = default_bgnd
        self.calib_button.bind(on_press=self.calibrate)

        cell1.add_widget(cell1h)
        cell1.add_widget(self.home_button)
        cell1.add_widget(cell1ch)
        cell1.add_widget(cell1bh)
        cell1.add_widget(cell1dh)
        cell1.add_widget(self.calib_button)

        HB.add_widget(cell1)
        self.pressure_button = Button(text='Read\nPressure')

        self.pressure_button.background_color = default_bgnd
        self.pressure_button.bind(on_press=self.read_pressure)

        cell1b = BoxLayout(orientation='vertical')
        cell1b.add_widget(self.pressure_button)
        self.pressure_label = Label(text='0.0 mmHg')
        cell1b.add_widget(self.pressure_label)

        HB.add_widget(cell1b)

        cell3 = BoxLayout(orientation='vertical')
        cell3a = BoxLayout(orientation='horizontal')
        label = Label(text='Systolic')
        self.textinputSystolic = FloatInput(text='120.0')
        cell3a.add_widget(label)
        cell3a.add_widget(self.textinputSystolic)
        cell3.add_widget(cell3a)

        cell3b = BoxLayout(orientation='horizontal')
        label = Label(text='Diastolic')
        self.textinputDiastolic = FloatInput(text='80.0')
        cell3b.add_widget(label)
        cell3b.add_widget(self.textinputDiastolic)
        cell3.add_widget(cell3b)

        cell3c = BoxLayout(orientation='horizontal')
        label = Label(text='HR')
        self.textinputHR = FloatInput(text='75.0')
        cell3c.add_widget(label)
        cell3c.add_widget(self.textinputHR)
        cell3.add_widget(cell3c)

        cell3d = BoxLayout(orientation='horizontal')
        label = Label(text='RR')
        self.textinputRR = FloatInput(text='10.0')
        cell3d.add_widget(label)
        cell3d.add_widget(self.textinputRR)
        cell3.add_widget(cell3d)

        HB.add_widget(cell3)

        self.play_button = Button(text='Play Waveform')

        self.play_button.background_color = default_bgnd
        self.play_button.bind(on_press=self.play_waveform)

        HB.add_widget(self.play_button)

        self.exit_button = Button(text='Exit')

        self.exit_button.background_color = default_bgnd
        self.exit_button.bind(on_press=self.exit_app)
        HB.add_widget(self.exit_button)

        superBox.add_widget(HB)
        #self.graph = Graph(xlabel='X', ylabel='Y', x_ticks_minor=5,
        #     x_ticks_major=25, y_ticks_major=50,
        #     y_grid_label=True, x_grid_label=True, padding=5,
        #     x_grid=True, y_grid=True, xmin=-0, xmax=500, ymin=0, ymax=200)
        #self.plot = MeshLinePlot(color=[1, 1, 1, 1])
        #self.plot.points = [(x, 50+50*math.sin(x / 10.)) for x in range(0, 501)]
        #self.graph.add_plot(self.plot)
        self.default_graph_waveform()
        superBox.add_widget(self.graph)
        #print(self.plot.points)
        return superBox

    def read_pulse_table(self):
        f = open('pulse256.dat', 'rb')
        a = f.read()
        f.close()
        self.pulse256 = struct.unpack("256h", a)
        #print(self.pulse256)

    def resample_HR(self, values, heartrate):
        out = []
        ratio = heartrate / self.baselineHR
        index = range(len(values))
        index0 = []
        x = 0
        while (x < (len(values) - 1)):
            index0.append(x)
            v = np.interp(x, index, values)
            out.append(v)
            x = x + ratio  # advance more slowly in time
        return out

    def default_graph_waveform(self):
        self.graph = Graph(xlabel='t (s) or steps',
                           ylabel='BP (mmHg)',
                           x_ticks_minor=5,
                           x_ticks_major=1.0,
                           y_ticks_major=50,
                           y_grid_label=True,
                           x_grid_label=True,
                           padding=5,
                           x_grid=True,
                           y_grid=True,
                           xmin=-0,
                           xmax=10.0,
                           ymin=0,
                           ymax=240)
        self.plot = MeshLinePlot(color=[1, 1, 1, 1])
        self.plot.points = [(x * 0.02, 5) for x in range(0, 501)]
        self.graph.add_plot(self.plot)

    def reset_graph_waveform(self):
        self.graph.xmin = 0
        self.graph.xmax = 10.0
        self.graph.x_ticks_major = 1.0
        self.plot.points = [(x * 0.02, 5) for x in range(0, 501)]

    def read_pressure_callback(self, x):
        (p, mm, t) = self.pressure.quick_read()
        swp = self.plot.points[self.index]
        copy = (self.index * 0.02, mm)
        self.plot.points[self.index] = copy
        self.index = (self.index + 1) % 500
        self.pressure_label.text = "%3.1f mmHg / %2.1f C" % (mm, t)

    def home_callback(self, x):
        h = int(self.textinputHomePos.text)
        print("home to %d" % h)
        self.pressure.home(h)
        self.state = None
        self.home_button.text = "Home Pos"
        self.home_button.background_color = [0.7, 0.7, 0.7, 1]
        return False

    def calibrate_inc_callback(self, x):
        p = self.pressure.one_calibrate(self.calib_inc, self.calib_delay)
        if (p >= self.calib_max):
            print("End calibrate")
            self.pressure.end_calibrate()
            self.state = None
            self.calib_button.text = "Calibrate"
            self.calib_button.background_color = [0.7, 0.7, 0.7, 1]
        else:
            self.home_event = Clock.schedule_once(self.calibrate_inc_callback,
                                                  0.0)
        print(self.calib_index, self.pressure.calib_mmHg,
              len(self.plot.points))
        self.plot.points[self.calib_index] = (
            self.pressure.calib_s[self.calib_index],
            self.pressure.calib_mmHg[self.calib_index])
        #print(self.plot.points)
        self.calib_index = self.calib_index + 1
        return False

    def calibrate_start_callback(self, x):
        h = int(self.textinputHomePos.text)
        cm = int(self.textinputCalibMax.text)
        ci = int(self.textinputCalibInc.text)

        cd = float(self.textinputCalibDelay.text)
        print("calibrate %d,%d, %d, %f" % (h, cm, ci, cd))
        h0 = h
        x = [h]
        while (h0 <= cm):
            h0 = h0 + ci
            x.append(h0)
        print(x)
        self.graph.xmin = h
        self.graph.xmax = cm
        self.graph.x_ticks_major = 100
        self.plot.points = []
        for x0 in x:
            self.plot.points.append((x0, 0))
        #self.graph.add_plot(self.plot)

        self.pressure.start_calibrate_curve(h, ci)
        self.calib_inc = ci
        self.calib_max = cm
        self.calib_delay = cd
        self.calib_index = 0
        self.home_event = Clock.schedule_once(self.calibrate_inc_callback,
                                              0.01)
        return False

    def play_more_callback(self, x):
        out = []
        for a in range(10):
            R = self.pressure.one_read_timeout()
            if (R is None):
                break
            else:
                s, t, pos = R
                p0 = np.interp(pos, self.steps, self.mmHgs)

                p1 = self.pressure.psi2mmHg(
                    int(s) * self.pressure.pressure_multiplier)
                t1 = float(t) * self.pressure.temp_multiplier
                #print(p0,p1)
                out.append(p0)
                out.append(p1)
                self.plot.points[self.play_i] = (
                    self.plot.points[self.play_i][0], p1)
                self.play_i = (self.play_i + 1) % 500
                self.pressure_label.text = "%3.1f mmHg / %2.1f C" % (p1, t1)
        if (self.savef):
            #print(out)
            s = struct.pack("{}f".format(len(out)), *out)
            self.savef.write(s)
        self.play_more_event = Clock.schedule_once(self.play_more_callback, 0)

    def play_calibrate_callback(self, x):
        # first get our waveform parameters
        h = int(self.textinputHomePos.text)
        cm = int(self.textinputCalibMax.text)
        ci = int(self.textinputCalibInc.text)
        systolic = float(self.textinputSystolic.text)
        diastolic = float(self.textinputDiastolic.text)
        heartrate = float(self.textinputHR.text)
        resprate = float(self.textinputRR.text)

        cd = float(self.textinputCalibDelay.text)
        print("play calibrate %d,%d, %d" % (h, cm, ci))
        print("Sys %f Dia %f" % (systolic, diastolic))
        (steps0, psi0, mmHg0) = self.pressure.calibrate_curve(h, cm, ci)
        self.steps = np.array(steps0)
        self.psis = np.array(psi0)
        self.mmHgs = np.array(mmHg0)
        # Now branch on whether using pulse_table (single pulse with cyclic indexing),
        # OR - whole waveform repeated.
        if (USE_PULSE_TABLE):
            print("Down with UPT....")
            v = self.pulse256
            minb = 0.0
            maxb = 8192.0
            print(minb, maxb)
            span = maxb - minb
            v0 = []
            # now convert to float actual mmHg value cycle
            for b in v:
                x = (float(b) - minb) / span * (systolic -
                                                diastolic) + diastolic
                v0.append(x)
            # and now calibrate to the right number of steps
            ys0 = []
            i = 0
            while (i < (len(v0))):
                x = v0[i]
                s = round(np.interp(x, self.mmHgs, self.steps))
                ys0.append(s)
                i = i + 1
            ys0.append(
                ys0[0])  # append the first value at the end for wrap-around
            self.pressure.write_table(ys0)
            hrindex = heartrate / 60.0 * 256.0 / 50.0  # index value per 20ms interval
            rrindex = resprate / 60.0 * 256.0 / 50  # index value per 20ms interval
            # now convert to X.8 format`
            print("Playing table...\n")
            self.pressure.play_table(round(hrindex * 256.0),
                                     round(rrindex * 256.0), cm, h)

        else:  # single recorded waveform sequence, possibly repeated
            f = open('TestPulses.dat', 'rb')
            a = f.readlines()
            f.close()
            values = []
            for l in a:
                x = float(l)
                values.append(x)

            v = values[:-20]
            if (not (self.baselineHR == heartrate)):
                print("RESAMPLING @ %f from %f" % (heartrate, self.baselineHR))
                values = self.resample_HR(values, heartrate)
            minb = 50000
            maxb = -50000
            for b in v:
                if (b > maxb):
                    maxb = b
            if (b < minb):
                minb = b
            print(minb, maxb)
            span = maxb - minb

            runs = 1
            v0 = []
            for i in range(runs):
                for b in v:
                    x = (b - minb) / span * (systolic - diastolic) + diastolic
                    v0.append(x)
            ys = []
            ys0 = []
            i = 0
            t = 0
            dt = 20e-3
            ts = []
            ps = []
            mms = []
            while (i < (len(v0))):
                x = v0[i]
                s = round(np.interp(x, self.mmHgs, self.steps))
                i = i + 25
                ts.append(t)
                t = t + dt
                ys0.append(s)

            for i in range(runs):
                for y in ys0:
                    ys.append(y)
            print(len(ys))
            self.pressure.write_waveform(ys)
            self.pressure.play_waveform(-1, cm, h)

        #self.pressure.start_reading()
        self.play_i = 0
        self.play_button.background_color = [0.7, 0.7, 0.7, 1]
        self.play_button.text = "Stop Playing..."
        self.state = "PLAY2"
        self.savef = open(SAVEFILE_NAME, "wb")
        self.play_more_event = Clock.schedule_once(self.play_more_callback, 0)
        return False

    def read_pressure(self, button):
        print("READ PRESSURE")
        if (self.state == None):
            self.index = 0
            self.state = 'PRESSURE'
            button.text = "Stop Reading\nPressure & Temp"
            button.background_color = [1, 0.5, 0.5, 1]
            self.reset_graph_waveform()
            self.pressure_event = Clock.schedule_interval(
                self.read_pressure_callback, 0.25)
        elif (self.state == 'PRESSURE'):
            self.state = None
            button.text = "Read\nPressure & Temp"
            button.background_color = [0.7, 0.7, 0.7, 1]
            self.pressure_event.cancel()

    def home(self, button):
        print("HOME")
        if (self.state == None):
            self.index = 0
            self.state = 'HOME'
            button.text = "Going Home"
            button.background_color = [1, 0.5, 0.5, 1]
            self.home_event = Clock.schedule_once(self.home_callback, 0.1)

    def calibrate(self, button):
        print("CALIBRATE")
        if (self.state == None):
            self.state = 'CALIBRATE'
            button.text = "Calibrating..."
            button.background_color = [1, 0.5, 0.5, 1]
            self.home_event = Clock.schedule_once(
                self.calibrate_start_callback, 0.25)

    def play_stop_callback(self, x):
        print("PLAY STOP CALLBACK")
        if (self.savef):
            self.savef.close()
            self.savef = None
        self.play_more_event.cancel()
        for i in range(1):  # drain any old readings
            s = self.pressure.one_read_timeout()
            if (not s):
                break
        #self.pressure.stop_reading()
        self.play_button.text = "Play Waveform"
        self.play_button.background_color = [0.7, 0.7, 0.7, 1]

        self.play_event.cancel()

    def play_waveform(self, button):
        print("PLAY WAVEFORM")
        if (self.state == None):
            self.state = 'PLAY'
            self.play_button.text = "Calibrating..."
            self.play_button.background_color = [1, 0.5, 0.5, 1]
            self.play_event = Clock.schedule_once(self.play_calibrate_callback,
                                                  0.25)
        elif (self.state == 'PLAY2'):
            print("STOPPING")
            self.pressure.set_params(1)
            print("STOPPING")
            self.state = None
            self.play_button.text = "Stopping Waveform"
            self.play_button.background_color = [0.5, 0.5, 1, 1]
            self.play_event = Clock.schedule_once(self.play_stop_callback,
                                                  0.25)

    def exit_app(self, button):
        print("EXIT")
        self.stop()
        self.root_window.close()
class GraphPlot(RelativeLayout):
    def __init__(self, **kwargs):
        super(GraphPlot, self).__init__(**kwargs)
        self.y_range = 10
        self.x_range = 10
        self.range_multiplier = [2, 2.5, 2]
        self.graph = Graph(xlabel="x",
                           ylabel="y",
                           x_ticks_major=self.x_range / 2,
                           y_ticks_major=self.y_range / 2,
                           y_grid_label=True,
                           x_grid_label=True,
                           x_grid=True,
                           y_grid=True,
                           xmin=-self.x_range,
                           xmax=self.x_range,
                           ymin=-self.y_range,
                           ymax=self.y_range,
                           draw_border=False)
        # graph.size = (1200, 400)
        # self.graph.pos = self.center

        self.plot = MeshLinePlot(color=[1, 1, 1, 1])
        x = -self.x_range
        self.plot.points = []
        while x < self.x_range:
            try:
                self.plot.points.append((x, sin(x)))
            except ZeroDivisionError:
                pass

            x += self.x_range / 100
        self.add_widget(self.graph)

        self.graph.add_plot(self.plot)

    def on_touch_down(self, touch):
        if touch.is_mouse_scrolling:
            # for whatever reason, the definition of scrollup and scrolldown are reversed
            if touch.button == 'scrollup':
                self.zoomOut()
            elif touch.button == 'scrolldown':
                self.zoomIn()

    def zoomIn(self):
        print(self.x_range)
        self.x_range = multiplyByFloat(self.x_range,
                                       1 / self.range_multiplier[0])
        self.y_range = multiplyByFloat(self.y_range,
                                       1 / self.range_multiplier[0])
        self.range_multiplier.insert(0, self.range_multiplier[2])
        del self.range_multiplier[-1]
        self.update()

    def zoomOut(self):
        print(self.x_range)
        self.x_range = multiplyByFloat(self.x_range, self.range_multiplier[0])
        self.y_range = multiplyByFloat(self.y_range, self.range_multiplier[0])
        self.range_multiplier.append(self.range_multiplier[0])
        self.range_multiplier.remove(self.range_multiplier[0])
        self.update()

    def update(self):
        self.remove_widget(self.graph)
        self.graph = Graph(xlabel="x",
                           ylabel="y",
                           x_ticks_major=self.x_range / 2,
                           y_ticks_major=self.y_range / 2,
                           y_grid_label=True,
                           x_grid_label=True,
                           x_grid=True,
                           y_grid=True,
                           xmin=-self.x_range,
                           xmax=self.x_range,
                           ymin=-self.y_range,
                           ymax=self.y_range,
                           draw_border=False)
        self.plot = MeshLinePlot(color=[1, 1, 1, 1])
        x = -self.x_range
        self.plot.points = []
        while x < self.x_range:
            try:
                self.plot.points.append((x, sin(x)))
            except ZeroDivisionError:
                pass

            x += self.x_range / 100
        self.add_widget(self.graph)

        self.graph.add_plot(self.plot)