Beispiel #1
0
    def test_geom_validation(self):
        def mkpt(x,y):
            return self.mkrow({'point x': str(x), 'point y': str(y)})

        # Invalid numbers
        i = mkpt('300a','20b')
        r = i.validate_row()

        self.assertFalse(r)
        self.assertHasError(i, errors.FLOAT_ERROR)

        # Crazy lat/lngs
        i = mkpt(300,20)
        r = i.validate_row()

        self.assertFalse(r)
        self.assertHasError(i, errors.INVALID_GEOM)

        i = mkpt(50,93)
        r = i.validate_row()

        self.assertFalse(r)
        self.assertHasError(i, errors.INVALID_GEOM)

        # Out of neighborhood (neighborhood created in setUp)
        ngeom = MultiPolygon(Polygon(
            ((0, 0), (0, 50), (50, 50), (50, 0), (0, 0))))

        neighborhood = Neighborhood(
            name='test neighborhood',
            region_id=34,
            city='blah',
            county='blarg',
            geometry=ngeom)

        neighborhood.save()

        i = mkpt(55,55)
        r = i.validate_row()

        self.assertFalse(r)
        self.assertHasError(i, errors.GEOM_OUT_OF_BOUNDS)

        i = mkpt(-5,-5)
        r = i.validate_row()

        self.assertFalse(r)
        self.assertHasError(i, errors.GEOM_OUT_OF_BOUNDS)

        # This should work...
        i = mkpt(25,25)
        r = i.validate_row()

        # Can't assert that r is true because other validation
        # logic may have tripped it
        self.assertNotHasError(i, errors.GEOM_OUT_OF_BOUNDS)
        self.assertNotHasError(i, errors.INVALID_GEOM)
        self.assertNotHasError(i, errors.FLOAT_ERROR)

        # If we add an exclusion zone, it should fail
        egeom = MultiPolygon(Polygon(
            ((10,10),(10,30),(30,30),(30,10),(10,10))))

        e = ExclusionMask(geometry=egeom, type='blah blah')
        e.save()

        i = mkpt(25,25)
        r = i.validate_row()

        self.assertNotHasError(i, errors.GEOM_OUT_OF_BOUNDS)
        self.assertNotHasError(i, errors.INVALID_GEOM)
        self.assertNotHasError(i, errors.FLOAT_ERROR)
        self.assertHasError(i, errors.EXCL_ZONE)
Beispiel #2
0
def setupTreemapEnv():
    settings.GEOSERVER_GEO_LAYER = ""
    settings.GEOSERVER_GEO_STYLE = ""
    settings.GEOSERVER_URL = ""

    r1 = ReputationAction(name="edit verified", description="blah")
    r2 = ReputationAction(name="edit tree", description="blah")
    r3 = ReputationAction(name="Administrative Action", description="blah")
    r4 = ReputationAction(name="add tree", description="blah")
    r5 = ReputationAction(name="edit plot", description="blah")
    r6 = ReputationAction(name="add plot", description="blah")

    for r in [r1, r2, r3, r4, r5, r6]:
        r.save()

    bv = BenefitValues(
        co2=0.02,
        pm10=9.41,
        area="InlandValleys",
        electricity=0.1166,
        voc=4.69,
        ozone=5.0032,
        natural_gas=1.25278,
        nox=12.79,
        stormwater=0.0078,
        sox=3.72,
        bvoc=4.96)

    bv.save()

    dbh = "[1.0, 2.0, 3.0]"

    rsrc = Resource(
        meta_species="BDM_OTHER",
        electricity_dbh=dbh,
        co2_avoided_dbh=dbh,
        aq_pm10_dep_dbh=dbh,
        region="Sim City",
        aq_voc_avoided_dbh=dbh,
        aq_pm10_avoided_dbh=dbh,
        aq_ozone_dep_dbh=dbh,
        aq_nox_avoided_dbh=dbh,
        co2_storage_dbh=dbh,
        aq_sox_avoided_dbh=dbh,
        aq_sox_dep_dbh=dbh,
        bvoc_dbh=dbh,
        co2_sequestered_dbh=dbh,
        aq_nox_dep_dbh=dbh,
        hydro_interception_dbh=dbh,
        natural_gas_dbh=dbh)
    rsrc.save()

    u = User.objects.filter(username="******")

    if u:
        u = u[0]
    else:
        u = User.objects.create_user("jim", "*****@*****.**", "jim")
        u.is_staff = True
        u.is_superuser = True
        u.save()
        up = UserProfile(user=u)
        up.save()
        u.reputation = Reputation(user=u)
        u.reputation.save()

    amy_filter_result = User.objects.filter(username="******")
    if not amy_filter_result:
        amy = User.objects.create_user("amy", "*****@*****.**", "amy")
    else:
        amy = amy_filter_result[0]
    amy.is_staff = False
    amy.is_superuser = False
    amy.save()
    amy_profile = UserProfile(user=amy)
    amy_profile.save()
    amy.reputation = Reputation(user=amy)
    amy.reputation.save()

    n1geom = MultiPolygon(
        Polygon(((0, 0), (100, 0), (100, 100), (0, 100), (0, 0))))
    n2geom = MultiPolygon(
        Polygon(((0, 101), (101, 101), (101, 200), (0, 200), (0, 101))))

    n1 = Neighborhood(
        name="n1",
        region_id=2,
        city="c1",
        state="PA",
        county="PAC",
        geometry=n1geom)
    n2 = Neighborhood(
        name="n2",
        region_id=2,
        city="c2",
        state="NY",
        county="NYC",
        geometry=n2geom)

    n1.save()
    n2.save()

    z1geom = MultiPolygon(
        Polygon(((0, 0), (100, 0), (100, 100), (0, 100), (0, 0))))
    z2geom = MultiPolygon(
        Polygon(((0, 100), (100, 100), (100, 200), (0, 200), (0, 100))))

    z1 = ZipCode(zip="19107", geometry=z1geom)
    z2 = ZipCode(zip="10001", geometry=z2geom)

    z1.save()
    z2.save()

    exgeom1 = MultiPolygon(
        Polygon(((0, 0), (25, 0), (25, 25), (0, 25), (0, 0))))
    ex1 = ExclusionMask(geometry=exgeom1, type="building")

    ex1.save()

    agn1 = AggregateNeighborhood(
        annual_stormwater_management=0.0,
        annual_electricity_conserved=0.0,
        annual_energy_conserved=0.0,
        annual_natural_gas_conserved=0.0,
        annual_air_quality_improvement=0.0,
        annual_co2_sequestered=0.0,
        annual_co2_avoided=0.0,
        annual_co2_reduced=0.0,
        total_co2_stored=0.0,
        annual_ozone=0.0,
        annual_nox=0.0,
        annual_pm10=0.0,
        annual_sox=0.0,
        annual_voc=0.0,
        annual_bvoc=0.0,
        total_trees=0,
        total_plots=0,
        location=n1)

    agn2 = AggregateNeighborhood(
        annual_stormwater_management=0.0,
        annual_electricity_conserved=0.0,
        annual_energy_conserved=0.0,
        annual_natural_gas_conserved=0.0,
        annual_air_quality_improvement=0.0,
        annual_co2_sequestered=0.0,
        annual_co2_avoided=0.0,
        annual_co2_reduced=0.0,
        total_co2_stored=0.0,
        annual_ozone=0.0,
        annual_nox=0.0,
        annual_pm10=0.0,
        annual_sox=0.0,
        annual_voc=0.0,
        annual_bvoc=0.0,
        total_trees=0,
        total_plots=0,
        location=n2)

    agn1.save()
    agn2.save()

    s1 = Species(symbol="s1", genus="testus1", species="specieius1")
    s2 = Species(symbol="s2", genus="testus2", species="specieius2")

    s1.save()
    s2.save()

    ie = ImportEvent(file_name='site_add')
    ie.save()
