コード例 #1
0
def main():
    base_dir, dry_run = process_input()

    for rec, pth in get_all_records(base_dir):
        print("\n\n******************\n")
        print("processing:", rec.oil_id, rec.metadata.name)
        fixer = FixAPI(rec)
        flag, msg = fixer.check()
        if flag is True:
            print(msg)
            print("Cleaning up!")
            fixer.cleanup()
            print("API is now:", rec.metadata.API)
            if not dry_run:
                print("Saving out:", pth)
                rec.to_file(pth)
            else:
                print("Nothing saved")
        elif flag is False:
            print(msg)
            print("It's a:", rec.metadata.product_type)
            print("Densities are:",
                  rec.sub_samples[0].physical_properties.densities)
        else:
            print(msg)
コード例 #2
0
def test_non_crude_one_density_far():
    # density at too far a temp to compute API
    oil = no_api_with_one_density_13C()
    oil.sub_samples[0].physical_properties.densities[0].ref_temp.value = 0.0
    fixer = FixAPI(oil)

    fixer.cleanup()
    assert oil.metadata.API is None
コード例 #3
0
def test_non_crude_one_density_close():
    oil = no_api_with_one_density_13C()

    fixer = FixAPI(oil)

    fixer.cleanup()

    assert isclose(oil.metadata.API, 30.06, rel_tol=1e4)
コード例 #4
0
def test_find_density_at_60F():
    oil = no_api_with_density()

    fixer = FixAPI(oil)

    result = fixer.find_density_at_60F()

    assert result == 875.1
コード例 #5
0
def test_add_density():
    oil = no_api_with_density()

    # before adding:
    assert oil.metadata.API is None

    fixer = FixAPI(oil)

    fixer.cleanup()

    assert isclose(oil.metadata.API, 30.06, rel_tol=1e4)
コード例 #6
0
def test_check_no_API():
    oil = no_api_with_density()

    fixer = FixAPI(oil)
    print("in test: API:", oil.metadata.API)

    flag, msg = fixer.check()

    assert flag is True

    assert msg.startswith(f"Cleanup: {fixer.ID}:")
    assert "No API value provided" in msg
コード例 #7
0
def test_find_density_at_60F_none():
    """
    if there are no density values, then this should not add an API
    """
    oil = no_api_with_density()

    oil.sub_samples[0].physical_properties.densities = DensityList()
    fixer = FixAPI(oil)

    result = fixer.find_density_at_60F()

    assert result is None
コード例 #8
0
def test_check_API_is_there_mismatch():
    """
    if there is an API, check() should return the empty string
    """
    oil = no_api_with_density()
    oil.metadata.API = 32.0

    fixer = FixAPI(oil)

    flag, msg = fixer.check()

    print(flag)
    print(msg)

    assert flag is True
    assert "doesn't match density data" in msg
コード例 #9
0
def test_check_API_is_there_correct():
    """
    if there is an API, check() should return the empty string
    """
    oil = no_api_with_density()
    oil.metadata.API = 30.06

    fixer = FixAPI(oil)

    flag, msg = fixer.check()

    print(flag)
    print(msg)

    assert flag is None
    assert "API is fine" in msg
コード例 #10
0
def test_non_crude_two_densities_not_straddle_60():
    oil = no_api_with_density()

    oil.metadata.product_type = "Refined Product NOS"

    oil.sub_samples[0].physical_properties.densities[0].ref_temp.value = 0.0
    oil.sub_samples[0].physical_properties.densities[0].ref_temp.unit = 'C'

    oil.sub_samples[0].physical_properties.densities[1].ref_temp.value = 10.0
    oil.sub_samples[0].physical_properties.densities[1].ref_temp.unit = 'C'

    fixer = FixAPI(oil)

    fixer.cleanup()

    assert oil.metadata.API is None
コード例 #11
0
def test_find_density_at_60F_two_values():
    """
    these are data that failed with earlier version

    [(995.0, -0.14999999999997726),
     (989.0, 14.850000000000023)]
    """
    oil = no_api_with_density()
    densities = oil.sub_samples[0].physical_properties.densities

    densities[0].density.value = .995
    # densities[0].density.unit = 'kg/m^3'
    densities[0].ref_temp.value = -0.14999999999997726

    densities[1].density.value = .989
    # densities[0].density.unit = 'kg/m^3'
    densities[1].ref_temp.value = 14.85

    fixer = FixAPI(oil)

    result = fixer.find_density_at_60F()

    assert isclose(result, 989.0, rel_tol=1e3)