async def get_shaped_timeseries(self, query: ShapeQuery) -> ModelResult: logger.debug( "\n--->>> Shape Query Called successfully on %s Model!! <<<---" % self.name) logger.debug("Spatial Component is: \n%s" % str(query.spatial)) logger.debug("Temporal Component is: \n%s" % str(query.temporal)) logger.debug( "\nDerived LAT1: %s\nDerived LON1: %s\nDerived LAT2: %s\nDerived LON2: %s" % query.spatial.expanded(0.05)) sr = await (self.get_shaped_resultcube(query)) logger.debug(sr) logger.debug(sr.data) # Check our param exists in the shaped result set if len(sr.data) > 0: logger.debug(">> Crack a beer we got there!! <<") dps = [ self.get_datapoint_for_param( b=sr.isel(time=t), param=self.outputs["readings"]["prefix"]) for t in range(0, len(sr["time"])) ] return ModelResult(model_name=self.name, data_points=dps) else: return ModelResult(model_name=self.name, data_points=[])
async def get_shaped_timeseries(self, query: ShapeQuery) -> ModelResult: logger.debug( "\n--->>> Shape Query Called successfully on %s Model!! <<<---" % self.name) # logger.debug("Spatial Component is: \n%s" % str(query.spatial)) # logger.debug("Temporal Component is: \n%s" % str(query.temporal)) # # logger.debug("\nDerived LAT1: %s\nDerived LON1: %s\nDerived LAT2: %s\nDerived LON2: %s" % # query.spatial.expanded(0.05)) sr = await (self.get_shaped_resultcube(query)) sr.load() dps = [] for r in sr['time']: t = r['time'].values o = sr.sel(time=t) p = self.outputs['readings']['prefix'] df = o[p].to_dataframe() df = df[p] # TODO - This is a quick hack to massage the datetime format into a markup suitable for D3 & ngx-charts! m = df.mean() dps.append(DataPoint(observation_time=str(t).replace('.000000000', '.000Z'), value=m, mean=m, minimum=df.min(), maximum=df.max(), deviation=0)) asyncio.sleep(1) return ModelResult(model_name=self.name, data_points=dps)
async def get_timeseries(self, query: SpatioTemporalQuery) -> ModelResult: """ Essentially just time slicing the resultcube. DataPoint actually handles the creation of values from stats. :param query: :return: """ logger.debug( "--->>> SpatioTemporal Query Called on %s Model!! <<<---" % self.name) sr = await (self.get_resultcube(query)) sr.load() asyncio.sleep(1) dps = [self.get_datapoint_for_param(b=sr.isel(time=t), param="DFMC") for t in range(0, len(sr["time"]))] return ModelResult(model_name=self.name, data_points=dps)
def subscribe(self, observer): if dev.DEBUG: dps = [] for i in range(3): dps.append( DataPoint(observation_time=dt.date(2018, 5, 17), value=i, mean=i, minimum=i, maximum=i, deviation=0)) observer.on_next( ModelResult(model_name='test', data_points=dps)) observer.on_completed() else: dps = [] pass
def subscribe(self, observer): if dev.DEBUG: logger.debug("Got subscription. Building response.") for model in self.models: dps = [] logger.debug('Building dummy response for model: %s' % model.name) for j in range(30): dps.append(DummyResults.dummy_single(j)) observer.on_next( ModelResult(model_name=model.name, data_points=dps)) observer.on_completed() else: dps = [] for model in self.models: model.subscribe(observer) # rx.Observable.merge() pass
async def get_shaped_timeseries(self, query: ShapeQuery) -> ModelResult: logger.debug( "\n--->>> Shape Query Called successfully on %s Model!! <<<---" % self.name) logger.debug("Spatial Component is: \n%s" % str(query.spatial)) logger.debug("Temporal Component is: \n%s" % str(query.temporal)) logger.debug("\nDerived LAT1: %s\nDerived LON1: %s\nDerived LAT2: %s\nDerived LON2: %s" % query.spatial.expanded(0.05)) dps = [] try: sr = await (self.get_shaped_resultcube(query)) sr.load() # Values in AWRA are in range 0..1 # Normalise to between 0-100% # sr[self.outputs["readings"]["prefix"]] *= 100 if dev.DEBUG: logger.debug("Shaped ResultCube is: \n%s" % sr) for r in sr['time']: t = r['time'].values o = sr.sel(time=t) p = self.outputs['readings']['prefix'] df = o[p].to_dataframe() df = df[p] # TODO - This is a quick hack to massage the datetime format into a markup suitable for D3 & ngx-charts! m = df.median() dps.append(DataPoint(observation_time=str(t).replace('.000000000', '.000Z'), value=m, mean=df.mean(), minimum=df.min(), maximum=df.max(), deviation=0)) except FileNotFoundError: logger.exception('Files not found for date range.') asyncio.sleep(1) return ModelResult(model_name=self.name, data_points=dps)
async def get_shaped_timeseries(self, query: ShapeQuery) -> ModelResult: logger.debug( "\n--->>> Shape Query Called successfully on %s Model!! <<<---" % self.name) logger.debug("Spatial Component is: \n%s" % str(query.spatial)) logger.debug("Temporal Component is: \n%s" % str(query.temporal)) logger.debug( "\nDerived LAT1: %s\nDerived LON1: %s\nDerived LAT2: %s\nDerived LON2: %s" % query.spatial.expanded(0.05)) sr = await (self.get_shaped_resultcube(query)) sr.load() # Values in AWRA are in range 0..1 # Normalise to between 0-100% sr[self.outputs["readings"]["prefix"]] *= 100 dps = [ self.get_datapoint_for_param( b=sr.sel(time=t), param=self.outputs["readings"]["prefix"]) for t in sr["time"] ] asyncio.sleep(1) return ModelResult(model_name=self.name, data_points=dps)
def get_timeseries(self, query: SpatioTemporalQuery) -> ModelResult: # MAGIC HAPPENS HERE # An array of mockup DataPoints for testing only dr = DummyResults() dps = dr.dummy_data(query) return ModelResult(self.name, dps)