示例#1
0
def _group_continuous_week_post(session, observation, observation_values):
    # observation_values expected to be sorted
    # observation values already have uneven frequency checked
    gid = quality_mapping.check_if_series_flagged(
        observation_values['quality_flag'], 'UNEVEN FREQUENCY').cumsum()
    # make series of week + year integers to further
    # split data to post at most one week at a time
    # ~10,000 pts of 1min data
    week_int = (gid.index.week + gid.index.year).values
    # combine the continuous groups with groups of weeks
    # gid is unique for each group since week_int and cumsum
    # increase monotonically and are positive
    gid += week_int
    observation_values['gid'] = gid
    for _, group in observation_values.groupby('gid'):
        session.post_observation_values(observation.observation_id,
                                        group[['value', 'quality_flag']],
                                        params='donotvalidate')
def test_check_if_series_flagged_key_fail():
    with pytest.raises(KeyError):
        quality_mapping.check_if_series_flagged(pd.Series([2, 3, 35]),
                                                ['NOK'])
def test_check_if_series_flagged_validated_fail():
    with pytest.raises(ValueError):
        quality_mapping.check_if_series_flagged(pd.Series([0, 1, 0]), 'OK')
def test_check_if_series_flagged_type_fail():
    with pytest.raises(TypeError):
        quality_mapping.check_if_series_flagged(pd.Series([2, 3, 35]),
                                                ['OK', b'CLOUDY', []])
def test_check_if_series_flagged(expected, desc):
    flags = pd.Series([2, 3, 2 | 1 << 9, 2 | 1 << 5 | 1 << 12 | 1])
    out = quality_mapping.check_if_series_flagged(flags, desc)
    assert_series_equal(out, expected)