def test_neighborhood_outside_nyc(self): from fixcity.bmabr.views import neighborhood_for_rack rack = Rack(address='i have no idea where this is', title='far away', date=datetime.utcfromtimestamp(0), email='*****@*****.**', location=Point(20.0, 20.0, srid=SRID), ) self.assertEqual(neighborhood_for_rack(rack), "<unknown>")
def test_neighborhood(self): from fixcity.bmabr.views import neighborhood_for_rack rack = Rack(address='67 s 3rd st, brooklyn, ny 11211', title='williamsburg somewhere', date=datetime.utcfromtimestamp(0), email='*****@*****.**', location=Point(-73.964858020364, 40.713349294636, srid=SRID), ) self.assertEqual(neighborhood_for_rack(rack), "Williamsburg")
def make_csv(bo, outfile): import csv csv_writer = csv.writer(outfile) # Initial heading row. Does DOT want this? csv_writer.writerow( ['date received', 'generated by', 'establishment', 'street address', 'from', 'to', 'borough', 'cb', 'neighborhood', # ... skip some we lack 'email', # ... skip some more ... 'status', # ... skip more ... 'image', 'doc', ]) from fixcity.bmabr.views import cross_streets_for_rack, neighborhood_for_rack from fixcity.bmabr.models import CommunityBoard from fixcity.bmabr.models import StatementOfSupport for rack in bo.racks: from_st, to_st = cross_streets_for_rack(rack) neighborhood = neighborhood_for_rack(rack) cb = CommunityBoard.objects.get(the_geom__intersects=rack.location) try: site_domain = Site.objects.get_current().domain photo_url = 'http://%s%s' % (site_domain, rack.photo.url) except (ValueError, AttributeError): photo_url = '' row = [ rack.date.strftime('%m/%d/%Y'), # 'date' rack.source or 'web', # 'generated by' rack.title, # 'establishment' rack.address, # 'street address' ... actually the whole address. from_st, # 'from' to_st, # 'to' cb.borough.boroname, # 'borough' ... actually should be a 2-letter code but we don't have those. cb.borocd, # 'cb' in DOT's extended format, eg. 301 for bk 1 neighborhood, # 'neighborhood' rack.email, # 'email' 'request', # 'status' photo_url, # 'image' ] statement_query = StatementOfSupport.objects.filter(s_rack=rack.id) for s in statement_query: row.append(s.file.url) csv_writer.writerow(row)
def make_csv(bo, outfile): logger.info('Start make_csv') import csv fieldnames = ("ID", "TrackNum", "DateIn", "Action_", "GenBy", "Requestor", "Address", "Address2", "ReqBoro", "ZipCode", "Phone", "Email", "Title", "RComment", "LocName", "LocAdd", "LocAddNum", "Street", "From_", "To_", "Width", "x", "y", "Boro", "LocZip", "CB", "Comments", "Area", "SubStation", "SubLine", "Status", "Sited", "SitedBy", "InspDate", "InspBy", "Side", "Sm", "Lg", "RackType", "MeterNum", "DOTRespDat", "CBNoteDate", "CommNote", "WorkOrder", "InstDate", "Invoice", "Image_", "txtImgName") # In python 2.7 you can do: csv_writer.writeheader() outfile.write(', '.join(fieldnames)) outfile.write('\r\n') csv_writer = csv.DictWriter(outfile, fieldnames) from fixcity.bmabr.views import cross_streets_for_rack, neighborhood_for_rack from fixcity.bmabr.models import CommunityBoard from fixcity.bmabr.models import StatementOfSupport for rack in bo.racks: from_st, to_st = cross_streets_for_rack(rack) neighborhood = neighborhood_for_rack(rack) cb = CommunityBoard.objects.get(the_geom__intersects=rack.location) try: site_domain = Site.objects.get_current().domain photo_url = 'http://%s%s' % (site_domain, rack.photo.url) except (ValueError, AttributeError): photo_url = '' row = { "ID": '', 'TrackNum': '', 'DateIn': rack.date.strftime('%m/%d/%Y'), 'Action_': 'REQUEST', 'GenBy': 'INTERNET', #rack.source or 'web', 'Requestor': rack.user or rack.email, 'Address': '', 'Address2': '', # user's address? 'ReqBoro': cb.borough.boroname, # user's or rack's?? actually should be a 2-letter code but we just have names. 'ZipCode': '', 'Phone': '', 'Email': rack.email, 'Title': '', # eg. Dr, Mr, Mrs ... 'RComment': rack.description, 'LocName': rack.title, 'LocAdd': '', # Number part of rack address? 'LocAddNum': '', # Number part of rack address again? 'Street': rack.address, # Should be just the street part? 'From_': from_st, 'To_': to_st, 'Width': '', # what's this? 'x': '', # maybe a longitude? but in some other units? 'y': '', # maybe a latitude? but what are the units?? 'Boro': cb.borough.borocode, # or what? should be '1' for manhattan?? 'LocZip': '', # rack's zip? don't have it. 'CB': cb.borocd, 'Comments': '', # for DOT's internal use? 'Area': neighborhood, 'SubStation': '', # subway station 'SubLine': '', # subway line 'Status': 'P', # always submit as 'Pending'. # DOT internal statuses: "sited" (approved for install), # "rejected" (with a comment), "installed" (DOT has # audited it post-install) 'Sited': '', 'SitedBy': '', # only if installed. 'InspDate': '', 'InspBy': '', 'Side': '', 'Sm': '', 'Lg': '', 'RackType': '', 'MeterNum': '', 'DOTRespDat': '', 'CBNoteDate': '', 'CommNote': '', 'WorkOrder': '', 'InstDate': '', 'Invoice': '', 'Image_': '', 'txtImgName': photo_url, # URL ok here? } statement_query = StatementOfSupport.objects.filter(s_rack=rack.id) for s in statement_query: # What to do with these? DOT doesn't really have a place for them. #row.append(s.file.url) pass # DictWriter doesn't handle encoding automatically. for k, v in row.items(): if v is None: v = u'' if isinstance(v, basestring): row[k] = v.encode('utf8') csv_writer.writerow(row) logger.info('Start make_csv')