Commit 5340403c authored by blb032's avatar blb032

blergen

parent 1fffb215
{
"cells": [
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"from urllib.request import urlopen\n",
"import json\n",
"import re\n",
"\n",
"API_KEY = \"AIzaSyCJkjXe-dVvbhcxfdwrsMzXbn2qmzZ0sJM\"\n",
"API_KEY2 = \"AIzaSyCRaRfZZvRUAGTz6EsRpii5AJMPDrEEklo\"\n",
"API_KEY3 = 'AIzaSyC3bTGeppurTHGv1Z5jF7SEMAJSBdx4RgA'"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"def get_loc_json(lat, long, api_key):\n",
" url_suffix = \"https://maps.googleapis.com/maps/api/geocode/json?latlng=\"\n",
" url_end = \"&key=\" + api_key\n",
" coord = str(lat) + ','+str(long)\n",
" full_url = url_suffix + coord + url_end\n",
" print(full_url)\n",
" resp = urlopen(full_url)\n",
" data = resp.read().decode('utf-8')\n",
" return json.loads(data)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
"class user:\n",
" def __init__(self, ID):\n",
" \"\"\"\n",
" ID is user ID\n",
" t is time that a measurement was taken\n",
" \"\"\"\n",
" self.ID = ID\n",
" self.times = []\n",
" self.lats = []\n",
" self.longs = []\n",
" self.places = [] #later on we can connect this to a dictionary and then we won't have to look up every location we are given\n",
"\n",
" def __str__(self):\n",
" return 'User ID: {} Created On: {} Places Visted: {}'.format(self.ID, self.times[0], len(self.places))\n",
" \n",
" def add_location(self, time, lat, long, place):\n",
" \"\"\"\n",
" Adds new values to user location dataset\n",
" \"\"\"\n",
" self.times.append(time)\n",
" self.lats.append(lat)\n",
" self.longs.append(long)\n",
" self.places.append(place)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class data_process:\n",
"\n",
" def __init__(self):\n",
" pass\n",
"\n",
" def data_reader(self, filename):\n",
" file = open(filename)\n",
" lines = file.readlines()\n",
" return lines\n",
"\n",
" def parseLine(self, line, regex, split):\n",
" lineList = re.split(regex, line, maxsplit = split)\n",
" return int(lineList[0]), str(lineList[1]), float(lineList[2]), float(lineList[3]), str(lineList[4])\n",
"\n",
" def create_user(self, ID):\n",
" '''\n",
" 0 - user ID\n",
" 1 - time\n",
" 2 - lat\n",
" 3 - long\n",
" 4 - place ID\n",
" '''\n",
" return user(int(ID))\n",
"\n",
" def create_user_set(self, regex, datafile):\n",
" user_set = {}\n",
" lines = self.data_reader(datafile)\n",
" for line in lines:\n",
" ID, time, lat, long, place = self.parseLine(line, regex, 5)\n",
" if ID not in user_set:\n",
" u = self.create_user(ID)\n",
" u.add_location(time, lat, long, place)\n",
" user_set[u.ID] = u\n",
" print(user_set[u.ID])\n",
" else:\n",
" user_set[u.ID].add_location(time, lat, long, place)\n",
"\n",
" return user_set"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"p = data_process()\n",
"bright_kite = p.create_user_set(r'\\t+', 'Datasets/Brightkite.txt')\n",
"print(a)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
......@@ -58,7 +58,7 @@ class data_process:
1 - time
2 - lat
3 - long
4 - place ID?
4 - place ID
'''
if len(lineList) >= 4:
print(lineList)
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment