Beispiel #1
0
    def generate_competition_day(self, target_directory: str, download_progress=None, start_time_buffer: int=0,
                                 include_hc_competitors: bool = True) -> CompetitionDay:

        # get info from website
        competition_name, date, plane_class = self._get_competition_day_info()
        competitors_info = self._get_competitors_info(include_hc_competitors)

        self.set_igc_directory(target_directory, competition_name, plane_class, date)

        competitors = list()
        tasks = list()
        files_downloaded = 0
        for competitor_info in competitors_info:
            competition_id = competitor_info['competition_id']
            igc_url = competitor_info['igc_url']
            ranking = competitor_info['ranking']

            # download files. skip if not valid
            try:
                file_path = self.download_flight(igc_url, competition_id)
            except URLError:
                print('{} is skipped because of invalid URL'.format(competition_id))
                continue

            files_downloaded += 1
            if download_progress is not None:
                download_progress(files_downloaded, len(competitors_info))

            try:
                try:  # try utf-8
                    with open(file_path, 'r', encoding='utf-8') as f:
                        parsed_igc_file = Reader().read(f)
                except UnicodeDecodeError:  # if not utf-8 use latin1
                    with open(file_path, 'r', encoding='latin1') as f:
                        parsed_igc_file = Reader().read(f)
            except Exception:
                print('{} is skipped because the file could not be parsed'.format(competition_id))
                continue

            trace_errors, trace = parsed_igc_file['fix_records']
            if len(trace_errors) != 0:
                print('{} is skipped because of invalid trace'.format(competition_id))
                continue

            # get info from file
            task, contest_information, competitor_information = get_info_from_comment_lines(parsed_igc_file, start_time_buffer)
            plane_model = competitor_information.get('plane_model', None)
            pilot_name = competitor_information.get('pilot_name', None)

            competitor = Competitor(trace, competition_id, plane_model, ranking, pilot_name)

            competitors.append(competitor)
            tasks.append(task)

        # Select task from tasks list
        task = self._select_task(tasks)

        return CompetitionDay(competition_name, date, plane_class, competitors, task)
Beispiel #2
0
    def generate_competition_day(self, target_directory: str, download_progress=None, start_time_buffer: int=0)\
            -> CompetitionDay:
        """

        :param target_directory: see super
        :param download_progress: see super
        :param start_time_buffer: see super
        :return:
        """

        # get info from website
        competition_name, date, plane_class = self._get_competition_day_info()
        table_info = self._get_table_info()

        self.set_igc_directory(target_directory, competition_name, plane_class,
                               date)

        competitors = list()
        tasks = list()
        files_downloaded = 0
        for table_entry in table_info:
            competition_id = table_entry['competition_id']
            igc_url = table_entry['igc_url']
            plane_model = table_entry['ranking']
            ranking = table_entry['plane_model']

            # download files
            file_path = self.download_flight(igc_url, competition_id)

            files_downloaded += 1
            if download_progress is not None:
                download_progress(files_downloaded, len(table_info))

            with open(file_path, 'r', encoding='utf-8') as f:
                parsed_igc_file = Reader().read(f)

            trace_errors, trace = parsed_igc_file['fix_records']

            # get info from file
            task, task_info, competitor_information = get_info_from_comment_lines(
                parsed_igc_file, start_time_buffer)
            pilot_name = competitor_information.get('pilot_name', None)

            competitor = Competitor(trace, competition_id, plane_model,
                                    ranking, pilot_name)

            competitors.append(competitor)
            tasks.append(task)

        # Select task from tasks list
        task = self._select_task(tasks)

        return CompetitionDay(competition_name, date, plane_class, competitors,
                              task)
Beispiel #3
0
    def generate_competition_day(self, target_directory: str, download_progress=None, start_time_buffer: int=0) -> CompetitionDay:
        """
        Generate a CompetitionDay for the specified SoaringSpot daily result page.
        Information is pulled from the overview table and from the igc files, which are automatically downloaded.

        :param target_directory: see super
        :param download_progress: see super
        :param start_time_buffer: see super
        :return:
        """

        # get info from website
        competition_name, date, plane_class = self._get_competition_day_info()
        competitors_info = self._get_competitors_info()

        self.set_igc_directory(target_directory, competition_name, plane_class, date)

        competitors = list()
        tasks = list()
        files_downloaded = 0
        for competitor_info in competitors_info:
            competition_id = competitor_info['competition_id']
            igc_url = competitor_info['igc_url']
            ranking = competitor_info['ranking']

            # download files
            file_path = self.download_flight(igc_url, competition_id)

            files_downloaded += 1
            if download_progress is not None:
                download_progress(files_downloaded, len(competitors_info))

            with open(file_path, 'r', encoding='utf-8') as f:
                parsed_igc_file = Reader().read(f)

            trace_errors, trace = parsed_igc_file['fix_records']

            # get info from file
            task, contest_information, competitor_information = get_info_from_comment_lines(parsed_igc_file, start_time_buffer)
            plane_model = competitor_information.get('plane_model', None)
            pilot_name = competitor_information.get('pilot_name', None)

            competitor = Competitor(trace, competition_id, plane_model, ranking, pilot_name)

            competitors.append(competitor)
            tasks.append(task)

        # Select task from tasks list
        task = self._select_task(tasks)

        return CompetitionDay(competition_name, date, plane_class, competitors, task)