Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. import pandas as pd
  2. import pymongo
  3. import urllib
  4. from bson.objectid import ObjectId
  5. from bson.son import SON
  6.  
  7. password = "FILL_ME"
  8.  
  9. url = 'mongodb://taxi:' + urllib.quote_plus(password) + '@olive083.dakao.io:27017/driver_record'
  10. client = pymongo.MongoClient(url)
  11. db = client['driver_record']
  12.  
  13. cursor = db.hour_drive_info.aggregate([
  14. {'$match': {'day': "20160922"}},
  15. {'$group': {
  16. '_id': "$taxi_id",
  17. 'raw_count': {'$sum' : "$raw_count"},
  18. 'raw_length': {'$sum' : "$raw_length"},
  19. 'time_drive': {'$sum' : "$time_drive"},
  20. 'time_pickup': {'$sum' : "$time_pickup"},
  21. 'time_break': {'$sum' : "$time_break"},
  22. 'time_wait': {'$sum' : "$time_wait"},
  23. }}
  24. ])
  25.  
  26. driveInfoDF = pd.DataFrame(list(cursor))
  27.  
  28.  
  29.  
  30. import psycopg2
  31. conn = psycopg2.connect("dbname='daum' user='taxi' host='taxi.gp.daumkakao.io' password='FILL_ME'")
  32. cur = conn.cursor()
  33. cur.execute("select driver_id, id from taxi.taxis")
  34. res = cur.fetchall()
  35. taxiDriverIdMapping = pd.DataFrame(res, columns = list(zip(*cur.description))[0])
  36.  
  37.  
  38. df = pd.merge(driveInfoDF, taxiDriverIdMapping, left_on='_id', right_on='id')
  39.  
  40. total_driver = len(df['driver_id'].value_counts())
  41.  
  42. df['time_drive'].sum()/ total_driver
  43. df['time_pickup'].sum()/ total_driver
  44. df['time_break'].sum()/ total_driver
  45. df['time_wait'].sum()/ total_driver
  46.  
  47. (df['time_drive'].sum() + df['time_pickup'].sum() + df['time_break'].sum() + df['time_wait'].sum()) / total_driver
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement