예제 #1
0
파일: models.py 프로젝트: nicorivas/tasador
 def createCondominio(self, addressNumber2):
     building = Building(real_estate=self,
                         propertyType=Building.TYPE_CONDOMINIO)
     building.save()
     self.buildings.add(building)
     self.save()
     return building
예제 #2
0
파일: models.py 프로젝트: nicorivas/tasador
    def createDepartamento(self,
                           addressNumber2=None,
                           addressNumber3=None,
                           apartment_building=None):
        if apartment_building == None:
            if addressNumber2 == None:
                # Si no nos dieron número de edificio, crearlo
                building = Building(real_estate=self,
                                    propertyType=Building.TYPE_EDIFICIO)
                building.save()
                apartment_building = ApartmentBuilding(building=building,
                                                       fromApartment=True)
                apartment_building.save()
            else:
                # Si nos dieron,
                buildings = self.buildings.filter(
                    propertyType=Building.TYPE_EDIFICIO)
                for building in buildings:
                    if building.apartmentbuilding.addressNumber2 == addressNumber2:
                        apartment_building = building.apartmentbuilding
                        break

        departamento = Apartment(apartment_building=apartment_building,
                                 addressNumber2=addressNumber3)
        departamento.save()

        self.buildings.add(apartment_building.building)
        self.save()

        return departamento
예제 #3
0
파일: models.py 프로젝트: nicorivas/tasador
 def createCasa(self, addressNumber2):
     building = Building(real_estate=self, propertyType=Building.TYPE_CASA)
     building.save()
     casa = House(building=building, addressNumber2=addressNumber2)
     casa.save()
     self.buildings.add(building)
     self.save()
     return casa
예제 #4
0
파일: models.py 프로젝트: nicorivas/tasador
 def createLocalComercial(self, addressNumber2):
     building = Building(real_estate=self,
                         propertyType=Building.TYPE_LOCAL_COMERCIAL)
     building.save()
     store = Store(building=building, addressNumber2=addressNumber2)
     store.save()
     self.buildings.add(building)
     self.save()
     return store
예제 #5
0
파일: models.py 프로젝트: nicorivas/tasador
 def createEdificio(self, addressNumber2):
     building = Building(real_estate=self,
                         propertyType=Building.TYPE_EDIFICIO)
     building.save()
     apartment_building = ApartmentBuilding(building=building,
                                            addressNumber2=addressNumber2,
                                            fromApartment=False)
     apartment_building.save()
     self.buildings.add(building)
     self.save()
     return apartment_building
예제 #6
0
def update_building_cache():
    Building.create_cache()
    BuildingGolden.create_cache()
    #BuildingPopulation.create_cache()
    BuildingProduction.create_cache()
    BuildingProductionCost.create_cache()
    BuildingUpgrade.create_cache()
    BuildingUpgradeCost.create_cache()
    BuildingResourceProtected.create_cache()
    BuildingRadar.create_cache()
    BuildingGoldHand.create_cache()
    BuildingFragment.create_cache()
    BuildingAttribute.create_cache()
    BuildingPlant.create_cache()
예제 #7
0
파일: docs.py 프로젝트: whiteprism/mywork
    def to_dict(self):
        _dict = {}
        _dict["hasSoldierLevel"] = True
        _dict["hasSoldiers"] = True
        _dict["key"] = self.pk
        _dict["soldiers"] = [
        ]  #[{"type": int(k), "count":v["num"]} for k,v in self.armies.items()]
        _dict["soldierLevel"] = [
        ]  #[{"type": int(k), "level":v["level"]} for k,v in self.armies.items()]

        #        if self.has_alliance or self.has_horde or self.has_dragonhome:
        if True:
            _soldiers = []
            #            if self.has_horde:
            _soldiers += Building.hordebarrack_soldiers()

            for k in _soldiers:
                if str(k) not in self.armies:
                    num = 0
                    level = 1
                else:
                    num = self.armies[str(k)]["num"]
                    level = self.armies[str(k)]["level"]

                _dict["soldiers"].append({"type": k, "count": num})
                _dict["soldierLevel"].append({"type": k, "level": level})

        return _dict
예제 #8
0
 def post(self, request):
     templateName = 'building/add.html' #pemanggilan ke building add.html
     form = BuildingForm(request.POST or None)
     if form.is_valid(): #ngecek apakah data sudah terisi semua atau belum makanya dibilang is valid
         b = Building()
         b.nama = form.cleaned_data['nama']
         b.luas = form.cleaned_data['luas']
         b.fasilitas = form.cleaned_data['fasilitas']
         b.save()
     else:
         data = {
             'form': form,
         }
         return render(request, templateName, data)
         
     return redirect('building:list')
예제 #9
0
def read_csv(source):
    #for reading unicode
    #f = codecs.open(source, 'r', encoding='utf-8')

    city_options = City.objects.filter(tag="ann_arbor")
    print len(city_options)
    if not len(city_options):
        city = City()
        city.name = "Ann Arbor"
        city.tag = to_tag(city.name)
        city.save()
    else:
        city = city_options[0]

    print city

    #TODO:
    #setup FeedInfo item
    #and also create a Source item

    permit_sub_types = []
    status_types = []
    building_nums = []
    applicants = []
    managers = []

    cache_file = "%s.json" % city.tag
    cache_destination = os.path.join(os.path.dirname(source), cache_file)
    #keep a local copy of data we've processed...
    #this should help with subsequent calls
    #to make sure we don't need to duplicate calls to remote geolocation APIs:
    local_cache = load_json(cache_destination, create=True)
    if not local_cache.has_key('buildings'):
        local_cache['buildings'] = {}
    if not local_cache.has_key('parcels'):
        local_cache['parcels'] = {}

    locations = {}
    for key, value in local_cache['buildings'].items():
        locations[key] = Location(value)

    #geocoder helper:
    geo = Geo()

    #with open('eggs.csv', 'rb') as csvfile:
    with codecs.open(source, 'rb', encoding='utf-8') as csvfile:
        #reader = csv.reader(csvfile, delimiter=' ', quotechar='|')
        reader = csv.reader(csvfile)

        #just print the first row:
        print '>, <'.join(reader.next())

        count = 0
        for row in reader:
            count += 1
            #could exit out early here, if needed
            if count > 10:
                pass

            print row

            #type of building (eg: sf attached, duplex, etc)
            permit_id = row[0]

            #should always be "RENTAL" (don't need to track this one)
            permit_type = row[1]
            if not permit_type == "RENTAL" and not permit_type == "MECHANICAL":
                raise ValueError, "Unexpected permit type: %s in row: %s" % (
                    permit_type, row)

            sub_type = row[2]

            #can use this to filter out non-rental or obsolete entries
            #don't need to track otherwise:
            status = row[3]
            parcel_id = row[4]
            address = row[5]

            #should be fixed per source:
            city = row[6]
            if not ((city.lower() == 'ann arbor') or (city == '')):
                raise ValueError, "Unexpected city: %s" % (city)

            sqft = row[7]
            number_of_buildings = row[8]
            applicant_name = row[9]
            number_of_stories = row[10]
            number_of_units = row[11]

            if (not status in ['EXPIRED', 'CLOSED']) and (permit_type
                                                          in ['RENTAL']):
                #check if we've started processing any results for this row
                #if local_cache['buildings'].has_key(address.upper()):
                #    local_cache_cur = local_cache['buildings'][address.upper()]
                #else:
                #    local_cache_cur = {}

                if locations.has_key(address.upper()):
                    location = locations[address.upper()]
                else:
                    location = Location()

                #do some geocoding, as needed:
                search = "%s, Ann Arbor MI" % address.upper()

                for source in location.sources:
                    geo.lookup(search, source, location)

                location.address_alt = search

                locations[address.upper()] = location

                #local_cache['buildings'][address.upper()] = local_cache_cur

                #and check if a previous building object in the db exists
                #CREATE A NEW BUILDING OBJECT HERE
                #cur_building = Building()
                bldg = Building()
                bldg.type = sub_type

            #back it up for later
            local_cache['buildings'] = {}
            for key, value in locations.items():
                local_cache['buildings'][key] = value.to_dict()

            save_json(cache_destination, local_cache)
            #exit()

            #THE FOLLOWING ARE FOR INFORMATIONAL PURPOSES ONLY
            #(to see what data is available)

            if not status in status_types:
                #print "adding: %s" % sub_type
                status_types.append(status)

            if not sub_type in permit_sub_types:
                #print "adding: %s" % sub_type
                permit_sub_types.append(sub_type)

            building_num = row[8]
            if not building_num in building_nums:
                #print "adding: %s" % sub_type
                building_nums.append(building_num)

            applicant = row[9]
            if (re.search('MGMT', applicant) or re.search('REALTY', applicant)
                    or re.search('PROPERTIES', applicant)
                    or re.search('MANAGEMENT', applicant)
                    or re.search('GROUP', applicant)
                    or re.search('LLC', applicant)
                    or re.search('L.L.C.', applicant)
                    or re.search('INC', applicant)):
                if not applicant in managers:
                    managers.append(applicant)
            else:
                if not applicant in applicants:
                    applicants.append(applicant)

            #print ', '.join(row)
            #print

    ## print permit_sub_types
    print status_types
    print building_nums

    save_results(locations)
