Пример #1
0
def hyperparam_results(model_id, task_key):
    r = api_request.get('platform/v1/model/hyperparam_allresults/{}'.format(model_id),
                        params={'api_key': rb.api_key,
                                'task_key': task_key})
    if r.status_code != 200:
        raise Exception(f"Error starting hyperparam_results for model {model_id}: {r.content.decode('utf-8')}")
    return r.json()
Пример #2
0
    def predicters(cls, site_id):
        path = '{}/site/models/{}'.format(cls.base_path, site_id)
        # FIXME: Implement logic to list models for site

        response = api_request.get(path)
        models = response.json()
        return models
Пример #3
0
    def forecast(cls, site_id, type='prioritized'):
        """Get the latest forecast for a site

        Args:
            site_id (str): id of the site
            type (str): type of forecast to return

                - ``prioritized`` returns best forecast at the time

                - ``ai`` only returns AI forecasts

                - ``physical`` only returns physical forecasts

                Default ``prioritized``

        Returns:
            dict:
            Returns a dict with the following format:
            ::

                {
                    'type' (str): # type same as params,
                    'ref_time' (DateTime): # date when forecast data updated,
                    'df' (pandas.DataFrame): # dataframe with forecast data
                }

            Example::

                >>> site_id = '4ab82692-3944-4069-9cbb-f9c59513c1c3'
                >>> data = rb.Site.forecast(site_id)
                >>> print(data['df'])
                                               forecast
                    valid_time
                    2020-10-14 00:00:00+00:00       77.3
                    2020-10-14 00:15:00+00:00       86.1
                    ...                             ...
                    2020-10-17 23:30:00+00:00       87.0
                    2020-10-17 23:45:00+00:00       86.6
        """
        path = '{}/site/forecast/latest/{}'.format(cls.base_path, site_id)
        params = {
            'type': type,
        }
        response = api_request.get(path, params=params)
        if response.status_code == 200:
            data = response.json()
            df = pd.DataFrame(data={'forecast': data['forecast']},
                              index=pd.to_datetime(data['valid_time']))
            df.index.name = 'valid_time'
            return {
                'type': data['type'],
                'ref_time': data['ref_time'],
                'df': df
            }
Пример #4
0
    def status(cls, pred):
        path = '/platform/v1/site/train/state/{}'.format(pred.site_id)
        r = api_request.get(path)

        status = {'status': None, 'history': []}
        if r.status_code == 200:
            data = r.json()
            if len(data) > 0:
                status['status'] = data[-1]['state']
                status['history'] = data
        return status
Пример #5
0
    def observation(cls, site_id, start_date, end_date=None):
        path = '{}/site/observation/{}'.format(cls.base_path, site_id)
        params = {'start_date': start_date, 'end_date': end_date}
        response = api_request.get(path, params=params)
        if response.status_code == 200:
            data = response.json()
            df = pd.DataFrame(data={'observation': data['power_kw']},
                              index=pd.to_datetime(data['valid_time']))
            df.index.name = 'valid_time'
            return df
        else:
            print(response.status_code)

        return None
Пример #6
0
    def status(cls, site_id):
        """Get the training status of your site.

        Args:
            site_id (str): id of site to get status of

        Returns:
            dict:

            Returns a dict with the training status.

            Possible states:

            - ``queued`` - training is queued

            - ``training`` - is currently training

            - ``complete`` - training is complete

            - ``retry`` - training failed but is retrying

            - ``failed`` - training failed (no more retry)

            Example::

                >>> site_id = '4ab82692-3944-4069-9cbb-f9c59513c1c3'
                >>> rb.Site.status(site_id)
                {
                    'status': 'complete',
                    'history': [
                        {'state': 'queued', 'timestamp_utc': '2020-10-12 13:04:17'},
                        {'state': 'training', 'timestamp_utc': '2020-10-12 13:04:22'},
                        {'state': 'complete', 'timestamp_utc': '2020-10-12 13:05:23'},
                    ]
                }
        """
        path = '{}/site/train/state/{}'.format(cls.base_path, site_id)
        r = api_request.get(path)

        status = {'status': None, 'history': []}
        if r.status_code == 200:
            data = r.json()
            if len(data) > 0:
                status['status'] = data[-1]['state']
                status['history'] = data
        return status
Пример #7
0
    def list(cls):
        """List all of your sites

        Returns:
            List: list with one dict per site

            Example::

                >>> sites = rb.Site.list()
                >>> print(sites)
                [
                    {'site_id': ..., }, # site 1
                    ...,
                    {'site_id': ...}, # site N
                ]
        """
        path = '{}/sites'.format(cls.base_path)
        response = api_request.get(path)
        return response.json()
Пример #8
0
    def get(cls, site_id):
        """Get a site by id

        Args:
            site_id (str): the id of the site

        Returns:
            dict: the config of the site

            Example::

                >>> site_id = '4ab82692-3944-4069-9cbb-f9c59513c1c3'
                >>> site_config = rb.Site.get(site_id)
                >>> print(site_config)
                {
                    'site_id': '4ab82692-3944-4069-9cbb-f9c59513c1c3',
                    'type': 'solar'
                }

        Raises:
            rebase.NotFoundError: if specified site does not exist
        """
        r = api_request.get('{}/site/{}'.format(cls.base_path, site_id))
        return r.json()
Пример #9
0
 def status(cls, id):
     path = '{}/layer/status/{}'.format(cls.base_path, id)
     response = api_request.get(path)
     if response.status_code == 404:
         raise NotFoundError(response.text)
     return response.json()
Пример #10
0
 def list(cls):
     path = '{}/layer/list'.format(cls.base_path)
     response = api_request.get(path)
     return response.json()
Пример #11
0
 def load_pickle(self, file_type):
     r = api_request.get('platform/v1/model/custom/download/{}/{}'.format(file_type, self.model_id))
     return dill.loads(r.content)
Пример #12
0
 def load_model_config(self):
     r = api_request.get('platform/v1/model/{}'.format(self.model_id))
     return r.json()