From b399c6d659d5f2808ed86496541324f17217a06d Mon Sep 17 00:00:00 2001 From: Paul Tran-Van Date: Wed, 14 Feb 2024 17:13:25 +0100 Subject: [PATCH 1/2] feat: Improve tracking logs We met a weird user re-creation. To clarify the user situation, we add some logs --- src/app/domain/geolocation/tracking/index.js | 4 +++- src/app/domain/geolocation/tracking/tracking.js | 4 +++- src/app/domain/geolocation/tracking/user.js | 14 +++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/app/domain/geolocation/tracking/index.js b/src/app/domain/geolocation/tracking/index.js index 9191cc698..c845f4ca5 100644 --- a/src/app/domain/geolocation/tracking/index.js +++ b/src/app/domain/geolocation/tracking/index.js @@ -25,12 +25,12 @@ import { WALKING_ACTIVITY, LOW_CONFIDENCE_THRESHOLD } from '/app/domain/geolocation/tracking/consts' +import { getOrCreateId } from '/app/domain/geolocation/tracking/user' export { Log, getAllLogs, sendLogFile } from '/app/domain/geolocation/helpers' export { getOrCreateId, updateId } from '/app/domain/geolocation/tracking/user' export { uploadData } from '/app/domain/geolocation/tracking/upload' export { GeolocationTrackingHeadlessTask } from '/app/domain/geolocation/tracking/headless' export { storeFetchServiceWebHook } from '/app/domain/geolocation/tracking/storage' -import { getOrCreateId } from '/app/domain/geolocation/tracking/user' export { clearAllCozyGPSMemoryData, @@ -228,6 +228,8 @@ export const startOpenPathUploadAndPipeline = async ({ }) => { try { const user = await getOrCreateId() + Log(`User: ${JSON.stringify(user)}`) + // Upload data to openpath server const uploadedCount = await uploadData(user, { untilTs, force }) if (uploadedCount >= 0) { diff --git a/src/app/domain/geolocation/tracking/tracking.js b/src/app/domain/geolocation/tracking/tracking.js index 94da49c5c..808cc05d0 100644 --- a/src/app/domain/geolocation/tracking/tracking.js +++ b/src/app/domain/geolocation/tracking/tracking.js @@ -483,7 +483,9 @@ export const getFilteredActivities = async ({ beforeTs, locations }) => { if (isMovingStillActivity(loc) || isUnknownActivity(loc)) { // Avoid unknown or "moving" still activities location.activity.type = inferMotionActivity(loc) - Log('Changed ' + loc.activity.type + ' to: ' + location.activity.type) + if (loc.activity.type !== location.activity.type) { + Log('Changed ' + loc.activity.type + ' to: ' + location.activity.type) + } } return translateEventToEMissionMotionActivity(location) }) diff --git a/src/app/domain/geolocation/tracking/user.js b/src/app/domain/geolocation/tracking/user.js index b5ec8e182..bea6453f0 100644 --- a/src/app/domain/geolocation/tracking/user.js +++ b/src/app/domain/geolocation/tracking/user.js @@ -26,6 +26,9 @@ export const getOrCreateId = async () => { } export const createUser = async user => { + Log( + `Request openpath server to create new user with id ${JSON.stringify(user)}` + ) let response = await fetch(SERVER_URL + '/profile/create', { method: 'POST', headers: { @@ -38,7 +41,12 @@ export const createUser = async user => { throw new Error('FAILED_EMISSION_USER_CREATION') // Could be no Internet, offline server or unknown issue. Won't trigger if user already exists. } else { const jsonTokenResponse = await response.json() - Log('Success creating user ' + user + ', UUID: ' + jsonTokenResponse.uuid) + Log( + 'Success creating user ' + + JSON.stringify(user) + + ', UUID: ' + + jsonTokenResponse.uuid + ) } } @@ -53,15 +61,19 @@ export const getOrCreateUser = async user => { body: JSON.stringify({ user: user }) }) if (respFetch.status === 403) { + Log("No openpath user found, let's create one.") return createUser(user) } response = await respFetch.json() const uuid = response?.user_id?.['$uuid'] if (!uuid) { + Log("No openpath uuid found, let's create the user.") await createUser(user) } return uuid } catch (err) { + // If the user actually exist, the creation will return the existing user + Log(`Error when trying to get openpath user, let's create one`) return createUser(user) } } From b9c63a8fceb0c6ee1ef68bcbe0d7ed035183930e Mon Sep 17 00:00:00 2001 From: Paul Tran-Van Date: Wed, 14 Feb 2024 17:25:02 +0100 Subject: [PATCH 2/2] refactor: Clarify func name --- src/app/domain/geolocation/tracking/tracking.js | 4 ++-- src/app/domain/geolocation/tracking/user.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/domain/geolocation/tracking/tracking.js b/src/app/domain/geolocation/tracking/tracking.js index 808cc05d0..fc968e32b 100644 --- a/src/app/domain/geolocation/tracking/tracking.js +++ b/src/app/domain/geolocation/tracking/tracking.js @@ -1,5 +1,5 @@ import { uploadUserCache } from '/app/domain/geolocation/tracking/upload' -import { getOrCreateUser } from '/app/domain/geolocation/tracking/user' +import { createOpenPathUserIfMissing } from '/app/domain/geolocation/tracking/user' import { getTs, Log, parseISOString } from '/app/domain/geolocation/helpers' import { getActivities, @@ -57,7 +57,7 @@ export const uploadTrackingData = async ( user, { force = false } = {} ) => { - await getOrCreateUser(user) + await createOpenPathUserIfMissing(user) if (!locations || locations.length === 0) { Log('No new locations') diff --git a/src/app/domain/geolocation/tracking/user.js b/src/app/domain/geolocation/tracking/user.js index bea6453f0..02920f233 100644 --- a/src/app/domain/geolocation/tracking/user.js +++ b/src/app/domain/geolocation/tracking/user.js @@ -50,7 +50,7 @@ export const createUser = async user => { } } -export const getOrCreateUser = async user => { +export const createOpenPathUserIfMissing = async user => { let response try { const respFetch = await fetch(SERVER_URL + '/profile/get', {