fork(1) download
  1. import googlemaps
  2. import urllib2
  3. import urllib
  4. import json
  5. import simplejson
  6. import math
  7. from pprint import pprint
  8. #API_KEY = 'AIzaSyCZE-Tw7JOB1z_Qr1PgBBLlMzRswPmS5N8'
  9. with open('data.json') as data_file:
  10. data_json = json.load(data_file)
  11. id = 1
  12. tmp = input()
  13. ans = []
  14. for tmp in data_json:
  15. src = tmp['pickup_latitude'],tmp['pickup_longitude']
  16. dest = tmp['drop_latitude'],tmp['drop_longitude']
  17. url = "http://m...content-available-to-author-only...s.com/maps/api/distancematrix/json?origins={0}&destinations={1}&mode=driving&language=en-EN&sensor=false".format(str(src),str(dest))
  18. res= simplejson.load(urllib.urlopen(url))
  19. drive_time = (res['rows'][0]['elements'][0]['duration']['text']).split()[0]
  20. drive_dist = (res['rows'][0]['elements'][0]['distance']['text']).split()[0]
  21. print(id)
  22. print(drive_dist)
  23. print(drive_time)
  24. print ("%0.5f km" %tmp['metered_distance']),
  25. print("%d minutes"%tmp['metered_time'])
  26. id = id+1
  27. try :
  28. t_dev = int(((abs(float(x['metered_time'])- float(drive_time))*1.0)/float(x['metered_time']))*100.0)
  29. d_dev = int(((abs(float(tmp['metered_distance']) - float(drive_dist))*1.0)/float(tmp['metered_distance']))*100.0)
  30. except :
  31. t_dev = 100
  32. d_dev = 100
  33.  
  34. #On assuming that system is faulty if time deviation or distance deviation is greater than 20%
  35. if t_dev > 20 or d_dev > 20 :
  36. ANS = { 'engagement_id' : res['engagement_id'], 'metered_distance': drive_dist, 'metered_time' : drive_time, 'time_deviation' : str(t_dev)+'%', 'distance_deviation' : str(d_dev)+'%' }
  37. print(ANS)
  38. ans.append(ANS)
  39. with open('ans.json', 'w') as outfile:
  40. json.dump(ans, outfile)
  41.  
  42.  
  43.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Traceback (most recent call last):
  File "/usr/lib/python3.4/py_compile.py", line 124, in compile
    _optimize=optimize)
  File "<frozen importlib._bootstrap>", line 1532, in source_to_code
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "./prog.py", line 17
    url = "http://maps.googleapis.com/maps/api/distancematrix/json?origins={0}&destinations={1}&mode=driving&language=en-EN&sensor=false".format(str(src),str(dest))
                                                                                                                                                                   ^
TabError: inconsistent use of tabs and spaces in indentation

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.4/py_compile.py", line 128, in compile
    raise py_exc
py_compile.PyCompileError: Sorry: TabError: inconsistent use of tabs and spaces in indentation (prog.py, line 17)
stdout
Standard output is empty