import re import csv from automation import xytogeo import pickle as cp from auxilary import bin_assign,trim Geo_dic ={} with open('../../data/RPD__Part_I_Crime_14_Days.csv') as fin: j=0 reader = csv.DictReader(fin) for row in reader: Geo_dic[(row["X"],row["Y"])] = xytogeo(row["X"],row["Y"])[:-3] print j j=j+1 # # if j>10: # # break #Geoid Dictionary # Geo_dic = {} # with open('../../data/dataset3.csv',"rb") as fin: # reader = csv.DictReader(fin) # for row in reader: # Geo_dic [(row["X"],row["Y"])] = row["GeoID"]
for row in csv.reader(csvinput): if row[0] == "X": top_row = copy.copy(row) #Finding necessary information to keep time_ind= row.index("OccurredFrom_Time") mon_ind= row.index("OccurredFrom_Date_Month") yr_ind = row.index("Reported_Date_Year") patrol_beat_ind = row.index("Patrol_Beat") crimetype_ind = row.index("Statute_Text") loctype_ind = row.index("Location_Type") geobeat_ind = row.index("Geo_Beat") geosec_ind = row.index("Geo_Section_Num") row=row[:2]+["GeoID"]+[row[time_ind],row[mon_ind],row[yr_ind],row[patrol_beat_ind],row[crimetype_ind],row[loctype_ind],row[geobeat_ind],row[geosec_ind]] #writing the necessary information and adding the binary datatype writer.writerow(row+["IsLarceny","IsBurglary","IsMotor Vehicle Theft","IsRobbery","IsAggravated Assault","IsMurder","Ismor","Isnoon","Isnight"]) else: if (row[0] and row[1]): crm_text = row[crimetype_ind] time_txt = int(row[time_ind]) ad_row= bin_assign(crm_text,time_txt) row=row[:2]+[xytogeo(row[0],row[1])[:-3]]+[row[time_ind],row[mon_ind],row[yr_ind],row[patrol_beat_ind],row[crimetype_ind],row[loctype_ind],row[geobeat_ind],row[geosec_ind]]+ad_row writer.writerow(row) i=i+1 print i # if i>10: # break
row[time_ind], row[mon_ind], row[yr_ind], row[patrol_beat_ind], row[crimetype_ind], row[loctype_ind], row[geobeat_ind], row[geosec_ind] ] #writing the necessary information and adding the binary datatype writer.writerow(row + [ "IsLarceny", "IsBurglary", "IsMotor Vehicle Theft", "IsRobbery", "IsAggravated Assault", "IsMurder", "Ismor", "Isnoon", "Isnight" ]) else: if (row[0] and row[1]): crm_text = row[crimetype_ind] time_txt = int(row[time_ind]) geoid = xytogeo(row[0], row[1])[:-3] ad_row, dic = bin_assign(crm_text, time_txt, ratio, geoid) ratio = dic row = row[:2] + [geoid] + [ row[time_ind], row[mon_ind], row[yr_ind], row[patrol_beat_ind], row[crimetype_ind], row[loctype_ind], row[geobeat_ind], row[geosec_ind] ] + ad_row writer.writerow(row) i = i + 1 print i # if i>10: # break csvoutput.close()
def get_paramforpredicition(X,Y): geoid = xytogeo(X,Y) near_loc = nearest(X,Y,geoid) params = Parameter_set[near_loc] return params
with open('../../data/RPD__Part_I_Crime_2011_to_Present.csv') as fin: with open('../../data/dataset7.csv', 'wb') as csvfile: j = 0 reader = csv.DictReader(fin) fieldnames = ["X", "Y", "GeoID"] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() for row in reader: j = j + 1 if (j > 56900 and j < 57400): if (row["X"] and row["Y"]): if j % 100 == 0: print j write_dic = {} write_dic["X"] = row["X"] write_dic["Y"] = row["Y"] write_dic["GeoID"] = xytogeo(row["X"], row["Y"])[:-3] writer.writerow(write_dic) # for row in reader: # if (row["X"] and row["Y"]): # write_dic={} # write_dic["X"] = row["X"] # write_dic["Y"] = row["Y"] # write_dic["GeoID"] = xytogeo(row["X"],row["Y"])[:-3] # print write_dic # writer.writerow(write_dic) # # if j>10: # # break