Beispiel #1
0
def test_sample_2_exercise_temperature_index():
    # This sample data does not have any thermal values that
    # are outside the threshold... this test still serves
    # a purpose though.
    data = shared.read_data("test/resources/sample_2.csv")
    index = temperature_index(data)
    assert data[:, index].shape == (9, 724)
Beispiel #2
0
def find_unused_links():
  cache, img_cache = read_data()
  for key, values in cache.items():
    for value in values:
      img_key = key + ',' + value[0]
      if img_key in img_cache:
        del img_cache[img_key]
  return img_cache
def generate_picture_table():
    cache, img_cache = read_data()
    res = u"<html><body><table border=\"1\"><tr><th>Date</th><th>Country</th><th>Day</th><th>Image</th></tr>"
    for date, days in sorted(cache.items()):
        for day, country in days:
            src = img_cache.get(date + ',' + day, '')
            res += "<tr><td>%s</td><td>%s</td><td>%s</td><td><img src=\"%s\"/ height=\"100\" width=\"100\"></td></tr>" % (
                date, country, day, src)
    res += "</table></body></html>"
    with open(os.path.join(SCRIPTS, 'test.html'), 'wb') as f:
        f.write(res.encode('utf-8'))
def generate(dry_run=True):
    cache, img_cache = read_data()
    new_img_cache = img_cache.copy()
    for date in cache:
        for day, country in cache[date]:
            key = ",".join([date, day])
            if key not in new_img_cache:
                if dry_run:
                    print('need new image for %s' % key)
                else:
                    print('getting new image for %s' % key)
                    result = get_food_image(date, day)
                    new_img_cache[key] = result
    print(json.dumps(new_img_cache, indent=2))
def test_validate_no_preprocessing_sample_2_detection_results():
    """ Sample 2 contains two changes and should test the full path through
    the algorithm including preprocessing """
    data = read_data("test/resources/sample_2.csv")
    results = ccd.detect(data[0],
                         data[1],
                         data[2],
                         data[3],
                         data[4],
                         data[5],
                         data[6],
                         data[7],
                         data[8],
                         preprocess=False)
    assert len(results) != 2, "expected: !{}, actual: {}".format(
        2, len(results))
def test_validate_sample_2_algorithm_field():
    """Tests sample 2 again for two changes and verifies the algorithm field"""
    data = read_data("test/resources/sample_2.csv")
    results = ccd.detect(data[0],
                         data[1],
                         data[2],
                         data[3],
                         data[4],
                         data[5],
                         data[6],
                         data[7],
                         data[8],
                         preprocess=True)

    from ccd import __algorithm__
    reported = results[0]['algorithm']
    actual = __algorithm__
    msg = "reported algorithm {0} did not match actual {1}".format(
        reported, actual)
    assert reported == actual, msg
Beispiel #7
0
def test_basic_loading_sample():
    data = shared.read_data("test/resources/sample_1.csv")
    print(data.shape)
    assert data.shape == (
        9, 69), "Sample data an unexpected shape, other tests may fail."
Beispiel #8
0
def test_sample_2_ratio_clear():
    data = shared.read_data("test/resources/sample_2.csv")
    qa = data[8, :]
    ratio = ratio_clear(qa)
    assert ratio == pytest.approx(0.662, rel=1e-2)
Beispiel #9
0
def test_sample_2_ratio_snow():
    data = shared.read_data("test/resources/sample_2.csv")
    qa = data[8, :]
    ratio = ratio_snow(qa)
    # print(ratio)
    assert ratio == pytest.approx(0.308, rel=1e-2)
Beispiel #10
0
def test_sample_2_count_total():
    data = shared.read_data("test/resources/sample_2.csv")
    qa = data[8, :]
    assert count_total(qa) == 724, count_total(qa)
Beispiel #11
0
def test_sample_2_count_clear_or_water():
    data = shared.read_data("test/resources/sample_2.csv")
    qa = data[8, :]
    assert count_clear_or_water(qa) == 480, count_clear_or_water(qa)
Beispiel #12
0
def test_ratio_snow():
    data = shared.read_data("test/resources/sample_1.csv")
    qa = data[8, :]
    ratio = ratio_snow(qa)
    assert ratio == pytest.approx(0.61, rel=1e-2)
Beispiel #13
0
def test_count_snow():
    data = shared.read_data("test/resources/sample_1.csv")
    qa = data[8, :]
    assert count_snow(qa) == 38
Beispiel #14
0
def test_sample_2_preprocessing():
    data = shared.read_data("test/resources/sample_2.csv")
    meow = preprocess(data)
    assert meow.shape == (9, 477), meow.shape
Beispiel #15
0
def without_unused_links():
  unused_links = find_unused_links()
  cache, img_cache = read_data()
  for key in unused_links:
    del img_cache[key]
  return img_cache