Ejemplo n.º 1
0
    def handle_row(self, row):
        self.log_verbose(row)

        # check the physical location
        ok, x, y = self.check_coords(row)
        if not ok: return

        plot = Plot()

        try:
            if self.base_srid != 4326:
                geom = Point(x, y, srid=self.base_srid)
                geom.transform(self.tf)
                self.log_verbose(geom)
                plot.geometry = geom
            else:
                plot.geometry = Point(x, y, srid=4326)
        except:
            self.log_error("ERROR: Geometry failed to transform", row)
            return

        # check the species (if any)
        ok, species = self.check_species(row)
        if not ok: return

        # check for tree info, should we create a tree or just a plot
        if species or self.check_tree_info(row):
            tree = Tree(plot=plot)
        else:
            tree = None

        if tree and species:
            tree.species = species[0]

        # check the proximity (try to match up with existing trees)
        # this may return a different plot/tree than created just above,
        # so don't set anything else on either until after this point
        ok, plot, tree = self.check_proximity(plot, tree, species, row)
        if not ok: return

        if row.get('ADDRESS') and not plot.address_street:
            plot.address_street = str(row['ADDRESS']).title()
            plot.geocoded_address = str(row['ADDRESS']).title()

        if not plot.geocoded_address:
            plot.geocoded_address = ""

        # FIXME: get this from the config?
        plot.address_state = 'CA'
        plot.import_event = self.import_event
        plot.last_updated_by = self.updater
        plot.data_owner = self.data_owner
        plot.readonly = self.readonly

        if row.get('PLOTTYPE'):
            for k, v in choices['plot_types']:
                if v == row['PLOTTYPE']:
                    plot.type = k
                    break

        if row.get('PLOTLENGTH'):
            plot.length = row['PLOTLENGTH']

        if row.get('PLOTWIDTH'):
            plot.width = row['PLOTWIDTH']

        if row.get('ID'):
            plot.owner_orig_id = row['ID']

        if row.get('ORIGID'):
            plot.owner_additional_properties = "ORIGID=" + str(row['ORIGID'])

        if row.get('OWNER_ADDITIONAL_PROPERTIES'):
            plot.owner_additional_properties = str(
                plot.owner_additional_properties) + " " + str(
                    row['OWNER_ADDITIONAL_PROPERTIES'])

        if row.get('OWNER_ADDITIONAL_ID'):
            plot.owner_additional_id = str(row['OWNER_ADDITIONAL_ID'])

        if row.get('POWERLINE'):
            for k, v in choices['powerlines']:
                if v == row['POWERLINE']:
                    plot.powerline = k
                    break

        sidewalk_damage = row.get('SIDEWALK')
        if sidewalk_damage is None or sidewalk_damage.strip() == "":
            pass
        elif sidewalk_damage is True or sidewalk_damage.lower(
        ) == "true" or sidewalk_damage.lower() == 'yes':
            plot.sidewalk_damage = 2
        else:
            plot.sidewalk_damage = 1

        plot.quick_save()

        pnt = plot.geometry
        n = Neighborhood.objects.filter(geometry__contains=pnt)
        z = ZipCode.objects.filter(geometry__contains=pnt)

        plot.neighborhoods = ""
        plot.neighborhood.clear()
        plot.zipcode = None

        if n:
            for nhood in n:
                if nhood:
                    plot.neighborhoods = plot.neighborhoods + " " + nhood.id.__str__(
                    )
                    plot.neighborhood.add(nhood)

        if z: plot.zipcode = z[0]

        plot.quick_save()

        if tree:
            tree.plot = plot
            tree.readonly = self.readonly
            tree.import_event = self.import_event
            tree.last_updated_by = self.updater

            if row.get('OWNER'):
                tree.tree_owner = str(row["OWNER"])

            if row.get('STEWARD'):
                tree.steward_name = str(row["STEWARD"])

            if row.get('SPONSOR'):
                tree.sponsor = str(row["SPONSOR"])

            if row.get('DATEPLANTED'):
                date_string = str(row['DATEPLANTED'])
                try:
                    date = datetime.strptime(date_string, "%m/%d/%Y")
                except:
                    pass
                try:
                    date = datetime.strptime(date_string, "%Y/%m/%d")
                except:
                    pass
                if not date:
                    raise ValueError(
                        "Date strings must be in mm/dd/yyyy or yyyy/mm/dd format"
                    )

                tree.date_planted = date.strftime("%Y-%m-%d")

            if row.get('DIAMETER'):
                tree.dbh = float(row['DIAMETER'])

            if row.get('HEIGHT'):
                tree.height = float(row['HEIGHT'])

            if row.get('CANOPYHEIGHT'):
                tree.canopy_height = float(row['CANOPYHEIGHT'])

            if row.get('CONDITION'):
                for k, v in choices['conditions']:
                    if v == row['CONDITION']:
                        tree.condition = k
                        break

            if row.get('CANOPYCONDITION'):
                for k, v in choices['canopy_conditions']:
                    if v == row['CANOPYCONDITION']:
                        tree.canopy_condition = k
                        break
            # FOR OTM INDIA
            # GIRTH_CM", "GIRTH_M", "HEIGHT_FT", "HEIGHT_M", "NEST", "BURROWS", "FLOWERS", "FRUITS", "NAILS", "POSTER", "WIRES", "TREE_GUARD", "NUISANCE", "NUISANCE_DESC", "HEALTH_OF_TREE", "FOUND_ON_GROUND", "GROUND_DESCRIPTION", "RISK_ON_TREE", "RISK_DESC", "RARE", "ENDANGERED", "VULNERABLE", "PEST_AFFECTED", "REFER_TO_DEPT", "SPECIAL_OTHER", "SPECIAL_OTHER_DESCRIPTION", "LATITUDE", "LONGITUDE", "CREATION_DATE", "DEVICE_ID", "TIME", "DATE"])

            if row.get('GIRTH_M'):
                tree.girth_m = float(row['GIRTH_M'])

            if row.get('HEIGHT_M'):
                tree.height_m = float(row['HEIGHT_M'])

            if row.get('NEST'):
                tree.nest = str(row['NEST'])

            if row.get('BURROWS'):
                tree.burrows = str(row['BURROWS'])

            if row.get('FLOWERS'):
                tree.flowers = str(row['FLOWERS'])

            if row.get('FRUITS'):
                tree.fruits = str(row['FRUITS'])

            if row.get('NAILS'):
                tree.nails = str(row['NAILS'])

            if row.get('POSTER'):
                tree.poster = str(row['POSTER'])

            if row.get('WIRES'):
                tree.wires = str(row['WIRES'])

            if row.get('TREE_GUARD'):
                tree.tree_guard = str(row['TREE_GUARD'])

            if row.get('NUISANCE'):
                tree.other_nuisance = bool(row['NUISANCE'])

            if row.get('NUISANCE_DESC'):
                tree.other_nuisance_desc = str(row['NUISANCE_DESC'])

            if row.get('HEALTH_OF_TREE'):
                tree.health_of_tree = str(row['HEALTH_OF_TREE'])

            if row.get('FOUND_ON_GROUND'):
                tree.found_on_ground = str(row['FOUND_ON_GROUND'])

            if row.get('GROUND_DESCRIPTION'):
                tree.ground_description = str(row['GROUND_DESCRIPTION'])

            if row.get('RISK_ON_TREE'):
                tree.risk_on_tree = str(row['RISK_ON_TREE'])

            if row.get('RISK_DESC'):
                tree.risk_desc = str(row['RISK_DESC'])

            if row.get('PEST_AFFECTED'):
                tree.pests = str(row['PEST_AFFECTED'])

            if row.get('REFER_TO_DEPT'):
                tree.refer_to_dept = str(row['REFER_TO_DEPT'])

            if row.get('SPECIAL_OTHER'):
                tree.special_other = str(row['SPECIAL_OTHER'])

            if row.get('SPECIAL_OTHER_DESCRIPTION'):
                tree.special_other_description = str(
                    row['SPECIAL_OTHER_DESCRIPTION'])

            if row.get('LATITUDE'):
                tree.latitude = str(row['LATITUDE'])

            if row.get('LONGITUDE'):
                tree.longitude = str(row['LONGITUDE'])

            if row.get('PRABHAG_ID'):
                tree.prabhag_id = str(row['PRABHAG_ID'])

            if row.get('CLUSTER_ID'):
                tree.cluster_id = str(row['CLUSTER_ID'])

            #if row.get('ID'):
            #    tree.id = str(row['ID'])

            #import pdb; pdb.set_trace()

            f = open("trees_in_otm_obj.log", "w")
            f.write("b4 save")
            f.write(str(tree.__dict__))
            tree.quick_save()
            f.write("after save \n")
            f.write(str(tree.__dict__))
            f.close()

            if row.get('PROJECT_1'):
                for k, v in Choices().get_field_choices('local'):
                    if v == row['PROJECT_1']:
                        local = TreeFlags(key=k,
                                          tree=tree,
                                          reported_by=self.updater)
                        local.save()
                        break
            if row.get('PROJECT_2'):
                for k, v in Choices().get_field_choices('local'):
                    if v == row['PROJECT_2']:
                        local = TreeFlags(key=k,
                                          tree=tree,
                                          reported_by=self.updater)
                        local.save()
                        break
            if row.get('PROJECT_3'):
                for k, v in Choices().get_field_choices('local'):
                    if v == row['PROJECT_3']:
                        local = TreeFlags(key=k,
                                          tree=tree,
                                          reported_by=self.updater)
                        local.save()
                        break

            # rerun validation tests and store results
            tree.validate_all()
