How to use the wily.operators.MetricType function in wily

To help you get started, we’ve selected a few wily examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tonybaloney / wily / src / wily / operators / raw.py View on Github external
from wily.operators import BaseOperator, MetricType, Metric


class RawMetricsOperator(BaseOperator):
    """Raw Metrics Operator."""

    name = "raw"
    defaults = {
        "exclude": None,
        "ignore": None,
        "summary": False,
        "include_ipynb": True,
        "ipynb_cells": True,
    }
    metrics = (
        Metric("loc", "Lines of Code", int, MetricType.Informational, sum),
        Metric("lloc", "L Lines of Code", int, MetricType.AimLow, sum),
        Metric("sloc", "S Lines of Code", int, MetricType.AimLow, sum),
        Metric("comments", "Multi-line comments", int, MetricType.AimHigh, sum),
        Metric("multi", "Multi lines", int, MetricType.Informational, sum),
        Metric("blank", "blank lines", int, MetricType.Informational, sum),
        Metric(
            "single_comments",
            "Single comment lines",
            int,
            MetricType.Informational,
            sum,
        ),
    )
    default_metric_index = 0  # LOC

    def __init__(self, config, targets):
github tonybaloney / wily / src / wily / operators / halstead.py View on Github external
"sort": False,
        "by_function": True,
        "include_ipynb": True,
        "ipynb_cells": True,
    }

    metrics = (
        Metric("h1", "Unique Operands", int, MetricType.AimLow, sum),
        Metric("h2", "Unique Operators", int, MetricType.AimLow, sum),
        Metric("N1", "Number of Operands", int, MetricType.AimLow, sum),
        Metric("N2", "Number of Operators", int, MetricType.AimLow, sum),
        Metric(
            "vocabulary", "Unique vocabulary (h1 + h2)", int, MetricType.AimLow, sum
        ),
        Metric("length", "Length of application", int, MetricType.AimLow, sum),
        Metric("volume", "Code volume", float, MetricType.AimLow, sum),
        Metric("difficulty", "Difficulty", float, MetricType.AimLow, sum),
        Metric("effort", "Effort", float, MetricType.AimLow, sum),
    )

    default_metric_index = 0  # MI

    def __init__(self, config, targets):
        """
        Instantiate a new HC operator.

        :param config: The wily configuration.
        :type  config: :class:`WilyConfig`
        """
        # TODO : Import config from wily.cfg
        logger.debug(f"Using {targets} with {self.defaults} for HC metrics")
github tonybaloney / wily / src / wily / operators / halstead.py View on Github external
name = "halstead"
    defaults = {
        "exclude": None,
        "ignore": None,
        "min": "A",
        "max": "C",
        "multi": True,
        "show": False,
        "sort": False,
        "by_function": True,
        "include_ipynb": True,
        "ipynb_cells": True,
    }

    metrics = (
        Metric("h1", "Unique Operands", int, MetricType.AimLow, sum),
        Metric("h2", "Unique Operators", int, MetricType.AimLow, sum),
        Metric("N1", "Number of Operands", int, MetricType.AimLow, sum),
        Metric("N2", "Number of Operators", int, MetricType.AimLow, sum),
        Metric(
            "vocabulary", "Unique vocabulary (h1 + h2)", int, MetricType.AimLow, sum
        ),
        Metric("length", "Length of application", int, MetricType.AimLow, sum),
        Metric("volume", "Code volume", float, MetricType.AimLow, sum),
        Metric("difficulty", "Difficulty", float, MetricType.AimLow, sum),
        Metric("effort", "Effort", float, MetricType.AimLow, sum),
    )

    default_metric_index = 0  # MI

    def __init__(self, config, targets):
        """
github tonybaloney / wily / src / wily / operators / raw.py View on Github external
"""Raw Metrics Operator."""

    name = "raw"
    defaults = {
        "exclude": None,
        "ignore": None,
        "summary": False,
        "include_ipynb": True,
        "ipynb_cells": True,
    }
    metrics = (
        Metric("loc", "Lines of Code", int, MetricType.Informational, sum),
        Metric("lloc", "L Lines of Code", int, MetricType.AimLow, sum),
        Metric("sloc", "S Lines of Code", int, MetricType.AimLow, sum),
        Metric("comments", "Multi-line comments", int, MetricType.AimHigh, sum),
        Metric("multi", "Multi lines", int, MetricType.Informational, sum),
        Metric("blank", "blank lines", int, MetricType.Informational, sum),
        Metric(
            "single_comments",
            "Single comment lines",
            int,
            MetricType.Informational,
            sum,
        ),
    )
    default_metric_index = 0  # LOC

    def __init__(self, config, targets):
        """
        Instantiate a new raw operator.

        :param config: The wily configuration.
