Skip to content

Commit

Permalink
Changed so that the database runs layers on all data but only display…
Browse files Browse the repository at this point in the history
…s locations using more than the user lang
  • Loading branch information
Oscar-Rydh committed May 8, 2017
1 parent 7811ad1 commit 73acdbb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
5 changes: 1 addition & 4 deletions database/database.py
Expand Up @@ -467,10 +467,7 @@ def select_everything_from_users (self):
SELECT * FROM users as u
LEFT OUTER JOIN predicted_user_locations as p
USING(user_id)
WHERE u.user_location IS NOT NULL
AND u.user_lang IS NOT NULL
AND u.user_time_zone IS NOT NULL
AND p.predicted_lat IS NULL
WHERE p.predicted_lat IS NULL
AND p.predicted_long IS NULL;
'''

Expand Down
2 changes: 1 addition & 1 deletion run_algorithm.py
Expand Up @@ -102,7 +102,7 @@ def add_time_zone_layer(user_time_zone, all_layers, statuscode=False):

def main():
db = Database('twitter-geo')
users = db.select_kill_all_newbs()
users = db.select_everything_from_users()
nbr_of_coordinates = 100
found_coordinates = []
i = 0
Expand Down
28 changes: 28 additions & 0 deletions web/database_text_searcher.py
Expand Up @@ -129,6 +129,34 @@ def select_users_with_predicted_coordinates(self):
USING(user_id);
"""

response = []
cur.execute(statement)
rows = cur.fetchall()
for row in rows:
response.append({
'lat': float(row[0]),
'lng': float(row[1]),
'user_id': str(row[2]),
'user_screen_name': str(row[3])
})

self.conn.commit()
cur.close()
return response

def select_all_users_with_more_then_lang_coordinates(self):
cur = self.conn.cursor()
statement = """
SELECT predicted_lat, predicted_long, user_id, user_screen_name
FROM predicted_user_locations
INNER JOIN users USING(user_id)
WHERE user_id NOT IN (
SELECT user_id
FROM users
WHERE user_lang IS NOT NULL
AND user_location IS NULL
AND user_time_zone IS NULL);
"""
response = []
cur.execute(statement)
rows = cur.fetchall()
Expand Down
4 changes: 1 addition & 3 deletions web/server.py
Expand Up @@ -92,9 +92,7 @@ def get_locations():
]

db = Database(DB_NAME)
print ('Getting from db')
data = db.select_users_with_predicted_coordinates()
print(data)
data = db.select_all_users_with_more_then_lang_coordinates()
return jsonify(data)

# {
Expand Down

0 comments on commit 73acdbb

Please sign in to comment.