Ejemplo n.º 2
0
    def handle_row(self, row):
        self.log_verbose(row)

        # check the physical location
        ok, x, y = self.check_coords(row)
        if not ok: return

        plot = Plot()

        try:
            if self.base_srid != 4326:
                geom = Point(x, y, srid=self.base_srid)
                geom.transform(self.tf)
                self.log_verbose(geom)
                plot.geometry = geom
            else:
                plot.geometry = Point(x, y, srid=4326)
        except:
            self.log_error("ERROR: Geometry failed to transform", row)
            return

        # check the species (if any)
        ok, species = self.check_species(row)
        if not ok: return

        # check for tree info, should we create a tree or just a plot
        if species or self.check_tree_info(row):
            tree = Tree(plot=plot)
        else:
            tree = None

        if tree and species:
            tree.species = species[0]

        # check the proximity (try to match up with existing trees)
        # this may return a different plot/tree than created just above,
        # so don't set anything else on either until after this point
        ok, plot, tree = self.check_proximity(plot, tree, species, row)
        if not ok: return

        if row.get('ADDRESS') and not plot.address_street:
            plot.address_street = str(row['ADDRESS']).title()
            plot.geocoded_address = str(row['ADDRESS']).title()

        if not plot.geocoded_address:
            plot.geocoded_address = ""

        # FIXME: get this from the config?
        plot.address_state = 'CA'
        plot.import_event = self.import_event
        plot.last_updated_by = self.updater
        plot.data_owner = self.data_owner
        plot.readonly = self.readonly

        if row.get('PLOTTYPE'):
            for k, v in choices['plot_types']:
                if v == row['PLOTTYPE']:
                    plot.type = k
                    break

        if row.get('PLOTLENGTH'):
            plot.length = row['PLOTLENGTH']

        if row.get('PLOTWIDTH'):
            plot.width = row['PLOTWIDTH']

        if row.get('ID'):
            plot.owner_orig_id = row['ID']

        if row.get('ORIGID'):
            plot.owner_additional_properties = "ORIGID=" + str(row['ORIGID'])

        if row.get('OWNER_ADDITIONAL_PROPERTIES'):
            plot.owner_additional_properties = str(
                plot.owner_additional_properties) + " " + str(
                    row['OWNER_ADDITIONAL_PROPERTIES'])

        if row.get('OWNER_ADDITIONAL_ID'):
            plot.owner_additional_id = str(row['OWNER_ADDITIONAL_ID'])

        if row.get('POWERLINE'):
            for k, v in choices['powerlines']:
                if v == row['POWERLINE']:
                    plot.powerline_conflict_potential = k
                    break

        sidewalk_damage = row.get('SIDEWALK')
        if sidewalk_damage is None or sidewalk_damage.strip() == "":
            pass
        elif sidewalk_damage is True or sidewalk_damage.lower(
        ) == "true" or sidewalk_damage.lower() == 'yes':
            plot.sidewalk_damage = 2
        else:
            plot.sidewalk_damage = 1

        plot.quick_save()

        pnt = plot.geometry
        n = Neighborhood.objects.filter(geometry__contains=pnt)
        z = ZipCode.objects.filter(geometry__contains=pnt)

        plot.neighborhoods = ""
        plot.neighborhood.clear()
        plot.zipcode = None

        if n:
            for nhood in n:
                if nhood:
                    plot.neighborhoods = plot.neighborhoods + " " + nhood.id.__str__(
                    )
                    plot.neighborhood.add(nhood)

        if z: plot.zipcode = z[0]

        plot.quick_save()

        if tree:
            tree.plot = plot
            tree.readonly = self.readonly
            tree.import_event = self.import_event
            tree.last_updated_by = self.updater

            if row.get('OWNER'):
                tree.tree_owner = str(row["OWNER"])

            if row.get('STEWARD'):
                tree.steward_name = str(row["STEWARD"])

            if row.get('SPONSOR'):
                tree.sponsor = str(row["SPONSOR"])

            if row.get('DATEPLANTED'):
                date_string = str(row['DATEPLANTED'])
                try:
                    date = datetime.strptime(date_string, "%m/%d/%Y")
                except:
                    pass
                try:
                    date = datetime.strptime(date_string, "%Y/%m/%d")
                except:
                    pass
                if not date:
                    raise ValueError(
                        "Date strings must be in mm/dd/yyyy or yyyy/mm/dd format"
                    )

                tree.date_planted = date.strftime("%Y-%m-%d")

            if row.get('DIAMETER'):
                tree.dbh = float(row['DIAMETER'])

            if row.get('HEIGHT'):
                tree.height = float(row['HEIGHT'])

            if row.get('CANOPYHEIGHT'):
                tree.canopy_height = float(row['CANOPYHEIGHT'])

            if row.get('CONDITION'):
                for k, v in choices['conditions']:
                    if v == row['CONDITION']:
                        tree.condition = k
                        break

            if row.get('CANOPYCONDITION'):
                for k, v in choices['canopy_conditions']:
                    if v == row['CANOPYCONDITION']:
                        tree.canopy_condition = k
                        break

            tree.quick_save()

            if row.get('PROJECT_1'):
                for k, v in Choices().get_field_choices('local'):
                    if v == row['PROJECT_1']:
                        local = TreeFlags(key=k,
                                          tree=tree,
                                          reported_by=self.updater)
                        local.save()
                        break
            if row.get('PROJECT_2'):
                for k, v in Choices().get_field_choices('local'):
                    if v == row['PROJECT_2']:
                        local = TreeFlags(key=k,
                                          tree=tree,
                                          reported_by=self.updater)
                        local.save()
                        break
            if row.get('PROJECT_3'):
                for k, v in Choices().get_field_choices('local'):
                    if v == row['PROJECT_3']:
                        local = TreeFlags(key=k,
                                          tree=tree,
                                          reported_by=self.updater)
                        local.save()
                        break

            # rerun validation tests and store results
            tree.validate_all()
