예제 #1
0
    def __init__(self, retour_selection, titre, parent_scm,
                 dict_eleves_par_groupe, **kwargs):
        self.titre = titre
        self.retour_selection = retour_selection
        self.parent_scm = parent_scm
        self.dict_eleves = dict_eleves_par_groupe
        self.dict_panneau_groupe = dict()
        super(Formation, self).__init__(**kwargs)

        for nom_groupe in self.dict_eleves.keys():
            tb = TabbedPanelItem(text=nom_groupe)
            panneaugr = PanneauGroupe(self.dict_eleves[nom_groupe],
                                      nom_cours=titre)
            self.dict_panneau_groupe[nom_groupe] = panneaugr
            tb.add_widget(panneaugr)
            self.nb.add_widget(tb)

        fin = TabbedPanelItem(text='Terminer')
        self.panfin = PanneauFinFormation(self.terminaison, self.recapitulatif)
        fin.add_widget(self.panfin)
        fin.bind(on_release=self.panfin.update)
        self.nb.add_widget(fin)
        self.panneau_fin = fin
        retour = TabbedPanelHeader(text='Retour')
        retour.bind(on_release=self.retour)
        self.nb.add_widget(retour)
        self.panneau_retour = retour
예제 #2
0
    def __init__(self, df, security_name, **kwargs):
        super(Application, self).__init__(**kwargs)
        self.orientation = 'vertical'
        tab_panel = TabbedPanel()
        tab_panel.do_default_tab = False
        tab_panel.background_color = (7 / 255, 0, 13 / 255, 1)
        tab_menu = TabbedPanelItem(text="Menu")
        tab_menu.background_color = (62 / 255, 142 / 255, 222 / 255, 1)
        tab_chart = TabbedPanelItem(text='Chart')
        tab_chart.background_color = (62 / 255, 142 / 255, 222 / 255, 1)
        tab_training = TabbedPanelItem(text='Training')
        tab_training.background_color = (62 / 255, 142 / 255, 222 / 255, 1)
        tab_validate = TabbedPanelItem(text='Validate')
        tab_validate.background_color = (62 / 255, 142 / 255, 222 / 255, 1)
        tab_future = TabbedPanelItem(text='Prediction')
        tab_future.background_color = (62 / 255, 142 / 255, 222 / 255, 1)

        tab_panel.add_widget(tab_menu)
        tab_panel.add_widget(tab_chart)
        tab_panel.add_widget(tab_training)
        tab_panel.add_widget(tab_validate)
        tab_panel.add_widget(tab_future)

        tab_menu.bind(on_press=lambda x: change_screen('menu'))

        chart_layout = FloatLayout()
        fig = plot_data(df, security_name.upper(), 30, 200)
        canvas = fig.canvas
        chart_layout.add_widget(canvas)
        tab_chart.add_widget(chart_layout)

        predict_frame = FloatLayout(opacity=1)
        predict_btn = Button(text='Run Prediction',
                             background_color=(62 / 255, 142 / 255, 222 / 255,
                                               1),
                             font_size=20,
                             pos_hint={
                                 "center_x": 0.5,
                                 "bottom": 0
                             },
                             size_hint=(0.3, 0.075))

        predict_btn.bind(on_press=lambda x: start_predict(df, security_name))
        predict_frame.add_widget(predict_btn)
        chart_layout.add_widget(predict_frame)

        def start_predict(df, security_name):
            que = queue.Queue()
            par_modeling = partial(modeling, security_name=security_name)
            process = threading.Thread(
                target=lambda q, arg1: q.put(par_modeling(arg1)),
                args=(que, df),
                daemon=True)
            process.start()

            Clock.schedule_once(
                lambda *args: tab_panel.switch_to(tab_training))

            train_fig = plt.figure(facecolor='#07000d')
            train_canvas = train_fig.canvas
            train_layout = FloatLayout()
            train_layout.add_widget(train_canvas)
            tab_training.add_widget(train_layout)

            if os.path.exists('training.csv'):
                os.remove('training.csv')

            def update_plot(fig):
                train_canvas = fig.canvas
                train_layout.clear_widgets()
                train_layout.add_widget(train_canvas)
                plt.close(fig)
                # for child in train_layout.children[:1]:
                #     train_layout.remove_widget(child)
                # Clock.schedule_once(lambda *args: tab_panel.switch_to(tab_training))

            def read_training(self):
                if os.path.exists('training.csv'):
                    loss_df = None
                    try:
                        loss_df = pd.read_csv('training.csv')
                    except Exception as e:
                        print(e)
                        pass
                    if loss_df is not None:
                        train_fig = plot_loss(loss_df)
                        update_plot(train_fig)
                if not process.is_alive():
                    Clock.unschedule(read_training)
                    val_fig, future_fig = que.get()
                    val_canvas = val_fig.canvas
                    val_layout = FloatLayout()
                    val_layout.add_widget(val_canvas)
                    tab_validate.add_widget(val_layout)

                    future_canvas = future_fig.canvas
                    future_layout = FloatLayout()
                    future_layout.add_widget(future_canvas)
                    tab_future.add_widget(future_layout)

                    Clock.schedule_once(
                        lambda *args: tab_panel.switch_to(tab_validate))

            Clock.schedule_interval(read_training, 0.1)

        Clock.schedule_once(lambda *args: tab_panel.switch_to(tab_chart))

        self.add_widget(tab_panel)