示例#1
0
文件: ssa_smg_db.py 项目: yisak/shyft
 def store(self, timeseries_dict):
     """ Input the list of Enki result timeseries_dict,
         where the keys are the wanted SmG ts-path names
         and the values are Enki result api.shyft_timeseries_double, time-series.
         If the named time-series does not exist, create it.
         Then store time-series data to the named entities.
         
     """
     # 0. First, get the list of ts identities that Tss uses
     list_of_names = timeseries_dict.keys()
     ListOf_TsIdentities = self._namelist_to_ListOf_TsIdentities(
         list_of_names)
     ok = False
     with repository(self.env) as tss:
         # 1. We check if any of the tsnames are missing..
         exists_kv_pairs = tss.repo.Exists(ListOf_TsIdentities)
         missing_list = List[MetaInfo]([])
         # 2. We create those missing..
         for e in exists_kv_pairs:
             if e.Value == False:
                 tsid = e.Key
                 mi = MetaInfo()
                 mi.Identity = tsid
                 mi.Description = 'Automatically created by shyft '
                 mi.Type = 9000  # just a general time-series
                 # Here we might fill in some properties to the created timeseries
                 # e.g. unit, if we could figure out that
                 missing_list.Add(mi)
         if missing_list.Count > 0:  # Yes, something was missing, create them
             created_list = tss.repo.Create(missing_list, True)
             #TODO verify we got them created
         # fetch tsids from the names
         ts_id_list = tss.repo.GetIdentities(
             tss.repo.FindMetaInfo(ListOf_TsIdentities))
         name_to_ts_id = {x.Name: x for x in ts_id_list}
         # 3. We store the datapoints (identity period, then  time,value)
         ssa_timeseries_list = List[TimeSeriesPointSegments](
             [])  # This is what Tss Xts eats
         for name, shyft_ts in iter(timeseries_dict.items()):
             ssa_ts = self._make_ssa_tsps_from_shyft_ts(
                 name_to_ts_id[name], shyft_ts)
             ssa_timeseries_list.Add(ssa_ts)
         error_list = tss.repo.Write(ssa_timeseries_list,
                                     False)  # Write into SmG!
         if error_list is None: ok = True
     return ok
示例#2
0
    def read_forecast(self,list_of_fc_id,period):
        if not period.valid():
           raise SmgDataError("period should be valid()  of type api.UtcPeriod")
        result = {}
        ListOf_fc_identities=self._namelist_to_ListOf_TsIdentities(list_of_fc_id)
        ts_id_list=[]

        with repository(self.env) as tss:
            ts_id_list= tss.repo.GetIdentities (tss.repo.FindMetaInfo(ListOf_fc_identities))

        ssa_period=self._make_ssa_Period_from_shyft_period(period)
        fcr= ForecastRepositorySmg(self.fc_env)
        read_forecasts = fcr.repo.ReadForecast(ts_id_list,ssa_period)
        if ts_id_list.Count != read_forecasts.Count:
            print( "WARNING: Could only find {} out of {} requested timeseries".format(read_forecasts.Count, ts_id_list.Count))
        for fc_ts in read_forecasts:
            key=fc_ts.Name
            result[key]=self._make_shyft_ts_from_ssa_ts(fc_ts)
        return result
示例#3
0
 def store(self, timeseries_dict):
     """ Input the list of Enki result timeseries_dict,
         where the keys are the wanted SmG ts-path names
         and the values are Enki result api.shyft_timeseries_double, time-series.
         If the named time-series does not exist, create it.
         Then store time-series data to the named entities.
         
     """
     # 0. First, get the list of ts identities that Tss uses
     list_of_names = timeseries_dict.keys()
     ListOf_TsIdentities = self._namelist_to_ListOf_TsIdentities(list_of_names)
     ok = False
     with repository(self.env) as tss:
         # 1. We check if any of the tsnames are missing..
         exists_kv_pairs = tss.repo.Exists(ListOf_TsIdentities)
         missing_list = List[MetaInfo]([])
         # 2. We create those missing..
         for e in exists_kv_pairs:
             if e.Value == False:
                 tsid = e.Key
                 mi = MetaInfo()
                 mi.Identity = tsid
                 mi.Description = "Automatically created by shyft "
                 mi.Type = 9000  # just a general time-series
                 # Here we might fill in some properties to the created timeseries
                 # e.g. unit, if we could figure out that
                 missing_list.Add(mi)
         if missing_list.Count > 0:  # Yes, something was missing, create them
             created_list = tss.repo.Create(missing_list, True)
             # TODO verify we got them created
         # fetch tsids from the names
         ts_id_list = tss.repo.GetIdentities(tss.repo.FindMetaInfo(ListOf_TsIdentities))
         name_to_ts_id = {x.Name: x for x in ts_id_list}
         # 3. We store the datapoints (identity period, then  time,value)
         ssa_timeseries_list = List[TimeSeriesPointSegments]([])  # This is what Tss Xts eats
         for name, shyft_ts in iter(timeseries_dict.items()):
             ssa_ts = self._make_ssa_tsps_from_shyft_ts(name_to_ts_id[name], shyft_ts)
             ssa_timeseries_list.Add(ssa_ts)
         error_list = tss.repo.Write(ssa_timeseries_list, False)  # Write into SmG!
         if error_list is None:
             ok = True
     return ok