Beispiel #3
0
    def setUp(self):
        ######
        # Request/Render mock
        ######
        def local_render_to_response(*args, **kwargs):
            from django.template import loader, RequestContext
            from django.http import HttpResponse

            httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)}
            hr = HttpResponse(loader.render_to_string(*args, **kwargs),
                              **httpresponse_kwargs)

            if hasattr(args[1], 'dicts'):
                hr.request_context = args[1].dicts

            return hr

        django.shortcuts.render_to_response = local_render_to_response

        ######
        # Content types
        ######
        r1 = ReputationAction(name="edit verified", description="blah")
        r2 = ReputationAction(name="edit tree", description="blah")
        r3 = ReputationAction(name="Administrative Action", description="blah")
        r4 = ReputationAction(name="add tree", description="blah")
        r5 = ReputationAction(name="edit plot", description="blah")
        r6 = ReputationAction(name="add plot", description="blah")
        r7 = ReputationAction(name="add stewardship", description="blah")
        r8 = ReputationAction(name="remove stewardship", description="blah")

        self.ra = [r1, r2, r3, r4, r5, r6, r7, r8]

        for r in self.ra:
            r.save()

        ######
        # Set up benefit values
        ######
        bv = BenefitValues(co2=0.02,
                           pm10=9.41,
                           area="InlandValleys",
                           electricity=0.1166,
                           voc=4.69,
                           ozone=5.0032,
                           natural_gas=1.25278,
                           nox=12.79,
                           stormwater=0.0078,
                           sox=3.72,
                           bvoc=4.96)

        bv.save()
        self.bv = bv

        dbh = "[1.0, 2.0, 3.0]"

        rsrc = Resource(meta_species="BDM_OTHER",
                        electricity_dbh=dbh,
                        co2_avoided_dbh=dbh,
                        aq_pm10_dep_dbh=dbh,
                        region="Sim City",
                        aq_voc_avoided_dbh=dbh,
                        aq_pm10_avoided_dbh=dbh,
                        aq_ozone_dep_dbh=dbh,
                        aq_nox_avoided_dbh=dbh,
                        co2_storage_dbh=dbh,
                        aq_sox_avoided_dbh=dbh,
                        aq_sox_dep_dbh=dbh,
                        bvoc_dbh=dbh,
                        co2_sequestered_dbh=dbh,
                        aq_nox_dep_dbh=dbh,
                        hydro_interception_dbh=dbh,
                        natural_gas_dbh=dbh)
        rsrc.save()
        self.rsrc = rsrc

        ######
        # Users
        ######
        u = User.objects.filter(username="******")

        if u:
            u = u[0]
        else:
            u = User.objects.create_user("jim", "*****@*****.**", "jim")
            u.is_staff = True
            u.is_superuser = True
            u.save()
            up = UserProfile(user=u)
            u.reputation = Reputation(user=u)
            u.reputation.save()

        self.u = u

        #######
        # Setup geometries -> Two stacked 100x100 squares
        #######
        n1geom = MultiPolygon(
            Polygon(((0, 0), (100, 0), (100, 100), (0, 100), (0, 0))))
        n2geom = MultiPolygon(
            Polygon(((0, 101), (101, 101), (101, 200), (0, 200), (0, 101))))

        n1 = Neighborhood(name="n1",
                          region_id=2,
                          city="c1",
                          state="PA",
                          county="PAC",
                          geometry=n1geom)
        n2 = Neighborhood(name="n2",
                          region_id=2,
                          city="c2",
                          state="NY",
                          county="NYC",
                          geometry=n2geom)

        n1.save()
        n2.save()

        z1geom = MultiPolygon(
            Polygon(((0, 0), (100, 0), (100, 100), (0, 100), (0, 0))))
        z2geom = MultiPolygon(
            Polygon(((0, 100), (100, 100), (100, 200), (0, 200), (0, 100))))

        z1 = ZipCode(zip="19107", geometry=z1geom)
        z2 = ZipCode(zip="10001", geometry=z2geom)

        z1.save()
        z2.save()

        exgeom1 = MultiPolygon(
            Polygon(((0, 0), (25, 0), (25, 25), (0, 25), (0, 0))))
        ex1 = ExclusionMask(geometry=exgeom1, type="building")

        ex1.save()

        agn1 = AggregateNeighborhood(annual_stormwater_management=0.0,
                                     annual_electricity_conserved=0.0,
                                     annual_energy_conserved=0.0,
                                     annual_natural_gas_conserved=0.0,
                                     annual_air_quality_improvement=0.0,
                                     annual_co2_sequestered=0.0,
                                     annual_co2_avoided=0.0,
                                     annual_co2_reduced=0.0,
                                     total_co2_stored=0.0,
                                     annual_ozone=0.0,
                                     annual_nox=0.0,
                                     annual_pm10=0.0,
                                     annual_sox=0.0,
                                     annual_voc=0.0,
                                     annual_bvoc=0.0,
                                     total_trees=0,
                                     total_plots=0,
                                     location=n1)

        agn2 = AggregateNeighborhood(annual_stormwater_management=0.0,
                                     annual_electricity_conserved=0.0,
                                     annual_energy_conserved=0.0,
                                     annual_natural_gas_conserved=0.0,
                                     annual_air_quality_improvement=0.0,
                                     annual_co2_sequestered=0.0,
                                     annual_co2_avoided=0.0,
                                     annual_co2_reduced=0.0,
                                     total_co2_stored=0.0,
                                     annual_ozone=0.0,
                                     annual_nox=0.0,
                                     annual_pm10=0.0,
                                     annual_sox=0.0,
                                     annual_voc=0.0,
                                     annual_bvoc=0.0,
                                     total_trees=0,
                                     total_plots=0,
                                     location=n2)

        agn1.save()
        agn2.save()

        self.agn1 = agn1
        self.agn2 = agn2

        self.z1 = z1
        self.z2 = z2
        self.n1 = n1
        self.n2 = n2

        ######
        # And we could use a few species...
        ######
        s1 = Species(symbol="s1", genus="testus1", species="specieius1")
        s2 = Species(symbol="s2", genus="testus2", species="specieius2")

        s1.save()
        s2.save()

        self.s1 = s1
        self.s2 = s2

        #######
        # Create some basic plots
        #######
        ie = ImportEvent(file_name='site_add')
        ie.save()

        self.ie = ie

        p1_no_tree = Plot(geometry=Point(50, 50),
                          last_updated_by=u,
                          import_event=ie,
                          present=True,
                          data_owner=u)
        p1_no_tree.save()

        p2_tree = Plot(geometry=Point(51, 51),
                       last_updated_by=u,
                       import_event=ie,
                       present=True,
                       data_owner=u)
        p2_tree.save()

        p3_tree_species1 = Plot(geometry=Point(50, 100),
                                last_updated_by=u,
                                import_event=ie,
                                present=True,
                                data_owner=u)
        p3_tree_species1.save()

        p4_tree_species2 = Plot(geometry=Point(50, 150),
                                last_updated_by=u,
                                import_event=ie,
                                present=True,
                                data_owner=u)
        p4_tree_species2.save()

        t1 = Tree(plot=p2_tree,
                  species=None,
                  last_updated_by=u,
                  import_event=ie)
        t1.present = True
        t1.save()

        t2 = Tree(plot=p3_tree_species1,
                  species=s1,
                  last_updated_by=u,
                  import_event=ie)
        t2.present = True
        t2.save()

        t3 = Tree(plot=p4_tree_species2,
                  species=s2,
                  last_updated_by=u,
                  import_event=ie)
        t3.present = True
        t3.save()

        self.p1_no_tree = p1_no_tree
        self.p2_tree = p2_tree
        self.p3_tree_species1 = p3_tree_species1
        self.p4_tree_species2 = p4_tree_species2

        self.plots = [p1_no_tree, p2_tree, p3_tree_species1, p4_tree_species2]

        self.t1 = t1
        self.t2 = t2
        self.t3 = t3
