def _make_xts_from_shyft_ts(name, shyft_ts): ''' Returns a ITimeSeries from shyft_ts ''' ta = convert_ta(shyft_ts.time_axis) mi = MetaInfo() mi.Identity = TsIdentity(0, name) xts = NetTimeSeries(mi, ta, Convert.create_net_array(shyft_ts.values.to_numpy())) return xts
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 enki ' # 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) # 3. We store the datapoints (identity period, then time,value) ssa_timeseries_list= List[SsaTimeSeries]([]) # This is what Tss Xts eats for name,shyft_ts in timeseries_dict.iteritems(): ssa_ts=self._make_ssa_ts_from_shyft_ts(name,shyft_ts) ssa_timeseries_list.Add(ssa_ts) ok=tss.repo.Write(ssa_timeseries_list) # Write into SmG! return ok
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
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
def store(self, ts_dict): """ Input the list of Enki result ts_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. Get the list of ts identities that tsr uses tsIdentities = self._namelist_to_ListOf_TsIdentities(ts_dict.keys()) res = False with TimeSeriesRepositorySmg(self.env) as tsr: # 1. Check if any of the tsnames are missing exists_kv_pairs = tsr.repo.Exists(tsIdentities) missing_list = List[MetaInfo]([]) # 2. 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 # 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: created_list = tsr.repo.Create(missing_list, True) # TODO: verify they have been created tsIdentities = tsr.repo.GetIdentities(tsr.repo.FindMetaInfo(tsIdentities)) ts_names = {x.Name: x for x in tsIdentities} # 3. Store the datapoints (identity period, then time, value) ssaTimeSeries = List[TimeSeriesPointSegments]([]) # This is what tsr Xts eats for name, shyft_ts in iter(ts_dict.items()): xts = self._make_ssa_tsps_from_shyft_ts(ts_names[name], shyft_ts) ssaTimeSeries.Add(xts) errors = tsr.repo.Write(ssaTimeSeries, False) # Write into SmG if errors is None: res = True return res
def _create_missing_ts(tsr, tsIds, is_forecast): missingList = List[MetaInfo]([]) tsExists = tsr.repo.Exists(tsIds) for e in tsExists: if not e.Value: # Specific for ShopIn mi = MetaInfo() mi.Identity = e.Key mi.Description = 'Automatically created by shyft' mi.Type = 9000 # General time-series mi.TimeStepConstraint = PointTimeStepConstraint.Hour mi.TimeSeriesValueHistoryMode = is_forecast missingList.Add(mi) if missingList.Count > 0: tsr.repo.Create(missingList, True)