Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
enedis_sge_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
enedis_sge_konnector
Commits
af1d4c91
Commit
af1d4c91
authored
1 year ago
by
Rémi PAILHAREY
Browse files
Options
Downloads
Patches
Plain Diff
feat: get off-peak hours and store them in account data
parent
aa9b2674
No related branches found
No related tags found
1 merge request
!52
feat: off-peak hours ratio
Pipeline
#91364
passed
1 year ago
Stage: test
Stage: build
Stage: update-instances
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/helpers/parsing.js
+26
-0
26 additions, 0 deletions
src/helpers/parsing.js
src/index.js
+68
-0
68 additions, 0 deletions
src/index.js
with
94 additions
and
0 deletions
src/helpers/parsing.js
+
26
−
0
View file @
af1d4c91
...
...
@@ -29,6 +29,31 @@ function parseUserAddress(result) {
][
'
point
'
][
'
donneesGenerales
'
][
'
adresseInstallation
'
]
}
/**
* Return User off-peak hours
* @param {string} result
* @returns {string}
* @example "3H00-8H00;13H30-16H30"
*/
function
parseUserOffPeakHours
(
result
)
{
log
(
'
info
'
,
'
Parsing user off-peak hours
'
)
const
json
=
JSON
.
stringify
(
result
)
const
rawOffPeakHours
=
JSON
.
parse
(
json
)[
'
Envelope
'
][
'
Body
'
][
'
consulterDonneesTechniquesContractuellesResponse
'
][
'
point
'
][
'
situationComptage
'
][
'
dispositifComptage
'
][
'
relais
'
][
'
plageHeuresCreuses
'
]
// extract off-peak hours from parentheses
let
match
=
rawOffPeakHours
.
match
(
/
\((
.*
?)\)
/
)
// Check if there is a match and return the content
if
(
match
)
{
return
match
[
1
]
}
else
{
throw
new
Error
(
'
invalid off-peak hours format
'
)
}
}
/**
* Return User contract start date
* @param {string} result
...
...
@@ -219,6 +244,7 @@ module.exports = {
parseSgeXmlData
,
parseTags
,
parseUserAddress
,
parseUserOffPeakHours
,
parseUserPdl
,
parseValue
,
parseValueHalfHour
,
...
...
This diff is collapsed.
Click to expand it.
src/index.js
+
68
−
0
View file @
af1d4c91
...
...
@@ -18,10 +18,12 @@ const {
parseValue
,
parseValueHalfHour
,
parsePointId
,
parseUserOffPeakHours
,
}
=
require
(
'
./helpers/parsing
'
)
const
{
consultationMesuresDetailleesMaxPower
,
consultationMesuresDetaillees
,
consulterDonneesTechniquesContractuelles
,
}
=
require
(
'
./requests/sge
'
)
const
{
updateBoConsent
,
...
...
@@ -347,6 +349,12 @@ async function deleteConsent(
*/
async
function
gatherData
(
baseUrl
,
apiAuthKey
,
sgeLogin
,
pointId
)
{
log
(
'
info
'
,
'
Querying data...
'
)
await
getOffPeakHours
(
`
${
baseUrl
}
/enedis_SGE_ConsultationDonneesTechniquesContractuelles/1.0`
,
apiAuthKey
,
sgeLogin
,
pointId
)
await
getData
(
`
${
baseUrl
}
/enedis_SGE_ConsultationMesuresDetaillees_v3/1.0`
,
apiAuthKey
,
...
...
@@ -368,6 +376,66 @@ async function gatherData(baseUrl, apiAuthKey, sgeLogin, pointId) {
log
(
'
info
'
,
'
Querying data: done
'
)
}
/**
* Get hour data
* @param {string} url
* @param {string} apiAuthKey
* @param {string} userLogin
* @param {string} pointId
*/
async
function
getOffPeakHours
(
url
,
apiAuthKey
,
userLogin
,
pointId
)
{
log
(
'
info
'
,
'
Fetching off-peak hours
'
)
const
sgeHeaders
=
{
'
Content-Type
'
:
'
text/xml;charset=UTF-8
'
,
apikey
:
apiAuthKey
,
}
const
{
response
}
=
await
soapRequest
({
url
:
url
,
headers
:
sgeHeaders
,
xml
:
consulterDonneesTechniquesContractuelles
(
pointId
,
userLogin
,
false
),
}).
catch
(
err
=>
{
log
(
'
error
'
,
'
consulterDonneesTechniquesContractuelles
'
)
log
(
'
error
'
,
err
)
Sentry
.
captureException
(
`consulterDonneesTechniquesContractuelles:
${
err
}
`
,
{
tags
:
{
section
:
'
getOffPeakHour
'
},
extra
:
{
pointId
:
pointId
,
},
}
)
return
err
})
const
result
=
await
xml2js
.
parseStringPromise
(
response
.
body
,
{
tagNameProcessors
:
[
parseTags
],
valueProcessors
:
[
parseValue
],
explicitArray
:
false
,
})
try
{
const
offPeakHours
=
parseUserOffPeakHours
(
result
)
log
(
'
debug
'
,
`Found off-peak hours :
${
offPeakHours
}
, store them in account data`
)
const
accountData
=
await
getAccount
(
ACCOUNT_ID
)
await
saveAccountData
(
ACCOUNT_ID
,
{
...
accountData
.
data
,
offPeakHours
,
})
}
catch
(
error
)
{
log
(
'
debug
'
,
'
Off-peak hours not found, remove them from account data
'
)
let
accountData
=
await
getAccount
(
ACCOUNT_ID
)
delete
accountData
.
data
.
offPeakHours
await
saveAccountData
(
ACCOUNT_ID
,
{
...
accountData
.
data
,
})
}
}
/**
* Get hour data
* @param {string} url
...
...
This diff is collapsed.
Click to expand it.
Ghost User
@ghost
mentioned in commit
27148e1e
·
1 year ago
mentioned in commit
27148e1e
mentioned in commit 27148e1e01a40b6586ef68a13cd0f25283dd6ca2
Toggle commit list
Rémi PAILHAREY
@rpailharey
mentioned in commit
c040836e
·
1 year ago
mentioned in commit
c040836e
mentioned in commit c040836ec9dc04607fcf939f7b19d22c86dbd81d
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