Пример #1
0
def test_apply_calibration_5():
    _, calibrations, _ = utils.initialize_webapp(cfg, serials)

    report = utils.find_report(calibrations['b'], nearest='2018-07-21')
    assert report.number == 'H386'
    data, _ = utils.read_database(report, 'temperature', start='2020-11-30', end='2021-05-29')
    uncalibrated = [
        ['2020-11-30T10:13:42', 18.2],
        ['2020-12-30T17:19:18', 33.6],
        ['2021-01-29T19:06:41', 30.4],
        ['2021-02-28T20:31:30', 34.7],
        ['2021-03-30T21:54:52', 16.5],
        ['2021-04-29T15:30:45', 26.2],
    ]
    for i in range(len(uncalibrated)):
        assert data[i][0] == uncalibrated[i][0]
        assert data[i][1] == uncalibrated[i][1]
    data2 = utils.apply_calibration(data, report)
    assert data2 is data  # calculation is done in-place
    calibrated = [
        ['2020-11-30T10:13:42', 18.2 + 0.01],
        ['2020-12-30T17:19:18', 33.6 + 0.01],
        ['2021-01-29T19:06:41', 30.4 + 0.01],
        ['2021-02-28T20:31:30', 34.7 + 0.01],
        ['2021-03-30T21:54:52', 16.5 + 0.01],
        ['2021-04-29T15:30:45', 26.2 + 0.01],
    ]
    for i in range(len(uncalibrated)):
        assert data2[i][0] == calibrated[i][0]
        assert data2[i][1] == calibrated[i][1]
Пример #2
0
def test_apply_calibration_4():
    _, calibrations, _ = utils.initialize_webapp(cfg, serials)

    report = utils.find_report(calibrations['f - Probe 2'])
    assert report.number == 'H389'
    data, _ = utils.read_database(report, 'temperature', start='2018-11-11', end='2019-06-09')
    uncalibrated = [
        ['2018-11-11T02:41:00', 24.9],
        ['2018-12-11T04:45:53', 18.2],
        ['2019-01-10T21:03:28', 35.3],
        ['2019-02-09T20:51:08', 17.1],
        ['2019-03-11T19:40:08', 33.2],
        ['2019-04-10T07:35:28', 18.0],
        ['2019-05-10T13:44:06', 27.8],
    ]
    for i in range(len(uncalibrated)):
        assert data[i][0] == uncalibrated[i][0]
        assert data[i][1] == uncalibrated[i][1]
    data2 = utils.apply_calibration(data, report)
    assert data2 is data  # calculation is done in-place
    calibrated = [
        ['2018-11-11T02:41:00', 24.9 + (0.1 + 0.06*24.9 + 0.01*(24.9**2) + 2.3e-4*(24.9**3))],
        ['2018-12-11T04:45:53', 18.2 + (0.1 + 0.06*18.2 + 0.01*(18.2**2) + 2.3e-4*(18.2**3))],
        ['2019-01-10T21:03:28', 35.3 + (0.1 + 0.06*35.3 + 0.01*(35.3**2) + 2.3e-4*(35.3**3))],
        ['2019-02-09T20:51:08', 17.1 + (0.1 + 0.06*17.1 + 0.01*(17.1**2) + 2.3e-4*(17.1**3))],
        ['2019-03-11T19:40:08', 33.2 + (0.1 + 0.06*33.2 + 0.01*(33.2**2) + 2.3e-4*(33.2**3))],
        ['2019-04-10T07:35:28', 18.0 + (0.1 + 0.06*18.0 + 0.01*(18.0**2) + 2.3e-4*(18.0**3))],
        ['2019-05-10T13:44:06', 27.8 + (0.1 + 0.06*27.8 + 0.01*(27.8**2) + 2.3e-4*(27.8**3))],
    ]
    for i in range(len(uncalibrated)):
        assert data2[i][0] == calibrated[i][0]
        assert data2[i][1] == calibrated[i][1]
