コード例 #1
0
def app():
    # Provide CONFIG values.
    config = dict(
      FLASK_DEBUG=True,
      WTF_CSRF_ENABLED=False,
      TESTING=True,
      CHEESE_SECRET_KEY=1,
      MAIL_DEFAULT_SENDER='*****@*****.**',
      SQLALCHEMY_DATABASE_URI = 'sqlite:///' + \
          tempfile.NamedTemporaryFile(suffix='.db').name, )
    app = create_app(config)
    app.testing = True
    print('Using db ' + app.config['SQLALCHEMY_DATABASE_URI'])
    with app.app_context():
        resetdb()
    return app
コード例 #2
0
import csv
import sys
from cheese.factory import create_app
from cheese.models import db, Results, BuildingTypes, WallConstructionTypes, OccupationTypes, SpaceHeatingTypes, CookingTypes, WaterHeatingTypes

app = create_app()
f = open(sys.argv[1], 'r')
reader = csv.reader(f)
for row in reader:
    print 'Result {}'.format(row)
    with app.app_context():
        result = Results.query.get(int(row[0]))
        result.building_type_id = BuildingTypes.query.filter_by(
            name=row[1].strip()).first().id
        result.wall_construction_type_id = WallConstructionTypes.query.filter_by(
            name=row[2].strip()).first().id
        result.occupation_type_id = OccupationTypes.query.filter_by(
            name=row[3].strip()).first().id
        result.primary_heating_type_id = int(row[4])
        result.secondary_heating_type_id = int(row[5])
        db.session.commit()
f.close()
コード例 #3
0
ファイル: run.py プロジェクト: jameshanlon/cheese
from cheese.factory import create_app
app = create_app()
コード例 #4
0
ファイル: dump-surveys.py プロジェクト: jameshanlon/cheese
from cheese.factory import create_app
app=create_app({})
from cheese.models import Surveys
with app.app_context():
  for x in Surveys.query.filter(Surveys.phase==4).all():
    print '{} {} {}'.format(x.id, x.survey_request_date, x.name)
  print len(Surveys.query.filter(Surveys.phase==4).all())

コード例 #5
0
import sys
import datetime
from cheese.factory import create_app
from cheese.models import db, Surveys
from cheese.settings import PHASE_START_DATES

config = dict()
app = create_app(config)

with app.app_context():
    for i, start_date in enumerate(PHASE_START_DATES):
        phase = i + 1
        end_date = start_date + datetime.timedelta(365.25)
        query = Surveys.query
        query = query.filter(Surveys.survey_request_date >= start_date)
        query = query.filter(Surveys.survey_request_date < end_date)
        for survey in query.all():
            if survey.phase == -1 or survey.phase == None:
                survey.phase = phase
                print 'Set phase {} for survey {}'.format(phase, survey.id)
    db.session.commit()
    print 'Surveys without a phase:'
    query = Surveys.query.filter(phase == None or phase == -1)
    for survey in query.all():
        print '  id {} in phase {}'.format(survey.id, survey.phase)
コード例 #6
0
ファイル: dump-surveys.py プロジェクト: jameshanlon/cheese
from cheese.factory import create_app
app = create_app({})
from cheese.models import Surveys, Results, BuildingTypes, WallConstructionTypes, CookingTypes, OccupationTypes, SpaceHeatingTypes, CookingTypes

survey_ids = [342, 426, 417, 440, 446, 461, 442, 473, 471, 476, 477, 482]

with app.app_context():
    for survey_id in survey_ids:
        survey = Surveys.query.get(survey_id)
        results = Results.query.filter(Results.survey_id == survey.id).all()
        if results == None:
            print 'No result for survey {}'.format(survey.id)
            continue
        elif len(results) > 1:
            print 'Multiple results for survey {}'.format(survey.id)
            continue
        result = results[0]
        print '=' * 50
        print 'SURVEY {}'.format(survey.id)
        print '=' * 50
        data = []
        data.append(('Survey date', result.date))
        data.append(('Householder\'s name', result.householders_name))
        data.append(('Lead surveyor', result.lead_surveyor))
        data.append(('Assistant surveyor', result.assistant_surveyor))
        data.append(('Building type', result.building_type.name
                     if result.building_type else 'Unspecified'))
        data.append(('Occupation type', result.occupation_type.name
                     if result.occupation_type else 'Unspecified'))
        data.append(('Number of occupants', result.num_occupants))
        data.append(('External temperature', result.external_temperature))
コード例 #7
0
import sys
import datetime
from cheese.factory import create_app
from cheese.models import db, Surveys
from cheese.settings import PHASE_START_DATES

config=dict()
app = create_app(config)

with app.app_context():
    for i, start_date in enumerate(PHASE_START_DATES):
        phase = i + 1
        end_date = start_date + datetime.timedelta(365.25)
        query = Surveys.query;
        query = query.filter(Surveys.survey_request_date >= start_date)
        query = query.filter(Surveys.survey_request_date < end_date)
        for survey in query.all():
            if survey.phase == -1 or survey.phase == None:
              survey.phase = phase
              print 'Set phase {} for survey {}'.format(phase, survey.id)
    db.session.commit()
    print 'Surveys without a phase:'
    query = Surveys.query.filter(phase==None or phase==-1)
    for survey in query.all():
        print '  id {} in phase {}'.format(survey.id, survey.phase)