Beispiel #4
0
    def setUp(self):
        ######
        # Request/Render mock
        ######
        def local_render_to_response(*args, **kwargs):
            from django.template import loader, RequestContext
            from django.http import HttpResponse

            httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)}
            hr = HttpResponse(
                loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)

            if hasattr(args[1], 'dicts'):
                hr.request_context = args[1].dicts

            return hr

        django.shortcuts.render_to_response = local_render_to_response
    
        ######
        # Content types
        ######
        r1 = ReputationAction(name="edit verified", description="blah")
        r2 = ReputationAction(name="edit tree", description="blah")
        r3 = ReputationAction(name="Administrative Action", description="blah")
        r4 = ReputationAction(name="add tree", description="blah")
        r5 = ReputationAction(name="edit plot", description="blah")
        r6 = ReputationAction(name="add plot", description="blah")
        r7 = ReputationAction(name="add stewardship", description="blah")
        r8 = ReputationAction(name="remove stewardship", description="blah")

        self.ra = [r1,r2,r3,r4,r5,r6,r7,r8]

        for r in self.ra:
            r.save()

        ######
        # Set up benefit values
        ######
        bv = BenefitValues(co2=0.02, pm10=9.41, area="InlandValleys",
                           electricity=0.1166,voc=4.69,ozone=5.0032,natural_gas=1.25278,
                           nox=12.79,stormwater=0.0078,sox=3.72,bvoc=4.96)

        bv.save()
        self.bv = bv


        dbh = "[1.0, 2.0, 3.0]"

        rsrc = Resource(meta_species="BDM_OTHER", electricity_dbh=dbh, co2_avoided_dbh=dbh,
                        aq_pm10_dep_dbh=dbh, region="Sim City", aq_voc_avoided_dbh=dbh,
                        aq_pm10_avoided_dbh=dbh, aq_ozone_dep_dbh=dbh, aq_nox_avoided_dbh=dbh,
                        co2_storage_dbh=dbh,aq_sox_avoided_dbh=dbh, aq_sox_dep_dbh=dbh,
                        bvoc_dbh=dbh, co2_sequestered_dbh=dbh, aq_nox_dep_dbh=dbh,
                        hydro_interception_dbh=dbh, natural_gas_dbh=dbh)
        rsrc.save()
        self.rsrc = rsrc

        ######
        # Users
        ######
        u = User.objects.filter(username="******")
            
        if u:
            u = u[0]
        else:
            u = User.objects.create_user("jim","*****@*****.**","jim")
            u.is_staff = True
            u.is_superuser = True
            u.save()
            up = UserProfile(user=u)
            u.reputation = Reputation(user=u)
            u.reputation.save()

        self.u = u
        

        #######
        # Setup geometries -> Two stacked 100x100 squares
        #######
        n1geom = MultiPolygon(Polygon(((0,0),(100,0),(100,100),(0,100),(0,0))))
        n2geom = MultiPolygon(Polygon(((0,101),(101,101),(101,200),(0,200),(0,101))))

        n1 = Neighborhood(name="n1", region_id=2, city="c1", state="PA", county="PAC", geometry=n1geom)
        n2 = Neighborhood(name="n2", region_id=2, city="c2", state="NY", county="NYC", geometry=n2geom)

        n1.save()
        n2.save()

        z1geom = MultiPolygon(Polygon(((0,0),(100,0),(100,100),(0,100),(0,0))))
        z2geom = MultiPolygon(Polygon(((0,100),(100,100),(100,200),(0,200),(0,100))))

        z1 = ZipCode(zip="19107",geometry=z1geom)
        z2 = ZipCode(zip="10001",geometry=z2geom)

        z1.save()
        z2.save()

        exgeom1 = MultiPolygon(Polygon(((0,0),(25,0),(25,25),(0,25),(0,0))))
        ex1 = ExclusionMask(geometry=exgeom1, type="building")

        ex1.save()

        agn1 = AggregateNeighborhood(
            annual_stormwater_management=0.0,
            annual_electricity_conserved=0.0,
            annual_energy_conserved=0.0,
            annual_natural_gas_conserved=0.0,
            annual_air_quality_improvement=0.0,
            annual_co2_sequestered=0.0,
            annual_co2_avoided=0.0,
            annual_co2_reduced=0.0,
            total_co2_stored=0.0,
            annual_ozone=0.0,
            annual_nox=0.0,
            annual_pm10=0.0,
            annual_sox=0.0,
            annual_voc=0.0,
            annual_bvoc=0.0,
            total_trees=0,
            total_plots=0,
            location = n1)

        agn2 = AggregateNeighborhood(
            annual_stormwater_management=0.0,
            annual_electricity_conserved=0.0,
            annual_energy_conserved=0.0,
            annual_natural_gas_conserved=0.0,
            annual_air_quality_improvement=0.0,
            annual_co2_sequestered=0.0,
            annual_co2_avoided=0.0,
            annual_co2_reduced=0.0,
            total_co2_stored=0.0,
            annual_ozone=0.0,
            annual_nox=0.0,
            annual_pm10=0.0,
            annual_sox=0.0,
            annual_voc=0.0,
            annual_bvoc=0.0,
            total_trees=0,
            total_plots=0,
            location = n2)

        agn1.save()
        agn2.save()

        self.agn1 = agn1
        self.agn2 = agn2

        self.z1 = z1
        self.z2 = z2
        self.n1 = n1
        self.n2 = n2

        ######
        # And we could use a few species...
        ######
        s1 = Species(symbol="s1",genus="testus1",species="specieius1")
        s2 = Species(symbol="s2",genus="testus2",species="specieius2")
        
        s1.save()
        s2.save()

        self.s1 = s1
        self.s2 = s2

        #######
        # Create some basic plots
        #######
        ie = ImportEvent(file_name='site_add')
        ie.save()

        self.ie = ie

        p1_no_tree = Plot(geometry=Point(50,50), last_updated_by=u, import_event=ie,present=True, data_owner=u)
        p1_no_tree.save()

        p2_tree = Plot(geometry=Point(51,51), last_updated_by=u, import_event=ie,present=True, data_owner=u)
        p2_tree.save()

        p3_tree_species1 = Plot(geometry=Point(50,100), last_updated_by=u, import_event=ie,present=True, data_owner=u)
        p3_tree_species1.save()

        p4_tree_species2 = Plot(geometry=Point(50,150), last_updated_by=u, import_event=ie,present=True, data_owner=u)
        p4_tree_species2.save()

        t1 = Tree(plot=p2_tree, species=None, last_updated_by=u, import_event=ie)
        t1.present = True
        t1.save()
        
        t2 = Tree(plot=p3_tree_species1, species=s1, last_updated_by=u, import_event=ie)
        t2.present = True
        t2.save()

        t3 = Tree(plot=p4_tree_species2, species=s2, last_updated_by=u, import_event=ie)
        t3.present = True
        t3.save()

        self.p1_no_tree = p1_no_tree
        self.p2_tree = p2_tree
        self.p3_tree_species1 = p3_tree_species1;
        self.p4_tree_species2 = p4_tree_species2;

        self.plots = [p1_no_tree, p2_tree, p3_tree_species1, p4_tree_species2]

        self.t1 = t1
        self.t2 = t2
        self.t3 = t3
