示例#1
0
    def test_DifferentGroupAlertLevels(self, session=None):
        sm1 = ShakeMap(shakemap_id='shakemap1', shakemap_version=1)

        session.add(sm1)

        group1 = create_group(name='GLOBAL')
        group2 = create_group(name='GLOBAL2')

        session.add_all([group1, group2])

        fac1 = Facility(facility_id=1, groups=[group1])

        fac2 = Facility(facility_id=2, groups=[group2])

        fs1 = FacilityShaking(shakemap=sm1, alert_level='gray', facility=fac1)

        fs2 = FacilityShaking(shakemap=sm1, alert_level='green', facility=fac2)

        session.add_all([fac1, fac2, fs1, fs2])

        session.commit()

        level1 = sm1.get_alert_level(group1)
        level2 = sm1.get_alert_level(group2)

        self.assertTrue(level1 == 'gray')
        self.assertTrue(level2 == 'green')

        objs = [sm1, group1, group2, fac1, fac2]
        for obj in objs:
            session.delete(obj)

        session.commit()
示例#2
0
    def test_multiple_group_impact(self):
        facility1 = Facility()
        facility2 = Facility()

        group1 = Group(facilities=[facility1])
        group2 = Group(facilities=[facility2])

        facility_shaking = [
            FacilityShaking(alert_level='green', facility=facility1),
            FacilityShaking(alert_level='red', facility=facility2)
        ]

        shakemap = ShakeMap(facility_shaking=facility_shaking)

        impact = shakemap.get_impact_summary()
        self.assertTrue(impact['green'] == 1)
        self.assertTrue(impact['red'] == 1)

        impact = shakemap.get_impact_summary(group1)
        self.assertTrue(impact['green'] == 1)
        self.assertTrue(impact['red'] == 0)

        impact = shakemap.get_impact_summary(group2)
        self.assertTrue(impact['green'] == 0)
        self.assertTrue(impact['red'] == 1)
示例#3
0
    def test_changedNotificationLength(self, session=None):
        sm1 = ShakeMap(shakemap_id='test_changedNotificationLength',
                       shakemap_version=1)

        sm2 = ShakeMap(shakemap_id='test_changedNotificationLength',
                       shakemap_version=2)

        session.add_all([sm1, sm2])

        group = create_group(name='GLOBAL')

        session.add(group)

        n1 = Notification(shakemap=sm1)

        n2 = Notification(shakemap=sm2)

        session.add_all([n1, n2])

        fac1 = Facility(facility_id=1, groups=[group])

        fac2 = Facility(facility_id=2, groups=[group])

        fac3 = Facility(facility_id=3, groups=[group])

        fs1 = FacilityShaking(shakemap=sm1, alert_level='green', facility=fac1)

        fs2 = FacilityShaking(shakemap=sm2, alert_level='green', facility=fac2)

        fs3 = FacilityShaking(shakemap=sm2, alert_level='gray', facility=fac3)

        session.add_all([fac1, fac2, fac3, fs1, fs2, fs3])

        session.commit()

        # check notification 1
        has_alert_level, new_inspection, update = check_notification_for_group(
            group, n2, session=session)

        self.assertTrue(has_alert_level)
        self.assertTrue(new_inspection)
        self.assertTrue(update)

        objs = [sm1, sm2, n1, n2, group, fac1, fac2, fac3]
        for obj in objs:
            session.delete(obj)

        session.commit()
示例#4
0
    def test_event_impact(self):
        facility_shaking = [
            FacilityShaking(alert_level = 'green')
        ]

        impact = get_event_impact(facility_shaking)
        self.assertTrue(impact['green'] == 1)
示例#5
0
    def test_geoJsonSetsProperties(self):
        f = Facility(lat_max=80,
                     lat_min=79,
                     lon_max=100,
                     lon_min=99,
                     name='TEST')

        fs = FacilityShaking(facility=f)

        geojson = fs.geojson

        self.assertEqual(geojson['properties']['name'], f.name)
示例#6
0
    def test_group_impact(self):
        facility = Facility()
        group = Group(facilities=[facility])

        facility_shaking = [
            FacilityShaking(alert_level='green', facility=facility)
        ]

        shakemap = ShakeMap(facility_shaking=facility_shaking)

        impact = shakemap.get_impact_summary(group)

        self.assertTrue(impact['green'] == 1)
示例#7
0
    def test_unchangedNotificationGreenGreen(self, session=None):
        sm1 = ShakeMap(shakemap_id='shakemap1', shakemap_version=1)

        sm2 = ShakeMap(shakemap_id='shakemap1', shakemap_version=2)

        session.add_all([sm1, sm2])

        group = create_group(name='GLOBAL')

        session.add(group)

        n1 = Notification(shakemap=sm1)

        n2 = Notification(shakemap=sm2)

        session.add_all([n1, n2])

        fac1 = Facility(facility_id=1)

        fs1 = FacilityShaking(shakemap=sm1, weight=1, facility=fac1)

        fs2 = FacilityShaking(shakemap=sm2, weight=1, facility=fac1)

        session.add_all([fac1, fs1, fs2])

        session.commit()

        # check notification 1
        has_alert_level, new_inspection, update = check_notification_for_group(
            group, n2, session=session)
        self.assertTrue(has_alert_level)
        self.assertFalse(new_inspection)
        self.assertTrue(update)

        objs = [sm1, sm2, n1, n2, group, fac1]
        for obj in objs:
            session.delete(obj)

        session.commit()
示例#8
0
    def test_geoJsonFacility(self):
        f = Facility(lat_max=80,
                     lat_min=79,
                     lon_max=100,
                     lon_min=99,
                     name='TEST')

        fs = FacilityShaking(facility=f)

        geojson = fs.geojson

        self.assertEqual(geojson['geometry']['type'], 'Point')
        self.assertEqual(geojson['geometry']['coordinates'][0], f.lon)
        self.assertEqual(geojson['geometry']['coordinates'][1], f.lat)
示例#9
0
    def test_changedNotificationNoneGrey(self, session=None):

        sm1 = ShakeMap(shakemap_id='shakemap1', shakemap_version=1)

        sm2 = ShakeMap(shakemap_id='shakemap1', shakemap_version=2)

        session.add_all([sm1, sm2])

        group = create_group(name='GLOBAL')

        session.add(group)

        n1 = Notification(shakemap=sm1)

        n2 = Notification(shakemap=sm2)

        session.add_all([n1, n2])

        facility = Facility(groups=[group])

        fs = FacilityShaking(shakemap=sm2,
                             alert_level='gray',
                             facility=facility)

        session.add(fs)

        session.commit()

        # check notification 1
        has_alert_level, new_inspection, update = check_notification_for_group(
            group, n2, session=session)
        self.assertTrue(has_alert_level)
        self.assertTrue(new_inspection)
        self.assertTrue(update)

        objs = [sm1, sm2, n1, n2, group]
        for obj in objs:
            session.delete(obj)

        session.commit()