示例#1
0
 def test_event_info_dict(self):
     """Test we can get a dictionary of location info nicely."""
     shake_event = ShakeEvent(SHAKE_ID, data_is_local_flag=True)
     result = shake_event.event_dict()
     #noinspection PyUnresolvedReferences
     expected_dict = {
         'place-name': u'n/a',
         'depth-name': u'Depth',
         'fatalities-name': u'Estimated fatalities',
         'fatalities-count': u'0',  # 44 only after render
         'elapsed-time': u'',  # empty as it will change
         'legend-name': u'Population density',
         'fatalities-range': '0 - 100',
         'longitude-name': u'Longitude',
         'located-label': u'Located',
         'distance-unit': u'km',
         'bearing-compass': u'n/a',
         'elapsed-time-name': u'Elapsed time since event',
         'exposure-table-name': u'Estimated number of people '
                                u'affected by each MMI level',
         'longitude-value': u'140\xb037\'12.00"E',
         'city-table-name': u'Places Affected',
         'bearing-text': u'bearing',
         'limitations': (
             u'This impact estimation is automatically generated and only '
             u'takes into account the population and cities affected by '
             u'different levels of ground shaking. The estimate is based '
             u'on ground shaking data from BMKG, population density data '
             u'from asiapop.org, place information from geonames.org and '
             u'software developed by BNPB. Limitations in the estimates of '
             u'ground shaking, population  data and place names datasets '
             u'may result in significant misrepresentation of the '
             u'on-the-ground situation in the figures shown here. '
             u'Consequently decisions should not be made solely on the '
             u'information presented here and should always be verified by '
             u'ground truthing and other reliable information sources. The '
             u'fatality calculation assumes that no fatalities occur for '
             u'shake levels below MMI 4. Fatality counts of less than 50 '
             u'are disregarded.'),
         'depth-unit': u'km',
         'latitude-name': u'Latitude',
         'mmi': '3.6',
         'map-name': u'Estimated Earthquake Impact',
         'date': '5-11-2013',
         'bearing-degrees': '0.00\xb0',
         'formatted-date-time': '05-Nov-13 06:08:09 ',
         'distance': '0.00',
         'direction-relation': u'of',
         'credits': (
             u'Supported by the Australia-Indonesia Facility for Disaster '
             u'Reduction, Geoscience Australia and the World Bank-GFDRR.'),
         'latitude-value': u'2\xb025\'48.00"S',
         'time': '6:8:9',
         'depth-value': '10.0'}
     result['elapsed-time'] = u''
     message = 'Got:\n%s\nExpected:\n%s\n' % (result, expected_dict)
     self.max_diff = None
     difference = DictDiffer(result, expected_dict)
     print difference.all()
     self.assertDictEqual(expected_dict, result, message)
示例#2
0
    def test_push_to_realtime(self):
        # only do the test if realtime test server is configured
        if is_realtime_rest_configured():

            working_dir = shakemap_extract_dir()
            shake_event = ShakeEvent(working_dir=working_dir, event_id=SHAKE_ID, locale="en", data_is_local_flag=True)
            # generate report
            shake_event.render_map()
            # push to realtime django
            push_shake_event_to_rest(shake_event)
            # check shake event exists
            session = get_realtime_session()
            earthquake_url = generate_earthquake_detail_url(SHAKE_ID)
            response = session.get(earthquake_url)
            self.assertEqual(response.status_code, requests.codes.ok)

            event_dict = shake_event.event_dict()
            earthquake_data = {
                "shake_id": shake_event.event_id,
                "magnitude": float(event_dict.get("mmi")),
                "depth": float(event_dict.get("depth-value")),
                "time": shake_event.shake_grid.time.strftime(INASAFE_REALTIME_DATETIME_FORMAT),
                "location": {
                    "type": "Point",
                    "coordinates": [shake_event.shake_grid.longitude, shake_event.shake_grid.latitude],
                },
                "location_description": event_dict.get("place-name"),
            }

            for key, value in earthquake_data.iteritems():
                self.assertEqual(response.json()[key], value)
示例#3
0
    def test_push_to_realtime(self):
        # only do the test if realtime test server is configured
        if is_realtime_rest_configured():

            working_dir = shakemap_extract_dir()
            shake_event = ShakeEvent(working_dir=working_dir,
                                     event_id=SHAKE_ID,
                                     locale='en',
                                     data_is_local_flag=True)
            # generate report
            shake_event.render_map()
            # push to realtime django
            push_shake_event_to_rest(shake_event)
            # check shake event exists
            session = get_realtime_session()
            earthquake_url = generate_earthquake_detail_url(SHAKE_ID)
            response = session.get(earthquake_url)
            self.assertEqual(response.status_code, requests.codes.ok)

            event_dict = shake_event.event_dict()
            earthquake_data = {
                'shake_id':
                shake_event.event_id,
                'magnitude':
                float(event_dict.get('mmi')),
                'depth':
                float(event_dict.get('depth-value')),
                'time':
                shake_event.shake_grid.time.strftime(
                    INASAFE_REALTIME_DATETIME_FORMAT),
                'location': {
                    'type':
                    'Point',
                    'coordinates': [
                        shake_event.shake_grid.longitude,
                        shake_event.shake_grid.latitude
                    ]
                },
                'location_description':
                event_dict.get('place-name')
            }

            for key, value in earthquake_data.iteritems():
                self.assertEqual(response.json()[key], value)
