def get_future_matches(hours): now = datetime.utcnow() from models.match import Match matches = Match.objects(match_date__gt=now, match_date__lte=now + timedelta(hours=hours)).order_by('match_date') response = [] for m in matches: match_date = m.match_date + timedelta(hours=8) match_date_str = datetime.strftime(match_date, '%Y-%m-%d %H:%M:%S') from models.match import MatchResponse match_response = MatchResponse(m.wubai_id, m.league, match_date_str, m.home_team, m.away_team, m.rang) response.append(match_response.__dict__) return jsonify(response)
def get_match(wubai_id): from models.match import Match m = Match.objects(wubai_id=wubai_id).first() match_date = m.match_date + timedelta(hours=8) match_date_str = datetime.strftime(match_date, '%Y-%m-%d %H:%M:%S') from models.match import MatchResponse response = MatchResponse(m.wubai_id, m.league, match_date_str, m.home_team, m.away_team, m.rang) if hasattr(m, 'home_score'): response.home_score = m.home_score if hasattr(m, 'away_score'): response.away_score = m.away_score if hasattr(m, 'result'): response.result = m.result if hasattr(m, 'result_rang'): response.result_rang = m.result_rang return jsonify(response.__dict__)
def get_accuracy(hours): now = datetime.utcnow() from models.match import Match matches = Match.objects(match_date__lt=now, match_date__gte=now - timedelta(hours=hours), result__exists=True) bingo = 0 for m in matches: wubai_id = m.wubai_id from models.odd import Odd o = Odd.objects(wubai_id=wubai_id).first() if o.profits: size = len(o.profits) total_init_profit_home = 0 total_init_profit_draw = 0 total_init_profit_away = 0 total_new_profit_home = 0 total_new_profit_draw = 0 total_new_profit_away = 0 for p in o.profits: total_init_profit_home += p['init_sp_profit']['init_profit_home'] total_init_profit_draw += p['init_sp_profit']['init_profit_draw'] total_init_profit_away += p['init_sp_profit']['init_profit_away'] total_new_profit_home += p['new_sp_profit']['new_profit_home'] total_new_profit_draw += p['new_sp_profit']['new_profit_draw'] total_new_profit_away += p['new_sp_profit']['new_profit_away'] profits = [round(total_init_profit_home / size, 3), round(total_init_profit_draw / size, 3), round(total_init_profit_away / size, 3), round(total_new_profit_home / size, 3), round(total_new_profit_draw / size, 3), round(total_new_profit_away / size, 3)] results = [3, 1, 0] if profits[3] < 0: results.remove(3) if profits[4] < 0: results.remove(1) if profits[5] < 0: results.remove(0) if m.result_rang in results: bingo += 1 if matches.count() > 0: response = {'bingo': round(bingo / matches.count() * 100, 1)} else: response = {'bingo': 0} return jsonify(response)