Beispiel #5
0
    def test_geom_validation(self):
        def mkpt(x, y):
            return self.mkrow({'point x': str(x), 'point y': str(y)})

        # Invalid numbers
        i = mkpt('300a', '20b')
        r = i.validate_row()

        self.assertFalse(r)
        self.assertHasError(i, errors.FLOAT_ERROR)

        # Crazy lat/lngs
        i = mkpt(300, 20)
        r = i.validate_row()

        self.assertFalse(r)
        self.assertHasError(i, errors.INVALID_GEOM)

        i = mkpt(50, 93)
        r = i.validate_row()

        self.assertFalse(r)
        self.assertHasError(i, errors.INVALID_GEOM)

        # Out of neighborhood (neighborhood created in setUp)
        ngeom = MultiPolygon(
            Polygon(((0, 0), (0, 50), (50, 50), (50, 0), (0, 0))))

        neighborhood = Neighborhood(name='test neighborhood',
                                    region_id=34,
                                    city='blah',
                                    county='blarg',
                                    geometry=ngeom)

        neighborhood.save()

        i = mkpt(55, 55)
        r = i.validate_row()

        self.assertFalse(r)
        self.assertHasError(i, errors.GEOM_OUT_OF_BOUNDS)

        i = mkpt(-5, -5)
        r = i.validate_row()

        self.assertFalse(r)
        self.assertHasError(i, errors.GEOM_OUT_OF_BOUNDS)

        # This should work...
        i = mkpt(25, 25)
        r = i.validate_row()

        # Can't assert that r is true because other validation
        # logic may have tripped it
        self.assertNotHasError(i, errors.GEOM_OUT_OF_BOUNDS)
        self.assertNotHasError(i, errors.INVALID_GEOM)
        self.assertNotHasError(i, errors.FLOAT_ERROR)

        # If we add an exclusion zone, it should fail
        egeom = MultiPolygon(
            Polygon(((10, 10), (10, 30), (30, 30), (30, 10), (10, 10))))

        e = ExclusionMask(geometry=egeom, type='blah blah')
        e.save()

        i = mkpt(25, 25)
        r = i.validate_row()

        self.assertNotHasError(i, errors.GEOM_OUT_OF_BOUNDS)
        self.assertNotHasError(i, errors.INVALID_GEOM)
        self.assertNotHasError(i, errors.FLOAT_ERROR)
        self.assertHasError(i, errors.EXCL_ZONE)
