33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
"""Run the redesign with disposable, synthetic data: python scripts/preview.py."""
|
|
import os
|
|
import sys
|
|
from datetime import datetime, timedelta
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
|
os.environ['FLASK_CONFIG'] = 'TestingConfig'
|
|
|
|
from app.config import TestingConfig
|
|
|
|
TestingConfig.SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:'
|
|
from app import create_app, db
|
|
from app.models import Profile, Reading, User
|
|
from werkzeug.security import generate_password_hash
|
|
|
|
app = create_app()
|
|
with app.app_context():
|
|
db.create_all()
|
|
user = User(username='demo', password_hash=generate_password_hash('preview-only'),
|
|
profile=Profile(name='Alex Morgan', timezone='Australia/Sydney'))
|
|
db.session.add(user)
|
|
db.session.flush()
|
|
now = datetime.utcnow().replace(minute=30, second=0, microsecond=0)
|
|
db.session.add_all([Reading(user_id=user.id, timestamp=now - timedelta(hours=12 * i),
|
|
systolic=122 + ((i * 7) % 19), diastolic=74 + ((i * 3) % 12), heart_rate=62 + i % 14)
|
|
for i in range(120)])
|
|
db.session.commit()
|
|
|
|
if __name__ == '__main__':
|
|
print('Synthetic preview: http://127.0.0.1:5055 — demo / preview-only', flush=True)
|
|
app.run(host='127.0.0.1', port=5055, use_reloader=False, debug=False)
|