github tonybaloney / wily / src / wily / commands / report.py View on Github external
:param console_format: Grid format style for tabulate
    :type  console_format: ``str``
    """
    logger.debug("Running report command")
    logger.info(f"-----------History for {metrics}------------")

    data = []
    metric_metas = []

    for metric in metrics:
        operator, metric = resolve_metric_as_tuple(metric)
        key = metric.name
        operator = operator.name
        # Set the delta colors depending on the metric type
        if metric.measure == MetricType.AimHigh:
            good_color = 32
            bad_color = 31
        elif metric.measure == MetricType.AimLow:
            good_color = 31
            bad_color = 32
        elif metric.measure == MetricType.Informational:
            good_color = 33
            bad_color = 33
        metric_meta = {
            "key": key,
            "operator": operator,
            "good_color": good_color,
            "bad_color": bad_color,
            "title": metric.description,
            "type": metric.type,
        }
github tonybaloney / wily / src / wily / operators / maintainability.py View on Github external
defaults = {
        "exclude": None,
        "ignore": None,
        "min": "A",
        "max": "C",
        "multi": True,
        "show": False,
        "sort": False,
        "include_ipynb": True,
        "ipynb_cells": True,
    }

    metrics = (
        Metric("rank", "Maintainability Ranking", str, MetricType.Informational, mode),
        Metric(
            "mi", "Maintainability Index", float, MetricType.AimHigh, statistics.mean
        ),
    )

    default_metric_index = 1  # MI

    def __init__(self, config, targets):
        """
        Instantiate a new MI operator.

        :param config: The wily configuration.
        :type  config: :class:`WilyConfig`
        """
        # TODO : Import config from wily.cfg
        logger.debug(f"Using {targets} with {self.defaults} for MI metrics")

        self.harvester = harvesters.MIHarvester(targets, config=Config(**self.defaults))
github tonybaloney / wily / src / wily / commands / report.py View on Github external
data = []
    metric_metas = []

    for metric in metrics:
        operator, metric = resolve_metric_as_tuple(metric)
        key = metric.name
        operator = operator.name
        # Set the delta colors depending on the metric type
        if metric.measure == MetricType.AimHigh:
            good_color = 32
            bad_color = 31
        elif metric.measure == MetricType.AimLow:
            good_color = 31
            bad_color = 32
        elif metric.measure == MetricType.Informational:
            good_color = 33
            bad_color = 33
        metric_meta = {
            "key": key,
            "operator": operator,
            "good_color": good_color,
            "bad_color": bad_color,
            "title": metric.description,
            "type": metric.type,
        }
        metric_metas.append(metric_meta)

    state = State(config)
    for archiver in state.archivers:
        history = state.index[archiver].revisions[:n][::-1]
        last = {}
github tonybaloney / wily / src / wily / operators / cyclomatic.py View on Github external
"ignore": None,
        "min": "A",
        "max": "F",
        "no_assert": True,
        "show_closures": False,
        "order": radon.complexity.SCORE,
        "include_ipynb": True,
        "ipynb_cells": True,
    }

    metrics = (
        Metric(
            "complexity",
            "Cyclomatic Complexity",
            float,
            MetricType.AimLow,
            statistics.mean,
        ),
    )

    default_metric_index = 0  # MI

    def __init__(self, config, targets):
        """
        Instantiate a new Cyclomatic Complexity operator.

        :param config: The wily configuration.
        :type  config: :class:`WilyConfig`
        """
        # TODO: Import config for harvester from .wily.cfg
        logger.debug(f"Using {targets} with {self.defaults} for CC metrics")
github tonybaloney / wily / src / wily / operators / maintainability.py View on Github external
name = "maintainability"
    defaults = {
        "exclude": None,
        "ignore": None,
        "min": "A",
        "max": "C",
        "multi": True,
        "show": False,
        "sort": False,
        "include_ipynb": True,
        "ipynb_cells": True,
    }

    metrics = (
        Metric("rank", "Maintainability Ranking", str, MetricType.Informational, mode),
        Metric(
            "mi", "Maintainability Index", float, MetricType.AimHigh, statistics.mean
        ),
    )

    default_metric_index = 1  # MI

    def __init__(self, config, targets):
        """
        Instantiate a new MI operator.

        :param config: The wily configuration.
        :type  config: :class:`WilyConfig`
        """
        # TODO : Import config from wily.cfg
        logger.debug(f"Using {targets} with {self.defaults} for MI metrics")