Ejemplo n.º 3
0
    def handle_row(self, row):
        self.log_verbose(row)

        # check the physical location
        ok, x, y = self.check_coords(row)
        if not ok: return

        plot = Plot()

        try:
            if self.base_srid != 4326:
                geom = Point(x, y, srid=self.base_srid)
                geom.transform(self.tf)
                self.log_verbose(geom)
                plot.geometry = geom
            else:
                plot.geometry = Point(x, y, srid=4326)
        except:
            self.log_error("ERROR: Geometry failed to transform", row)
            return

        # check the species (if any)
        ok, species = self.check_species(row)
        if not ok: return

        # check for tree info, should we create a tree or just a plot
        if species or self.check_tree_info(row):
            tree = Tree(plot=plot)
        else:
            tree = None

        if tree and species:
            tree.species = species[0]


        # check the proximity (try to match up with existing trees)
        # this may return a different plot/tree than created just above,
        # so don't set anything else on either until after this point
        ok, plot, tree = self.check_proximity(plot, tree, species, row)
        if not ok: return


        if row.get('ADDRESS') and not plot.address_street:
            plot.address_street = str(row['ADDRESS']).title()
            plot.geocoded_address = str(row['ADDRESS']).title()

        if not plot.geocoded_address:
            plot.geocoded_address = ""

        # FIXME: get this from the config?
        plot.address_state = 'CA'
        plot.import_event = self.import_event
        plot.last_updated_by = self.updater
        plot.data_owner = self.data_owner
        plot.readonly = self.readonly

        if row.get('PLOTTYPE'):
            for k, v in choices['plot_types']:
                if v == row['PLOTTYPE']:
                    plot.type = k
                    break;

        if row.get('PLOTLENGTH'):
            plot.length = row['PLOTLENGTH']

        if row.get('PLOTWIDTH'):
            plot.width = row['PLOTWIDTH']

        if row.get('ID'):
            plot.owner_orig_id = row['ID']

        if row.get('ORIGID'):
            plot.owner_additional_properties = "ORIGID=" + str(row['ORIGID'])

        if row.get('OWNER_ADDITIONAL_PROPERTIES'):
            plot.owner_additional_properties = str(plot.owner_additional_properties) + " " + str(row['OWNER_ADDITIONAL_PROPERTIES'])

        if row.get('OWNER_ADDITIONAL_ID'):
            plot.owner_additional_id = str(row['OWNER_ADDITIONAL_ID'])

        if row.get('POWERLINE'):
            for k, v in choices['powerlines']:
                if v == row['POWERLINE']:
                    plot.powerline_conflict_potential = k
                    break;

        sidewalk_damage = row.get('SIDEWALK')
        if sidewalk_damage is None or sidewalk_damage.strip() == "":
            pass
        elif sidewalk_damage is True or sidewalk_damage.lower() == "true" or sidewalk_damage.lower() == 'yes':
            plot.sidewalk_damage = 2
        else:
            plot.sidewalk_damage = 1

        plot.quick_save()

        pnt = plot.geometry
        n = Neighborhood.objects.filter(geometry__contains=pnt)
        z = ZipCode.objects.filter(geometry__contains=pnt)

        plot.neighborhoods = ""
        plot.neighborhood.clear()
        plot.zipcode = None

        if n:
            for nhood in n:
                if nhood:
                    plot.neighborhoods = plot.neighborhoods + " " + nhood.id.__str__()
                    plot.neighborhood.add(nhood)

        if z: plot.zipcode = z[0]

        plot.quick_save()

        if tree:
            tree.plot = plot
            tree.readonly = self.readonly
            tree.import_event = self.import_event
            tree.last_updated_by = self.updater

            if row.get('OWNER'):
                tree.tree_owner = str(row["OWNER"])

            if row.get('STEWARD'):
                tree.steward_name = str(row["STEWARD"])

            if row.get('SPONSOR'):
                tree.sponsor = str(row["SPONSOR"])

            if row.get('DATEPLANTED'):
                date_string = str(row['DATEPLANTED'])
                try:
                    date = datetime.strptime(date_string, "%m/%d/%Y")
                except:
                    pass
                try:
                    date = datetime.strptime(date_string, "%Y/%m/%d")
                except:
                    pass
                if not date:
                    raise ValueError("Date strings must be in mm/dd/yyyy or yyyy/mm/dd format")

                tree.date_planted = date.strftime("%Y-%m-%d")

            if row.get('DIAMETER'):
                tree.dbh = float(row['DIAMETER'])

            if row.get('HEIGHT'):
                tree.height = float(row['HEIGHT'])

            if row.get('CANOPYHEIGHT'):
                tree.canopy_height = float(row['CANOPYHEIGHT'])

            if row.get('CONDITION'):
                for k, v in choices['conditions']:
                    if v == row['CONDITION']:
                        tree.condition = k
                        break;

            if row.get('CANOPYCONDITION'):
                for k, v in choices['canopy_conditions']:
                    if v == row['CANOPYCONDITION']:
                        tree.canopy_condition = k
                        break;

            tree.quick_save()

            if row.get('PROJECT_1'):
                for k, v in Choices().get_field_choices('local'):
                    if v == row['PROJECT_1']:
                        local = TreeFlags(key=k,tree=tree,reported_by=self.updater)
                        local.save()
                        break;
            if row.get('PROJECT_2'):
                for k, v in Choices().get_field_choices('local'):
                    if v == row['PROJECT_2']:
                        local = TreeFlags(key=k,tree=tree,reported_by=self.updater)
                        local.save()
                        break;
            if row.get('PROJECT_3'):
                for k, v in Choices().get_field_choices('local'):
                    if v == row['PROJECT_3']:
                        local = TreeFlags(key=k,tree=tree,reported_by=self.updater)
                        local.save()
                        break;

            # rerun validation tests and store results
            tree.validate_all()
