def practice_arithmetic(dbs, communicator, user, operation, min_x, max_x, min_y, max_y): # Get or add pertinent arithmetic records: #q = dbs.query(db.Performance).filter_by(user = user).filter(db.Performance.x >= min_x).filter(db.Performance.x <= max_x).filter(db.Performance.y >= min_y).filter(db.Performance.y <= max_y).filter(db.Performance.operation == operation).order_by(db.Performance.recent_speed_ms.desc()).order_by(db.Performance.id) prefs = db.get_preferences(dbs, user.username) if prefs.start_x: min_x = max(min_x, prefs.start_x) if prefs.start_y: min_y = max(min_y, prefs.start_y) q = dbs.query(db.Performance).filter_by(user=user).filter( db.Performance.x >= min_x).filter(db.Performance.x <= max_x).filter( db.Performance.y >= min_y).filter( db.Performance.y <= max_y).filter( db.Performance.operation == operation).order_by( db.Performance.id) records = q.all() existing_combos = [(r.x, r.y) for r in records] for combo in [(a, b) for a in range(min_x, max_x + 1) for b in range(min_y, max_y + 1)]: # all combos as 2-tuples if combo not in existing_combos: # Add additional combo: dbs.add( db.Performance(user_id=user.id, x=combo[0], y=combo[1], operation=operation)) dbs.commit() # Re-fetch, to get default values: records = q.all() # Now run the practice: _practice(dbs, communicator, records, 5000) # threshold of 4 seconds for arithmetic operations
def post(self): user_id = self.get_current_user() messages = self.messages.copy() if self.get_argument('email-form', default=None): mail = self.get_argument('email', default='') letter = self.get_argument('newsletter', default=False) resubscribe = self.get_argument('resubscribe', default=False) == 'on' db.change_preferences(user_id, mail, letter, resubscribe) messages['mail'] = 'Mail preferences updated' elif self.get_argument('password-form', default=None): password = self.get_argument('current_password') new_pw = self.get_argument('password') new_pw_dup = self.get_argument('password_dup') if new_pw != new_pw_dup: messages['password_error'] = 'Passwords don\'t match' else: try: db.change_password(user_id, password, new_pw) messages['password'] = '******' except db.UserError as e: messages['password_error'] = e.message prefs = db.get_preferences(user_id) self.render('settings.html', prefs=prefs, **messages)
def parse_args(channel_id, args): args = args.split(' ') if args[0] == 'preferences': # TODO: format this in a nice way (get ordered dict out) return 'Your lunch-spinner preferences are %s' % (str( db.get_preferences(channel_id).items())) elif args[0] == 'setup': new_valid_settings = parse_valid_settings(args) all_settings = db.set_preferences(channel_id, new_valid_settings) # TODO: reload restaurants upon settings change # get_restaurants(channel_id) return "We've set your preference to %s \n Your settings are now: %s" % ( new_valid_settings, db.get_preferences(channel_id))
def get(self): userid = self.get_current_user() keys = db.get_keys(userid) prefs = db.get_preferences(userid) error = self.get_argument("error", "") context = self.get_argument("context", "") self.render('settings.html', keys=keys, prefs=prefs, error=error, context=context)
def _math(ws_method, again): sess = b.request.environ.get('beaker.session') dbs = session_maker() prefs = db.get_preferences(dbs, sess['username']) ac, no_source_length = make_audios() return b.template('math', ws_protocol=k_ws_protocol, ws_url_prefix=k_ws_url_prefix, ws_method=ws_method, intro=k_math_intro, trial=sess.get('trial', 0), again=gurl(again), timer_minutes=prefs.time_minutes, counter=prefs.count, audio_controls=ac, audio_count=no_source_length)
def get(self): user_id = self.get_current_user() prefs = db.get_preferences(user_id) self.render('settings.html', prefs=prefs, **self.messages)
def requestPrefs(): if request.method == 'POST': data = db.get_preferences(1) lots = db.get_lots(1) res = prefs.processPrefs(data, lots) return createJSON(res)
def preferences(): dbs = session_maker() sess = b.request.environ.get('beaker.session') prefs = db.get_preferences(dbs, sess['username']).__dict__ return b.template('preferences', username=sess['username'], values=prefs)
def get_restaurants(channel_id): businesses = refresh_business_list(db.get_preferences(channel_id)) db.set_restaurants(channel_id, businesses)