Skip to content

Commit

Permalink
Merge pull request #978 from mapswipe/dev
Browse files Browse the repository at this point in the history
Release - 2024 October
  • Loading branch information
thenav56 authored Oct 30, 2024
2 parents 62310b0 + 7485e42 commit 0f8a455
Show file tree
Hide file tree
Showing 23 changed files with 152 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ function HeatmapComponent(props: HeatmapComponentProps) {
const map = useMap();

useEffect(() => {
map.gestureHandling.enable();
// NOTE: We need to cast type of map here because of how gesture handle plugin works
type MapWithGestureHandle = typeof map & { gestureHandling: { enable: () => void }};
(map as MapWithGestureHandle).gestureHandling.enable();
}, [map]);

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions community-dashboard/app/components/ItemSelectInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
IoPeople,
IoSearch,
} from 'react-icons/io5';
import { _cs } from '@togglecorp/fujs';
import { isFalsyString, _cs } from '@togglecorp/fujs';
import {
useQuery,
gql,
Expand Down Expand Up @@ -192,7 +192,7 @@ function ItemSelectInput<Name extends string>(props: ItemSelectInputProps<Name>)
() => ([
...(usersData?.map((user) => ({
id: user.userId,
name: user.username ?? 'Unknown',
name: (isFalsyString(user.username) ? user.userId : user.username),
type: 'user' as const,
})) ?? []),
...(userGroupsData?.map((userGroup) => ({
Expand Down
9 changes: 6 additions & 3 deletions community-dashboard/app/components/MemberItem/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Link, generatePath } from 'react-router-dom';
import { isDefined } from '@togglecorp/fujs';
import { isDefined, isFalsyString } from '@togglecorp/fujs';

import NumberOutput from '#components/NumberOutput';
import routes from '#base/configs/routes';
Expand All @@ -13,7 +13,7 @@ interface Props {
totalMappingProjects: number;
totalSwipeTime: number;
totalSwipes: number;
username: string;
username?: string | null;
userId: string;
isActive: boolean;
};
Expand All @@ -27,14 +27,17 @@ function MemberItem(props: Props) {
{ userId: member.userId },
);

// NOTE: OSM user does not have username stored
const memberName = isFalsyString(member.username) ? member.userId : member.username;

return (
<div className={styles.member}>
<div className={styles.memberName}>
<Link
className={styles.link}
to={path}
>
{member.username}
{memberName}
</Link>
{!member.isActive && (
<div className={styles.inactive}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function SearchSelectInput<
);

const optionRendererParamsDefault = useCallback(
(key: T, option: O) => {
(key: T, option: O): P => {
const isActive = key === value;

return {
Expand Down
17 changes: 14 additions & 3 deletions community-dashboard/app/views/UserDashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import React, { useMemo } from 'react';
import { gql, useQuery } from '@apollo/client';
import { encodeDate } from '@togglecorp/fujs';
import { encodeDate, isDefined, isFalsyString } from '@togglecorp/fujs';
import { useParams, generatePath, Link } from 'react-router-dom';

import useUrlState from '#hooks/useUrlState';
Expand Down Expand Up @@ -181,11 +181,22 @@ function UserDashboard(props: Props) {

const filteredStats = filteredUserStats?.userStats?.filteredStats;

// NOTE: OSM user does not have username stored
const userName = useMemo(() => {
if (isDefined(userStats) && isDefined(userStats.user)) {
return isFalsyString(userStats.user.username)
? userStats.user.userId
: userStats.user.username;
}

return null;
}, [userStats]);

return (
<Page
className={className}
variant="user"
heading={userStats?.user.username}
heading={userName}
totalSwipes={totalSwipes}
totalSwipesLastMonth={totalSwipesLastMonth}
totalTimeSpent={totalSwipeTime}
Expand Down
6 changes: 3 additions & 3 deletions community-dashboard/app/views/UserGroupDashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useMemo, useState } from 'react';
import { gql, useQuery, useLazyQuery } from '@apollo/client';
import { encodeDate } from '@togglecorp/fujs';
import { encodeDate, isFalsyString } from '@togglecorp/fujs';
import { useParams } from 'react-router-dom';

import StatsBoard from '#views/StatsBoard';
Expand Down Expand Up @@ -137,7 +137,7 @@ const USER_MEMBERSHIPS_EXPORT = gql`
type UserGroupMember = NonNullable<NonNullable<NonNullable<UserGroupStatsQuery['userGroup']>['userMemberships']>['items']>[number];

function memberKeySelector(member: UserGroupMember) {
return member.username;
return member.userId;
}

interface DateRangeValue {
Expand Down Expand Up @@ -239,7 +239,7 @@ function UserGroupDashboard(props: Props) {
['User', 'Total swipes', 'Project contributed', 'Time spent(mins)'],
...(newUserMembershipsData?.map((user) => (
[
user.username,
isFalsyString(user.username) ? user.userId : user.username,
user.totalSwipes,
user.totalMappingProjects,
user.totalSwipeTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Migration(migrations.Migration):
("start_time", models.DateTimeField(blank=True, null=True)),
("end_time", models.DateTimeField(blank=True, null=True)),
("items_count", models.SmallIntegerField(default=0)),
("app_version", models.CharField(max_length=999)),
("client_type", models.CharField(max_length=999)),
],
options={
"db_table": "mapping_sessions",
Expand Down
2 changes: 2 additions & 0 deletions django/apps/existing_database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ class MappingSession(Model):
start_time = models.DateTimeField(blank=True, null=True)
end_time = models.DateTimeField(blank=True, null=True)
items_count = models.SmallIntegerField(null=False, default=0)
app_version = models.CharField(max_length=999)
client_type = models.CharField(max_length=999)

class Meta:
managed = False
Expand Down
4 changes: 2 additions & 2 deletions django/apps/existing_database/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class UserGroupLatestStatsType:
@strawberry.type
class UserGroupUserStatsType:
user_id: str
username: str
username: str | None
total_mapping_projects: int
total_swipes: int
total_swipe_time: TimeInSeconds
Expand Down Expand Up @@ -545,7 +545,7 @@ async def id(self, info: Info, root: UserGroup) -> strawberry.ID:
class UserGroupUserMembershipType:
id: strawberry.ID
user_id: str
username: str
username: str | None
is_active: bool
# Stats
total_mapping_projects: int
Expand Down
4 changes: 2 additions & 2 deletions django/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ type UserGroupTypeCountList {
type UserGroupUserMembershipType {
id: ID!
userId: String!
username: String!
username: String
isActive: Boolean!
totalMappingProjects: Int!
totalSwipes: Int!
Expand All @@ -241,7 +241,7 @@ type UserGroupUserMembershipTypeCountList {

type UserGroupUserStatsType {
userId: String!
username: String!
username: String
totalMappingProjects: Int!
totalSwipes: Int!
totalSwipeTime: TimeInSeconds!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ def results_to_file(
start_time = dateutil.parser.parse(result_data["startTime"])
end_time = dateutil.parser.parse(result_data["endTime"])
timestamp = end_time
app_version = result_data.get("appVersion", "")
client_type = result_data.get("clientType", "")

if type(result_data["results"]) is dict:
for taskId, result in result_data["results"].items():
Expand All @@ -279,6 +281,8 @@ def results_to_file(
start_time,
end_time,
result,
app_version,
client_type,
]
)
elif type(result_data["results"]) is list:
Expand All @@ -303,6 +307,8 @@ def results_to_file(
start_time,
end_time,
result,
app_version,
client_type,
]
)
else:
Expand Down Expand Up @@ -361,6 +367,8 @@ def save_results_to_postgres(
"start_time",
"end_time",
"result",
"app_version",
"client_type",
]
p_con.copy_from(results_file, result_temp_table, columns)
results_file.close()
Expand Down Expand Up @@ -420,9 +428,11 @@ def save_results_to_postgres(
nextval('mapping_sessions_mapping_session_id_seq'),
min(start_time),
max(end_time),
count(*)
count(*),
app_version,
client_type
FROM {result_temp_table}
GROUP BY project_id, group_id, user_id
GROUP BY project_id, group_id, user_id, app_version, client_type
ON CONFLICT (project_id,group_id,user_id)
DO NOTHING;
INSERT INTO {result_table}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def get_results(
ms.start_time as timestamp,
ms.start_time,
ms.end_time,
ms.app_version,
ms.client_type,
{result_sql},
-- the username for users which login to MapSwipe with their
-- OSM account is not defined or ''.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
from dataclasses import asdict, dataclass

from mapswipe_workers.definitions import logger
from mapswipe_workers.project_types.tile_map_service.tutorial import (
TileMapServiceBaseTutorial,
TileMapServiceBaseTutorialTask,
)
from mapswipe_workers.project_types.tile_server import BaseTileServer
from mapswipe_workers.utils import tile_functions


@dataclass
class ChangeDetectionTutorialTask(TileMapServiceBaseTutorialTask):
urlB: str


class ChangeDetectionTutorial(TileMapServiceBaseTutorial):
"""The subclass for an TMS Grid based Tutorial."""

Expand Down Expand Up @@ -36,11 +44,16 @@ def create_tutorial_tasks(self):

super().create_tutorial_tasks()

modified_tasks = []
for task in self.tasks[101]:
_, tile_x, tile_y = task.taskId_real.split("-")
task.urlB = tile_functions.tile_coords_zoom_and_tileserver_to_url(
urlB = tile_functions.tile_coords_zoom_and_tileserver_to_url(
int(tile_x), int(tile_y), self.zoomLevel, self.tileServerB
)
modified_tasks.append(
ChangeDetectionTutorialTask(**asdict(task), urlB=urlB)
)
self.tasks[101] = modified_tasks

logger.info(
f"{self.projectId}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
from dataclasses import asdict, dataclass

from mapswipe_workers.definitions import logger
from mapswipe_workers.project_types.tile_map_service.tutorial import (
TileMapServiceBaseTutorial,
TileMapServiceBaseTutorialTask,
)
from mapswipe_workers.project_types.tile_server import BaseTileServer
from mapswipe_workers.utils import tile_functions


@dataclass
class CompletenessTutorialTask(TileMapServiceBaseTutorialTask):
urlB: str


class CompletenessTutorial(TileMapServiceBaseTutorial):
"""The subclass for an TMS Grid based Tutorial."""

Expand Down Expand Up @@ -36,11 +44,14 @@ def create_tutorial_tasks(self):

super().create_tutorial_tasks()

modified_tasks = []
for task in self.tasks[101]:
_, tile_x, tile_y = task.taskId_real.split("-")
task.urlB = tile_functions.tile_coords_zoom_and_tileserver_to_url(
urlB = tile_functions.tile_coords_zoom_and_tileserver_to_url(
int(tile_x), int(tile_y), self.zoomLevel, self.tileServerB
)
modified_tasks.append(CompletenessTutorialTask(**asdict(task), urlB=urlB))
self.tasks[101] = modified_tasks

logger.info(
f"{self.projectId}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Dict, List
from typing import Dict, List, Union

from mapswipe_workers.definitions import logger
from mapswipe_workers.firebase.firebase import Firebase
Expand All @@ -25,8 +25,8 @@ class TileMapServiceBaseTutorial(BaseTutorial):
def __init__(self, tutorial_draft):
super().__init__(tutorial_draft)

self.groups: Dict[str, TileMapServiceBaseGroup] = {}
self.tasks: Dict[str, List[TileMapServiceBaseTutorialTask]] = (
self.groups: Dict[Union[str, int], TileMapServiceBaseGroup] = {}
self.tasks: Dict[Union[str, int], List[TileMapServiceBaseTutorialTask]] = (
{}
) # dict keys are group ids

Expand Down
4 changes: 2 additions & 2 deletions mapswipe_workers/mapswipe_workers/utils/api_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def remove_noise_and_add_user_info(json: dict) -> dict:
for i, subset in enumerate(chunk_list):
changeset_results = query_osmcha(subset, changeset_results)
progress = round(100 * ((i + 1) / len(chunk_list)), 1)
logger.info(f"finished query {i+1}/{len(chunk_list)}, {progress}")
logger.info(f"finished query {i + 1}/{len(chunk_list)}, {progress}")

missing_ids = [i for i, v in changeset_results.items() if v is None]
chunk_list = chunks(missing_ids, batch_size)
Expand All @@ -160,7 +160,7 @@ def remove_noise_and_add_user_info(json: dict) -> dict:
for i, subset in enumerate(chunk_list):
changeset_results = query_osm(subset, changeset_results)
progress = round(100 * ((i + 1) / len(chunk_list)), 1)
logger.info(f"finished query {i+1}/{len(chunk_list)}, {progress}")
logger.info(f"finished query {i + 1}/{len(chunk_list)}, {progress}")

for feature in json["features"]:
changeset = changeset_results[int(feature["properties"]["changesetId"])]
Expand Down
10 changes: 9 additions & 1 deletion mapswipe_workers/tests/integration/set_up.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ def create_test_project(
set_postgres_test_data(project_type, "users", "user")
set_firebase_test_data(project_type, "user_groups", "user_group", "")
set_firebase_test_data(project_type, "results", fixture_name, project_id)
set_postgres_test_data(project_type, "mapping_sessions", fixture_name)
set_postgres_test_data(project_type, "mapping_sessions", fixture_name, columns=[
"project_id",
"group_id",
"user_id",
"mapping_session_id",
"start_time",
"end_time",
"items_count",
])
set_postgres_test_data(project_type, mapping_sessions_results, fixture_name)
if create_user_group_session_data:
set_postgres_test_data(
Expand Down
Loading

0 comments on commit 0f8a455

Please sign in to comment.