Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/mapping/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ def get_client_type(cls, value: str) -> "MappingSessionClientTypeEnum":
"web": cls.WEB,
}.get(value, cls.UNKNOWN)

@classmethod
def get_client_type_label_sql(cls, field: str) -> str:
return f"""
CASE {field}
WHEN {cls.MOBILE_ANDROID.value} THEN 'android'
WHEN {cls.MOBILE_IOS.value} THEN 'ios'
WHEN {cls.WEB.value} THEN 'web'
ELSE 'unknown'
END
"""


class MappingSession(models.Model):
"""Model representing a mapping session where a contributor user worked on a specific project task group."""
Expand Down
6 changes: 4 additions & 2 deletions apps/project/exports/mapping_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from apps.contributor.models import ContributorUser
from apps.mapping.models import (
MappingSession,
MappingSessionClientTypeEnum,
MappingSessionResult,
)
from apps.project.models import Project, ProjectTask, ProjectTaskGroup
Expand All @@ -19,7 +20,6 @@


def generate_mapping_results(*, destination_filename: Path, project: Project) -> pd.DataFrame:
# TODO: client_type IS ENUM -- CONVERT TO VALUE?
sql_query = sql.SQL(f"""
COPY (
SELECT
Expand All @@ -38,7 +38,9 @@ def generate_mapping_results(*, destination_filename: Path, project: Project) ->
MS.{fd_name(MappingSession.start_time)} as start_time,
MS.{fd_name(MappingSession.end_time)} as end_time,
MS.{fd_name(MappingSession.app_version)} as app_version,
MS.{fd_name(MappingSession.client_type)} as client_type,
(
{MappingSessionClientTypeEnum.get_client_type_label_sql(f"MS.{fd_name(MappingSession.client_type)}")}
) as client_type,
MSR.{fd_name(MappingSessionResult.result)} as result,
-- the username for users which login to MapSwipe with their
-- OSM account is not defined or ''.
Expand Down
2 changes: 1 addition & 1 deletion apps/project/exports/project_stats_by_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,6 @@ def get_project_history(

# merge contributors and progress
project_history_df = progress_by_date_df.merge(contributors_by_date_df, left_on="day", right_on="day")
project_history_df["project_id"] = project.id
project_history_df["project_id"] = project.firebase_id
project_history_df.to_csv(destination_filename)
return project_history_df
3 changes: 2 additions & 1 deletion apps/project/exports/project_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def generate_project_tasks(
PTG.{fd_name(ProjectTaskGroup.firebase_id)} as group_id,
PT.{fd_name(ProjectTask.firebase_id)} as task_id,
-- Metadata
ST_AsText({fd_name(ProjectTask.geometry)}) AS geom,
-- NOTE: Using ST_Multi only to make the exports backward compatible with previous exports
ST_AsText(ST_Multi({fd_name(ProjectTask.geometry)})) AS geom,
'{project.project_type_specifics.get("zoom_level")}' as tile_z,
-- NOTE: Existing tile_x and tile_y are passed from project_type_specifics now
-- NOTE: this is destructured by normalize_project_type_specifics(write_sql_to_gzipped_csv)
Expand Down
9 changes: 6 additions & 3 deletions apps/project/exports/tasking_manager_geometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ def _get_row_value[T: int | float](

task_id = row[1]

task_x = _get_row_value(column_index_map, row, "task_x")
task_y = _get_row_value(column_index_map, row, "task_y")
task_z = _get_row_value(column_index_map, row, "task_z")
# TODO: rename all task_N to tile_N
task_x = _get_row_value(column_index_map, row, "tile_x")
task_y = _get_row_value(column_index_map, row, "tile_y")
task_z = _get_row_value(column_index_map, row, "tile_z")

# TODO: Add no_count here and use later
project_data.append(
Expand Down Expand Up @@ -108,6 +109,8 @@ def _get_row_value[T: int | float](
task_x,
task_y,
task_z,
# NOTE: We do not flatten to 2D only for backwards compatibility
skip_flatten=True,
),
},
)
Expand Down
2 changes: 1 addition & 1 deletion apps/project/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ def send_slack_message_for_project(project_id: int, action: Literal["progress-ch
update_base_slack_message(client=mapslack, project=project, ts=base_slack_message_ts)
if action == "progress-change":
project.slack_progress_notifications = project.progress
project.save(update_fields=["slack_message_notifications"])
project.save(update_fields=["slack_progress_notifications"])
Loading
Loading