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'])
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)
import pytz from django.test import TestCase from lizard_fewsjdbc.tests.factories import JdbcSourceFactory from controlnext.calc_model import CalculationModel from controlnext.conf import settings from controlnext.demand_table import DemandTable from controlnext.fews_data import FewsJdbcDataSource from controlnext.utils import round_date, mktim from controlnext.tests.factories import GrowerInfoFactory, BasinFactory logger = logging.getLogger(__name__) w26_0 = mktim(2012, 6, 25, 0, 0) # monday, 0:00, week 26 (d = 20000) w27_0 = mktim(2012, 7, 2, 0, 0) # monday, 0:00, week 27 (d = 20000) w28_0 = mktim(2012, 7, 9, 0, 0) # monday, 0:00, week 28 (d = 19000) w28_5 = mktim(2012, 7, 12, 12, 0) # middle of week 28 w29_0 = mktim(2012, 7, 16, 0, 0) # sunday, 0:00, week 29 (d = 18000) w29_5 = mktim(2012, 7, 19, 12, 0) # middle of week 29 w30_0 = mktim(2012, 7, 23, 0, 0) # sunday, 0:00, week 30 (d = 17000) w30_5 = mktim(2012, 7, 26, 12, 0) # middle of week 30 (d = 17000) # TODO: setup dynamically, otherwise tests will fail after a while wNOW = mktim(2012, 12, 5, 0, 0) wNOW_5 = mktim(2012, 12, 8, 12, 0)