SHARE
TWEET

Untitled

a guest Mar 23rd, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from sympy import *
  2. from sympy.geometry import *
  3. import json
  4. import pprint
  5. import pandas as pd
  6. from multiprocessing import Pool as ThreadPool, freeze_support
  7. import time
  8.  
  9. __author__ = 'Matthew'
  10.  
  11. # def minDistance():
  12.  
  13.  
  14. def main():
  15.     # pool = ThreadPool(8)
  16.  
  17.     dfW = pd.DataFrame()
  18.     data = pd.read_csv('Unique_Weather_Station.csv', sep=",", usecols=(0, 6, 7)) # To read 1st,7th and 8th columns
  19.  
  20.  
  21.  
  22.     weatherLongLat = []
  23.     for index, row in data.iterrows():
  24.         weatherLongLat.append([row['Longitude (Decimal Degrees)'], row['Latitude (Decimal Degrees)'], row['name']])
  25.  
  26.  
  27.     dfC = pd.DataFrame()
  28.     data = pd.read_csv('cleanedCollisions.csv',sep=",",usecols=(4, 7, 12, 16, 20, 24)) # To read 1st,2nd and 4th columns
  29.     collisionLongLat = []
  30.     i = 0
  31.     for index, row in data.iterrows():
  32.         collisionLongLat.append([row["LONGITUDE"], row["LATITUDE"], i, row["hourStart"], row["dayOfWeek"], row["month"], row["year"]])
  33.         i += 1
  34.     #
  35.     # pool.map(minDistance, zip(long, lat))
  36.     #
  37.     # # close the pool and wait for the work to finish
  38.     # pool.close()
  39.     # pool.join()
  40.  
  41.  
  42. #NOTE: FINISH
  43.  
  44.  
  45.  
  46.     shortestPath = []
  47.     i = 0
  48.     for longLatC in collisionLongLat:
  49.         distanceList = []
  50.         for longLatW in weatherLongLat:
  51.             #Accident ID, Hour, Day, Month, Year, Station Name,
  52.             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))])
  53.  
  54.         min = distanceList[0][2]
  55.         minList = distanceList[0]
  56.         for distance in distanceList:
  57.             if distance[2] < min:
  58.                 min = distance[2]
  59.                 minList = distance[:-1]
  60.  
  61.         shortestPath.append(minList)
  62.         print i
  63.         i += 1
  64.  
  65.     label = ["hourStart", "dayOfWeek", "month", "year", 'name']
  66.     dfFinal = pd.DataFrame.from_records(minList, columns=label)
  67.     writer = pd.ExcelWriter('simple-report.xlsx', engine='xlsxwriter')
  68.     dfFinal.to_excel(writer, index=False)
  69.     writer.save()
  70.  
  71.     # print shortestPath
  72.  
  73.  
  74. if __name__ == '__main__':
  75.      freeze_support()
  76.      main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top