Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tracemob
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
POCS
cozy
tracemob
Commits
dfd10d06
Commit
dfd10d06
authored
4 years ago
by
paultranvan
Browse files
Options
Downloads
Patches
Plain Diff
fix: Avoid duplicates
parent
10cf73ec
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/index.js
+2
-1
2 additions, 1 deletion
src/index.js
src/lib.js
+6
-3
6 additions, 3 deletions
src/lib.js
src/timeseries.js
+14
-2
14 additions, 2 deletions
src/timeseries.js
with
22 additions
and
6 deletions
src/index.js
+
2
−
1
View file @
dfd10d06
...
...
@@ -57,7 +57,8 @@ async function start(fields) {
try
{
/* Fetch new trips from the start date and save them in geojson doctype */
const
lastSavedTripDate
=
await
fetchAndSaveTrips
(
token
,
startDate
,
{
excludeFirst
:
!
firstRun
excludeFirst
:
!
firstRun
,
accountId
:
this
.
accountId
})
if
(
lastSavedTripDate
)
{
log
(
'
info
'
,
`Save last trip date :
${
lastSavedTripDate
}
`
)
...
...
This diff is collapsed.
Click to expand it.
src/lib.js
+
6
−
3
View file @
dfd10d06
...
...
@@ -7,7 +7,10 @@ const {
getServerCollectionFromDate
,
getTripsForDay
}
=
require
(
'
./trace-requests
'
)
const
{
saveTrip
,
updateTripsWithManualEntries
}
=
require
(
'
./timeseries.js
'
)
const
{
saveTripForAccount
,
updateTripsWithManualEntries
}
=
require
(
'
./timeseries.js
'
)
function
filterTripsByDate
(
trips
,
tripStartDates
)
{
return
trips
.
filter
(
trip
=>
{
...
...
@@ -26,7 +29,7 @@ function filterTripsByDate(trips, tripStartDates) {
module
.
exports
.
fetchAndSaveTrips
=
async
function
(
token
,
startDate
,
{
excludeFirst
=
true
}
{
excludeFirst
=
true
,
accountId
}
)
{
/* Extract the days having saved trips */
log
(
'
info
'
,
`Fetch trips metadata from
${
startDate
.
toISOString
()}
`
)
...
...
@@ -59,7 +62,7 @@ module.exports.fetchAndSaveTrips = async function(
/* Save the trips in database */
const
savePromises
=
tripsToSave
.
map
(
async
trip
=>
{
return
new
Promise
(
resolve
=>
resolve
(
saveTrip
(
trip
)))
return
new
Promise
(
resolve
=>
resolve
(
saveTrip
ForAccount
(
accountId
,
trip
)))
})
log
(
'
info
'
,
`Save
${
savePromises
.
length
}
trips`
)
await
Promise
.
all
(
savePromises
)
...
...
This diff is collapsed.
Click to expand it.
src/timeseries.js
+
14
−
2
View file @
dfd10d06
...
...
@@ -25,8 +25,20 @@ async function findSavedTripByDates(startDate, endDate) {
return
trips
.
data
.
length
>
0
?
trips
.
data
[
0
]
:
null
}
async
function
isTripInDatabaseForAccount
(
accountId
,
trip
)
{
const
startDate
=
trip
.
properties
.
start_fmt_time
const
endDate
=
trip
.
properties
.
end_fmt_time
const
tripInDb
=
await
findSavedTripByDates
(
startDate
,
endDate
)
return
tripInDb
&&
tripInDb
.
cozyMetadata
.
sourceAccount
===
accountId
}
// TODO: use saveTimeSeries from cozy-client models
const
saveTrip
=
async
function
(
trip
)
{
const
saveTripForAccount
=
async
function
(
accountId
,
trip
)
{
const
tripInDb
=
await
isTripInDatabaseForAccount
(
accountId
,
trip
)
if
(
tripInDb
)
{
// Avoid duplicates for the same account
return
}
const
startDate
=
trip
.
properties
.
start_fmt_time
const
endDate
=
trip
.
properties
.
end_fmt_time
const
timeserie
=
{
...
...
@@ -60,6 +72,6 @@ async function updateTripsWithManualEntries(manualEntries, { entryKey }) {
}
module
.
exports
=
{
saveTrip
,
saveTrip
ForAccount
,
updateTripsWithManualEntries
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment