Beispiel #1
0
    def test_calculate_metrics_with_populated_channels_full_of_zeroes_should_raise_a_zero_division_error(
            self):
        channels = {'X': np.array([0])}
        parameters = {'c': 2, 'm': 2}

        with pytest.raises(ZeroDivisionError):
            _, _, _ = MetricsCalculation.calculate_metrics(
                channels, parameters, None)
Beispiel #2
0
 def test_calculate_metrics_with_None_performance_metrics_should_return_None_performance_metrics(
         self):
     _, _, metrics = MetricsCalculation.calculate_metrics(
         {'X': np.array([1])}, {
             'c': 0,
             'm': 0
         }, None)
     assert metrics is None
Beispiel #3
0
 def test_calculate_metrics_with_not_None_performance_metrics_should_return_more_elements_in_metrics(
         self):
     metrics = pd.DataFrame()
     start = metrics.shape[0]
     _, _, metrics = MetricsCalculation.calculate_metrics(
         {'X': np.array([1])}, {
             'c': 0,
             'm': 0
         }, metrics)
     end = metrics.shape[0]
     assert start < end
Beispiel #4
0
    def test_calculate_metrics_with_populated_parameters_should_return_correct_calculations(
            self):
        channels = {'X': np.array([1])}
        parameters = {'c': 0, 'm': 0}
        channels, parameters, _ = MetricsCalculation.calculate_metrics(
            channels, parameters, None)

        assert sum(channels.get('Y')) == 0
        assert sum(channels.get('A')) == 1
        assert sum(channels.get('B')) == 1
        assert sum(channels.get('C')) == 2
        assert parameters.get('b') == 1
Beispiel #5
0
    def test_calculate_metrics_with_populated_channels_and_parameters_should_return_more_elements_in_both_channels_and_parameters(
            self):
        channels = {'X': np.array([1])}
        parameters = {'c': 0, 'm': 0}
        channels_start_keycount = len(channels)
        parameters_start_keycount = len(parameters)

        channels, parameters, _ = MetricsCalculation.calculate_metrics(
            channels, parameters, None)

        channels_end_keycount = len(channels)
        parameters_end_keycount = len(parameters)
        assert channels_start_keycount < channels_end_keycount
        assert parameters_start_keycount < parameters_end_keycount
Beispiel #6
0
 def test_calculate_metrics_with_empty_dictionaries_should_return_exception(
         self):
     with pytest.raises(AttributeError):
         MetricsCalculation.calculate_metrics({}, {})
Beispiel #7
0
from app.ingest_data import DataIngestor
from app.calculate_metrics import MetricsCalculation
import pandas as pd
import time
import os

# Metrics collection
if os.path.isfile('./data/performance/performance_metrics.csv'):
    metrics = pd.read_csv('./data/performance/performance_metrics.csv')
else:
    metrics = pd.DataFrame()

channels, parameters, metrics = DataIngestor.ingest_data(
    './data/channels.txt', './data/parameters.txt', metrics)
channels, parameters, metrics = MetricsCalculation.calculate_metrics(
    channels, parameters, metrics)

# Performance metrics gathering for data persistence
if metrics is not None:
    start = time.time()

MetricsCalculation.persist_data(channels, 'channels')
MetricsCalculation.persist_data(parameters, 'parameters')

# Performance metrics gathering for data persistence
if metrics is not None:
    end = time.time()
    metrics = metrics.append(
        {
            'key': 'metrics_persisting',
            'value': end - start