Esempio n. 1
0
    def on_enter(self):
        # change the navigation bar title
        ab = self.manager.nav_bar
        ab.build_valuation_advanced_nav_bar()
        ab.set_title('Single Run: Set Parameters')

        data_manager = App.get_running_app().data_manager
        MODEL_PARAMS = data_manager.get_valuation_model_params(self.iso)

        if not MODEL_PARAMS:
            popup = WarningPopup()
            popup.bind(on_dismiss=partial(ab.go_to_screen, 'load_data'))
            popup.dismiss_button.text = 'Go back'
            popup.popup_text.text = 'We need a market area in the "Select Data" screen selected first to populate this area.'
            popup.open()
Esempio n. 2
0
    def __init__(self, write_directory=None, write_function=None, chooser_description=None, format_description=None, data_validation_function=None, **kwargs):
        super(DataImporter, self).__init__(**kwargs)

        if write_directory is None:
            self.write_directory = ""
        else:
            self.write_directory = write_directory
        
        if write_function is None:
            def _write_time_series_csv(fname, dataframe):
                """Writes a generic time series dataframe to a two-column csv. 
                
                The data is inferred to be at an hourly time resolution for one standard year.

                Parameters
                ----------
                fname : str
                    Name of the file to be saved without an extension
                dataframe : Pandas DataFrame
                    DataFrame containing a single Series of the data
                
                Returns
                -------
                str
                    The save destination of the resulting file.
                """
                save_destination = os.path.join(self.write_directory, fname + ".csv")

                data_column_name = dataframe.columns[0]

                datetime_start = datetime(2019, 1, 1, 0)
                hour_range = pd.date_range(start=datetime_start, periods=len(dataframe), freq="H")
                dataframe["DateTime"] = hour_range

                dataframe[["DateTime", data_column_name]].to_csv(save_destination, index=False)
                
                return save_destination
            
            self.write_function = _write_time_series_csv
        else:
            self.write_function = write_function

        if chooser_description is None:
            self.chooser_description = "Select a .csv file to import data from."
        else:
            self.chooser_description = chooser_description
        
        file_chooser_screen = self.screen_manager.get_screen("FileChooser")
        file_chooser_screen.file_chooser_body_text.text = self.chooser_description

        if format_description is None:
            self.format_description = "Specify the data column."
        else:
            self.format_description = format_description

        format_analyzer_screen = self.screen_manager.get_screen("FormatAnalyzer")
        format_analyzer_screen.format_analyzer_body_text.text = self.format_description
    
        if data_validation_function is None:
            def _default_data_validation_function(dataframe, data_column_name):
                if len(dataframe) != 8760:
                    raise ValueError("The length of the time series must be 8760 (got {0}).".format(len(dataframe)))
                
                data_column = dataframe[data_column_name]

                try:
                    data_column.astype("float")
                except ValueError:
                    raise ValueError("The selected data column could not be interpeted as numeric float values.")


            self.data_validation_function = _default_data_validation_function
        else:
            self.data_validation_function = data_validation_function

        # Bind DataImporter dismissal to successful data import.
        completion_popup = WarningPopup()
        completion_popup.title = "Success!"
        completion_popup.popup_text.text = "Data successfully imported."
        completion_popup.bind(on_dismiss=self.dismiss)

        self.screen_manager.completion_popup = completion_popup