Skip to content

Commit 8e7526e

Browse files
committed
Merge branch 'benni.new-project-types' of https://github.com/mapswipe/python-mapswipe-workers into benni.new-project-types
2 parents 2938256 + 0c735af commit 8e7526e

File tree

3 files changed

+70
-10
lines changed

3 files changed

+70
-10
lines changed

tests/test_export_old_projects.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from mapswipe_workers.basic import BaseFunctions
2+
3+
def test_export_old_projects():
4+
5+
project_ids = [3, 124, 5519, 13523]
6+
BaseFunctions.run_export('production', project_ids)
7+
8+
9+
if __name__ == '__main__':
10+
test_export_old_projects()

tests/test_mock_results.py

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import time
33
import pickle
44
from mapswipe_workers.basic import BaseFunctions
5-
5+
import requests
6+
import json
67

78
def create_build_area_result_in_firebase(
89
project_id,
@@ -58,8 +59,10 @@ def simulate_user_contributions(
5859

5960
# get groups from firebase for this project
6061
fb_db = firebase.database()
61-
groups = fb_db.child("groups").child(project_id).order_by_child("completedCount").limit_to_first(5).get()
6262

63+
# temporary workaround because of faulty string encoding
64+
'''
65+
groups = fb_db.child("groups").child(project_id).order_by_child("completedCount").limit_to_first(5).get()
6366
for group in groups.each():
6467
group_id = group.key()
6568
val = group.val()
@@ -87,11 +90,53 @@ def simulate_user_contributions(
8790
firebase,
8891
)
8992
print("created footprint results in firebase")
90-
93+
9194
# update groups completed count
9295
old_completed_count = fb_db.child("groups").child(project_id).child(group_id).child("completedCount").get().val()
9396
fb_db.child("groups").child(project_id).child(group_id).update({"completedCount":old_completed_count+1})
9497
print("updated completed count")
98+
'''
99+
100+
firebase_instance = 'dev-mapswipe'
101+
groups_url = 'https://{firebase_instance}.firebaseio.com/groups/{project_id}.json?orderBy=%22completedCount%22&limitToFirst=5'.format(
102+
project_id=project_id,
103+
firebase_instance=firebase_instance
104+
)
105+
106+
groups = json.loads(requests.get(groups_url).text)
107+
for group_id in groups.keys():
108+
109+
val = groups[group_id]
110+
tasks = val['tasks']
111+
task_ids = tasks.keys()
112+
113+
if project_type == 1:
114+
count = val['count']
115+
random_sample = random.sample(task_ids, int(count / 2))
116+
for task_id in random_sample:
117+
create_build_area_result_in_firebase(
118+
project_id,
119+
task_id,
120+
user_id,
121+
firebase,
122+
)
123+
print("created build area results in firebase")
124+
elif project_type == 2:
125+
for task_id in task_ids:
126+
create_footprint_result_in_firebase(
127+
project_id,
128+
task_id,
129+
user_id,
130+
firebase,
131+
)
132+
print("created footprint results in firebase")
133+
134+
# update groups completed count
135+
old_completed_count = fb_db.child("groups").child(project_id).child(group_id).child(
136+
"completedCount").get().val()
137+
fb_db.child("groups").child(project_id).child(group_id).update({"completedCount": old_completed_count + 1})
138+
print("updated completed count")
139+
95140

96141

97142
if __name__ == '__main__':
@@ -103,10 +148,5 @@ def simulate_user_contributions(
103148
imported_projects = pickle.load(f)
104149

105150
# Generate mock results for first two of the imported projects
106-
project_id = imported_projects[0][1]
107-
project_type = imported_projects[0][1]
108-
simulate_user_contributions(project_id, project_type, modus)
109-
110-
project_id = imported_projects[1][1]
111-
project_type = imported_projects[1][1]
112-
simulate_user_contributions(project_id, project_type, modus)
151+
for import_key, project_id, project_type in imported_projects:
152+
simulate_user_contributions(project_id, project_type, modus)

tests/test_update_old_projects.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from mapswipe_workers.basic import BaseFunctions
2+
3+
def test_update_old_projects():
4+
5+
project_ids = [3, 124, 5519, 13523]
6+
BaseFunctions.run_update('production', project_ids)
7+
8+
9+
if __name__ == '__main__':
10+
test_update_old_projects()

0 commit comments

Comments
 (0)