Пример #1
0
    def testTimeout(self):
        try:
            geojson = fdgis.make_map(
                "https://www.arlnow.com/2017/06/13/wawa-considering-arlington-as-part-of-d-c-area-expansion/",
                timeout=5,
                timeout_raises_exception=True,
                debug=True)
        except Exception as e:
            self.assertTrue("timeout" in str(e).lower())

        geojson = fdgis.make_map("asdifhauwehf", timeout=1)
        self.assertEqual(geojson, None)
Пример #2
0
 def testParisWithTimeZone(self):
     source = "I love Paris"
     geojson = fdgis.make_map(source,
                              debug=True,
                              end_user_timezone="America/New_York")
     self.assertEqual(geojson['features'][0]['properties']['country_code'],
                      "FR")
Пример #3
0
 def testClarendon(self):
     source = "I like Clarendon"
     geojson = fdgis.make_map(source,
                              debug=True,
                              end_user_timezone="America/New_York")
     self.assertEqual(geojson['features'][0]['properties']['timezone'],
                      "America/New_York")
Пример #4
0
 def testParisUnitedState(self):
     source = "Where is Paris, United States?"
     response = fdgis.make_map(source, debug=False)
     self.assertEqual(response['features'][0]['properties']['name'],
                      "Paris")
     self.assertEqual(response['features'][0]['properties']['country_code'],
                      "US")
Пример #5
0
 def testWithoutHttp(self):
     geojson = fdgis.make_map(
         "raw.githubusercontent.com/FirstDraftGIS/fdgis/master/fdgis/tests/test.txt",
         debug=True)
     self.assertEqual(len(geojson['features']), 1)
     self.assertEqual(geojson['features'][0]['properties']['name'],
                      "Australia")
Пример #6
0
 def testParisTexas(self):
     source = "Where is Paris, Texas?"
     response = fdgis.make_map(source, debug=True)
     self.assertEqual(response['features'][0]['properties']['name'],
                      "Paris")
     self.assertEqual(response['features'][0]['properties']['country_code'],
                      "US")
     self.assertEqual(response['features'][0]['properties']['admin1code'],
                      "TX")
Пример #7
0
 def testAleppo(self):
     source = "Where is Aleppo, Syria?"
     response = fdgis.make_map(source, debug=False)
     #self.assertEqual(response['features'][0]['geometry']['geometries'][0]['coordinates'], [-74.49987, 40.16706])
     self.assertEqual(response['features'][0]['properties']['name'],
                      "Aleppo")
     self.assertEqual(response['features'][0]['properties']['country_code'],
                      "SY")
     self.assertEqual(len(response['features']), 1)
Пример #8
0
 def test_bethesda(self):
     source = "bethesda"
     geojson = fdgis.make_map(source, case_insensitive=True, debug=True)
     try:
         self.assertEqual(geojson['features'][0]['properties']['name'],
                          "Bethesda")
     except Exception as e:
         print "geojson:", geojson
         raise e
Пример #9
0
 def testTextAndTxt(self):
     txt_file = open(path_to_directory_of_this_file + "/test.txt", "rb")
     text = "I want to go to Rome, Italy"
     response = fdgis.make_map([txt_file, text], debug=True)
     features = response['features']
     self.assertTrue(
         [f for f in features if f['properties']['name'] == "Australia"])
     self.assertTrue(
         [f for f in features if f['properties']['name'] == "Rome"])
     txt_file.close()
Пример #10
0
 def testStructuredLinks(self):
     for extension in ["csv", "tsv", "xlsx"]:
         try:
             url = "https://raw.githubusercontent.com/FirstDraftGIS/fdgis/master/fdgis/tests/test." + extension
             geojson = fdgis.make_map(url)
             self.assertEqual(len(geojson['features']), 7)
         except Exception as e:
             print("caught exception testing url: " + url)
             print(e)
             raise e
Пример #11
0
 def testShp1(self):
     source = "Where is Richmond, VA?"
     zipped_shapefile = fdgis.make_map(source,
                                       map_format="shapefile",
                                       debug=True)
     try:
         from django.contrib.gis.gdal import DataSource
     except:
         DataSource = None
     if DataSource:
         path_to_tmp_dir = mkdtemp()
         zipped_shapefile.extractall(path_to_tmp_dir)
         for filename in listdir(path_to_tmp_dir):
             if filename.endswith(".shp"):
                 ds = DataSource(join(path_to_tmp_dir, filename))
                 self.assertEqual(ds.layer_count, 1)
                 self.assertEqual(
                     list(list(ds)[0])[0].get("name"), "Richmond")