def read_csv(source):
    #for reading unicode
    #f = codecs.open(source, 'r', encoding='utf-8')

    city_options = City.objects.filter(tag="ann_arbor")
    print len(city_options)
    if not len(city_options):
        city = City()
        city.name = "Ann Arbor"
        city.tag = to_tag(city.name)
        city.save()
    else:
        city = city_options[0]

    print city

    #TODO:
    #setup FeedInfo item
    #and also create a Source item

    permit_sub_types = []
    status_types = []
    building_nums = []
    applicants = []
    managers = []

    cache_file = "%s.json" % city.tag
    cache_destination = os.path.join(os.path.dirname(source), cache_file)
    #keep a local copy of data we've processed...
    #this should help with subsequent calls
    #to make sure we don't need to duplicate calls to remote geolocation APIs:
    local_cache = load_json(cache_destination, create=True)
    if not local_cache.has_key('buildings'):
        local_cache['buildings'] = {}
    if not local_cache.has_key('parcels'):
        local_cache['parcels'] = {}
    
    locations = {}
    for key, value in local_cache['buildings'].items():
        locations[key] = Location(value)
    

    #geocoder helper:
    geo = Geo()
    
    #with open('eggs.csv', 'rb') as csvfile:
    with codecs.open(source, 'rb', encoding='utf-8') as csvfile:
        #reader = csv.reader(csvfile, delimiter=' ', quotechar='|')
        reader = csv.reader(csvfile)

        #just print the first row:
        print '>, <'.join(reader.next())

        count = 0
        for row in reader:
            count += 1
            #could exit out early here, if needed
            if count > 10:
                pass

            print row
            
            #type of building (eg: sf attached, duplex, etc)
            permit_id = row[0]

            #should always be "RENTAL" (don't need to track this one)
            permit_type = row[1]
            if not permit_type == "RENTAL" and not permit_type == "MECHANICAL":
                raise ValueError, "Unexpected permit type: %s in row: %s" % (
                    permit_type, row)
            
            sub_type = row[2]
            
            #can use this to filter out non-rental or obsolete entries
            #don't need to track otherwise:
            status = row[3]
            parcel_id = row[4]
            address = row[5]

            #should be fixed per source:
            city = row[6]
            if not ( (city.lower() == 'ann arbor') or (city == '') ):
                raise ValueError, "Unexpected city: %s" % (city)

            sqft = row[7]
            number_of_buildings = row[8]
            applicant_name = row[9]
            number_of_stories = row[10]
            number_of_units = row[11]
            
            if (not status in ['EXPIRED', 'CLOSED']) and (permit_type in ['RENTAL']):
                #check if we've started processing any results for this row
                #if local_cache['buildings'].has_key(address.upper()):
                #    local_cache_cur = local_cache['buildings'][address.upper()]
                #else:
                #    local_cache_cur = {}

                if locations.has_key(address.upper()):
                    location = locations[address.upper()]
                else:
                    location = Location()

                #do some geocoding, as needed:
                search = "%s, Ann Arbor MI" % address.upper()

                for source in location.sources:
                    geo.lookup(search, source, location)

                location.address_alt = search

                locations[address.upper()] = location

                #local_cache['buildings'][address.upper()] = local_cache_cur
                

                #and check if a previous building object in the db exists
                #CREATE A NEW BUILDING OBJECT HERE
                #cur_building = Building()
                bldg = Building()
                bldg.type = sub_type
                


            #back it up for later
            local_cache['buildings'] = {}
            for key, value in locations.items():
                local_cache['buildings'][key] = value.to_dict()
            
            save_json(cache_destination, local_cache)
            #exit()

            #THE FOLLOWING ARE FOR INFORMATIONAL PURPOSES ONLY
            #(to see what data is available)

            if not status in status_types:
                #print "adding: %s" % sub_type
                status_types.append(status)


            if not sub_type in permit_sub_types:
                #print "adding: %s" % sub_type
                permit_sub_types.append(sub_type)

            building_num = row[8]
            if not building_num in building_nums:
                #print "adding: %s" % sub_type
                building_nums.append(building_num)


            applicant = row[9]
            if ( re.search('MGMT', applicant) or
                 re.search('REALTY', applicant) or 
                 re.search('PROPERTIES', applicant) or 
                 re.search('MANAGEMENT', applicant) or 
                 re.search('GROUP', applicant) or 
                 re.search('LLC', applicant) or 
                 re.search('L.L.C.', applicant) or 
                 re.search('INC', applicant)
                 ):
                if not applicant in managers:
                    managers.append(applicant)
            else:
                if not applicant in applicants:
                    applicants.append(applicant)
            
            

            #print ', '.join(row)
            #print

    ## print permit_sub_types
    print status_types
    print building_nums

    save_results(locations)
