initial commit
This commit is contained in:
86
db/default.py
Normal file
86
db/default.py
Normal file
@@ -0,0 +1,86 @@
|
||||
# python
|
||||
# File: db/debug.py
|
||||
|
||||
import random
|
||||
from models.child import Child
|
||||
from models.task import Task
|
||||
from models.reward import Reward
|
||||
from models.image import Image
|
||||
from tinydb import Query
|
||||
from db.db import child_db, task_db, reward_db, image_db
|
||||
from api.image_api import IMAGE_TYPE_ICON, IMAGE_TYPE_PROFILE
|
||||
|
||||
def populate_default_data():
|
||||
# Create tasks
|
||||
task_defs = [
|
||||
('default_001', "Be Respectful", 2, True, ''),
|
||||
('default_002', "Brush Teeth", 2, True, ''),
|
||||
('default_003', "Go To Bed", 2, True, ''),
|
||||
('default_004', "Do What You Are Told", 2, True, ''),
|
||||
('default_005', "Make Your Bed", 2, True, ''),
|
||||
('default_006', "Do Homework", 2, True, ''),
|
||||
]
|
||||
tasks = []
|
||||
for _id, name, points, is_good, image in task_defs:
|
||||
t = Task(name=name, points=points, is_good=is_good, image_id=image, id=_id)
|
||||
tq = Query()
|
||||
_result = task_db.search(tq.id == _id)
|
||||
if not _result:
|
||||
task_db.insert(t.to_dict())
|
||||
else:
|
||||
task_db.update(t.to_dict(), tq.id == _id)
|
||||
tasks.append(t.to_dict())
|
||||
|
||||
# Create 4 rewards
|
||||
reward_defs = [
|
||||
('default_001', "Special Trip", "Go to a park or a museum", 3,''),
|
||||
('default_002', "Money", "Money is always nice", 8, ''),
|
||||
('default_003', "Choose Dinner", "What shall we eat?", 12, 'meal'),
|
||||
('default_004', "Tablet Time", "Play your games", 5, 'tablet'),
|
||||
('default_005', "Computer Time", "Minecraft or Roblox?", 5, 'computer-game'),
|
||||
('default_006', "TV Time", "Too much is bad for you.", 5, ''),
|
||||
]
|
||||
rewards = []
|
||||
for _id, name, desc, cost, image in reward_defs:
|
||||
r = Reward(name=name, description=desc, cost=cost, image_id=image, id=_id)
|
||||
rq = Query()
|
||||
_result = reward_db.search(rq.id == _id)
|
||||
if not _result:
|
||||
reward_db.insert(r.to_dict())
|
||||
else:
|
||||
reward_db.update(r.to_dict(), rq.id == _id)
|
||||
rewards.append(r.to_dict())
|
||||
|
||||
image_defs = [
|
||||
('computer-game', IMAGE_TYPE_ICON, '.png', True),
|
||||
('ice-cream', IMAGE_TYPE_ICON, '.png', True),
|
||||
('meal', IMAGE_TYPE_ICON, '.png', True),
|
||||
('playground', IMAGE_TYPE_ICON, '.png', True),
|
||||
('tablet', IMAGE_TYPE_ICON, '.png', True),
|
||||
('boy01', IMAGE_TYPE_PROFILE, '.png', True),
|
||||
('girl01', IMAGE_TYPE_PROFILE, '.png', True),
|
||||
('girl02', IMAGE_TYPE_PROFILE, '.png', True),
|
||||
('boy02', IMAGE_TYPE_PROFILE, '.png', True),
|
||||
('boy03', IMAGE_TYPE_PROFILE, '.png', True),
|
||||
('girl03', IMAGE_TYPE_PROFILE, '.png', True),
|
||||
('boy04', IMAGE_TYPE_PROFILE, '.png', True),
|
||||
('girl04', IMAGE_TYPE_PROFILE, '.png', True),
|
||||
]
|
||||
images = []
|
||||
for _id, _type, ext, perm in image_defs:
|
||||
iq = Query()
|
||||
_result = image_db.search(iq.id == _id)
|
||||
if not _result:
|
||||
image_db.insert(Image(_type, ext, perm, id=_id).to_dict())
|
||||
else:
|
||||
image_db.update(Image(_type, ext, perm, id=_id).to_dict(), iq.id == _id)
|
||||
images.append(Image(_type, ext, perm, id=_id).to_dict())
|
||||
|
||||
return {
|
||||
"images": images,
|
||||
"tasks": tasks,
|
||||
"rewards": rewards
|
||||
}
|
||||
|
||||
if __name__ == "__main__":
|
||||
result = populate_default_data()
|
||||
Reference in New Issue
Block a user