diff --git a/database/database.py b/database/database.py index 11409b8..6558df8 100644 --- a/database/database.py +++ b/database/database.py @@ -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; ''' diff --git a/run_algorithm.py b/run_algorithm.py index 0844d7c..5e9070c 100644 --- a/run_algorithm.py +++ b/run_algorithm.py @@ -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 diff --git a/web/database_text_searcher.py b/web/database_text_searcher.py index 34678d5..2336b71 100644 --- a/web/database_text_searcher.py +++ b/web/database_text_searcher.py @@ -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() diff --git a/web/server.py b/web/server.py index 67f2d5c..f5b80d8 100644 --- a/web/server.py +++ b/web/server.py @@ -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) # {