src/server/server.py
def check_pilot_laps_win(pass_node_index, num_laps_win):
    '''Checks if a pilot has completed enough laps to win.'''
    win_pilot_id = -1
    win_lap_tstamp = 0
    profile_freqs = json.loads(getCurrentProfile().frequencies)
                             # dict for current heat with key=node_index, value=pilot_id
    node_pilot_dict = dict(Database.HeatNode.query.with_entities(Database.HeatNode.node_index, Database.HeatNode.pilot_id). \
                      filter(Database.HeatNode.heat_id==RACE.current_heat, Database.HeatNode.pilot_id!=Database.PILOT_ID_NONE).all())

    for node in INTERFACE.nodes:
        if profile_freqs["f"][node.index] != RHUtils.FREQUENCY_ID_NONE:
            pilot_id = node_pilot_dict.get(node.index)
            if pilot_id:
                lap_count = max(0, len(RACE.get_active_laps()[node.index]) - 1)

                            # if (other) pilot crossing for possible winning lap then wait
                            #  in case lap time turns out to be earliest:
                if node.pass_crossing_flag and node.index != pass_node_index and lap_count == num_laps_win - 1:
                    logger.info('check_pilot_laps_win waiting for crossing, Node {0}'.format(node.index+1))
                    return -1
                if lap_count >= num_laps_win:
                    lap_data = filter(lambda lap : lap['lap_number']==num_laps_win, RACE.get_active_laps()[node.index])
                    logger.debug('check_pilot_laps_win Node {0} pilot_id={1} tstamp={2}'.format(node.index+1, pilot_id, lap_data.lap_time_stamp))
                             # save pilot_id for earliest lap time:
                    if win_pilot_id < 0 or lap_data[0]['lap_time_stamp'] < win_lap_tstamp:
                        win_pilot_id = pilot_id
                        win_lap_tstamp = lap_data[0]['lap_time_stamp']
    logger.debug('check_pilot_laps_win returned win_pilot_id={0}'.format(win_pilot_id))
    return win_pilot_id
Checks if a pilot has completed enough laps to win.
Checks if a pilot has completed enough laps to win.
Checks if a pilot has completed enough laps to win .
def check_pilot_laps_win(pass_node_index, num_laps_win):
    win_pilot_id = -1
    win_lap_tstamp = 0
    profile_freqs = json.loads(getCurrentProfile().frequencies)
    node_pilot_dict = dict(Database.HeatNode.query.with_entities(Database.HeatNode.node_index, Database.HeatNode.pilot_id). \
                      filter(Database.HeatNode.heat_id==RACE.current_heat, Database.HeatNode.pilot_id!=Database.PILOT_ID_NONE).all())
    for node in INTERFACE.nodes:
        if profile_freqs["f"][node.index] != RHUtils.FREQUENCY_ID_NONE:
            pilot_id = node_pilot_dict.get(node.index)
            if pilot_id:
                lap_count = max(0, len(RACE.get_active_laps()[node.index]) - 1)
                if node.pass_crossing_flag and node.index != pass_node_index and lap_count == num_laps_win - 1:
                    logger.info('check_pilot_laps_win waiting for crossing, Node {0}'.format(node.index+1))
                    return -1
                if lap_count >= num_laps_win:
                    lap_data = filter(lambda lap : lap['lap_number']==num_laps_win, RACE.get_active_laps()[node.index])
                    logger.debug('check_pilot_laps_win Node {0} pilot_id={1} tstamp={2}'.format(node.index+1, pilot_id, lap_data.lap_time_stamp))
                    if win_pilot_id < 0 or lap_data[0]['lap_time_stamp'] < win_lap_tstamp:
                        win_pilot_id = pilot_id
                        win_lap_tstamp = lap_data[0]['lap_time_stamp']
    logger.debug('check_pilot_laps_win returned win_pilot_id={0}'.format(win_pilot_id))
    return win_pilot_id
def check_pilot_laps_win ( pass_node_index , num_laps_win ) : win_pilot_id = - 1 win_lap_tstamp = 0 profile_freqs = json . loads ( getCurrentProfile ( ) . frequencies ) node_pilot_dict = dict ( Database . HeatNode . query . with_entities ( Database . HeatNode . node_index , Database . HeatNode . pilot_id ) . filter ( Database . HeatNode . heat_id == RACE . current_heat , Database . HeatNode . pilot_id != Database . PILOT_ID_NONE ) . all ( ) ) for node in INTERFACE . nodes : if profile_freqs [ "f" ] [ node . index ] != RHUtils . FREQUENCY_ID_NONE : pilot_id = node_pilot_dict . get ( node . index ) if pilot_id : lap_count = max ( 0 , len ( RACE . get_active_laps ( ) [ node . index ] ) - 1 ) if node . pass_crossing_flag and node . index != pass_node_index and lap_count == num_laps_win - 1 : logger . info ( 'check_pilot_laps_win waiting for crossing, Node {0}' . format ( node . index + 1 ) ) return - 1 if lap_count >= num_laps_win : lap_data = filter ( lambda lap : lap [ 'lap_number' ] == num_laps_win , RACE . get_active_laps ( ) [ node . index ] ) logger . debug ( 'check_pilot_laps_win Node {0} pilot_id={1} tstamp={2}' . format ( node . index + 1 , pilot_id , lap_data . lap_time_stamp ) ) if win_pilot_id < 0 or lap_data [ 0 ] [ 'lap_time_stamp' ] < win_lap_tstamp : win_pilot_id = pilot_id win_lap_tstamp = lap_data [ 0 ] [ 'lap_time_stamp' ] logger . debug ( 'check_pilot_laps_win returned win_pilot_id={0}' . format ( win_pilot_id ) ) return win_pilot_id
Checks if a pilot has completed enough laps to win.
Checks if a pilot has completed enough laps to win .
'''Checks if a pilot has completed enough laps to win.''' # dict for current heat with key=node_index, value=pilot_id # if (other) pilot crossing for possible winning lap then wait #  in case lap time turns out to be earliest: # save pilot_id for earliest lap time:
pass_node_index
num_laps_win