def get_event_matchschedule_json(global_config, year, event_code, team_str = None):
        
    global_config['logger'].debug( 'GET Event Schedule Json' )

    # derive our competition name from the FIRST event code 
    competition = WebCommonUtils.map_event_code_to_comp(year+event_code)

    store_data_to_file = False
    result = []
    
    if team_str is None:
        exp_filename = ''
        event_matches = get_event_data_from_tba( '%s%s/matches' % (year,event_code.lower()) )
    else:
        exp_filename = '_%s' % team_str
        event_matches = WebTeamData.get_team_data_from_tba( team_str, 'event/%s%s/matches' % (year,event_code.lower()) )
        
    match_schedule = dict()
    
    match_schedule['event'] = event_code.lower()
    match_schedule['columns'] = [ 'Round', 'Match', 'Red_1', 'Red_2', 'Red_3', 'Blue_1', 'Blue_2', 'Blue_3' ]
    match_schedule['qualification'] = []
    match_schedule['quarter_finals'] = []
    match_schedule['semi_finals'] = []
    match_schedule['finals'] = []
    if len(event_matches):

        # matches is now a list of lists, with the first element of the list being the list of column headings
        # take the list of columngs and apply to each of the subsequent rows to build the json response
        
        # the entire match set is returned from TBA, filter out the matches for the desired round
        for match in event_matches:
            comp_level = match['comp_level']
            if comp_level in ('qf', 'sf'):
                match_str = '%s-%s' % (match['set_number'],match['match_number'])
            else:
                match_str = str(match['match_number'])
                
            match_entry = [ comp_level, match_str,
                            match['alliances']['red']['team_keys'][0].lstrip('frc'),
                            match['alliances']['red']['team_keys'][1].lstrip('frc'),
                            match['alliances']['red']['team_keys'][2].lstrip('frc'),
                            match['alliances']['blue']['team_keys'][0].lstrip('frc'),
                            match['alliances']['blue']['team_keys'][1].lstrip('frc'),
                            match['alliances']['blue']['team_keys'][2].lstrip('frc') ]
            
            if comp_level == 'qm':
                match_schedule['qualification'].append(match_entry)
            elif comp_level == 'qf':
                match_schedule['quarter_finals'].append(match_entry)
            elif comp_level == 'sf':
                match_schedule['semi_finals'].append(match_entry)
            elif comp_level == 'f':
                match_schedule['finals'].append(match_entry)
                
        store_data_to_file = True
        
        # the qualification match schedule needs to be sorted, the sort will be done by the second
        # element of each row, which is the match number
        match_schedule['qualification'].sort(key=lambda match_list: int(match_list[1]))      
    else:
        # we were not able to retrieve the data from FIRST, so let's return any stored file with the 
        # information, otherwise we will return an empty json payload
        stored_file_data = FileSync.get( global_config, '%s/EventData/matchschedule%s.json' % (competition,exp_filename) )
        if stored_file_data != '':
            return stored_file_data
    
    json_str = json.dumps(match_schedule)
    
    if store_data_to_file:
        try:
            FileSync.put( global_config, '%s/EventData/matchschedule%s.json' % (competition,exp_filename), 'text', json_str)
        except:
            raise
    return json_str    
