-
Notifications
You must be signed in to change notification settings - Fork 5
/
__init__.py
92 lines (77 loc) · 2.61 KB
/
__init__.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
import os
from werkzeug.contrib.cache import SimpleCache
from flask import Flask, request, session, g, redirect, url_for, abort, \
render_template, flash
from sqlite3 import dbapi2 as sqlite3
import glob
import xml.etree.ElementTree as ET
# for user login
# pip install Flask-Login
from flask_login import LoginManager, login_required, login_user, \
logout_user, UserMixin, AnonymousUserMixin, current_user
# http://blog.csdn.net/yatere/article/details/78860852
# from time import sleep
from concurrent.futures import ThreadPoolExecutor, as_completed
OFFICIAL_MAILBOX = '[email protected]'
DATABASE = './auto_quiz.db'
FILE_DIR = './static/dataset/'
DKT_SESS_DAT = "dkt_sessions.csv"
BATCH_SIZE = 16
MAX_SESS = 16
N_EPOCH = 16
DKT_MODEL = "model.ckpt"
MODEL_LOG_FOLDER = "./log/"
THRESHOLD_ACC = 0.6
THRESHOLD_AUC = 0.5
ID_ENCODING_FILE = 'id_encoding.csv'
ID_CATEGORY_FILE = 'id_category.csv'
EN_CATEGORY_FILE = 'en_category.csv'
TOPIC_NAMES_FILE = 'topic_names.csv'
# create the application
app = Flask(__name__)
# http://blog.csdn.net/yannanxiu/article/details/52916892
# http://werkzeug.pocoo.org/docs/0.14/contrib/cache/
# cache
user_cache = SimpleCache()
executor = ThreadPoolExecutor(2)
# Load default config and override config from an environment variable
app.config.update(dict(
DATABASE=os.path.join(app.root_path, 'auto_quiz.db'),
# DEBUG=True,
SECRET_KEY='development key',
USERNAME='admin',
PASSWORD='default'
))
app.config.from_envvar('FLASKR_SETTINGS', silent=True)
# login management
login_manager = LoginManager()
login_manager.setup_app(app)
DEBUG_FILE = 'debug_info.txt'
def debug_output(output_string):
# debug print into file
file_path = os.path.join(app.root_path, DEBUG_FILE)
with open(file_path, 'a') as f:
f.write("{0}\n".format(output_string))
return True
class User(UserMixin):
def __init__(self, user_name, user_id):
self.user_id = user_id
self.user_name = user_name
def get_id(self):
try:
return unicode(self.user_id) # python 2
except NameError:
return str(self.user_id) # python 3
def get_name(self):
try:
return unicode(self.user_name) # python 2
except NameError:
return str(self.user_name) # python 3
def debug_introduce(self):
print ("hello, I am {0}, my id is {1}".format(self.user_name, self.user_id))
class AnonymousUser(AnonymousUserMixin):
def get_name(self):
return None
def debug_introduce(self):
print ("hello, I am annonymous user")
login_manager.anonymous_user = AnonymousUser