예제 #1
0
    def execute_query(self):
        """Executes the PVWatts query using the given parameters."""
        try:
            api_key, pv_params = self.get_inputs()
            self.api_key = api_key
        except ValueError as e:
            popup = WarningPopup()
            popup.popup_text.text = str(e)
            popup.open()
        except InputError as e:
            popup = WarningPopup()
            popup.popup_text.text = str(e)
            popup.open()
        else:
            # Reset screen.
            self.reset_screen()
            self.save_button.disabled = True

            # Form query.
            api_query = URL_PVWATTS
            query_segs = []
            for k, v in pv_params.items():
                query_segs.append('{key}={value}'.format(key=k, value=v))

            api_query += '&'.join(query_segs)
            # print(api_query)

            try:
                self._query_api(api_query)
            except requests.ConnectionError:
                popup = ConnectionErrorPopup()
                popup.popup_text.text = 'There was an issue connecting to the API. Check your connection settings and try again.'
                popup.open()
예제 #2
0
    def _populate_utility_rate_structures(self, eia_id):
        """Executes OpenEI API query for given EIA ID."""
        api_root = APIROOT_OPENEI + VERSION_OPENEI + REQUEST_FMT_OPENEI + DETAIL_OPENEI
        api_query = api_root + '&api_key=' + self.api_key + '&eia=' + eia_id

        try:
            thread_query = threading.Thread(
                target=self._query_api_for_rate_structures, args=[api_query])
            thread_query.start()
        except requests.ConnectionError:
            popup = ConnectionErrorPopup()
            popup.popup_text.text = 'There was an issue querying the OpenEI database. Check your connection settings and try again.'
            popup.open()
        finally:
            self.search_button.disabled = False

        # thread_query = threading.Thread(target=self._query_api_for_rate_structures, args=[api_query])
        # thread_query.start()

        # Open loading screen.
        self.loading_screen = LoadingModalView()
        self.loading_screen.loading_text.text = 'Retrieving rate structures...'
        self.loading_screen.open()
예제 #3
0
            def _execute_search():
                # Open loading screen.
                # self.loading_screen = LoadingModalView()
                # self.loading_screen.loading_text.text = 'Retrieving rate structures...'
                # self.loading_screen.open()

                if self.utility_ref_table.empty:
                    try:
                        self._download_utility_ref_table()
                    except requests.ConnectionError:
                        popup = ConnectionErrorPopup()
                        popup.popup_text.text = 'There was an issue connecting to and downloading the lists of utilities. Check your connection settings and try again.'
                        popup.open()
                        return
                    finally:
                        self.search_button.disabled = False

                # Filter DataFrame by search type/query and drop duplicate entries.
                if search_type == 'state':
                    utility_data_filtered = self.utility_ref_table.loc[
                        self.utility_ref_table['state'].str.lower(
                        ).str.contains(search_query)
                        | self.utility_ref_table['state name'].str.lower(
                        ).str.contains(search_query)]
                elif search_type == 'zip':
                    utility_data_filtered = self.utility_ref_table.loc[
                        self.utility_ref_table[search_type] == search_query]
                else:
                    utility_data_filtered = self.utility_ref_table.loc[
                        self.utility_ref_table[search_type].str.lower(
                        ).str.contains(search_query)]

                utility_data_filtered = utility_data_filtered[[
                    'eiaid', 'utility_name', 'state', 'ownership'
                ]]
                utility_data_filtered.drop_duplicates(inplace=True)

                logging.info(
                    'RateStructureDM: Utility table filter completed.')
                self.search_button.disabled = False

                if utility_data_filtered.empty:
                    logging.warning(
                        'RateStructureDM: No results matched the query.')

                    popup = WarningPopup()
                    popup.popup_text.text = 'No results matched your query.'
                    popup.open()

                # Enable search results selector.
                fade_in_animation(self.utility_select_bx)
                self._populate_utility_selector(utility_data_filtered)
예제 #4
0
 def on_connection_error_occurred(self, instance, value):
     if value:
         popup = ConnectionErrorPopup()
         popup.popup_text.text = 'There was an issue connecting to the profile database. Check your connection settings and try again.'
         popup.open()