示例#4
0
    def read(self,list_of_ts_id,period):
        """Open a connection to the SMG database and fetch all the time series given in list_of_ts_id.
        ts_id is currently the full unique name of the smg-ts. We could/should also support using
        unique number/keys instead. -more efficient, and more robust to namechanges.
        Return the result as a dictionary of shyft_ts."""
        if not period.valid():
           raise SmgDataError("period should be valid()  of type api.UtcPeriod")

        result = {}
        raw_data = []
        ListOf_TsIdentities=self._namelist_to_ListOf_TsIdentities(list_of_ts_id)
        ssa_period=self._make_ssa_Period_from_shyft_period(period)
        with repository(self.env) as tsr:
            raw_data = tsr.repo.ReadRawPoints(ListOf_TsIdentities,ssa_period)
        if len(list_of_ts_id) != raw_data.Count:
            print( "WARNING: Could only find {} out of {} requested timeseries".format(raw_data.Count, len(list_of_ts_id)))
        for d in raw_data:
            key = d.Name #todo : if self.keys_are_names else d.Info.Id
            result[key] = self._make_shyft_ts_from_ssa_ts(d)
        return result
示例#5
0
文件: ssa_smg_db.py 项目: yisak/shyft
    def read_forecast(self, list_of_fc_id, period):
        if not period.valid():
            raise SmgDataError(
                "period should be valid()  of type api.UtcPeriod")
        result = {}
        ListOf_fc_identities = self._namelist_to_ListOf_TsIdentities(
            list_of_fc_id)
        ts_id_list = []

        with repository(self.env) as tss:
            ts_id_list = tss.repo.GetIdentities(
                tss.repo.FindMetaInfo(ListOf_fc_identities))

        ssa_period = self._make_ssa_Period_from_shyft_period(period)
        fcr = ForecastRepositorySmg(self.fc_env)
        read_forecasts = fcr.repo.ReadForecast(ts_id_list, ssa_period)
        if ts_id_list.Count != read_forecasts.Count:
            print("WARNING: Could only find {} out of {} requested timeseries".
                  format(read_forecasts.Count, ts_id_list.Count))
        for fc_ts in read_forecasts:
            key = fc_ts.Name
            result[key] = self._make_shyft_ts_from_ssa_ts(fc_ts)
        return result
示例#6
0
文件: ssa_smg_db.py 项目: yisak/shyft
    def read(self, list_of_ts_id, period):
        """Open a connection to the SMG database and fetch all the time series given in list_of_ts_id.
        ts_id is currently the full unique name of the smg-ts. We could/should also support using
        unique number/keys instead. -more efficient, and more robust to namechanges.
        Return the result as a dictionary of shyft_ts."""
        if not period.valid():
            raise SmgDataError(
                "period should be valid()  of type api.UtcPeriod")

        result = {}
        raw_data = []
        ListOf_TsIdentities = self._namelist_to_ListOf_TsIdentities(
            list_of_ts_id)
        ssa_period = self._make_ssa_Period_from_shyft_period(period)
        with repository(self.env) as tsr:
            raw_data = tsr.repo.ReadRawPoints(ListOf_TsIdentities, ssa_period)
        if len(list_of_ts_id) != raw_data.Count:
            print("WARNING: Could only find {} out of {} requested timeseries".
                  format(raw_data.Count, len(list_of_ts_id)))
        for d in raw_data:
            key = d.Name  #todo : if self.keys_are_names else d.Info.Id
            result[key] = self._make_shyft_ts_from_ssa_ts(d)
        return result