Skip to content

Commit df8e720

Browse files
committed
sort projects by projectNumber
1 parent 3171378 commit df8e720

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

mapswipe_workers/python_scripts/update_project_status.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
import time
3-
from typing import List
3+
from typing import List, OrderedDict
44

55
import schedule as sched
66

@@ -9,7 +9,7 @@
99
from mapswipe_workers.utils.slack_helper import send_slack_message
1010

1111

12-
def get_projects(status: str) -> dict:
12+
def get_projects(status: str) -> OrderedDict:
1313
"""Load 'active' projects from Firebase."""
1414
fb_db = firebaseDB()
1515
projects = (
@@ -20,7 +20,7 @@ def get_projects(status: str) -> dict:
2020

2121

2222
def filter_projects_by_name_and_progress(
23-
projects: dict, filter_string: str, progress_threshold: int
23+
projects: OrderedDict, filter_string: str, progress_threshold: int
2424
) -> List[str]:
2525
"""Filter projects by name (lowercase) and progress."""
2626
selected_project_ids = []
@@ -62,6 +62,12 @@ def run_update_project_status(filter_string: str) -> None:
6262
)
6363

6464
inactive_projects = get_projects(status="inactive")
65+
# We sort projects by their attribute "projectNumber" to ensure that
66+
# always the lowest one will be set to "status=active" next.
67+
inactive_projects = OrderedDict(
68+
sorted(inactive_projects.items(), key=lambda x: x[1]["projectNumber"])
69+
)
70+
6571
new_active_projects = filter_projects_by_name_and_progress(
6672
inactive_projects, filter_string, progress_threshold=0,
6773
)[0 : len(finished_projects)]

0 commit comments

Comments
 (0)