示例#4
0
    def test_event_info_dict(self):
        """Test we can get a dictionary of location info nicely."""
        working_dir = shakemap_extract_dir()
        shake_event = ShakeEvent(working_dir=working_dir, event_id=SHAKE_ID, data_is_local_flag=True)
        result = shake_event.event_dict()
        software_tag = (
            "This report was created using InaSAFE version %s. "
            "Visit http://inasafe.org for more information." % get_version()
        )

        # noinspection PyUnresolvedReferences
        expected_dict = {
            "place-name": u"n/a",
            "depth-name": u"Depth",
            "fatalities-name": u"Estimated fatalities",
            "fatalities-count": u"0",  # 44 only after render
            "elapsed-time": u"",  # empty as it will change
            "legend-name": u"Population count per grid cell",
            "fatalities-range": "0 - 100",
            "longitude-name": u"Longitude",
            "located-label": u"Located",
            "distance-unit": u"km",
            "bearing-compass": u"n/a",
            "elapsed-time-name": u"Elapsed time since event",
            "exposure-table-name": u"Estimated number of people " u"affected by each MMI level",
            "longitude-value": u"140\xb037\u203212.00\u2033E",
            "city-table-name": u"Nearby Places",
            "bearing-text": u"bearing",
            "limitations": (
                u"This impact estimation is automatically generated and only "
                u"takes into account the population and cities affected by "
                u"different levels of ground shaking. The estimate is based "
                u"on ground shaking data from BMKG, population count data "
                u"derived by AIFDR from worldpop.org.uk, place information "
                u"from geonames.org and software developed by BNPB. "
                u"Limitations in the estimates of ground shaking, population "
                u"and place names datasets may result in significant "
                u"misrepresentation of the on-the-ground situation in the "
                u"figures shown here. Consequently decisions should not be "
                u"made solely on the information presented here and should "
                u"always be verified by ground truthing and other reliable "
                u"information sources. The fatality calculation assumes that "
                u"no fatalities occur for shake levels below MMI 4. Fatality "
                u"counts of less than 50 are disregarded."
            ),
            "depth-unit": u"km",
            "latitude-name": u"Latitude",
            "mmi": "3.6",
            "map-name": u"Estimated Earthquake Impact",
            "date": "5-11-2013",
            "bearing-degrees": "0.00\xb0",
            "formatted-date-time": "05-Nov-13 06:08:09 LMT",
            "distance": "0.00",
            "direction-relation": u"of",
            "software-tag": software_tag,
            "credits": (
                u"Supported by the Australia-Indonesia Facility for Disaster "
                u"Reduction, Geoscience Australia and the World Bank-GFDRR."
            ),
            "latitude-value": u"2\xb025\u203248.00\u2033S",
            "time": "6:8:9",
            "depth-value": "10.0",
        }
        result["elapsed-time"] = u""
        message = "Got:\n%s\nExpected:\n%s\n" % (result, expected_dict)
        self.max_diff = None
        difference = DictDiffer(result, expected_dict)
        print difference.all()
        self.assertDictEqual(expected_dict, result, message)
示例#5
0
    def test_event_info_dict(self):
        """Test we can get a dictionary of location info nicely."""
        working_dir = shakemap_extract_dir()
        shake_event = ShakeEvent(
            working_dir=working_dir,
            event_id=SHAKE_ID,
            data_is_local_flag=True)
        result = shake_event.event_dict()
        software_tag = ('This report was created using InaSAFE version %s. '
                        'Visit http://inasafe.org for more information.' %
                        get_version())

        # noinspection PyUnresolvedReferences
        expected_dict = {
            'place-name': u'n/a',
            'depth-name': u'Depth',
            'fatalities-name': u'Estimated fatalities',
            'fatalities-count': u'0',  # 44 only after render
            'elapsed-time': u'',  # empty as it will change
            'legend-name': u'Population count per grid cell',
            'fatalities-range': '0 - 100',
            'longitude-name': u'Longitude',
            'located-label': u'Located',
            'distance-unit': u'km',
            'bearing-compass': u'n/a',
            'elapsed-time-name': u'Elapsed time since event',
            'exposure-table-name': u'Estimated number of people '
                                   u'affected by each MMI level',
            'longitude-value': u'140\xb037\u203212.00\u2033E',
            'city-table-name': u'Nearby Places',
            'bearing-text': u'bearing',
            'limitations': (
                u'This impact estimation is automatically generated and only '
                u'takes into account the population and cities affected by '
                u'different levels of ground shaking. The estimate is based '
                u'on ground shaking data from BMKG, population count data '
                u'derived by AIFDR from worldpop.org.uk, place information '
                u'from geonames.org and software developed by BNPB. '
                u'Limitations in the estimates of ground shaking, population '
                u'and place names datasets may result in significant '
                u'misrepresentation of the on-the-ground situation in the '
                u'figures shown here. Consequently decisions should not be '
                u'made solely on the information presented here and should '
                u'always be verified by ground truthing and other reliable '
                u'information sources. The fatality calculation assumes that '
                u'no fatalities occur for shake levels below MMI 4. Fatality '
                u'counts of less than 50 are disregarded.'),
            'depth-unit': u'km',
            'latitude-name': u'Latitude',
            'mmi': '3.6',
            'map-name': u'Estimated Earthquake Impact',
            'date': '5-11-2013',
            'bearing-degrees': '0.00\xb0',
            'formatted-date-time': '05-Nov-13 06:08:09 ',
            'distance': '0.00',
            'direction-relation': u'of',
            'software-tag': software_tag,
            'credits': (
                u'Supported by the Australia-Indonesia Facility for Disaster '
                u'Reduction, Geoscience Australia and the World Bank-GFDRR.'),
            'latitude-value': u'2\xb025\u203248.00\u2033S',
            'time': '6:8:9',
            'depth-value': '10.0'}
        result['elapsed-time'] = u''
        message = 'Got:\n%s\nExpected:\n%s\n' % (result, expected_dict)
        self.max_diff = None
        difference = DictDiffer(result, expected_dict)
        print difference.all()
        self.assertDictEqual(expected_dict, result, message)
