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_datapoint_for_param(b, param): """ Takes the mean min and max values for datapoints at a particular time slice. :param b: :param param: :return: """ bin_ = b.to_dataframe() # TODO - This is a quick hack to massage the datetime format into a markup suitable for D3 & ngx-charts! tvalue = str(b["time"].values).replace('.000000000', '.000Z') avalue = bin_[param].median() logger.debug( "\n>>>> Datapoint creation. (time={}, value={})".format(tvalue, avalue)) asyncio.sleep(1) return DataPoint(observation_time=tvalue, value=avalue, mean=bin_[param].mean(), minimum=bin_[param].min(), maximum=bin_[param].max(), deviation=bin_[param].std())
def dummy_single(v): # Dummy data for testing... # value, mean, min, max, std five_values = [np.random.random_sample() for j in range(5)] five_values = pd.DataFrame(five_values) # print(five_values) return DataPoint( dt.date(2018, 1, v + 1).strftime("%Y-%m-%dT00:00:00.000Z"), five_values[0].mean(), five_values[0].mean(), five_values[0].min(), five_values[0].max(), five_values[0].std())
def dummy_series(): response = [] for i in range(1, 30): # Dummy data for testing... # value, mean, min, max, std five_values = [np.random.random_sample() for j in range(5)] five_values = pd.DataFrame(five_values) # print(five_values) response.append( DataPoint( dt.date(2018, 1, i).strftime("%Y-%m-%dT00:00:00.000Z"), five_values[0].mean(), five_values[0].mean(), five_values[0].min(), five_values[0].max(), five_values[0].std())) return response
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
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)