forked from iamadamhair/ispy_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
99 lines (71 loc) · 2.02 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import os
import time
import logging as log
from game import Game
import models
import questions
import config
import database as db
class Main:
def __init__(self):
"""
Entry point of the simulation
"""
self._init_logger()
db.init_driver()
db.connect(config.db['address'], config.db['username'], config.db['password'], config.db['database'], unix_socket=config.db['socket'])
if config.setup:
self.setup()
start = time.time()
self.simulate()
end = time.time()
log.info('Simulation complete! (Took %ds)', int(end - start))
def simulate(self):
"""
Run the simulation
"""
log.info('Starting simulation')
games_folder = os.getcwd() + '/Human_Games'
wins = 0
losses = 0
num_questions = 0
avg_win = 0
avg_lose = 0
questions_asked = {}
question_answers = {}
for number in range(16, 31):
game = Game(number)
game_wins, game_losses, game_num_questions, game_win_avg, game_lose_avg, game_answers, game_questions = game.play()
questions_asked[game.id] = game_questions
question_answers = game_answers
wins += game_wins
losses += game_losses
num_questions += game_num_questions
avg_win += game_win_avg
avg_lose += game_lose_avg
models.build(game, 3, questions_asked, question_answers)
def setup(self):
"""
Perform optional pre-simulation tasks
"""
log.info('Performing setup')
db.cursor.execute('DELETE FROM Pqd')
db.connection.commit()
questions.copy_into_answers()
questions.build_pqd()
models.build(Game(15), 1)
for number in range(16, 31):
models.evaluation_1(Game(number))
def _init_logger(self):
"""
Setup logger
"""
log.basicConfig(level='DEBUG', format='[ %(levelname)-5.5s] %(message)s')
rootLogger = log.getLogger()
fileFormatter = log.Formatter('%(asctime)s [ %(levelname)-5.5s] %(message)s')
fileHandler = log.FileHandler('log.txt')
fileHandler.setFormatter(fileFormatter)
rootLogger.addHandler(fileHandler)
log.info('\n'*8 + '='*31 + '| NEW SIMULATION |' + '='*31 + '\n')
if __name__ == '__main__':
Main()