Пример #3
0
def test_apply_calibration_2():
    _, calibrations, _ = utils.initialize_webapp(cfg, serials)

    report = utils.find_report(calibrations['f - Probe 1'])
    assert report.number == 'H842'
    data, _ = utils.read_database(report, 'humidity', start='2018-11-11', end='2019-06-09')
    uncalibrated = [
        ['2018-11-11T02:41:00', 26.2],
        ['2018-12-11T04:45:53', 32.1],
        ['2019-01-10T21:03:28', 20.4],
        ['2019-02-09T20:51:08', 36.8],
        ['2019-03-11T19:40:08', 32.5],
        ['2019-04-10T07:35:28', 75.4],
        ['2019-05-10T13:44:06', 41.2],
    ]
    for i in range(len(uncalibrated)):
        assert data[i][0] == uncalibrated[i][0]
        assert data[i][1] == uncalibrated[i][1]
    data2 = utils.apply_calibration(data, report)
    assert data2 is data  # calculation is done in-place
    calibrated = [
        ['2018-11-11T02:41:00', 26.2 + (-8.3 + 1.23*26.2 + 3.56e-3*(26.2**2))],
        ['2018-12-11T04:45:53', 32.1 + (-8.3 + 1.23*32.1 + 3.56e-3*(32.1**2))],
        ['2019-01-10T21:03:28', 20.4 + (-8.3 + 1.23*20.4 + 3.56e-3*(20.4**2))],
        ['2019-02-09T20:51:08', 36.8 + (-8.3 + 1.23*36.8 + 3.56e-3*(36.8**2))],
        ['2019-03-11T19:40:08', 32.5 + (-8.3 + 1.23*32.5 + 3.56e-3*(32.5**2))],
        ['2019-04-10T07:35:28', 75.4 + (-8.3 + 1.23*75.4 + 3.56e-3*(75.4**2))],
        ['2019-05-10T13:44:06', 41.2 + (-8.3 + 1.23*41.2 + 3.56e-3*(41.2**2))],
    ]
    for i in range(len(uncalibrated)):
        assert data2[i][0] == calibrated[i][0]
        assert data2[i][1] == calibrated[i][1]
Пример #4
0
def test_apply_calibration_1():
    _, calibrations, _ = utils.initialize_webapp(cfg, serials)

    report = utils.find_report(calibrations['f - Probe 1'])
    assert report.number == 'H842'
    data, _ = utils.read_database(report, 'temperature', start='2018-11-11', end='2019-06-09')
    uncalibrated = [
        ['2018-11-11T02:41:00', 22.3],
        ['2018-12-11T04:45:53', 27.9],
        ['2019-01-10T21:03:28', 34.4],
        ['2019-02-09T20:51:08', 23.0],
        ['2019-03-11T19:40:08', 20.5],
        ['2019-04-10T07:35:28', 21.3],
        ['2019-05-10T13:44:06', 29.3],
    ]
    for i in range(len(uncalibrated)):
        assert data[i][0] == uncalibrated[i][0]
        assert data[i][1] == uncalibrated[i][1]
    data2 = utils.apply_calibration(data, report)
    assert data2 is data  # calculation is done in-place
    calibrated = [
        ['2018-11-11T02:41:00', 22.3 + (0.002 + 0.32*22.3)],
        ['2018-12-11T04:45:53', 27.9 + (0.002 + 0.32*27.9)],
        ['2019-01-10T21:03:28', 34.4 + (0.002 + 0.32*34.4)],
        ['2019-02-09T20:51:08', 23.0 + (0.002 + 0.32*23.0)],
        ['2019-03-11T19:40:08', 20.5 + (0.002 + 0.32*20.5)],
        ['2019-04-10T07:35:28', 21.3 + (0.002 + 0.32*21.3)],
        ['2019-05-10T13:44:06', 29.3 + (0.002 + 0.32*29.3)],
    ]
    for i in range(len(uncalibrated)):
        assert data2[i][0] == calibrated[i][0]
        assert data2[i][1] == calibrated[i][1]
Пример #5
0
def test_apply_calibration_6():
    _, calibrations, _ = utils.initialize_webapp(cfg, serials)

    data = {
        'error': None,
        'alias': 'something',
        'datetime': '2020-11-30T10:13:42',
        'temperature': 26.2,
        'humidity': 59.4,
        'dewpoint': 17.6,
    }

    data_copy = data.copy()

    calibrated = {
        'error': None,
        'alias': 'something',
        'datetime': '2020-11-30T10:13:42',
        'temperature': 26.2 + 0.01,
        'humidity': 59.4 + (-9.5 + 0.326*59.4 - 0.00505*(59.4**2) + 0.0000321*(59.4**3)),
        'dewpoint': 17.6,
    }

    report = utils.find_report(calibrations['b'], nearest='2018-07-21')
    assert report.number == 'H386'
    data2 = utils.apply_calibration(data, report)
    assert data2 is data  # calculation is done in-place
    assert data2['error'] is calibrated['error']
    assert data2['alias'] == calibrated['alias']
    assert data2['datetime'] == calibrated['datetime']
    assert abs(data2['temperature'] - calibrated['temperature']) < 1e-10
    assert abs(data2['humidity'] - calibrated['humidity']) < 1e-10
    assert data2['dewpoint'] == calibrated['dewpoint']

    for report in utils.find_reports(calibrations, '01234', nearest='2018-07-21'):
        data_copy = utils.apply_calibration(data_copy, report)
    assert data_copy['error'] is calibrated['error']
    assert data_copy['alias'] == calibrated['alias']
    assert data_copy['datetime'] == calibrated['datetime']
    assert abs(data_copy['temperature'] - calibrated['temperature']) < 1e-10
    assert abs(data_copy['humidity'] - calibrated['humidity']) < 1e-10
    assert data_copy['dewpoint'] == calibrated['dewpoint']
