Пример #1
0
    def run_check(self):
        passed = None
        threshold_param = self.get_param('threshold')
        if threshold_param is not None:
            passed = self.scan.has_minimum_pings(threshold_param.value)
        else:
            passed = self.scan.has_minimum_pings()

        messages = (
            None
            if passed
            else (
                ["Minimum ping count is less than threshold count of 10"]
                if threshold_param is None
                else (
                    ["Minimum ping count is less than threshold count of {}".format(threshold_param.value)]
                )
            )
        )

        state = ScanState.PASS if passed else ScanState.FAIL

        self._output = QajsonOutputs(
            execution=None,
            files=None,
            count=None,
            percentage=None,
            messages=messages,
            check_state=state
        )
Пример #2
0
    def get_outputs(self) -> QajsonOutputs:

        execution = QajsonExecution(start=self.start_time,
                                    end=self.end_time,
                                    status=self.execution_status,
                                    error=self.error_message)

        data = {
            "failed_cell_count_noisy_edges":
            self.failed_cell_count_noisy_edges,
            "failed_cell_adjacent_cells": self.failed_cell_adjacent_cells
        }

        map_feature = geojson.FeatureCollection(self.geojson_points)
        map = geojson.mapping.to_mapping(map_feature)

        data['map'] = map

        return QajsonOutputs(execution=execution,
                             files=None,
                             count=None,
                             percentage=None,
                             messages=[],
                             data=data,
                             check_state=GridCheckState.cs_pass)
Пример #3
0
    def run_check(self):
        scan_result = self.scan.date_match()

        self._output = QajsonOutputs(
            execution=None,
            files=None,
            count=None,
            percentage=None,
            messages=scan_result.messages,
            data=scan_result.data,
            check_state=scan_result.state
        )
Пример #4
0
    def run_check(self):
        scan_result = self.scan.ellipsoid_height_availability()

        self._output = QajsonOutputs(
            execution=None,
            files=None,
            count=None,
            percentage=None,
            messages=scan_result.messages,
            data=scan_result.data,
            check_state=scan_result.state
        )
Пример #5
0
    def get_outputs(self) -> QajsonOutputs:

        execution = QajsonExecution(start=self.start_time,
                                    end=self.end_time,
                                    status=self.execution_status,
                                    error=self.error_message)

        data = {
            "failed_cell_count": self.failed_cell_count,
            "total_cell_count": self.total_cell_count,
            "fraction_failed": self.failed_cell_count / self.total_cell_count,
            "grid_resolution": self.grid_resolution
        }

        if self.spatial_qajson:
            data['map'] = self.tiles_geojson

        if self.failed_cell_count > 0:
            percent_failed = (self.failed_cell_count / self.total_cell_count *
                              100)
            msg = (
                f"{self.failed_cell_count} nodes failed the resolution check "
                f"this represents {percent_failed:.1f}% of all nodes within "
                "data.")
            return QajsonOutputs(execution=execution,
                                 files=None,
                                 count=None,
                                 percentage=None,
                                 messages=[msg],
                                 data=data,
                                 check_state=GridCheckState.cs_fail)
        else:
            return QajsonOutputs(execution=execution,
                                 files=None,
                                 count=None,
                                 percentage=None,
                                 messages=[],
                                 data=data,
                                 check_state=GridCheckState.cs_pass)
Пример #6
0
    def run_check(self):
        check_state = ScanState.FAIL
        message = ""
        if (self.scan.file_exits and self.scan.file_non_zero_size):
            check_state = ScanState.PASS
        elif (self.scan.file_exits):
            # then file exists, but has zero size
            check_state = ScanState.FAIL
            message = "Trueheave file is empty (zero size)"
        else:
            check_state = ScanState.FAIL
            message = "Trueheave file does not exist"

        self._output = QajsonOutputs(
            execution=None,
            files=None,
            count=None,
            percentage=None,
            messages=[message],
            data=None,
            check_state=check_state
        )
