Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sympy import *
- from sympy.geometry import *
- import json
- import pprint
- import pandas as pd
- from multiprocessing import Pool as ThreadPool, freeze_support
- import time
- __author__ = 'Matthew'
- # def minDistance():
- def main():
- # pool = ThreadPool(8)
- dfW = pd.DataFrame()
- data = pd.read_csv('Unique_Weather_Station.csv', sep=",", usecols=(0, 6, 7)) # To read 1st,7th and 8th columns
- weatherLongLat = []
- for index, row in data.iterrows():
- weatherLongLat.append([row['Longitude (Decimal Degrees)'], row['Latitude (Decimal Degrees)'], row['name']])
- dfC = pd.DataFrame()
- data = pd.read_csv('cleanedCollisions.csv',sep=",",usecols=(4, 7, 12, 16, 20, 24)) # To read 1st,2nd and 4th columns
- collisionLongLat = []
- i = 0
- for index, row in data.iterrows():
- collisionLongLat.append([row["LONGITUDE"], row["LATITUDE"], i, row["hourStart"], row["dayOfWeek"], row["month"], row["year"]])
- i += 1
- #
- # pool.map(minDistance, zip(long, lat))
- #
- # # close the pool and wait for the work to finish
- # pool.close()
- # pool.join()
- #NOTE: FINISH
- shortestPath = []
- i = 0
- for longLatC in collisionLongLat:
- distanceList = []
- for longLatW in weatherLongLat:
- #Accident ID, Hour, Day, Month, Year, Station Name,
- distanceList.append([longLatC[2], longLatC[3], longLatC[4], longLatC[5], longLatW[2], sqrt(((float(longLatC[0]) - float(longLatW[0]))**2) + ((float(longLatC[1]) - float(longLatW[1]))**2))])
- min = distanceList[0][2]
- minList = distanceList[0]
- for distance in distanceList:
- if distance[2] < min:
- min = distance[2]
- minList = distance[:-1]
- shortestPath.append(minList)
- print i
- i += 1
- label = ["hourStart", "dayOfWeek", "month", "year", 'name']
- dfFinal = pd.DataFrame.from_records(minList, columns=label)
- writer = pd.ExcelWriter('simple-report.xlsx', engine='xlsxwriter')
- dfFinal.to_excel(writer, index=False)
- writer.save()
- # print shortestPath
- if __name__ == '__main__':
- freeze_support()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement