Beispiel #1
0
    def read(cls, fp, short_name=None, keep_task_path=False, from_CIVL=False):
        """ A XML reader to read FSDB files
            Unfortunately the fsdb format isn't published so much of this is simply an
            exercise in reverse engineering.

            Input:
                - fp:           STR: filepath
                - from_CIVL:    BOOL: look for pilot on CIVL database
        """
        """read the fsdb file"""
        try:
            tree = ET.parse(fp)
            root = tree.getroot()
        except ET.Error:
            print("FSDB Read Error.")
            return None

        pilots = []
        tasks = []
        """Comp Info"""
        print("Getting Comp Info...")
        fs_comp = root.find('FsCompetition')
        comp = Comp.from_fsdb(fs_comp, short_name)
        """Formula"""
        comp.formula = Formula.from_fsdb(fs_comp)
        comp.formula.comp_class = comp.comp_class
        """Pilots"""
        print("Getting Pilots Info...")
        if from_CIVL:
            print('*** get from CIVL database')
        p = root.find('FsCompetition').find('FsParticipants')
        for pil in p.iter('FsParticipant'):
            pilot = Participant.from_fsdb(pil, from_CIVL=from_CIVL)
            # pp(pilot.as_dict())
            pilots.append(pilot)

        comp.participants = pilots
        """Tasks"""
        print("Getting Tasks Info...")
        t = root.find('FsCompetition').find('FsTasks')
        for tas in t.iter('FsTask'):
            '''create task obj'''
            task = Task.from_fsdb(tas, comp.time_offset, keep_task_path)
            '''check if task was valid'''
            if task is not None:
                if not task.task_path:
                    task.create_path()
                # task.time_offset = int(comp.time_offset)
                """Task Results"""
                node = tas.find('FsParticipants')
                if node is not None:
                    task.pilots = []
                    print("Getting Results Info...")
                    for res in node.iter('FsParticipant'):
                        '''pilots results'''
                        pilot = FlightResult.from_fsdb(res, task)
                        task.pilots.append(pilot)
                tasks.append(task)

        return cls(comp, tasks, fp)