예제 #11
0
def make_building(location, bldg_id, city, feed_source, parcel_id=None, bldg_type=None, no_units=None, sqft=None):
    """
    add the building to the database
    """

    full_city = '%s, IN, USA' % city.name
    match = False
    #find an address to use
    for geo_source in location.sources:
        if not match:
            source_list = location.get_source(geo_source)
            if len(source_list) and source_list[0]['place'] and source_list[0]['place'] != full_city:
                print "using: %s to check: %s" % (geo_source, source_list[0]['place'])
                match = True

                #TODO: process this a bit more...
                #probably don't want city and zip here:

                #keeping city and zip minimizes chance for overlap
                #especially since this is used as a key
                #can always take it out on display, if necessary
                cur_address = source_list[0]['place']


                if parcel_id == None:
                    cid = "%s-%s" % (city.tag, bldg_id)
                else:
                    cid = parcel_id

                print "Checking parcel id: %s" % (cid)

                parcels = Parcel.objects.filter(custom_id=cid)
                if parcels.exists():
                    parcel = parcels[0]
                    print "Already had parcel: %s" % parcel.custom_id
                else:
                    parcel = Parcel()
                    parcel.custom_id = cid
                    parcel.save()
                    print "Created new parcel: %s" % parcel.custom_id


                buildings = Building.objects.filter(city=city).filter(address=cur_address)

                bldg = None
                #check if a previous building object in the db exists
                if buildings.exists():
                    bldg = buildings[0]
                    print "Already had: %s" % bldg.address
                else:
                    #if not, 
                    #CREATE A NEW BUILDING OBJECT HERE
                    #cur_building = Building()
                    bldg = Building()

                    bldg.address = source_list[0]['place']
                    bldg.latitude = float(source_list[0]['lat'])
                    bldg.longitude = float(source_list[0]['lng'])

                    bldg.parcel = parcel
                    bldg.geocoder = geo_source
                    bldg.source = feed_source

                    bldg.city = city
                    bldg.state = city.state

                    if bldg_type:
                        bldg.type = bldg_type
                    if no_units:
                        bldg.number_of_units = no_units
                    if sqft:
                        bldg.sqft = sqft

                    bldg.save()


                    print "Created new building: %s" % bldg.address

                return bldg
            else:
                print "Skipping: %s with value: %s" % (geo_source, source_list[0]['place'])
예제 #12
0
def get_buildings():
    return Building.get_all_list()
예제 #13
0
def get_building(pk):
    return Building.get(int(pk))