<commit_before>import json
from logcollector.models import DataPoint


def to_dict(response):
    return json.loads(response.data.decode())


def test_can_post_new_data(test_app, db):
    assert db.session.query(DataPoint).count() == 5
    test_app.post('/new', data={'timestamp': '1000000060', 'dim1': 6,
                                'dim2': 3, 'value': 60})
    assert db.session.query(DataPoint).count() == 6
    assert db.session.query(DataPoint).get(6).value == 60


class TestMean:
    def test_mean(self, test_app, db):
        res = test_app.get('/mean/1000000000/1000000050')
        assert to_dict(res) == {'mean': 30.0}

    def test_mean_with_dim1(self, test_app):
        res = test_app.get('/mean/1000000000/1000000050?dim1=1')
        assert to_dict(res) == {'mean': 10}

    def test_mean_with_dim2(self, test_app):
        res = test_app.get('/mean/1000000000/1000000050?dim2=1')
        assert to_dict(res) == {'mean': 15}

    def test_mean_with_dim1_and_dim2(self, test_app, db):
        db.session.add(DataPoint('1000000060', 5, 3, 60))
        db.session.commit()
        res = test_app.get('/mean/1000000000/1000000060?dim1=5&dim2=3')
        assert to_dict(res) == {'mean': 55.0}<commit_msg>Tests for MIN<commit_after>import json
from logcollector.models import DataPoint


def to_dict(response):
    return json.loads(response.data.decode())


def test_can_post_new_data(test_app, db):
    assert db.session.query(DataPoint).count() == 5
    test_app.post('/new', data={'timestamp': '1000000060', 'dim1': 6,
                                'dim2': 3, 'value': 60})
    assert db.session.query(DataPoint).count() == 6
    assert db.session.query(DataPoint).get(6).value == 60


class TestMean:
    def test_mean(self, test_app, db):
        res = test_app.get('/mean/1000000000/1000000050')
        assert to_dict(res) == {'mean': 30.0}

    def test_mean_with_dim1(self, test_app):
        res = test_app.get('/mean/1000000000/1000000050?dim1=1')
        assert to_dict(res) == {'mean': 10}

    def test_mean_with_dim2(self, test_app):
        res = test_app.get('/mean/1000000000/1000000050?dim2=1')
        assert to_dict(res) == {'mean': 15}

    def test_mean_with_dim1_and_dim2(self, test_app, db):
        db.session.add(DataPoint('1000000060', 5, 3, 60))
        db.session.commit()
        res = test_app.get('/mean/1000000000/1000000060?dim1=5&dim2=3')
        assert to_dict(res) == {'mean': 55.0}


class TestMin:
    def test_min(self, test_app):
        res = test_app.get('/min/1000000000/1000000050')
        assert to_dict(res) == {'min': 10}

    def test_min_with_dim1(self, test_app):
        res = test_app.get('/min/1000000000/1000000050?dim1=2')
        assert to_dict(res) == {'min': 20}

    def test_min_with_dim2(self, test_app):
        res = test_app.get('/min/1000000000/1000000050?dim2=2')
        assert to_dict(res) == {'min': 30}

    def test_min_with_dim1_and_dim2(self, test_app, db):
        db.session.add(DataPoint('1000000060', 5, 3, 60))
        db.session.commit()
        res = test_app.get('/min/1000000000/1000000060?dim1=5&dim2=3')
        assert to_dict(res) == {'min': 50}

{'fraction_non_alphanumeric': 0.15587301587301589, 'fraction_numerical': 0.12317460317460317, 'mean_word_length': 3.263870094722598, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 29, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7179071', 'n_tokens_mistral': 1400, 'n_tokens_neox': 1127, 'n_words': 197}