Esempio n. 1
0
    def get_time_series(self,
                        time_series,
                        query_string='',
                        shared_username=None,
                        shared_api_key=None):
        """Retrieves a time series.

           The model parameter should be a string containing the
           time series id or the dict returned by
           create_time_series.
           As a time series is an evolving object that is processed
           until it reaches the FINISHED or FAULTY state, the function will
           return a dict that encloses the time series
           values and state info available at the time it is called.

           If this is a shared time series, the username and
           sharing api key must also be provided.
        """
        check_resource_type(time_series,
                            TIME_SERIES_PATH,
                            message="A time series id is needed.")
        time_series_id = get_time_series_id(time_series)
        if time_series_id:
            return self._get("%s%s" % (self.url, time_series_id),
                             query_string=query_string,
                             shared_username=shared_username,
                             shared_api_key=shared_api_key)
Esempio n. 2
0
    def create_forecast(self, time_series, input_data=None,
                        args=None, wait_time=3, retries=10):
        """Creates a new forecast.

        """
        time_series_id = get_time_series_id(time_series)
        resource_type = get_resource_type(time_series_id)
        if resource_type == TIME_SERIES_PATH and time_series_id is not None:
            check_resource(time_series_id,
                           query_string=TINY_RESOURCE,
                           wait_time=wait_time, retries=retries,
                           raise_on_error=True, api=self)
        else:
            raise Exception("A time series model id is needed to create a"
                            " forecast. %s found." % resource_type)

        if input_data is None:
            input_data = {}
        create_args = {}
        if args is not None:
            create_args.update(args)
        create_args.update({
            "input_data": input_data})
        if time_series_id is not None:
            create_args.update({
                "timeseries": time_series_id})

        body = json.dumps(create_args)
        return self._create(self.forecast_url, body,
                            verify=self.verify_prediction)
Esempio n. 3
0
    def create_forecast(self, time_series, input_data=None,
                        args=None, wait_time=3, retries=10):
        """Creates a new forecast.

        """
        time_series_id = get_time_series_id(time_series)
        resource_type = get_resource_type(time_series_id)
        if resource_type == TIME_SERIES_PATH and time_series_id is not None:
            check_resource(time_series_id,
                           query_string=TINY_RESOURCE,
                           wait_time=wait_time, retries=retries,
                           raise_on_error=True, api=self)
        else:
            raise Exception("A time series model id is needed to create a"
                            " forecast. %s found." % resource_type)

        if input_data is None:
            input_data = {}
        create_args = {}
        if args is not None:
            create_args.update(args)
        create_args.update({
            "input_data": input_data})
        if time_series_id is not None:
            create_args.update({
                "timeseries": time_series_id})

        body = json.dumps(create_args)
        return self._create(self.forecast_url, body,
                            verify=self.verify_prediction)
Esempio n. 4
0
    def delete_time_series(self, time_series):
        """Deletes a time series.

        """
        check_resource_type(time_series, TIME_SERIES_PATH,
                            message="A time series id is needed.")
        time_series_id = get_time_series_id(time_series)
        if time_series_id:
            return self._delete("%s%s" % (self.url, time_series_id))
Esempio n. 5
0
    def update_time_series(self, time_series, changes):
        """Updates a time series.

        """
        check_resource_type(time_series,
                            TIME_SERIES_PATH,
                            message="A time series id is needed.")
        time_series_id = get_time_series_id(time_series)
        if time_series_id:
            body = json.dumps(changes)
            return self._update("%s%s" % (self.url, time_series_id), body)
Esempio n. 6
0
    def update_time_series(self, time_series, changes):
        """Updates a time series.

        """
        check_resource_type(time_series, TIME_SERIES_PATH,
                            message="A time series id is needed.")
        time_series_id = get_time_series_id(
            time_series)
        if time_series_id:
            body = json.dumps(changes)
            return self._update(
                "%s%s" % (self.url, time_series_id), body)
Esempio n. 7
0
    def get_time_series(self, time_series, query_string='',
                        shared_username=None, shared_api_key=None):
        """Retrieves a time series.

           The model parameter should be a string containing the
           time series id or the dict returned by
           create_time_series.
           As a time series is an evolving object that is processed
           until it reaches the FINISHED or FAULTY state, the function will
           return a dict that encloses the time series
           values and state info available at the time it is called.

           If this is a shared time series, the username and
           sharing api key must also be provided.
        """
        check_resource_type(time_series, TIME_SERIES_PATH,
                            message="A time series id is needed.")
        time_series_id = get_time_series_id(
            time_series)
        if time_series_id:
            return self._get("%s%s" % (self.url, time_series_id),
                             query_string=query_string,
                             shared_username=shared_username,
                             shared_api_key=shared_api_key)