def get_event_matchresults_json(global_config, year, event_code, round_str, team_str = None):
        
    global_config['logger'].debug( 'GET Event Results Json' )


    if round_str == 'qual':
        match_selector = 'qm'
    elif round_str == 'quarters':
        match_selector = 'qf'
    elif round_str == 'semis':
        match_selector = 'sf'
    elif round_str == 'finals':
        match_selector = 'f'
        
    # derive our competition name from the FIRST event code 
    competition = WebCommonUtils.map_event_code_to_comp(year+event_code)

    store_data_to_file = False
    result = []
    
    result.append('{ "event" : "%s",\n' % (event_code.lower()))
    
    if team_str is None:
        exp_filename = ''
        event_matches = get_event_data_from_tba( '%s%s/matches' % (year,event_code.lower()), api_version='v3' )
    else:
        exp_filename = '_%s' % team_str
        event_matches = WebTeamData.get_team_data_from_tba( team_str, 'event/%s%s/matches' % (year,event_code.lower()) )
        
    if len(event_matches):

        # matches is now a list of lists, with the first element of the list being the list of column headings
        # take the list of columngs and apply to each of the subsequent rows to build the json response
        result.append('  "last_updated": "%s",\n' % time.strftime('%c'))
        headings = [ 'Match', 'Start Time', 'Red 1', 'Red 2', 'Red 3', 'Blue 1', 'Blue 2', 'Blue 3', 'Red Score', 'Blue Score' ]
        
        result.append('  "columns" : [\n')

        for heading in headings:
            result.append('    { "sTitle": "%s" }' % heading)
            result.append(',\n')
        if len(headings)>0:
            result = result[:-1]
        result.append(' ],\n')
        result.append('  "matchresults" : [\n')
    
        # the entire match set is returned from TBA, filter out the matches for the desired round
        for match in event_matches:
            
            if str(match['comp_level']) == match_selector:
                result.append('       [ ')
                
                # Match number
                try:
                    if global_config['json_no_links'] == 'Yes':
                        result.append( '"%s", ' % str(match['match_number']) )
                    else:
                        raise
                except:
                    result.append( '"%s", ' % get_match_hyperlink(competition, match) )

                # Match start time
                match_epoch_time = int(match['time'])
                time_format_str = '%a %b %d - %I:%M %p'
                match_time_str = datetime.datetime.fromtimestamp(match_epoch_time).strftime(time_format_str)
                result.append( '"%s", ' % match_time_str )
                
                try:
                    if global_config['json_no_links'] == 'Yes':
                        # Red alliance teams
                        result.append( '"%s", ' % str(match['alliances']['red']['team_keys'][0]).lstrip('frc') )
                        result.append( '"%s", ' % str(match['alliances']['red']['team_keys'][1]).lstrip('frc') )
                        result.append( '"%s", ' % str(match['alliances']['red']['team_keys'][2]).lstrip('frc') )
                        
                        # Blue alliance teams
                        result.append( '"%s", ' % str(match['alliances']['blue']['team_keys'][0]).lstrip('frc') )
                        result.append( '"%s", ' % str(match['alliances']['blue']['team_keys'][1]).lstrip('frc') )
                        result.append( '"%s", ' % str(match['alliances']['blue']['team_keys'][2]).lstrip('frc') )
                    else:
                        raise
                except:
                    # Red alliance teams
                    result.append( '"%s", ' % get_team_hyperlink( competition, str(match['alliances']['red']['team_keys'][0]).lstrip('frc') ) )
                    result.append( '"%s", ' % get_team_hyperlink( competition, str(match['alliances']['red']['team_keys'][1]).lstrip('frc') ) )
                    result.append( '"%s", ' % get_team_hyperlink( competition, str(match['alliances']['red']['team_keys'][2]).lstrip('frc') ) )
                    
                    # Blue alliance teams
                    result.append( '"%s", ' % get_team_hyperlink( competition, str(match['alliances']['blue']['team_keys'][0]).lstrip('frc') ) )
                    result.append( '"%s", ' % get_team_hyperlink( competition, str(match['alliances']['blue']['team_keys'][1]).lstrip('frc') ) )
                    result.append( '"%s", ' % get_team_hyperlink( competition, str(match['alliances']['blue']['team_keys'][2]).lstrip('frc') ) )
                    
                # Red alliance score
                
                score = str(match['alliances']['red']['score'])
                if score == '-1':
                    score = '-'
                result.append( '"%s", ' % score )
                
                # Blue alliance score
                score = str(match['alliances']['blue']['score'])
                if score == '-1':
                    score = '-'
                result.append( '"%s" ' % score )
                
                
                result.append(' ],\n')
                store_data_to_file = True

        if store_data_to_file is True:
            result = result[:-1]
            result.append(' ]\n')
            
        result.append(' ]\n')

    else:
        # we were not able to retrieve the data from FIRST, so let's return any stored file with the 
        # information, otherwise we will return an empty json payload
        stored_file_data = FileSync.get( global_config, '%s/EventData/matchresults_%s%s.json' % (competition,round_str,exp_filename) )
        if stored_file_data != '':
            return stored_file_data
    
    result.append(' }\n')
    json_str = ''.join(result)
    if store_data_to_file:
        try:
            FileSync.put( global_config, '%s/EventData/matchresults_%s%s.json' % (competition,round_str,exp_filename), 'text', json_str)
        except:
            raise
    return json_str