def GetPredictions(): """Returns all of the predictions (and can filter by org).""" org_filter = request.args.get('org', False) if org_filter: predictions = Prediction.query(Prediction.org == org_filter).fetch() else: predictions = Prediction.query().fetch() for prediction in predictions: # TODO(goldhaber): add these to the datastore prediction.url = 'predictions/' + prediction.key.urlsafe() prediction.price = GetPriceByPredictionId( prediction.key.urlsafe()) * 100 return render_template('predictions.html', predictions=predictions)
def scoring(): #go through all predictions, check if should be scored predictions = Prediction.query( ndb.AND(Prediction.outcome != "UNKNOWN", Prediction.resolved == False)).fetch() audit = [] # Get all trades by prediction_id for p in predictions: resolve = p.outcome trades = Trade.query(Trade.prediction_id == p.key).fetch() # Get user id from those trades users = [trade.user_id.get() for trade in trades] for u in users: # check user ledger, map outcome to 1 or 0 based on prediction outcome ledger = [i for i in u.user_ledger if i.prediction_id == p.key.urlsafe()] if resolve == 'CONTRACT_ONE': earned = ledger[0].contract_one else: earned = ledger[0].contract_two u.balance += earned audit.append({'user': u, 'earned': earned}) u.put() p.resolved = True p.put() return audit