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
ed87268b
Commit
ed87268b
authored
1 year ago
by
Rémi PAILHAREY
Browse files
Options
Downloads
Patches
Plain Diff
feat: store off-peak hours
parent
ebbd568a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!56
v1.4.0
,
!52
feat: off-peak hours ratio
Changes
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
+67
-0
67 additions, 0 deletions
src/index.js
with
93 additions
and
0 deletions
src/helpers/parsing.js
+
26
−
0
View file @
ed87268b
...
...
@@ -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
+
67
−
0
View file @
ed87268b
...
...
@@ -18,10 +18,12 @@ const {
parseValue
,
parseValueHalfHour
,
parsePointId
,
parseUserOffPeakHours
,
}
=
require
(
'
./helpers/parsing
'
)
const
{
consultationMesuresDetailleesMaxPower
,
consultationMesuresDetaillees
,
consulterDonneesTechniquesContractuelles
,
}
=
require
(
'
./requests/sge
'
)
const
{
updateBoConsent
,
...
...
@@ -352,12 +354,77 @@ async function gatherData(baseUrl, apiAuthKey, sgeLogin, pointId) {
'
/enedis_SGE_ConsultationMesuresDetaillees_v3/1.0
'
,
baseUrl
).
href
const
contractUrl
=
new
URL
(
'
/enedis_SGE_ConsultationDonneesTechniquesContractuelles/1.0
'
,
baseUrl
).
href
await
getData
(
measuresUrl
,
apiAuthKey
,
sgeLogin
,
pointId
)
await
getMaxPowerData
(
measuresUrl
,
apiAuthKey
,
sgeLogin
,
pointId
)
await
getDataHalfHour
(
measuresUrl
,
apiAuthKey
,
sgeLogin
,
pointId
)
await
getOffPeakHours
(
contractUrl
,
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.
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