コード例 #1
0
def process_file(session, attr_definitions, data_filename):
    print 'processing %s'%data_filename
    
    # Initialize the file_attributes dictionary in preparation for the
    # parsing of the data file
    file_attributes = {}
    
    # Parse the data file, storing all the information in the file_attributes
    # dictionary
    FileParser.FileParser(data_filename).parse(file_attributes)

    # The team number can be retrieved from the Team attribute, one of the
    # mandatory attributes within the data file
    team = file_attributes['Team']
    
    # Also, extract the competition name, too, if it has been included in
    # the data file
    if file_attributes.has_key('Competition'):
        competition = file_attributes['Competition']
    else:
        competition = global_config['this_competition'] + global_config['this_season']

        if competition == None:
            raise Exception( 'Competition Not Specified!')

    DataModel.addTeamToEvent(session, team, competition)
    
    if file_attributes.has_key('Scouter'):
        scouter = file_attributes['Scouter']
    else:
        scouter = 'Unknown'
        
    if file_attributes.has_key('Match'):
        category = 'Match'
    else:
        if '_Pit_' in data_filename:
            category = 'Pit'
        else:
            category = 'Other'

    # Loop through the attributes from the data file and post them to the
    # database
    for attribute, value in file_attributes.iteritems():
        if value is None:
            value = ''
        try:
            attr_definition = attr_definitions.get_definition(attribute)
            if attr_definition == None:
                err_str = 'ERROR: No Attribute Defined For Attribute: %s' % attribute
                print err_str
            elif attr_definition['Database_Store']=='Yes':
                try:
                    DataModel.createOrUpdateAttribute(session, team, competition, category, attribute, value, attr_definition)
                except Exception, exception:
                    traceback.print_exc(file=sys.stdout)
                    exc_type, exc_value, exc_traceback = sys.exc_info()
                    exception_info = traceback.format_exception(exc_type, exc_value,exc_traceback)
                    for line in exception_info:
                        line = line.replace('\n','')
                        global_config['logger'].debug(line)
        except Exception:
            err_str = 'ERROR: Attribute Could Not Be Processed: %s' % attribute
            traceback.print_exc(file=sys.stdout)
            exc_type, exc_value, exc_traceback = sys.exc_info()
            exception_info = traceback.format_exception(exc_type, exc_value,exc_traceback)
            for line in exception_info:
                line = line.replace('\n','')
                global_config['logger'].debug(line)
            print err_str
            
        if category == 'Match':
            try:
                match = file_attributes['Match']
                DataModel.createOrUpdateMatchDataAttribute(session, team, competition, match, scouter, attribute, value)
            except:
                err_str = 'ERROR: Match Data Attribute Could Not Be Processed: %s' % attribute
                traceback.print_exc(file=sys.stdout)
                exc_type, exc_value, exc_traceback = sys.exc_info()
                exception_info = traceback.format_exception(exc_type, exc_value,exc_traceback)
                for line in exception_info:
                    line = line.replace('\n','')
                    global_config['logger'].debug(line)
                print err_str
            
    score = DataModel.calculateTeamScore(session, team, competition, attr_definitions)
    DataModel.setTeamScore(session, team, competition, score)
コード例 #2
0
def process_file(global_config, session, attr_definitions, data_filename):
    print "processing %s" % data_filename

    # Initialize the file_attributes dictionary in preparation for the
    # parsing of the data file
    file_attributes = {}

    # Parse the data file, storing all the information in the file_attributes
    # dictionary
    FileParser.FileParser(data_filename).parse(file_attributes)

    # The team number can be retrieved from the Team attribute, one of the
    # mandatory attributes within the data file
    team = file_attributes["Team"]

    # Also, extract the competition name, too, if it has been included in
    # the data file
    if file_attributes.has_key("Competition"):
        # check if the global_config indicates that we're working with the 2014-era tablet UI that may not
        # format the competition string as we expect it to be. If we are in 'legacy' mode, then ignore the
        # competition setting in the file and apply the competition/season from the config
        if global_config.has_key("legacy_tablet_ui") and global_config["legacy_tablet_ui"].lower() == "yes":
            competition = global_config["this_competition"] + global_config["this_season"]
        else:
            competition = file_attributes["Competition"]
    else:
        # if no competition setting attribute is in the file, then apply the competition/season from the config
        competition = global_config["this_competition"] + global_config["this_season"]

        if competition == None:
            raise Exception("Competition Not Specified!")

    DataModel.addTeamToEvent(session, team, competition)

    if file_attributes.has_key("Scouter"):
        scouter = file_attributes["Scouter"]
    else:
        scouter = "Unknown"

    if "_Match" in data_filename:
        category = "Match"
        if not file_attributes.has_key("Match"):
            file_attributes["Match"] = "0"
    elif "_Pit_" in data_filename:
        category = "Pit"
    else:
        category = "Other"

    # Loop through the attributes from the data file and post them to the
    # database
    for attribute, value in file_attributes.iteritems():
        if value is None:
            value = ""
        try:
            attr_definition = attr_definitions.get_definition(attribute)
            if attr_definition == None:
                err_str = "ERROR: No Attribute Defined For Attribute: %s" % attribute
                print err_str
            elif attr_definition["Database_Store"] == "Yes":
                try:
                    DataModel.createOrUpdateAttribute(
                        session, team, competition, category, attribute, value, attr_definition
                    )
                except Exception, exception:
                    traceback.print_exc(file=sys.stdout)
                    exc_type, exc_value, exc_traceback = sys.exc_info()
                    exception_info = traceback.format_exception(exc_type, exc_value, exc_traceback)
                    for line in exception_info:
                        line = line.replace("\n", "")
                        global_config["logger"].debug(line)
        except Exception:
            err_str = "ERROR: Attribute Could Not Be Processed: %s" % attribute
            traceback.print_exc(file=sys.stdout)
            exc_type, exc_value, exc_traceback = sys.exc_info()
            exception_info = traceback.format_exception(exc_type, exc_value, exc_traceback)
            for line in exception_info:
                line = line.replace("\n", "")
                global_config["logger"].debug(line)
            print err_str

        if category == "Match":
            try:
                match = file_attributes["Match"]
                DataModel.createOrUpdateMatchDataAttribute(session, team, competition, match, scouter, attribute, value)
            except:
                err_str = "ERROR: Match Data Attribute Could Not Be Processed: %s" % attribute
                traceback.print_exc(file=sys.stdout)
                exc_type, exc_value, exc_traceback = sys.exc_info()
                exception_info = traceback.format_exception(exc_type, exc_value, exc_traceback)
                for line in exception_info:
                    line = line.replace("\n", "")
                    global_config["logger"].debug(line)
                print err_str

    score = DataModel.calculateTeamScore(session, team, competition, attr_definitions)
    DataModel.setTeamScore(session, team, competition, score)