示例#6
0
 def test_event_info_dict(self):
     """Test we can get a dictionary of location info nicely."""
     shake_id = '20120726022003'
     shake_event = ShakeEvent(shake_id)
     result = shake_event.event_dict()
     #noinspection PyUnresolvedReferences
     expected_dict = {'place-name': PyQt4.QtCore.QString(u'n/a'),
                      'depth-name': PyQt4.QtCore.QString(u'Depth'),
                      'fatalities-name': PyQt4.QtCore.QString(
                          u'Estimated fatalities'),
                      'fatalities-count': u'0',  # 44 only after render
                      'elapsed-time': u'',  # empty as it will change
                      'legend-name': PyQt4.QtCore.QString(
                          u'Population density'),
                      'fatalities-range': '0 - 100',
                      'longitude-name': PyQt4.QtCore.QString(u'Longitude'),
                      'located-label': PyQt4.QtCore.QString(u'Located'),
                      'distance-unit': PyQt4.QtCore.QString(u'km'),
                      'bearing-compass': u'n/a',
                      'elapsed-time-name': PyQt4.QtCore.QString(
                          u'Elapsed time since event'),
                      'exposure-table-name': PyQt4.QtCore.QString(
                          u'Estimated number of people affected by each '
                          u'MMI level'),
                      'longitude-value': u'124\xb027\'0.00"E',
                      'city-table-name': PyQt4.QtCore.QString(
                          u'Places Affected'),
                      'bearing-text': PyQt4.QtCore.QString(u'bearing'),
                      'limitations': PyQt4.QtCore.QString(
                          u'This impact estimation is automatically '
                          u'generated and only takes into account the '
                          u'population and cities affected by different '
                          u'levels of ground shaking. The estimate is '
                          u'based on ground shaking data from BMKG, '
                          u'population density data from asiapop.org, '
                          u'place information from geonames.org and '
                          u'software developed by BNPB. Limitations in '
                          u'the estimates of ground shaking, '
                          u'population  data and place names datasets may'
                          u' result in significant misrepresentation of '
                          u'the on-the-ground situation in the figures '
                          u'shown here. Consequently decisions should not'
                          u' be made solely on the information presented '
                          u'here and should always be verified by ground '
                          u'truthing and other reliable information '
                          u'sources. The fatality calculation assumes '
                          u'that no fatalities occur for shake levels '
                          u'below MMI 4. Fatality counts of less than 50 '
                          u'are disregarded.'),
                      'depth-unit': PyQt4.QtCore.QString(u'km'),
                      'latitude-name': PyQt4.QtCore.QString(u'Latitude'),
                      'mmi': '5.0',
                      'map-name': PyQt4.QtCore.QString(
                          u'Estimated Earthquake Impact'),
                      'date': '26-7-2012',
                      'bearing-degrees': '0.00\xb0',
                      'formatted-date-time': '26-Jul-12 02:15:35 ',
                      'distance': '0.00',
                      'direction-relation': PyQt4.QtCore.QString(u'of'),
                      'credits': PyQt4.QtCore.QString(
                          u'Supported by the Australia-Indonesia Facility'
                          u' for Disaster Reduction, Geoscience Australia '
                          u'and the World Bank-GFDRR.'),
                      'latitude-value': u'0\xb012\'36.00"S',
                      'time': '2:15:35', 'depth-value': '11.0'}
     result['elapsed-time'] = u''
     message = 'Got:\n%s\nExpected:\n%s\n' % (result, expected_dict)
     self.max_diff = None
     difference = DictDiffer(result, expected_dict)
     print difference.all()
     self.assertDictEqual(expected_dict, result, message)