Пример #6
0
def test_apply_calibration_3():
    _, calibrations, _ = utils.initialize_webapp(cfg, serials)

    report = utils.find_report(calibrations['f - Probe 1'])
    assert report.number == 'H842'
    data, _ = utils.read_database(report, 'dewpoint', start='2018-11-11', end='2019-06-09')
    uncalibrated = [
        ['2018-11-11T02:41:00', 2.0],
        ['2018-12-11T04:45:53', 9.7],
        ['2019-01-10T21:03:28', 8.7],
        ['2019-02-09T20:51:08', 7.5],
        ['2019-03-11T19:40:08', 3.4],
        ['2019-04-10T07:35:28', 16.8],
        ['2019-05-10T13:44:06', 14.8],
    ]
    for i in range(len(uncalibrated)):
        assert data[i][0] == uncalibrated[i][0]
        assert data[i][1] == uncalibrated[i][1]
    data2 = utils.apply_calibration(data, report)
    assert data2 is data  # calculation is done in-place
    for i in range(len(uncalibrated)):
        assert data2[i][0] == uncalibrated[i][0]
        assert data2[i][1] == uncalibrated[i][1]
Пример #7
0
def test_apply_calibration_8():
    _, calibrations, _ = utils.initialize_webapp(cfg, serials)

    data1 = {
        'error': 'yes',
        'alias': '',
        'datetime': '2020-11-30T10:13:42',
        'temperature': None,
        'humidity': None,
        'dewpoint': None,
    }

    report = utils.find_report(calibrations['b'])
    data1_out = utils.apply_calibration(data1, report)
    assert data1_out['error'] == 'yes'
    assert len(data1_out['alias']) == 0
    assert data1_out['datetime'] == '2020-11-30T10:13:42'
    assert data1_out['temperature'] is None
    assert data1_out['humidity'] is None
    assert data1_out['dewpoint'] is None

    data2 = {
        'error': 'abc123',
        'alias': 'xyZ',
        'datetime': '2021-06-11T03:12:19',
        'temperature1': None,
        'humidity1': None,
        'dewpoint1': None,
        'temperature2': None,
        'humidity2': None,
        'dewpoint2': None,
    }

    report1 = utils.find_report(calibrations['f - Probe 1'])
    report2 = utils.find_report(calibrations['f - Probe 2'])
    data2_out = utils.apply_calibration(utils.apply_calibration(data2, report1), report2)
    assert data2_out['error'] == 'abc123'
    assert data2_out['alias'] == 'xyZ'
    assert data2_out['datetime'] == '2021-06-11T03:12:19'
    assert data2_out['temperature1'] is None
    assert data2_out['humidity1'] is None
    assert data2_out['dewpoint1'] is None
    assert data2_out['temperature2'] is None
    assert data2_out['humidity2'] is None
    assert data2_out['dewpoint2'] is None

    data3 = {
        'error': 'abc123',
        'alias': 'j knmc k',
        'datetime': '2021-06-11T03:12:19',
        'temperature1': None,
        'humidity1': None,
        'dewpoint1': None,
        'temperature2': None,
        'humidity2': None,
        'dewpoint2': None,
    }

    for report in utils.find_reports(calibrations, '56789'):
        data3 = utils.apply_calibration(data3, report)
    assert data3['error'] == 'abc123'
    assert data3['alias'] == 'j knmc k'
    assert data3['datetime'] == '2021-06-11T03:12:19'
    assert data3['temperature1'] is None
    assert data3['humidity1'] is None
    assert data3['dewpoint1'] is None
    assert data3['temperature2'] is None
    assert data3['humidity2'] is None
    assert data3['dewpoint2'] is None

    data4 = {
        'error': 'yes',
        'alias': 'alias',
        'datetime': '2020-11-30T10:13:42',
        'temperature': None,
        'humidity': None,
        'dewpoint': None,
    }
    for report in utils.find_reports(calibrations, '01234'):
        data4 = utils.apply_calibration(data4, report)
    assert data4['error'] == 'yes'
    assert data4['alias'] == 'alias'
    assert data4['datetime'] == '2020-11-30T10:13:42'
    assert data4['temperature'] is None
    assert data4['humidity'] is None
    assert data4['dewpoint'] is None
Пример #8
0
def test_apply_calibration_7():
    _, calibrations, _ = utils.initialize_webapp(cfg, serials)

    data = {
        'error': None,
        'alias': 'abcd',
        'datetime': '2020-11-30T10:13:42',
        'temperature1': 26.2,
        'humidity1': 59.4,
        'dewpoint1': 17.6,
        'temperature2': 24.8,
        'humidity2': 45.7,
        'dewpoint2': 11.3,
    }

    data_copy = data.copy()
    data2_copy = data.copy()

    calibrated = {
        'error': None,
        'alias': 'abcd',
        'datetime': '2020-11-30T10:13:42',
        'temperature1': 26.2 + (0.04 + 0.13*26.2),
        'humidity1': 59.4 + (-10.2 + 0.393*59.4 - 0.00637*(59.4**2) + 0.000039*(59.4**3)),
        'dewpoint1': 17.6,
        'temperature2': 24.8 + (0.1 + 0.06*24.8 + 0.01*(24.8**2) + 2.3e-4*(24.8**3)),
        'humidity2': 45.7 + (4.2 + 0.931*45.7 + 0.00482*(45.7**2)),
        'dewpoint2': 11.3,
    }

    report1 = utils.find_report(calibrations['f - Probe 1'], nearest='2018-07-21')
    assert report1.number == 'H388'
    data1 = utils.apply_calibration(data, report1)
    assert data1 is data  # calculation is done in-place

    # temperature1 and humidity1 had the calibration equation applied
    assert data1['error'] is calibrated['error']
    assert data1['alias'] == calibrated['alias']
    assert data1['datetime'] == calibrated['datetime']
    assert abs(data1['temperature1'] - calibrated['temperature1']) < 1e-10
    assert abs(data1['humidity1'] - calibrated['humidity1']) < 1e-10
    assert data1['dewpoint1'] == calibrated['dewpoint1']
    assert data1['temperature2'] == data['temperature2']
    assert data1['humidity2'] == data['humidity2']
    assert data1['dewpoint2'] == calibrated['dewpoint2']

    report2 = utils.find_report(calibrations['f - Probe 2'], nearest='2018-07-21')
    assert report2.number == 'H389'
    data2 = utils.apply_calibration(data1, report2)
    assert data2 is data  # calculation is done in-place
    assert data2 is data1  # calculation is done in-place

    # temperature2 and humidity2 had the calibration equation applied
    assert data2['error'] is calibrated['error']
    assert data2['alias'] == calibrated['alias']
    assert data2['datetime'] == calibrated['datetime']
    assert abs(data2['temperature1'] - calibrated['temperature1']) < 1e-10
    assert abs(data2['humidity1'] - calibrated['humidity1']) < 1e-10
    assert data2['dewpoint1'] == calibrated['dewpoint1']
    assert abs(data2['temperature2'] - calibrated['temperature2']) < 1e-10
    assert abs(data2['humidity2'] - calibrated['humidity2']) < 1e-10
    assert data2['dewpoint2'] == calibrated['dewpoint2']

    report1 = utils.find_report(calibrations['f - Probe 1'], nearest='2018-07-21')
    report2 = utils.find_report(calibrations['f - Probe 2'], nearest='2018-07-21')
    for r in [report1, report2]:
        data_copy = utils.apply_calibration(data_copy, r)
    assert data_copy['error'] is calibrated['error']
    assert data_copy['alias'] == calibrated['alias']
    assert data_copy['datetime'] == calibrated['datetime']
    assert abs(data_copy['temperature1'] - calibrated['temperature1']) < 1e-10
    assert abs(data_copy['humidity1'] - calibrated['humidity1']) < 1e-10
    assert data_copy['dewpoint1'] == calibrated['dewpoint1']
    assert abs(data_copy['temperature2'] - calibrated['temperature2']) < 1e-10
    assert abs(data_copy['humidity2'] - calibrated['humidity2']) < 1e-10
    assert data_copy['dewpoint2'] == calibrated['dewpoint2']

    for report in utils.find_reports(calibrations, '56789', nearest='2018-07-21'):
        data2_copy = utils.apply_calibration(data2_copy, report)
    assert data2_copy['error'] is calibrated['error']
    assert data2_copy['alias'] == calibrated['alias']
    assert data2_copy['datetime'] == calibrated['datetime']
    assert abs(data2_copy['temperature1'] - calibrated['temperature1']) < 1e-10
    assert abs(data2_copy['humidity1'] - calibrated['humidity1']) < 1e-10
    assert data2_copy['dewpoint1'] == calibrated['dewpoint1']
    assert abs(data2_copy['temperature2'] - calibrated['temperature2']) < 1e-10
    assert abs(data2_copy['humidity2'] - calibrated['humidity2']) < 1e-10
    assert data2_copy['dewpoint2'] == calibrated['dewpoint2']