Beispiel #6
0
def setupTreemapEnv():
    settings.GEOSERVER_GEO_LAYER = ""
    settings.GEOSERVER_GEO_STYLE = ""
    settings.GEOSERVER_URL = ""

    def local_render_to_response(*args, **kwargs):
        from django.template import loader, RequestContext
        from django.http import HttpResponse

        httpresponse_kwargs = {"mimetype": kwargs.pop("mimetype", None)}
        hr = HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)

        if hasattr(args[1], "dicts"):
            hr.request_context = args[1].dicts

        return hr

    django.shortcuts.render_to_response = local_render_to_response

    r1 = ReputationAction(name="edit verified", description="blah")
    r2 = ReputationAction(name="edit tree", description="blah")
    r3 = ReputationAction(name="Administrative Action", description="blah")
    r4 = ReputationAction(name="add tree", description="blah")
    r5 = ReputationAction(name="edit plot", description="blah")
    r6 = ReputationAction(name="add plot", description="blah")
    r7 = ReputationAction(name="add stewardship", description="blah")
    r8 = ReputationAction(name="remove stewardship", description="blah")

    for r in [r1, r2, r3, r4, r5, r6, r7, r8]:
        r.save()

    bv = BenefitValues(
        co2=0.02,
        pm10=9.41,
        area="InlandValleys",
        electricity=0.1166,
        voc=4.69,
        ozone=5.0032,
        natural_gas=1.25278,
        nox=12.79,
        stormwater=0.0078,
        sox=3.72,
        bvoc=4.96,
    )

    bv.save()

    dbh = "[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]"
    dbh2 = "[2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]"

    rsrc1 = Resource(meta_species="BDM OTHER", region="NoEastXXX")
    rsrc2 = Resource(meta_species="BDL OTHER", region="NoEastXXX")

    rsrc1.save()
    rsrc2.save()

    u = User.objects.filter(username="******")

    if u:
        u = u[0]
    else:
        u = User.objects.create_user("jim", "*****@*****.**", "jim")
        u.is_staff = True
        u.is_superuser = True
        u.save()
        up = UserProfile(user=u)
        up.save()
        u.reputation = Reputation(user=u)
        u.reputation.save()

    amy_filter_result = User.objects.filter(username="******")
    if not amy_filter_result:
        amy = User.objects.create_user("amy", "*****@*****.**", "amy")
    else:
        amy = amy_filter_result[0]
        amy.is_staff = False
        amy.is_superuser = False
        amy.save()
        amy_profile = UserProfile(user=amy)
        amy_profile.save()
        amy.reputation = Reputation(user=amy)
        amy.reputation.save()

    olivia_filter_result = User.objects.filter(username="******")
    if not amy_filter_result:
        olivia = User.objects.create_user("olivia", "*****@*****.**", "olivia")
    else:
        olivia = olivia_filter_result[0]
        olivia.is_staff = False
        olivia.is_superuser = False
        olivia.save()
        olivia_profile = UserProfile(user=olivia)
        olivia_profile.save()
        olivia.reputation = Reputation(user=olivia)
        olivia.reputation.save()

    n1geom = MultiPolygon(Polygon(((0, 0), (100, 0), (100, 100), (0, 100), (0, 0))))
    n2geom = MultiPolygon(Polygon(((0, 101), (101, 101), (101, 200), (0, 200), (0, 101))))

    n1 = Neighborhood(name="n1", region_id=2, city="c1", state="PA", county="PAC", geometry=n1geom)
    n2 = Neighborhood(name="n2", region_id=2, city="c2", state="NY", county="NYC", geometry=n2geom)

    n1.save()
    n2.save()

    z1geom = MultiPolygon(Polygon(((0, 0), (100, 0), (100, 100), (0, 100), (0, 0))))
    z2geom = MultiPolygon(Polygon(((0, 100), (100, 100), (100, 200), (0, 200), (0, 100))))

    z1 = ZipCode(zip="19107", geometry=z1geom)
    z2 = ZipCode(zip="10001", geometry=z2geom)

    z1.save()
    z2.save()

    exgeom1 = MultiPolygon(Polygon(((0, 0), (25, 0), (25, 25), (0, 25), (0, 0))))
    ex1 = ExclusionMask(geometry=exgeom1, type="building")

    ex1.save()

    agn1 = AggregateNeighborhood(
        annual_stormwater_management=0.0,
        annual_electricity_conserved=0.0,
        annual_energy_conserved=0.0,
        annual_natural_gas_conserved=0.0,
        annual_air_quality_improvement=0.0,
        annual_co2_sequestered=0.0,
        annual_co2_avoided=0.0,
        annual_co2_reduced=0.0,
        total_co2_stored=0.0,
        annual_ozone=0.0,
        annual_nox=0.0,
        annual_pm10=0.0,
        annual_sox=0.0,
        annual_voc=0.0,
        annual_bvoc=0.0,
        total_trees=0,
        total_plots=0,
        location=n1,
    )

    agn2 = AggregateNeighborhood(
        annual_stormwater_management=0.0,
        annual_electricity_conserved=0.0,
        annual_energy_conserved=0.0,
        annual_natural_gas_conserved=0.0,
        annual_air_quality_improvement=0.0,
        annual_co2_sequestered=0.0,
        annual_co2_avoided=0.0,
        annual_co2_reduced=0.0,
        total_co2_stored=0.0,
        annual_ozone=0.0,
        annual_nox=0.0,
        annual_pm10=0.0,
        annual_sox=0.0,
        annual_voc=0.0,
        annual_bvoc=0.0,
        total_trees=0,
        total_plots=0,
        location=n2,
    )

    agn1.save()
    agn2.save()

    s1 = Species(symbol="s1", genus="testus1", species="specieius1", cultivar_name="", family="", alternate_symbol="a1")
    s2 = Species(symbol="s2", genus="testus2", species="specieius2", cultivar_name="", family="", alternate_symbol="a2")
    s3 = Species(symbol="s3", genus="testus2", species="specieius3", cultivar_name="", family="", alternate_symbol="a3")

    s1.native_status = "True"
    s1.fall_conspicuous = True
    s1.flower_conspicuous = True
    s1.palatable_human = True

    s2.native_status = "True"
    s2.fall_conspicuous = False
    s2.flower_conspicuous = True
    s2.palatable_human = False
    s2.wildlife_value = True

    s3.wildlife_value = True

    s1.save()
    s2.save()
    s3.save()

    s1.resource.add(rsrc1)
    s2.resource.add(rsrc2)
    s3.resource.add(rsrc2)

    ie = ImportEvent(file_name="site_add")
    ie.save()