Пример #7
0
    def get_outputs(self) -> QajsonOutputs:

        execution = QajsonExecution(start=self.start_time,
                                    end=self.end_time,
                                    status=self.execution_status,
                                    error=self.error_message)

        if len(self.density_histogram) == 0:
            # there's no data to check, so fail
            return QajsonOutputs(
                execution=execution,
                files=None,
                count=None,
                percentage=None,
                messages=[
                    'No counts were extracted, was a valid raster provided'
                ],
                data=None,
                check_state=GridCheckState.cs_fail)

        # sort the list of sounding counts and the number of occurances
        counts = collections.OrderedDict(sorted(
            self.density_histogram.items()))

        messages = []
        data = {}
        check_state = None

        lowest_sounding_count, occurances = next(iter(counts.items()))
        if lowest_sounding_count < self._min_spn:
            c = 0
            for sounding_count, occurances in iter(counts.items()):
                if sounding_count >= self._min_spn:
                    break
                c += occurances
            messages.append(
                f'{c} nodes were found to be under the Minimum Soundings per '
                f'node setting ({self._min_spn})')
            check_state = GridCheckState.cs_fail

        total_soundings = sum(counts.values())
        under_threshold_soundings = 0
        for sounding_count, occurances in counts.items():
            if sounding_count >= self._min_spn_ap:
                break
            under_threshold_soundings += occurances

        percentage_over_threshold = \
            (1.0 - under_threshold_soundings / total_soundings) * 100.0

        if percentage_over_threshold < self._min_spn_p:
            messages.append(
                f'{percentage_over_threshold:.1f}% of nodes were found to have a '
                f'sounding count above {self._min_spn_ap}. This is required to'
                f' be {self._min_spn_p}% of all nodes')
            check_state = GridCheckState.cs_fail

        if check_state is None:
            check_state = GridCheckState.cs_pass

        str_key_counts = collections.OrderedDict()
        for key, val in counts.items():
            str_key_counts[str(key)] = val

        data['chart'] = {'type': 'histogram', 'data': str_key_counts}

        if self.spatial_qajson:
            data['map'] = self.tiles_geojson

        result = QajsonOutputs(execution=execution,
                               files=None,
                               count=None,
                               percentage=None,
                               messages=messages,
                               data=data,
                               check_state=check_state)

        return result
Пример #8
0
    def run_checks(self,
                   progress_callback: Callable = None,
                   qajson_update_callback: Callable = None,
                   is_stopped: Callable = None):
        """ Excutes all checks on a file-by-file basis

        :param progress_callback Callable: function reference that is passed
            a float between the value of 0.0 and 1.0 to indicate progress
            of the checks. Optional.
        :param qajson_update_callback Callable: function reference that is
            to be called when the qajson related to this check has been
            updated by the check. Optional.
        :param is_stopped Callable: if this function returns True the check
            runner will stop processing (eventually)
        """
        if self._file_checks is None:
            raise RuntimeError("CheckRunner is not initialized")

        # to support accurate progress reporting get size of all files
        total_file_size = 0
        processed_files_size = 0
        for (filename, filetype), checklist in self._file_checks.items():
            if os.path.exists(filename):
                total_file_size += os.path.getsize(filename)

        for (filename, filetype), checklist in self._file_checks.items():
            if is_stopped is not None and is_stopped():
                return

            file_size = 0
            if os.path.exists(filename):
                file_size = os.path.getsize(filename)
            file_size_fraction = 1
            if total_file_size != 0:
                file_size_fraction = file_size / total_file_size
            _, extension = os.path.splitext(filename)
            # remove the `.` char from extension
            file_extension = extension[1:]

            # read metadata from header
            scan = get_scan(filename, file_extension, filetype)

            def prog_cb(scan_progress):
                p = scan_progress * file_size + processed_files_size
                if progress_callback is not None:
                    progress_callback(p / total_file_size)

            scan.scan_datagram(prog_cb)

            processed_files_size += file_size

            for checkdata in checklist:
                checkid = checkdata.info.id
                checkversion = checkdata.info.version

                checkparams = []
                if checkdata.inputs.params is not None:
                    checkparams = checkdata.inputs.params

                checkoutputs = QajsonOutputs()
                checkstatus = None
                checkerrormessage = None
                checkstart = datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")
                # get check based on id and version
                check = get_check(checkid, checkversion, scan, checkparams)
                try:
                    check.run_check()
                    checkstatus = "completed"
                    # merge two dicts; checkoutputs and check.output
                    checkoutputs = check.output
                except Exception as e:
                    checkstatus = "failed"
                    checkerrormessage = traceback.format_exc()
                checkend = datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f")

                checkoutputs.execution = QajsonExecution(
                    start=checkstart,
                    end=checkend,
                    status=checkstatus,
                    error=checkerrormessage)

                self._add_output(checkid, filename, checkoutputs)

            # qajson for all checks is updated on a file by file basis. So
            # call the update after a file has finished processing, and
            # not after each check.
            if qajson_update_callback is not None:
                qajson_update_callback()