Exemplo n.º 1
0
 def wager_from_row(r):
     events = self.get_events(r['wager_id'])
     return surprise.wager(wager_id = r['wager_id'],
           wager_date = r['wager_date'],
           ext_id = r['external_id'],
           stake = r['stake'],
           system_size = r['system_size'],
           manager = r['manager'],
           win_amount = r['win_amount'],
           events = events,
           hits = self.get_hits(events))
Exemplo n.º 2
0
def parse_wager(w):
    def parse_selection(s):
        return {
            "home": (True if "home" in s else False),
            "tie": (True if "tie" in s else False),
            "away": (True if "away" in s else False),
        }

    def parse_datetime(t):
        return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(t / 1000))

    # parse selections
    rawSelections = w["wager"]["selections"][0]["outcomes"]
    selections = enumerate(map(lambda s: parse_selection(s), rawSelections))
    selections = map(lambda (i, s): (i, s), selections)

    # make dictionary with id as a key for easy addressing
    # (even though the array is probably in order anyway)
    rows = dict(map(lambda r: (int(r["id"]), r), w["draw"]["rows"]))

    def getScore(d, k):
        if "score" in d:
            return d["score"][k]

    events = map(
        lambda (i, s): surprise.event(
            row_id=i,
            choose_home=s["home"],
            choose_tie=s["tie"],
            choose_away=s["away"],
            home_team=rows[i]["outcome"]["home"]["name"],
            away_team=rows[i]["outcome"]["away"]["name"],
            home_score=getScore(rows[i]["result"], "home"),
            away_score=getScore(rows[i]["result"], "away"),
        ),
        selections,
    )

    # parse wager high level data, create wager
    wager_date = parse_datetime(w["wager"]["transactionTime"])
    external_id = w["wager"]["id"]
    stake = w["wager"]["stake"]
    system_size = w["wager"]["systemLevel"]
    win_amount = w["winning"]["amount"]

    return surprise.wager(
        wager_date=wager_date,
        ext_id=external_id,
        stake=stake,
        system_size=system_size,
        win_amount=win_amount,
        events=events,
    )
Exemplo n.º 3
0
def get_wagers(session, txs):
    
    def get_wager(session, tx_id):
        r = session.get('https://www.veikkaus.fi/api/v1/sport-games/wagers/'+tx_id, headers=headers) 
        return json.loads(r.text)

    def parse_selection(s):
        return {'home': (True if 'home' in s else False), 
                'tie': (True if 'tie' in s else False),
                'away': (True if 'away' in s else False) 
        }
        

    w = map(lambda x: get_wager(session,x), txs)
    w = filter(lambda x: 'draw' in x and x['draw']['gameName'] == 'SPORT', w)
    
    #parse selections
    rawSelections = w[0]['wager']['selections'][0]['outcomes']
    selections = enumerate(map(lambda s: parse_selection(s), rawSelections)) 
    selections = map(lambda (i, s): (i,s), selections) 
    
    #make dictionary with id as a key for easy addressing 
    #(even though the array is probably in order anyway) 
    rows = dict(map(lambda r: (int(r['id']), r), w[0]['draw']['rows']))
    
    events = map(lambda (i,s): 
                 surprise.event(
                     row_id=i,
                     choose_home=s['home'],
                     choose_tie=s['tie'],
                     choose_away=s['away'],
                     home_team=rows[i]['outcome']['home']['name'],
                     away_team=rows[i]['outcome']['away']['name'],
                     home_score=rows[i]['result']['score']['home'],
                     away_score=rows[i]['result']['score']['away']
                 ), selections)
    
    #parse wager high level data, create wager
    wager = surprise.wager(events=events) 
    
    return wager