Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
egl_konnector
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
Container registry
Model registry
Operate
Environments
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
web-et-numerique
Factory
LLLE_Project
egl_konnector
Commits
138a8d94
Commit
138a8d94
authored
1 year ago
by
Rémi PAILHAREY
Browse files
Options
Downloads
Patches
Plain Diff
chore: jsdoc and format
parent
6210f57c
Branches
Branches containing commit
No related tags found
1 merge request
!30
313 aggregation issue
Pipeline
#76603
passed
1 year ago
Stage: test
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/index.js
+40
-15
40 additions, 15 deletions
src/index.js
with
40 additions
and
15 deletions
src/index.js
+
40
−
15
View file @
138a8d94
...
@@ -47,8 +47,9 @@ const rangeDate = {
...
@@ -47,8 +47,9 @@ const rangeDate = {
}
}
module
.
exports
=
new
BaseKonnector
(
start
)
module
.
exports
=
new
BaseKonnector
(
start
)
/**
/**
* Sentry
* Sentry
configuration
*/
*/
Sentry
.
init
({
Sentry
.
init
({
dsn
:
dsn
:
...
@@ -67,9 +68,14 @@ Sentry.init({
...
@@ -67,9 +68,14 @@ Sentry.init({
],
],
})
})
// The start function is run by the BaseKonnector instance only when it got all the account
/**
// information (fields). When you run this connector yourself in 'standalone' mode or 'dev' mode,
* The start function is run by the BaseKonnector instance only when it receives all the account
// the account information come from ./konnector-dev-config.json file
* information (fields). When you run this connector in 'standalone' mode or 'dev' mode,
* the account information comes from the ./konnector-dev-config.json file.
*
* @param {object} fields - The account information fields.
* @param {object} cozyParameters - Cozy platform parameters.
*/
async
function
start
(
fields
,
cozyParameters
)
{
async
function
start
(
fields
,
cozyParameters
)
{
const
transaction
=
Sentry
.
startTransaction
({
const
transaction
=
Sentry
.
startTransaction
({
op
:
'
konnector
'
,
op
:
'
konnector
'
,
...
@@ -93,8 +99,9 @@ async function start(fields, cozyParameters) {
...
@@ -93,8 +99,9 @@ async function start(fields, cozyParameters) {
log
(
'
info
'
,
'
Successfully logged in
'
)
log
(
'
info
'
,
'
Successfully logged in
'
)
const
eglData
=
await
getData
(
response
,
baseUrl
,
apiAuthKey
)
const
eglData
=
await
getData
(
response
,
baseUrl
,
apiAuthKey
)
if
(
eglData
)
{
if
(
eglData
)
{
log
(
'
debug
'
,
'
Process
egl
daily data
'
)
log
(
'
debug
'
,
'
Process
EGL
daily data
'
)
const
filteredDocuments
=
await
hydrateAndFilter
(
const
filteredDocuments
=
await
hydrateAndFilter
(
eglData
,
eglData
,
rangeDate
.
day
.
doctype
,
rangeDate
.
day
.
doctype
,
...
@@ -104,18 +111,18 @@ async function start(fields, cozyParameters) {
...
@@ -104,18 +111,18 @@ async function start(fields, cozyParameters) {
)
)
await
addData
(
filteredDocuments
,
rangeDate
.
day
.
doctype
)
await
addData
(
filteredDocuments
,
rangeDate
.
day
.
doctype
)
log
(
'
debug
'
,
'
Aggregate
egl
monthly load data
'
)
log
(
'
debug
'
,
'
Aggregate
EGL
monthly load data
'
)
const
monthlyLoads
=
aggregateMonthlyLoad
(
eglData
)
const
monthlyLoads
=
aggregateMonthlyLoad
(
eglData
)
log
(
'
debug
'
,
'
Store aggregated
egl
monthly load data
'
)
log
(
'
debug
'
,
'
Store aggregated
EGL
monthly load data
'
)
await
updateOrCreate
(
await
updateOrCreate
(
monthlyLoads
,
monthlyLoads
,
rangeDate
.
month
.
doctype
,
rangeDate
.
month
.
doctype
,
rangeDate
.
month
.
keys
rangeDate
.
month
.
keys
)
)
log
(
'
debug
'
,
'
Aggregate
egl
yearly load data
'
)
log
(
'
debug
'
,
'
Aggregate
EGL
yearly load data
'
)
const
yearlyLoads
=
aggregateYearlyLoad
(
monthlyLoads
)
const
yearlyLoads
=
aggregateYearlyLoad
(
monthlyLoads
)
log
(
'
debug
'
,
'
Store aggregated
egl
yearly load data
'
)
log
(
'
debug
'
,
'
Store aggregated
EGL
yearly load data
'
)
await
updateOrCreate
(
await
updateOrCreate
(
yearlyLoads
,
yearlyLoads
,
rangeDate
.
year
.
doctype
,
rangeDate
.
year
.
doctype
,
...
@@ -124,6 +131,7 @@ async function start(fields, cozyParameters) {
...
@@ -124,6 +131,7 @@ async function start(fields, cozyParameters) {
}
else
{
}
else
{
log
(
'
debug
'
,
'
No data found
'
)
log
(
'
debug
'
,
'
No data found
'
)
}
}
transaction
.
setStatus
(
Tracing
.
SpanStatus
.
Ok
)
transaction
.
setStatus
(
Tracing
.
SpanStatus
.
Ok
)
transaction
.
finish
()
transaction
.
finish
()
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -142,6 +150,13 @@ async function start(fields, cozyParameters) {
...
@@ -142,6 +150,13 @@ async function start(fields, cozyParameters) {
}
}
}
}
/**
* Aggregates the load data by month, summing the load of each day for each month.
*
* @param {FormattedData[]} data - The data to aggregate.
*
* @returns {FormattedData[]} - An array of aggregated data by month.
*/
function
aggregateMonthlyLoad
(
data
)
{
function
aggregateMonthlyLoad
(
data
)
{
const
monthlyLoad
=
{}
const
monthlyLoad
=
{}
...
@@ -167,11 +182,19 @@ function aggregateMonthlyLoad(data) {
...
@@ -167,11 +182,19 @@ function aggregateMonthlyLoad(data) {
return
Object
.
values
(
monthlyLoad
)
return
Object
.
values
(
monthlyLoad
)
}
}
/**
* Aggregates the load data by year, summing the load of each month for each year.
*
* @param {FormattedData[]} data - The data to aggregate.
*
* @returns {FormattedData[]} - An array of aggregated data by year.
*/
function
aggregateYearlyLoad
(
data
)
{
function
aggregateYearlyLoad
(
data
)
{
const
yearlyLoad
=
{}
const
yearlyLoad
=
{}
for
(
const
entry
of
data
)
{
for
(
const
entry
of
data
)
{
const
{
year
,
load
}
=
entry
const
{
year
,
load
}
=
entry
if
(
!
yearlyLoad
[
year
])
{
if
(
!
yearlyLoad
[
year
])
{
yearlyLoad
[
year
]
=
{
yearlyLoad
[
year
]
=
{
load
:
load
,
load
:
load
,
...
@@ -260,7 +283,7 @@ async function authenticate(login, password, baseUrl, apiAuthKey) {
...
@@ -260,7 +283,7 @@ async function authenticate(login, password, baseUrl, apiAuthKey) {
* @typedef {Object} GetDataResponse
* @typedef {Object} GetDataResponse
* @property {number} codeRetour
* @property {number} codeRetour
* @property {string} libelleRetour
* @property {string} libelleRetour
* @property {
Array<
Releve
>
} resultatRetour
* @property {Releve
[]
} resultatRetour
*/
*/
/**
/**
...
@@ -273,12 +296,12 @@ async function authenticate(login, password, baseUrl, apiAuthKey) {
...
@@ -273,12 +296,12 @@ async function authenticate(login, password, baseUrl, apiAuthKey) {
/**
/**
* Retrieves data from a specified API using the provided response data and API configuration.
* Retrieves data from a specified API using the provided response data and API configuration.
*
*
* @param {A
pi
Response} response - The authentication response containing a valid token.
* @param {A
uth
Response} response - The authentication response containing a valid token.
* @param {string} baseUrl - The base URL for the data request.
* @param {string} baseUrl - The base URL for the data request.
* @param {string} apiAuthKey - The API authentication key.
* @param {string} apiAuthKey - The API authentication key.
*
*
* @throws {Error} - Throws an error with an error code in case of data retrieval failure.
* @throws {Error} - Throws an error with an error code in case of data retrieval failure.
* @returns {Promise<FormattedData>} - A promise that resolves to the retrieved and formatted data.
* @returns {Promise<FormattedData
[]
>} - A promise that resolves to the retrieved and formatted data.
*/
*/
async
function
getData
(
response
,
baseUrl
,
apiAuthKey
)
{
async
function
getData
(
response
,
baseUrl
,
apiAuthKey
)
{
const
dataRequest
=
{
const
dataRequest
=
{
...
@@ -304,6 +327,7 @@ async function getData(response, baseUrl, apiAuthKey) {
...
@@ -304,6 +327,7 @@ async function getData(response, baseUrl, apiAuthKey) {
respData
.
resultatRetour
.
sort
(
function
(
a
,
b
)
{
respData
.
resultatRetour
.
sort
(
function
(
a
,
b
)
{
return
new
Date
(
a
.
DateReleve
)
-
new
Date
(
b
.
DateReleve
)
return
new
Date
(
a
.
DateReleve
)
-
new
Date
(
b
.
DateReleve
)
})
})
switch
(
respData
.
codeRetour
)
{
switch
(
respData
.
codeRetour
)
{
case
100
:
case
100
:
return
format
(
respData
)
return
format
(
respData
)
...
@@ -337,6 +361,7 @@ async function getData(response, baseUrl, apiAuthKey) {
...
@@ -337,6 +361,7 @@ async function getData(response, baseUrl, apiAuthKey) {
end
:
endDate
,
end
:
endDate
,
},
},
})
})
if
(
axios
.
isAxiosError
(
error
))
{
if
(
axios
.
isAxiosError
(
error
))
{
throw
new
Error
(
errors
.
VENDOR_DOWN
)
throw
new
Error
(
errors
.
VENDOR_DOWN
)
}
}
...
@@ -363,14 +388,14 @@ async function getData(response, baseUrl, apiAuthKey) {
...
@@ -363,14 +388,14 @@ async function getData(response, baseUrl, apiAuthKey) {
* @param {GetDataResponse} response - The data response to be formatted.
* @param {GetDataResponse} response - The data response to be formatted.
*
*
* @throws {Error} - Throws an error with an error code in case of data processing failure.
* @throws {Error} - Throws an error with an error code in case of data processing failure.
* @returns {
Array<
FormattedData
>
} - An array of formatted data objects.
* @returns {FormattedData
[]
} - An array of formatted data objects.
*/
*/
function
format
(
response
)
{
function
format
(
response
)
{
log
(
'
info
'
,
'
origin response size is:
'
+
response
.
resultatRetour
.
length
)
log
(
'
info
'
,
'
origin response size is:
'
+
response
.
resultatRetour
.
length
)
// Store first value as reference for index processing
// Store first value as reference for index processing
let
refValue
=
response
.
resultatRetour
[
0
]
let
refValue
=
response
.
resultatRetour
[
0
]
// Create copy of data without first value
// Create
a
copy of data without
the
first value
const
data
=
response
.
resultatRetour
const
data
=
response
.
resultatRetour
.
slice
(
1
)
.
slice
(
1
)
.
filter
(
value
=>
value
.
ValeurIndex
)
.
filter
(
value
=>
value
.
ValeurIndex
)
...
@@ -392,7 +417,7 @@ function format(response) {
...
@@ -392,7 +417,7 @@ function format(response) {
throw
errors
.
VENDOR_DOWN
throw
errors
.
VENDOR_DOWN
}
}
// Change index ref value
// Change
the
index ref
erence
value
refValue
=
value
refValue
=
value
return
{
return
{
...
...
This diff is collapsed.
Click to expand it.
Rémi PAILHAREY
@rpailharey
mentioned in commit
3f035b0d
·
1 year ago
mentioned in commit
3f035b0d
mentioned in commit 3f035b0d14c9c6779d431614fd0e0e57212a91c0
Toggle commit list
Rémi PAILHAREY
@rpailharey
mentioned in commit
8631f233
·
1 year ago
mentioned in commit
8631f233
mentioned in commit 8631f233c715285944cb26eb5d223c139dd38b47
Toggle commit list
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