def scores(self): # get a data connection beast = dataBeast("funkyTrain", "level") # get the game ids gids = beast.distinct("game") # collect game names and the top 5 sids/top scores for each game tables = "" for gid in gids: name = beast.execute("SELECT name FROM games where gid = %s" % gid) scores = beast.select( "(SELECT name from users where uid = user), score", {"game": gid}, sort="score DESC", limit=5 ) tables += gp_template.get_def("table").render(title=name, data=scores) return tables
def user(self): #are we a logged in user? # print cherrypy.response.cookie #cherrypy.response.cookie['funkyTrainUser'] = '******' cookie = cherrypy.request.cookie output = "test" output += str(cookie) for name in cookie.keys(): output+=name #output = cherrypy.response.cookie["funkyTrainUser"].value if cookie.has_key('funkyTrainUser'): #get a data connection beast = dataBeast("funkyTrain", "users") #get the game ids now = datetime.date.today() today = now.strftime("%Y-%m-%d") #get the user's name and the training program they are on username = cookie['funkyTrainUser'].value #username = "******" start = beast.select("start", {'name':username}) tpid = beast.select("currentTraining", {'name':username}) sid = beast.select("uid", {'name':username}) #if it's the first day the user logged in, kick the training off if not start: beast.update("start", "'%s'" % today, {'name':username}) trainingDay = 1 start = now #otherwise figure out which day of training we are on else: trainingDay = (now - start).days + 1 output = "%s, day %s of training.<br/>" % (today, trainingDay) cherrypy.response.cookie['funkyTrainDay'] = trainingDay beast.setTable("training") pre, post, training = beast.select("pre, post, training", {'tpid': tpid}) training = training.split(',') training = map(lambda x: int(x), training) tdays = [pre] + training + [post] #which phase are we in? if trainingDay == pre: phase = 'pre' elif trainingDay == post: phase = 'post' elif trainingDay in training: phase = 'training' else: phase = None schedule = [['training day', 'date']] for td in tdays: calDay = start + datetime.timedelta(days=td-1) schedule.append([td, calDay.strftime("%Y-%m-%d")]) if phase: games = beast.select("%sGames" % phase, {'tpid':tpid}) games = games.split(',') beast.setTable("completed") completed = beast.distinct("gid", {'day':trainingDay, 'sid':sid}) if type(completed) != list: completed = [completed] completed = map(lambda x: int(x), completed) for game in games: if int(game) not in completed: url, name = beast.execute("SELECT url, name FROM games", {"gid":game}) output += "<a href='%s'>%s</a><br/>" % (url, name) output += gp_template.get_def("table").render(title="Your training schedule", data=schedule) else: output += ":(" return output
# gamePage.py # generation of static game content from mako_defs import gp_template import databeast import os root = "/var/www/Project-EFH/" beast = databeast.dataBeast("funkyTrain", "training") # build the <head> scripts = ["jquery", "css/common.css", "js/common.js", "js/main.js"] output = gp_template.get_def("head").render(title="all aboard the funkyTrain", scripts=scripts) # header div header = gp_template.get_def("header").render(user="") # some content messages = gp_template.get_def("title_div").render(ID="messages", title="Messages", data="No messages.", title_lvl=3) scores = gp_template.get_def("title_div").render(ID="scores", title="High Scores", data=":)", title_lvl=3) # schedule = gp_template.get_def("title_div").render(ID="schedule", title="Your training schedule", data="", title_lvl=3) # footer div footer = gp_template.get_def("footer").render() # add it to the <body> output += gp_template.get_def("body").render(data=header + messages + scores + footer)
root = '/var/www/Project-EFH/' beast = databeast.dataBeast("funkyTrain", "games") scripts = ['jquery', 'gamequery', '../js/Subject.js', '../js/shuffler.js', '../js/gameFuncs.js', '../js/common.js', '../js/sprintf.js', '../js/makeCueList.js', '../css/common.css', '../css/gamePage.css'] for gid in beast.distinct('gid'): #get some game info filename = beast.select("filename", {'gid':gid}) game = beast.select("name", {'gid':gid}) instructions = beast.select("notes", {'gid':gid}) #build the header extrascripts = ['%s.css' % filename, '%s_constants.js' % filename, '%s.js' % filename] arg = scripts + extrascripts output = gp_template.get_def("head").render(title=game, scripts=arg) info_content = [] header = gp_template.get_def("header").render(user="") #game info div controls = beast.select("controls", {'gid':gid}) info_content.append(['Controls', controls]) #links #links="<a href='../index.html'>Your Home Page</a><br/>" #info_content.append(['', links]) info_content.append(['', gp_template.get_def("game_stats").render()])
#gamePage.py #generation of static game content from mako_defs import gp_template import databeast import os root = '/var/www/Project-EFH/' beast = databeast.dataBeast("funkyTrain", "training") #build the <head> scripts = ['jquery', 'css/common.css', 'js/common.js', 'js/login.js'] output = gp_template.get_def("head").render(title='all aboard the funkyTrain', scripts=scripts) #header div header = gp_template.get_def("header").render(user="") #some content about = gp_template.get_def("title_div").render(ID="", title="funkyTrain", data="<p>An investigation into the trainability of executive function being conducted by CDL-UWO</p>", title_lvl=2) loginBox = gp_template.get_def("login_box").render() #footer div footer = gp_template.get_def("footer").render() #add it to the <body> output += gp_template.get_def("body").render(data=header + about + loginBox + footer) f = open(os.path.join(root, "index.html"), "w") f.write("<html>")
def index(self): self.beast = databeast.dataBeast("funkyTrain", "users") create = gp_template.get_def("account_create").render() reset = gp_template.get_def("account_reset").render() adjust = gp_template.get_def("account_adjust").render() return create + reset + adjust