-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathteach.py
75 lines (50 loc) · 1.69 KB
/
teach.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import asyncio
from db import setup_mongo
from settings import config
async def train_and_save(collection):
"""
Train your model and save it for later.
The template of the function used for training the model.
You need to write the code reponsible for data
preprocessing and training the model of ML algorithm you chose.
"""
# Create you model - choose any classification algorithm you wish.
# Extract features and labels from tha data in the database.
cursor = collection.find({})
async for document in cursor:
data = document['data']
# Train the model.
# Store the model so that it can be loaded later using load_model.
async def load_model():
"""
Load a trained model that you prepared in `train_and_save` earlier.
"""
import time
# The game will not start unless this callback finishes, take your
# time to load/compile the model now.
time.sleep(2)
return None
async def predict(model, yV, hV, s, x, ts):
"""
Make predictions during a game.
Given incoming data return an iterable of boolean values indicating
which controls should be active.
Should return a tuple of booleans (PRESS_UP, PRESS_LEFT, PRESS_RIGHT)
"""
import time
now = int(time.time())
press_up = (now % 5) < 3
press_left = (now % 10) < 4
press_right = (now % 10) > 5
return press_up, press_left, press_right
def main():
loop = asyncio.get_event_loop()
mongo = setup_mongo(loop)
db = mongo[config.DBNAME]
collection = db[config.COLLECTION_NAME]
try:
loop.run_until_complete(train_and_save(collection))
finally:
mongo.close()
if __name__ == '__main__':
main()