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
0e950806
Commit
0e950806
authored
2 years ago
by
Hugo SUBTIL
Browse files
Options
Downloads
Patches
Plain Diff
feat: add dynamical date
parent
6eddeb29
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!6
Feat/get consumption data
Pipeline
#28208
passed
2 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/index.js
+101
-7
101 additions, 7 deletions
src/index.js
with
101 additions
and
7 deletions
src/index.js
+
101
−
7
View file @
0e950806
...
...
@@ -15,10 +15,10 @@ moment.tz.setDefault('Europe/Paris') // set the timezone
/*** Connector Constants ***/
const
manualExecution
=
process
.
env
.
COZY_JOB_MANUAL_EXECUTION
===
'
true
'
?
true
:
false
cons
t
startDailyDate
=
manualExecution
le
t
startDailyDate
=
manualExecution
?
moment
().
subtract
(
12
,
'
month
'
)
:
moment
().
subtract
(
6
,
'
month
'
)
cons
t
startDailyDateString
=
startDailyDate
.
format
(
'
YYYY-MM-DD
'
)
le
t
startDailyDateString
=
startDailyDate
.
format
(
'
YYYY-MM-DD
'
)
// const startLoadDate = moment().subtract(7, 'day')
// const startLoadDateString = startLoadDate.format('YYYY-MM-DD')
const
endDate
=
moment
()
...
...
@@ -33,8 +33,6 @@ module.exports = new BaseKonnector(start)
// secret api key.
async
function
start
(
fields
,
cozyParameters
)
{
log
(
'
info
'
,
'
Gathering data ...
'
)
console
.
log
(
fields
.
wso2BaseUrl
)
console
.
log
(
cozyParameters
)
let
baseUrl
=
fields
.
wso2BaseUrl
let
apiAuthKey
=
fields
.
apiToken
let
loginUtilisateur
=
fields
.
loginUtilisateur
...
...
@@ -49,6 +47,13 @@ async function start(fields, cozyParameters) {
log
(
'
info
'
,
'
Successfully logged in
'
)
//TODO: get compteur start data
await
getDataStartDate
(
`
${
baseUrl
}
/enedis_SGE_ConsultationDonneesTechniquesContractuelles/1.0`
,
apiAuthKey
,
loginUtilisateur
,
fields
.
pointId
)
await
getData
(
`
${
baseUrl
}
/enedis_SGE_ConsultationMesuresDetaillees/1.0`
,
apiAuthKey
,
...
...
@@ -57,6 +62,40 @@ async function start(fields, cozyParameters) {
)
log
(
'
info
'
,
'
Konnector process end
'
)
}
/**
*
* @param {string} url
* @param {string} apiAuthKey
* @param {string} userLogin
* @param {number} pointId
*/
async
function
getDataStartDate
(
url
,
apiAuthKey
,
userLogin
,
pointId
)
{
log
(
'
info
'
,
'
Fetching data start date
'
)
const
sampleHeaders
=
{
'
Content-Type
'
:
'
text/xml;charset=UTF-8
'
,
apikey
:
apiAuthKey
,
}
const
{
response
}
=
await
soapRequest
({
url
:
url
,
headers
:
sampleHeaders
,
xml
:
userTechnicalData
(
pointId
,
userLogin
),
}).
catch
(
err
=>
{
log
(
'
error
'
,
'
technicalDataResponse
'
)
log
(
'
error
'
,
err
)
return
err
})
xml2js
.
parseString
(
response
.
body
,
{
tagNameProcessors
:
[
parseTags
],
valueProcessors
:
[
parseValue
],
explicitArray
:
false
,
},
processStartDate
()
)
}
/**
*
...
...
@@ -71,6 +110,7 @@ async function getData(url, apiAuthKey, userLogin, pointId) {
'
Content-Type
'
:
'
text/xml;charset=UTF-8
'
,
apikey
:
apiAuthKey
,
}
const
{
response
}
=
await
soapRequest
({
url
:
url
,
headers
:
sampleHeaders
,
...
...
@@ -81,6 +121,7 @@ async function getData(url, apiAuthKey, userLogin, pointId) {
endDateString
),
}).
catch
(
err
=>
{
log
(
'
error
'
,
'
userMesureDetailles
'
)
log
(
'
error
'
,
err
)
return
err
})
...
...
@@ -141,9 +182,39 @@ function processData() {
}
}
/**
* Parse data
*/
function
processStartDate
()
{
return
async
(
err
,
result
)
=>
{
if
(
err
)
{
log
(
'
error
'
,
err
)
throw
err
}
// update start Date with contract openning date
startDailyDate
=
moment
(
parseSgeXmlTechnicalData
(
result
),
'
YYYY-MM-DD
'
)
startDailyDateString
=
startDailyDate
.
format
(
'
YYYY-MM-DD
'
)
}
}
/**
* Return start date
* @param {string} result
* @returns {string}
*/
function
parseSgeXmlTechnicalData
(
result
)
{
log
(
'
info
'
,
'
Parsing technical data
'
)
let
json
=
JSON
.
stringify
(
result
)
return
JSON
.
parse
(
json
)[
'
Envelope
'
][
'
Body
'
][
'
consulterDonneesTechniquesContractuellesResponse
'
][
'
point
'
][
'
donneesGenerales
'
][
'
dateDerniereModificationFormuleTarifaireAcheminement
'
]
}
/**
*
* @param {
*
} result
* @param {
string
} result
* @returns {SGEData[]}
*/
function
parseSgeXmlData
(
result
)
{
...
...
@@ -159,7 +230,7 @@ function parseSgeXmlData(result) {
* @param {EnedisKonnectorData[]} data
* @param {string} doctype
* @param {string[]} filterKeys
* @returns
* @returns
{Promise<*>}
*/
async
function
storeData
(
data
,
doctype
,
filterKeys
)
{
log
(
'
debug
'
,
doctype
,
'
Store into
'
)
...
...
@@ -204,6 +275,30 @@ function userMesureDetailles(pointId, userLogin, startDt, endDt) {
`
}
/**
* Get user technical data
* @param {string} pointId
* @param {string} userLogin
* @returns {string}
*/
function
userTechnicalData
(
pointId
,
userLogin
)
{
log
(
'
info
'
,
`Query userMesureDetailles`
)
return
`<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v2="http://www.enedis.fr/sge/b2b/services/consulterdonneestechniquescontractuelles/v1.0"
xmlns:v1="http://www.enedis.fr/sge/b2b/technique/v1.0">
<soapenv:Header/>
<soapenv:Body>
<v2:consulterDonneesTechniquesContractuelles>
<pointId>
${
pointId
}
</pointId>
<loginUtilisateur>
${
userLogin
}
</loginUtilisateur>
<autorisationClient>true</autorisationClient>
</v2:consulterDonneesTechniquesContractuelles>
</soapenv:Body>
</soapenv:Envelope>
`
}
/**
* Format data for DB storage
* @param {SGEData[]} data
...
...
@@ -211,7 +306,6 @@ function userMesureDetailles(pointId, userLogin, startDt, endDt) {
*/
async
function
formateDataForDoctype
(
data
)
{
log
(
'
info
'
,
'
Formating data
'
)
console
.
log
(
data
)
// record
return
data
.
map
(
record
=>
{
let
date
=
moment
(
record
.
d
,
'
YYYY/MM/DD h:mm:ss
'
)
...
...
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