Beispiel #7
0
def setupTreemapEnv():
    Choices(field="plot_type", key="blah", value="blah", key_type="str").save()

    r1 = ReputationAction(name="edit verified", description="blah")
    r2 = ReputationAction(name="edit tree", description="blah")
    r3 = ReputationAction(name="Administrative Action", description="blah")
    r4 = ReputationAction(name="add tree", description="blah")
    r5 = ReputationAction(name="edit plot", description="blah")
    r6 = ReputationAction(name="add plot", description="blah")

    for r in [r1, r2, r3, r4, r5, r6]:
        r.save()

    bv = BenefitValues(co2=0.02,
                       pm10=9.41,
                       area="InlandValleys",
                       electricity=0.1166,
                       voc=4.69,
                       ozone=5.0032,
                       natural_gas=1.25278,
                       nox=12.79,
                       stormwater=0.0078,
                       sox=3.72,
                       bvoc=4.96)

    bv.save()

    dbh = "[1.0, 2.0, 3.0]"

    rsrc = Resource(meta_species="BDM_OTHER",
                    electricity_dbh=dbh,
                    co2_avoided_dbh=dbh,
                    aq_pm10_dep_dbh=dbh,
                    region="Sim City",
                    aq_voc_avoided_dbh=dbh,
                    aq_pm10_avoided_dbh=dbh,
                    aq_ozone_dep_dbh=dbh,
                    aq_nox_avoided_dbh=dbh,
                    co2_storage_dbh=dbh,
                    aq_sox_avoided_dbh=dbh,
                    aq_sox_dep_dbh=dbh,
                    bvoc_dbh=dbh,
                    co2_sequestered_dbh=dbh,
                    aq_nox_dep_dbh=dbh,
                    hydro_interception_dbh=dbh,
                    natural_gas_dbh=dbh)
    rsrc.save()

    u = User.objects.filter(username="******")

    if u:
        u = u[0]
    else:
        u = User.objects.create_user("jim", "*****@*****.**", "jim")
        u.is_staff = True
        u.is_superuser = True
        u.save()
        up = UserProfile(user=u)
        u.reputation = Reputation(user=u)
        u.reputation.save()

    n1geom = MultiPolygon(
        Polygon(((0, 0), (100, 0), (100, 100), (0, 100), (0, 0))))
    n2geom = MultiPolygon(
        Polygon(((0, 101), (101, 101), (101, 200), (0, 200), (0, 101))))

    n1 = Neighborhood(name="n1",
                      region_id=2,
                      city="c1",
                      state="PA",
                      county="PAC",
                      geometry=n1geom)
    n2 = Neighborhood(name="n2",
                      region_id=2,
                      city="c2",
                      state="NY",
                      county="NYC",
                      geometry=n2geom)

    n1.save()
    n2.save()

    z1geom = MultiPolygon(
        Polygon(((0, 0), (100, 0), (100, 100), (0, 100), (0, 0))))
    z2geom = MultiPolygon(
        Polygon(((0, 100), (100, 100), (100, 200), (0, 200), (0, 100))))

    z1 = ZipCode(zip="19107", geometry=z1geom)
    z2 = ZipCode(zip="10001", geometry=z2geom)

    z1.save()
    z2.save()

    exgeom1 = MultiPolygon(
        Polygon(((0, 0), (25, 0), (25, 25), (0, 25), (0, 0))))
    ex1 = ExclusionMask(geometry=exgeom1, type="building")

    ex1.save()

    agn1 = AggregateNeighborhood(annual_stormwater_management=0.0,
                                 annual_electricity_conserved=0.0,
                                 annual_energy_conserved=0.0,
                                 annual_natural_gas_conserved=0.0,
                                 annual_air_quality_improvement=0.0,
                                 annual_co2_sequestered=0.0,
                                 annual_co2_avoided=0.0,
                                 annual_co2_reduced=0.0,
                                 total_co2_stored=0.0,
                                 annual_ozone=0.0,
                                 annual_nox=0.0,
                                 annual_pm10=0.0,
                                 annual_sox=0.0,
                                 annual_voc=0.0,
                                 annual_bvoc=0.0,
                                 total_trees=0,
                                 total_plots=0,
                                 location=n1)

    agn2 = AggregateNeighborhood(annual_stormwater_management=0.0,
                                 annual_electricity_conserved=0.0,
                                 annual_energy_conserved=0.0,
                                 annual_natural_gas_conserved=0.0,
                                 annual_air_quality_improvement=0.0,
                                 annual_co2_sequestered=0.0,
                                 annual_co2_avoided=0.0,
                                 annual_co2_reduced=0.0,
                                 total_co2_stored=0.0,
                                 annual_ozone=0.0,
                                 annual_nox=0.0,
                                 annual_pm10=0.0,
                                 annual_sox=0.0,
                                 annual_voc=0.0,
                                 annual_bvoc=0.0,
                                 total_trees=0,
                                 total_plots=0,
                                 location=n2)

    agn1.save()
    agn2.save()

    s1 = Species(symbol="s1", genus="testus1", species="specieius1")
    s2 = Species(symbol="s2", genus="testus2", species="specieius2")

    s1.save()
    s2.save()

    ie = ImportEvent(file_name='site_add')
    ie.save()
