Esempio n. 1
0
def get_model_score(model, day):
    try:
        ms = ModelScore.query.filter_by(model_id=model.id, day=day, region='e').one()
    except NoResultFound:
        ms = ModelScore()
        ms.region = 'e'
        ms.model = model
        ms.day = day
    return ms
Esempio n. 2
0
 def testModel(self):
     """ Evaluates methods not annotated as @property"""
     ml = Model()
     ml.name = 'Test Model'
     ml.type = 'google'
     ml.public = True
     ml.data = 'matlab_function,1'
     db.session.add(ml)
     score = 6.5
     day = datetime.date.today() - datetime.timedelta(days=3)
     for i in xrange(4):
         ms = ModelScore()
         ms.day = day + datetime.timedelta(days=i)
         ms.region = 'e'
         ms.value = score - i
         ms.model_id = 1
         db.session.add(ms)
     db.session.commit()
     dbmodel = db.session.query(Model).first()
     expected = db.session.query(ModelScore).all()
     result_get_scores = dbmodel.get_scores(start=day, end=datetime.date.today(), region='e', resolution=1)
     self.assertEqual(result_get_scores, expected)
     result_regions = dbmodel.scores_for('e').all()
     self.assertEqual(result_regions, expected)
     result_get_data = dbmodel.get_data()
     self.assertEqual(result_get_data['matlab_function'], 'matlab_function')
     self.assertEqual(result_get_data['average_window_size'], 1)
Esempio n. 3
0
def run(model, start, end, csv_file=None, **kwargs):
    if csv_file is None:
        raise FluDetectorError('No CSV file provided')
    logger.info('Reading CSV file into %s' % str(model))
    csv_reader = csv.reader(csv_file)

    headers = next(csv_reader)

    day_index = find_matching_index(headers, ['Day', 'Date'], required=True)
    region_index = find_region_index(headers)

    logger.debug('Found columns for regions %s' %
                 ', '.join(region_index.keys()))

    logger.info('Reading rows...')
    for row_index, row in enumerate(csv_reader):
        day = datetime.strptime(row[day_index], '%Y-%m-%d').date()

        if day < start or day > end:
            continue

        for region, col_index in region_index.iteritems():
            try:
                value = float(row[col_index])
            except ValueError:
                logger.debug('Skipping row %d column %d, not a float' %
                             (row_index + 1, col_index))
                continue
            try:
                ms = ModelScore.query.filter_by(model_id=model.id,
                                                day=day,
                                                region=region).one()
            except NoResultFound:
                ms = ModelScore()
                ms.region = region
                ms.model = model
                ms.day = day
            ms.value = value
            db.session.add(ms)

    db.session.commit()
    logger.info('Done!')
Esempio n. 4
0
 def setUp(self):
     db.init_app(GoogleTest.create_app())
     db.create_all()
     db.engine.execute('insert into model values (1, "Test Model", "google", 1, "matlab_function,1")')
     score = 6.5
     start_date = datetime.date.today() - datetime.timedelta(days=5)
     for i in xrange(4):
         ms = ModelScore()
         ms.day = start_date + datetime.timedelta(days=i)
         ms.region = 'e'
         ms.value = score - i
         ms.model_id = 1
         db.session.add(ms)
         gs = GoogleScore()
         gs.day = start_date + datetime.timedelta(days=i)
         gs.value = score - i
         gs.term_id = 1
         db.session.add(gs)
     db.session.commit()
     db.engine.execute('insert into google_term values (1, "Term 1")')
     db.engine.execute('insert into model_google_terms values (1, 1)')