def pushResults(gpid, gpresultlist, qresultlist, fastest): # if (logging.isEnabledFor(logging.DEBUG)): logging.debug ("Gp results ", json.dumps(gpresultlist)) logging.debug ("Qu results ", json.dumps(qresultlist)) logging.debug ("Fastest lap ", json.dumps(fastest)) driverlist = drivers.getAllDriverData(firebase_url, season) gpdata = calendar.getCalendarData(firebase_url, season, gpid) results = dict() if fastest: fastestlap = dict() driver = driverlist[fastest] fastestlap['d_id'] = driver['d_id'] fastestlap['info'] = driver['d_name'] fastestlap['points'] = 3 results['fastestlap'] = fastestlap results['qlresults'] = [] results['gpresults'] = [] for idx, val in enumerate(qresultlist): if val in driverlist: driver = driverlist[val] result = dict() result['driverid'] = driver['d_id'] result['position'] = idx + 1 result['points'] = len(qresultlist) - idx result['info'] = driver['d_name'] results['qlresults'].append(result) gpdata['gp_status'] = __GP_QUAL for idx, val in enumerate(gpresultlist): if val in driverlist: driver = driverlist[val] result = dict() result['driverid'] = driver['d_id'] result['position'] = idx + 1 result['points'] = len(gpresultlist) - idx result['info'] = driver['d_name'] results['gpresults'].append(result) gpdata['gp_status'] = __GP_RACE gpdata['results'] = results query = "/calendar/" + str(gpdata['gp_year']) + "/" + str(gpdata['gp_id']) + ".json" logging.info ("Pushing results to " + query) firebase.curlPut(firebase_url + query, json.dumps(gpdata))
def checkBetvalues(gp_id, user_id): gpdata = calendar.getCalendarData(firebase_url, season, gp_id) userlist = profiles.getUserData(firebase_url, user_id) logging.info ("Checking bet values for gp = " + gp_id) for user in userlist: logging.info ("-----------------------------------------------------------------") userid = user['userid'] currentbet = dict() logging.info ("Checking bet values for user = "******"User " + userid + " has bet for " + gp_id ) userbets = user['bets'] currentbet = userbets[gp_id] if 'results' in gpdata: currentbet = calculateScore(currentbet, gpdata['results']) else: logging.info ("User " + userid + " has no bets for gp " + gp_id) currentbet = dict() currentbet['status'] = __BET_MISSING currentbet['gp_id'] = gp_id currentbet['gp_name'] = gpdata['gp_short_name'] currentbet['userid'] = userid currentbet['totalpoints'] = 0 query = "/users/" + str(userid) + "/bets/" + str(gp_id) + ".json" firebase.curlPut(firebase_url + query, json.dumps(currentbet)) query = "/users/" + str(userid) + "/scores/" + str(gp_id) + ".json" firebase.curlPut(firebase_url + query, json.dumps(currentbet)) query = "/scores/" + season + "/" + str(gp_id) + "/" + str(userid) + ".json" firebase.curlPut(firebase_url + query, json.dumps(currentbet)) query = "/calendar/" + season + "/" + str(gp_id) + "/scores/" + str(userid) + ".json" firebase.curlPut(firebase_url + query, json.dumps(currentbet)) if gpdata['gp_status'] < __GP_QUAL: closeGP(gpdata)