Beispiel #8
0
def setupTreemapEnv():
    settings.GEOSERVER_GEO_LAYER = ""
    settings.GEOSERVER_GEO_STYLE = ""
    settings.GEOSERVER_URL = ""

    def local_render_to_response(*args, **kwargs):
        from django.template import loader, RequestContext
        from django.http import HttpResponse

        httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)}
        hr = HttpResponse(loader.render_to_string(*args, **kwargs),
                          **httpresponse_kwargs)

        if hasattr(args[1], 'dicts'):
            hr.request_context = args[1].dicts

        return hr

    django.shortcuts.render_to_response = local_render_to_response

    r1 = ReputationAction(name="edit verified", description="blah")
    r2 = ReputationAction(name="edit tree", description="blah")
    r3 = ReputationAction(name="Administrative Action", description="blah")
    r4 = ReputationAction(name="add tree", description="blah")
    r5 = ReputationAction(name="edit plot", description="blah")
    r6 = ReputationAction(name="add plot", description="blah")
    r7 = ReputationAction(name="add stewardship", description="blah")
    r8 = ReputationAction(name="remove stewardship", description="blah")

    for r in [r1, r2, r3, r4, r5, r6, r7, r8]:
        r.save()

    bv = BenefitValues(co2=0.02,
                       pm10=9.41,
                       area="InlandValleys",
                       electricity=0.1166,
                       voc=4.69,
                       ozone=5.0032,
                       natural_gas=1.25278,
                       nox=12.79,
                       stormwater=0.0078,
                       sox=3.72,
                       bvoc=4.96)

    bv.save()

    dbh = "[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]"
    dbh2 = "[2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]"

    rsrc1 = Resource(meta_species="BDM OTHER", region="NoEastXXX")
    rsrc2 = Resource(meta_species="BDL OTHER", region="NoEastXXX")

    rsrc1.save()
    rsrc2.save()

    u = User.objects.filter(username="******")

    if u:
        u = u[0]
    else:
        u = User.objects.create_user("jim", "*****@*****.**", "jim")
        u.is_staff = True
        u.is_superuser = True
        u.save()
        up = UserProfile(user=u)
        up.save()
        u.reputation = Reputation(user=u)
        u.reputation.save()

    amy_filter_result = User.objects.filter(username="******")
    if not amy_filter_result:
        amy = User.objects.create_user("amy", "*****@*****.**", "amy")
    else:
        amy = amy_filter_result[0]
        amy.is_staff = False
        amy.is_superuser = False
        amy.save()
        amy_profile = UserProfile(user=amy)
        amy_profile.save()
        amy.reputation = Reputation(user=amy)
        amy.reputation.save()

    olivia_filter_result = User.objects.filter(username="******")
    if not amy_filter_result:
        olivia = User.objects.create_user("olivia", "*****@*****.**",
                                          "olivia")
    else:
        olivia = olivia_filter_result[0]
        olivia.is_staff = False
        olivia.is_superuser = False
        olivia.save()
        olivia_profile = UserProfile(user=olivia)
        olivia_profile.save()
        olivia.reputation = Reputation(user=olivia)
        olivia.reputation.save()

    n1geom = MultiPolygon(
        Polygon(((0, 0), (100, 0), (100, 100), (0, 100), (0, 0))))
    n2geom = MultiPolygon(
        Polygon(((0, 101), (101, 101), (101, 200), (0, 200), (0, 101))))

    n1 = Neighborhood(name="n1",
                      region_id=2,
                      city="c1",
                      state="PA",
                      county="PAC",
                      geometry=n1geom)
    n2 = Neighborhood(name="n2",
                      region_id=2,
                      city="c2",
                      state="NY",
                      county="NYC",
                      geometry=n2geom)

    n1.save()
    n2.save()

    z1geom = MultiPolygon(
        Polygon(((0, 0), (100, 0), (100, 100), (0, 100), (0, 0))))
    z2geom = MultiPolygon(
        Polygon(((0, 100), (100, 100), (100, 200), (0, 200), (0, 100))))

    z1 = ZipCode(zip="19107", geometry=z1geom)
    z2 = ZipCode(zip="10001", geometry=z2geom)

    z1.save()
    z2.save()

    exgeom1 = MultiPolygon(
        Polygon(((0, 0), (25, 0), (25, 25), (0, 25), (0, 0))))
    ex1 = ExclusionMask(geometry=exgeom1, type="building")

    ex1.save()

    agn1 = AggregateNeighborhood(annual_stormwater_management=0.0,
                                 annual_electricity_conserved=0.0,
                                 annual_energy_conserved=0.0,
                                 annual_natural_gas_conserved=0.0,
                                 annual_air_quality_improvement=0.0,
                                 annual_co2_sequestered=0.0,
                                 annual_co2_avoided=0.0,
                                 annual_co2_reduced=0.0,
                                 total_co2_stored=0.0,
                                 annual_ozone=0.0,
                                 annual_nox=0.0,
                                 annual_pm10=0.0,
                                 annual_sox=0.0,
                                 annual_voc=0.0,
                                 annual_bvoc=0.0,
                                 total_trees=0,
                                 total_plots=0,
                                 location=n1)

    agn2 = AggregateNeighborhood(annual_stormwater_management=0.0,
                                 annual_electricity_conserved=0.0,
                                 annual_energy_conserved=0.0,
                                 annual_natural_gas_conserved=0.0,
                                 annual_air_quality_improvement=0.0,
                                 annual_co2_sequestered=0.0,
                                 annual_co2_avoided=0.0,
                                 annual_co2_reduced=0.0,
                                 total_co2_stored=0.0,
                                 annual_ozone=0.0,
                                 annual_nox=0.0,
                                 annual_pm10=0.0,
                                 annual_sox=0.0,
                                 annual_voc=0.0,
                                 annual_bvoc=0.0,
                                 total_trees=0,
                                 total_plots=0,
                                 location=n2)

    agn1.save()
    agn2.save()

    s1 = Species(symbol="s1",
                 genus="testus1",
                 species="specieius1",
                 cultivar_name='',
                 family='',
                 alternate_symbol='a1')
    s2 = Species(symbol="s2",
                 genus="testus2",
                 species="specieius2",
                 cultivar_name='',
                 family='',
                 alternate_symbol='a2')
    s3 = Species(symbol="s3",
                 genus="testus2",
                 species="specieius3",
                 cultivar_name='',
                 family='',
                 alternate_symbol='a3')

    s1.native_status = 'True'
    s1.fall_conspicuous = True
    s1.flower_conspicuous = True
    s1.palatable_human = True

    s2.native_status = 'True'
    s2.fall_conspicuous = False
    s2.flower_conspicuous = True
    s2.palatable_human = False
    s2.wildlife_value = True

    s3.wildlife_value = True

    s1.save()
    s2.save()
    s3.save()

    s1.resource.add(rsrc1)
    s2.resource.add(rsrc2)
    s3.resource.add(rsrc2)

    ie = ImportEvent(file_name='site_add')
    ie.save()