Ejemplo n.º 4
0
    def handle_row(self, row):
        self.log_verbose(row)

        # check the physical location
        ok, x, y = self.check_coords(row)
        if not ok:
            return

        plot = Plot()

        try:
            if self.base_srid != 4326:
                geom = Point(x, y, srid=self.base_srid)
                geom.transform(self.tf)
                self.log_verbose(geom)
                plot.geometry = geom
            else:
                plot.geometry = Point(x, y, srid=4326)
        except:
            self.log_error("ERROR: Geometry failed to transform", row)
            return

        # check the species (if any)
        ok, species = self.check_species(row)
        if not ok:
            return

        # check for tree info, should we create a tree or just a plot
        if species or self.check_tree_info(row):
            tree = Tree(plot=plot)
        else:
            tree = None

        if tree and species:
            tree.species = species[0]

        # check the proximity (try to match up with existing trees)
        # this may return a different plot/tree than created just above,
        # so don't set anything else on either until after this point
        ok, plot, tree = self.check_proximity(plot, tree, species, row)
        if not ok:
            return

        if row.get("ADDRESS") and not plot.address_street:
            plot.address_street = str(row["ADDRESS"]).title()
            plot.geocoded_address = str(row["ADDRESS"]).title()

        if not plot.geocoded_address:
            plot.geocoded_address = ""

        # FIXME: get this from the config?
        plot.address_state = "CA"
        plot.import_event = self.import_event
        plot.last_updated_by = self.updater
        plot.data_owner = self.data_owner
        plot.readonly = self.readonly

        if row.get("PLOTTYPE"):
            for k, v in choices["plot_types"]:
                if v == row["PLOTTYPE"]:
                    plot.type = k
                    break

        if row.get("PLOTLENGTH"):
            plot.length = row["PLOTLENGTH"]

        if row.get("PLOTWIDTH"):
            plot.width = row["PLOTWIDTH"]

        if row.get("ID"):
            plot.owner_orig_id = row["ID"]

        if row.get("ORIGID"):
            plot.owner_additional_properties = "ORIGID=" + str(row["ORIGID"])

        if row.get("OWNER_ADDITIONAL_PROPERTIES"):
            plot.owner_additional_properties = (
                str(plot.owner_additional_properties) + " " + str(row["OWNER_ADDITIONAL_PROPERTIES"])
            )

        if row.get("OWNER_ADDITIONAL_ID"):
            plot.owner_additional_id = str(row["OWNER_ADDITIONAL_ID"])

        if row.get("POWERLINE"):
            for k, v in choices["powerlines"]:
                if v == row["POWERLINE"]:
                    plot.powerline = k
                    break

        sidewalk_damage = row.get("SIDEWALK")
        if sidewalk_damage is None or sidewalk_damage.strip() == "":
            pass
        elif sidewalk_damage is True or sidewalk_damage.lower() == "true" or sidewalk_damage.lower() == "yes":
            plot.sidewalk_damage = 2
        else:
            plot.sidewalk_damage = 1

        plot.quick_save()

        pnt = plot.geometry
        n = Neighborhood.objects.filter(geometry__contains=pnt)
        z = ZipCode.objects.filter(geometry__contains=pnt)

        plot.neighborhoods = ""
        plot.neighborhood.clear()
        plot.zipcode = None

        if n:
            for nhood in n:
                if nhood:
                    plot.neighborhoods = plot.neighborhoods + " " + nhood.id.__str__()
                    plot.neighborhood.add(nhood)

        if z:
            plot.zipcode = z[0]

        plot.quick_save()

        if tree:
            tree.plot = plot
            tree.readonly = self.readonly
            tree.import_event = self.import_event
            tree.last_updated_by = self.updater

            if row.get("OWNER"):
                tree.tree_owner = str(row["OWNER"])

            if row.get("STEWARD"):
                tree.steward_name = str(row["STEWARD"])

            if row.get("SPONSOR"):
                tree.sponsor = str(row["SPONSOR"])

            if row.get("DATEPLANTED"):
                date_string = str(row["DATEPLANTED"])
                try:
                    date = datetime.strptime(date_string, "%m/%d/%Y")
                except:
                    pass
                try:
                    date = datetime.strptime(date_string, "%Y/%m/%d")
                except:
                    pass
                if not date:
                    raise ValueError("Date strings must be in mm/dd/yyyy or yyyy/mm/dd format")

                tree.date_planted = date.strftime("%Y-%m-%d")

            if row.get("DIAMETER"):
                tree.dbh = float(row["DIAMETER"])

            if row.get("HEIGHT"):
                tree.height = float(row["HEIGHT"])

            if row.get("CANOPYHEIGHT"):
                tree.canopy_height = float(row["CANOPYHEIGHT"])

            if row.get("CONDITION"):
                for k, v in choices["conditions"]:
                    if v == row["CONDITION"]:
                        tree.condition = k
                        break

            if row.get("CANOPYCONDITION"):
                for k, v in choices["canopy_conditions"]:
                    if v == row["CANOPYCONDITION"]:
                        tree.canopy_condition = k
                        break
            # FOR OTM INDIA
            # GIRTH_CM", "GIRTH_M", "HEIGHT_FT", "HEIGHT_M", "NEST", "BURROWS", "FLOWERS", "FRUITS", "NAILS", "POSTER", "WIRES", "TREE_GUARD", "NUISANCE", "NUISANCE_DESC", "HEALTH_OF_TREE", "FOUND_ON_GROUND", "GROUND_DESCRIPTION", "RISK_ON_TREE", "RISK_DESC", "RARE", "ENDANGERED", "VULNERABLE", "PEST_AFFECTED", "REFER_TO_DEPT", "SPECIAL_OTHER", "SPECIAL_OTHER_DESCRIPTION", "LATITUDE", "LONGITUDE", "CREATION_DATE", "DEVICE_ID", "TIME", "DATE"])

            if row.get("GIRTH_M"):
                tree.girth_m = float(row["GIRTH_M"])

            if row.get("HEIGHT_M"):
                tree.height_m = float(row["HEIGHT_M"])

            if row.get("NEST"):
                tree.nest = str(row["NEST"])

            if row.get("BURROWS"):
                tree.burrows = str(row["BURROWS"])

            if row.get("FLOWERS"):
                tree.flowers = str(row["FLOWERS"])

            if row.get("FRUITS"):
                tree.fruits = str(row["FRUITS"])

            if row.get("NAILS"):
                tree.nails = str(row["NAILS"])

            if row.get("POSTER"):
                tree.poster = str(row["POSTER"])

            if row.get("WIRES"):
                tree.wires = str(row["WIRES"])

            if row.get("TREE_GUARD"):
                tree.tree_guard = str(row["TREE_GUARD"])

            if row.get("NUISANCE"):
                tree.other_nuisance = bool(row["NUISANCE"])

            if row.get("NUISANCE_DESC"):
                tree.other_nuisance_desc = str(row["NUISANCE_DESC"])

            if row.get("HEALTH_OF_TREE"):
                tree.health_of_tree = str(row["HEALTH_OF_TREE"])

            if row.get("FOUND_ON_GROUND"):
                tree.found_on_ground = str(row["FOUND_ON_GROUND"])

            if row.get("GROUND_DESCRIPTION"):
                tree.ground_description = str(row["GROUND_DESCRIPTION"])

            if row.get("RISK_ON_TREE"):
                tree.risk_on_tree = str(row["RISK_ON_TREE"])

            if row.get("RISK_DESC"):
                tree.risk_desc = str(row["RISK_DESC"])

            if row.get("PEST_AFFECTED"):
                tree.pests = str(row["PEST_AFFECTED"])

            if row.get("REFER_TO_DEPT"):
                tree.refer_to_dept = str(row["REFER_TO_DEPT"])

            if row.get("SPECIAL_OTHER"):
                tree.special_other = str(row["SPECIAL_OTHER"])

            if row.get("SPECIAL_OTHER_DESCRIPTION"):
                tree.special_other_description = str(row["SPECIAL_OTHER_DESCRIPTION"])

            if row.get("LATITUDE"):
                tree.latitude = str(row["LATITUDE"])

            if row.get("LONGITUDE"):
                tree.longitude = str(row["LONGITUDE"])

            if row.get("PRABHAG_ID"):
                tree.prabhag_id = str(row["PRABHAG_ID"])

            if row.get("CLUSTER_ID"):
                tree.cluster_id = str(row["CLUSTER_ID"])

            # if row.get('ID'):
            #    tree.id = str(row['ID'])

            # import pdb; pdb.set_trace()

            f = open("trees_in_otm_obj.log", "w")
            f.write("b4 save")
            f.write(str(tree.__dict__))
            tree.quick_save()
            f.write("after save \n")
            f.write(str(tree.__dict__))
            f.close()

            if row.get("PROJECT_1"):
                for k, v in Choices().get_field_choices("local"):
                    if v == row["PROJECT_1"]:
                        local = TreeFlags(key=k, tree=tree, reported_by=self.updater)
                        local.save()
                        break
            if row.get("PROJECT_2"):
                for k, v in Choices().get_field_choices("local"):
                    if v == row["PROJECT_2"]:
                        local = TreeFlags(key=k, tree=tree, reported_by=self.updater)
                        local.save()
                        break
            if row.get("PROJECT_3"):
                for k, v in Choices().get_field_choices("local"):
                    if v == row["PROJECT_3"]:
                        local = TreeFlags(key=k, tree=tree, reported_by=self.updater)
                        local.save()
                        break

            # rerun validation tests and store results
            tree.validate_all()