def handle(self, **options):
        grower = GrowerInfo.objects.get(pk=1)
        basin =  grower.basin_set.all()[0]
        self.ds = FewsJdbcDataSource(basin)
        tbl = DemandTable()
        model = CalculationModel(tbl, self.ds)

        now = datetime.datetime.now(pytz.utc)
        history = now - datetime.timedelta(days=1)
        future = now + datetime.timedelta(days=5)

        now = round_date(now)
        history = round_date(history)
        future = round_date(future)

        self.mkplot('history', history, now)
        self.mkplot('span', history, future)
        self.mkplot('future', now, future)

        now = mktim(2012, 8, 5, 8, 0)  # some rain fell here
        now = round_date(datetime.datetime.now(tz=pytz.utc))
        future = now + settings.CONTROLNEXT_FILL_PREDICT_FUTURE

        ts = model.predict_fill(now, future, 20, 100, 100)

        plot('predict_fill', ts['scenarios']['mean']['prediction'],
             ts['history'])
        # plot('predict_fill_rain', ts['rain'])
        plot('predict_fill_uitstroom',
             ts['scenarios']['mean']['intermediate']['uitstroom'])
        plot('predict_fill_toestroom',
             ts['scenarios']['mean']['intermediate']['toestroom'])
        plot('predict_fill_max_uitstroom',
             ts['intermediate']['max_uitstroom'])
        plot('predict_fill_watervraag', ts['intermediate']['demand'])
Esempio n. 2
0
    def prediction(self, t0, desired_fill_pct, demand_exaggerate, rain_exaggerate):
        tbl = DemandTable()
        ds = FewsJdbcDataSource()
        model = CalculationModel(tbl, ds)

        future = t0 + fill_predict_future

        prediction = model.predict_fill(t0, future, desired_fill_pct, demand_exaggerate, rain_exaggerate)

        # TODO should use dict comprehension in py > 2.6
        data = dict(
            [(name, series_to_js(scenario["prediction"])) for name, scenario in prediction["scenarios"].items()]
        )
        data["history"] = series_to_js(prediction["history"])
        graph_info = {
            "data": data,
            "x0": datetime_to_js(t0),
            "y_marking_min": min_berging_pct,
            "y_marking_max": max_berging_pct,
            "x_marking_omslagpunt": datetime_to_js(prediction["scenarios"]["mean"]["omslagpunt"]),
            "y_marking_desired_fill": desired_fill_pct,
            "desired_fill": desired_fill_pct,
        }
        result = {
            "graph_info": graph_info,
            "overflow_24h": prediction["scenarios"]["mean"]["overstort_24h"],
            "overflow_5d": prediction["scenarios"]["mean"]["overstort_5d"],
            "demand_week": tbl.get_week_demand_on(t0),
            "demand_24h": tbl.get_total_demand(t0, t0 + datetime.timedelta(hours=24)),
            "current_fill": prediction["current_fill"],
        }
        return result
Esempio n. 3
0
    def advanced(self, t0, desired_fill_pct, demand_exaggerate, rain_exaggerate, graph_type):
        tbl = DemandTable()
        ds = FewsJdbcDataSource()
        model = CalculationModel(tbl, ds)

        future = t0 + fill_predict_future

        prediction = model.predict_fill(t0, future, desired_fill_pct, demand_exaggerate, rain_exaggerate)

        data = []
        unit = ""
        if graph_type == "demand":
            data = prediction["intermediate"]["demand"]
            unit = "m3"
        elif graph_type == "max_uitstroom":
            data = prediction["intermediate"]["max_uitstroom"]
            unit = "m3"
        elif graph_type == "toestroom":
            data = prediction["scenarios"]["mean"]["intermediate"]["toestroom"]
            unit = "m3"
        elif graph_type == "uitstroom":
            data = prediction["scenarios"]["mean"]["intermediate"]["uitstroom"]
            unit = "m3"

        result = {"graph_info": {"data": series_to_js(data), "x0": datetime_to_js(t0), "unit": unit}}
        return result
Esempio n. 4
0
    def prediction(self, t0, outflow_open, outflow_closed, outflow_capacity):
        tbl = EvaporationTable(self.basin, self.constants.rain_flood_surface)
        ds = FewsJdbcDataSource(self.basin, self.constants)
        model = CalculationModel(tbl, ds)
        future = t0 + settings.CONTROLNEXT_FILL_PREDICT_FUTURE

        prediction = model.predict_fill(t0, future, outflow_open,
                                        outflow_closed, outflow_capacity)
        data = {name: self.series_to_js(scenario['prediction'])
                for name, scenario in prediction['scenarios'].items()}
        data['history'] = self.series_to_js(prediction['history'])
        graph_info = {
            'data': data,
        }
        result = {
            'graph_info': graph_info,
            'overflow_24h': prediction['scenarios']['mean']['overstort_24h'],
            'overflow_5d': prediction['scenarios']['mean']['overstort_5d'],
        }
        return result
Esempio n. 5
0
class CalculationModelTest(TestCase):

    def setUp(self):
        tbl = DemandTable()
        self.tbl = tbl

        jdbc_source = JdbcSourceFactory.create(
            connector_string=('jdbc:vjdbc:rmi://p-fews-jd-d3.external-nens.'
                              'local:2001/VJdbc,FewsDataStore'),
            customfilter='',
            filter_tree_root='',
            jdbc_tag_name='controlnext_delfland',
            jdbc_url=('jdbc:vjdbc:rmi://p-fews-jd-d3.external-nens.local:2001'
                      '/VJdbc,FewsDataStore'),
            name='controlnext',
            slug='controlnext',
            usecustomfilter=False,
            timezone_string='UTC'
        )
        self.grower_info = GrowerInfoFactory.create(jdbc_source=jdbc_source)

        basin = BasinFactory.create(owner=self.grower_info,
                                    jdbc_source=jdbc_source)
        ds = FewsJdbcDataSource(basin)
        self.ds = ds
        self.model = CalculationModel(tbl, ds)

    @mock.patch('controlnext.fews_data.FewsJdbcDataSource.get_fill',
                get_fill_mock_data)
    @mock.patch('controlnext.fews_data.FewsJdbcDataSource.get_rain',
                get_rain_mock_data)
    def test_calc_model(self):
        now = mktim(2012, 8, 5, 8, 0)  # some rain fell here
        now = round_date(datetime.datetime.now(tz=pytz.utc))
        future = now + settings.CONTROLNEXT_FILL_PREDICT_FUTURE

        ts = self.model.predict_fill(now, future, 20, 100, 100)

        self.assertGreater(len(ts['scenarios']['mean']['prediction']), 10)
Esempio n. 6
0
    def setUp(self):
        tbl = DemandTable()
        self.tbl = tbl

        jdbc_source = JdbcSourceFactory.create(
            connector_string=('jdbc:vjdbc:rmi://p-fews-jd-d3.external-nens.'
                              'local:2001/VJdbc,FewsDataStore'),
            customfilter='',
            filter_tree_root='',
            jdbc_tag_name='controlnext_delfland',
            jdbc_url=('jdbc:vjdbc:rmi://p-fews-jd-d3.external-nens.local:2001'
                      '/VJdbc,FewsDataStore'),
            name='controlnext',
            slug='controlnext',
            usecustomfilter=False,
            timezone_string='UTC'
        )
        self.grower_info = GrowerInfoFactory.create(jdbc_source=jdbc_source)

        basin = BasinFactory.create(owner=self.grower_info,
                                    jdbc_source=jdbc_source)
        ds = FewsJdbcDataSource(basin)
        self.ds = ds
        self.model = CalculationModel(tbl, ds)