Пример #12
0
def run(debug=True):

    try:

        start = datetime.now()

        if debug: print("starting test")

        number_of_correct_features = 0
        number_of_incorrect_features = 0

        filenames = listdir(PATH_TO_DIRECTORY_OF_INPUT_DATA)
        if debug: print("filenames:", filenames)
        for filename in filenames:
            if debug: print("filename:", filename)
            path_to_date = PATH_TO_DIRECTORY_OF_INPUT_DATA + "/" + filename
            for order in listdir(path_to_date):
                sources = []
                path_to_order = path_to_date + "/" + order
                if debug: print("path_to_order:", path_to_order)

                path_to_source_data_folder = path_to_order + "/source_data"
                for filename in listdir(path_to_source_data_folder):
                    with open(path_to_source_data_folder + "/" +
                              filename) as f:
                        sources.append(f.read())
                print("sources:", sources)
                geojson = fdgis.make_map(sources)
                print("geojson:", geojson)

                # test results
                correct = {}
                with open(path_to_order + "/results.tsv") as f:
                    for name, x, y in list(csv.reader(f, delimiter="\t"))[1:]:
                        try:
                            correct[name] = {"x": float(x), "y": float(y)}
                        except Exception as e:
                            print("x:", [x])
                            print("y:", [y])

                if debug: print("correct:", correct)
                if len(geojson['features']) == 0:
                    raise Exception("no features!")
                for feature in geojson['features']:
                    name = feature['properties']['name']
                    try:
                        print("name:", [name])
                    except:
                        pass
                    x, y = feature['geometry']['geometries'][0]['coordinates']
                    if debug: print("x:", x)
                    if debug: print("y:", y)
                    correct_props = correct.get(name, None)
                    print("\tcorrect_props:", correct_props)
                    if correct_props:
                        correct_x = correct_props['x']
                        correct_y = correct_props['y']
                        if debug: print("\tcorrect_props:", correct_props)
                        if correct_x and correct_y and correct_x != "NONE" and correct_y != "NONE":
                            if correct_x == x and correct_y == y:
                                number_of_correct_features += 1
                            else:
                                number_of_incorrect_features += 1

        if debug:
            print("number_of_correct_features:", number_of_correct_features)
        if debug:
            print("number_of_incorrect_features:",
                  number_of_incorrect_features)
        accuracy = float(number_of_correct_features) / (
            number_of_correct_features + number_of_incorrect_features)
        if debug: print("accuracy:", accuracy)

        total_seconds = (datetime.now() - start).total_seconds()
        if debug: print("total_seconds:", total_seconds)

        Test.objects.create(accuracy=accuracy, duration=total_seconds)

        if debug: print("finishing test")

    except Exception as e:

        print("CAUGHT EXCEPTION in ai.test:", e)
Пример #13
0
 def testNonAscii(self):
     source = "Despite a promise not to campaign following the attack Thursday night on Paris’s renowned Champs-Élysées boulevard, far-right candidate Marine Le Pen reinforced her anti-immigrant message in a Friday speech, calling on the French government to immediately reinstate border checks and expel foreigners being monitored by the intelligence services."
     response = fdgis.make_map(source, debug=True)
     print("response:" + str(response))
Пример #14
0
 def testNJ(self):
     source = "He visited New Jersey last year."
     response = fdgis.make_map(source)
     self.assertEqual(
         response['features'][0]['geometry']['geometries'][0]
         ['coordinates'], [-74.49987, 40.16706])
Пример #15
0
 def testParis(self):
     source = "I love Paris"
     geojson = fdgis.make_map(source, debug=True)
     self.assertEqual(geojson['features'][0]['properties']['country_code'],
                      "FR")
Пример #16
0
 def test1(self):
     #quote from news
     source = u"\u0625\u0633\u0631\u0627\u0626\u064a\u0644 \u062a\u0633\u062a\u0628\u062f\u0644 \u0627\u0644\u0628\u0648\u0627\u0628\u0627\u062a \u0627\u0644\u0625\u0644\u0643\u062a\u0631\u0648\u0646\u064a\u0629 \u0628\u0627\u0644\u0623\u0642\u0635\u0649 \u0628\u0643\u0627\u0645\u064a\u0631\u0627\u062a \u0645\u062a\u0637\u0648\u0631\u0629"
     geojson = fdgis.make_map(source, debug=True)
Пример #17
0
 def testArlingtonTX(self):
     source = "He visited Arlington, TX"
     response = fdgis.make_map(source)
     self.assertEqual(
         response['features'][0]['geometry']['geometries'][0]
         ['coordinates'], [-97.10807, 32.73569])
Пример #18
0
 def testPDFLink(self):
     source = "https://www.state.gov/documents/organization/253169.pdf"
     geojson = fdgis.make_map(source, map_format="json")
Пример #19
0
 def testArlingtonVA(self):
     source = "He visited Arlington, VA"
     response = fdgis.make_map(source)
     self.assertEqual(
         response['features'][0]['geometry']['geometries'][0]
         ['coordinates'], [-77.10428, 38.88101])
Пример #20
0
 def testTxt(self):
     filepath = path_to_directory_of_this_file + "/test.txt"
     geojson = fdgis.make_map(filepath)
     self.assertEqual(len(geojson['features']), 1)
Пример #21
0
 def testFormats(self):
     for _format in ["csv", "tsv", "xlsx"]:
         filepath = path_to_directory_of_this_file + "/test." + _format
         geojson = fdgis.make_map(filepath)
         self.assertEqual(len(geojson['features']), 7)
Пример #22
0
 def testDocx(self):
     with open(path_to_directory_of_this_file + "/test.docx", "rb") as f:
         geojson = fdgis.make_map(f, map_format="geojson")
         self.assertTrue(len(geojson['features']) >= 1)
Пример #23
0
 def testImages(self):
     source = "He visited Arlington, VA"
     image = fdgis.make_map(source, map_format="png")
     image.save("/tmp/test.png")