Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
grdf_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
grdf_konnector
Commits
2ac37d31
Commit
2ac37d31
authored
3 years ago
by
Hugo SUBTIL
Browse files
Options
Downloads
Patches
Plain Diff
fix: handling of grdf error code.
parent
bb854c0b
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
konnector-dev-config.json
+0
-7
0 additions, 7 deletions
konnector-dev-config.json
manifest.konnector
+1
-1
1 addition, 1 deletion
manifest.konnector
package.json
+1
-1
1 addition, 1 deletion
package.json
src/index.js
+28
-54
28 additions, 54 deletions
src/index.js
with
30 additions
and
63 deletions
konnector-dev-config.json
deleted
100755 → 0
+
0
−
7
View file @
bb854c0b
{
"COZY_URL"
:
"http://cozy.tools:8080"
,
"fields"
:
{
"login"
:
"metropole_de_lyon_grdf"
,
"password"
:
"P-tndq12i+c?"
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
manifest.konnector
+
1
−
1
View file @
2ac37d31
{
"version": "1.0.
1
",
"version": "1.0.
2
",
"name": "GRDF",
"type": "konnector",
"language": "node",
...
...
This diff is collapsed.
Click to expand it.
package.json
+
1
−
1
View file @
2ac37d31
{
"name"
:
"grdf"
,
"version"
:
"1.0.
1
"
,
"version"
:
"1.0.
2
"
,
"description"
:
""
,
"repository"
:
{
"type"
:
"git"
,
...
...
This diff is collapsed.
Click to expand it.
src/index.js
+
28
−
54
View file @
2ac37d31
...
...
@@ -7,7 +7,6 @@ const {
log
}
=
require
(
'
cozy-konnector-libs
'
)
// const https = require('https') //optional for ssl issue
const
getAccountId
=
require
(
'
./helpers/getAccountId
'
)
const
moment
=
require
(
'
moment
'
)
require
(
'
moment-timezone
'
)
...
...
@@ -18,9 +17,13 @@ moment.tz.setDefault('Europe/Paris') // set the timezone
const
manualExecution
=
process
.
env
.
COZY_JOB_MANUAL_EXECUTION
===
'
true
'
?
true
:
false
const
startDate
=
manualExecution
?
moment
().
subtract
(
1
,
'
year
'
).
format
(
'
YYYY-MM-DD
'
)
:
moment
().
subtract
(
3
,
'
year
'
).
format
(
'
YYYY-MM-DD
'
)
?
moment
()
.
subtract
(
1
,
'
year
'
)
.
format
(
'
YYYY-MM-DD
'
)
:
moment
()
.
subtract
(
3
,
'
year
'
)
.
format
(
'
YYYY-MM-DD
'
)
const
endDate
=
moment
()
.
startOf
(
'
day
'
)
.
subtract
(
1
,
'
day
'
)
...
...
@@ -57,8 +60,6 @@ async function start(fields) {
const
grdfData
=
await
getData
(
fields
.
access_token
,
id_pce
)
if
(
grdfData
)
{
// log("debug", "Clean data retrieve by old scraping konnector")
// await cleanOldData()
log
(
'
debug
'
,
'
Process grdf daily data
'
)
const
processedLoadData
=
await
processData
(
grdfData
,
...
...
@@ -87,7 +88,7 @@ async function start(fields) {
}
}
//Retrieve data from grdf API
//
Retrieve data from grdf API
async
function
getData
(
token
,
idPCE
)
{
log
(
'
debug
'
,
'
ENTERING GETDATA
'
)
var
myHeaders
=
new
Headers
()
...
...
@@ -118,8 +119,24 @@ async function getData(token, idPCE) {
return
result
.
match
(
/.+/g
).
map
(
s
=>
{
result
=
JSON
.
parse
(
s
)
if
(
result
.
statut_restitution
!==
null
)
{
log
(
'
debug
'
,
'
OAUTH OUTDATED :
'
+
result
.
statut_restitution
.
message
)
throw
errors
.
USER_ACTION_NEEDED_OAUTH_OUTDATED
log
(
'
warn
'
,
'
USER_ACTION_NEEDED_OAUTH_OUTDATED :
'
+
result
.
statut_restitution
.
message
+
'
/ Period:
'
+
result
.
periode
.
date_debut
+
'
/
'
+
result
.
periode
.
date_fin
)
/**
* Handle no data issue when retreving grdf data.
* 1000008 code stands for "Il n'y a pas de données correspondant à ce PCE sur la période demandée".
* If there is no data, return null data in order to be filtered before saving
*/
if
(
result
.
statut_restitution
.
code
!==
'
1000008
'
)
{
throw
errors
.
USER_ACTION_NEEDED_OAUTH_OUTDATED
}
return
{
energie
:
null
}
}
return
result
.
consommation
})
...
...
@@ -129,54 +146,11 @@ async function getData(token, idPCE) {
throw
error
})
const
filteredRep
=
rep
.
filter
(
function
(
el
)
{
return
(
el
.
energie
!=
null
||
el
.
volume_brut
!=
null
)
return
el
.
energie
!=
null
||
el
.
volume_brut
!=
null
})
return
filteredRep
}
/**
* Get All actual daily data stored in the db
* Return the list of daily data
*/
// async function cleanOldData() {
// if(moment().diff(moment("2020-12-02", "DD/MM/YYYY")) > 0){
// log('debug', 'No cleaning to do')
// return false
// } else {
// log('debug', 'Start cleaning old data')
// const documents = await cozyClient.data.findAll('com.grandlyon.grdf.day')
// if (documents && documents.length > 0) {
// const result = []
// for (const doc of documents) {
// const deleteResult = await cozyClient.data.delete('com.grandlyon.grdf.day', doc)
// result.push(deleteResult)
// }
// log("debug", "NB OF DELETED OLD DAY DATA : " + result.length)
// }
// const documentsMonth = await cozyClient.data.findAll('com.grandlyon.grdf.month')
// if (documentsMonth && documentsMonth.length > 0) {
// const result = []
// for (const doc of documentsMonth) {
// const deleteResult = await cozyClient.data.delete('com.grandlyon.grdf.month', doc)
// result.push(deleteResult)
// }
// log("debug", "NB OF DELETED OLD MONTH DATA : " + result.length)
// }
// const documentsYear = await cozyClient.data.findAll('com.grandlyon.grdf.year')
// if (documentsYear && documentsYear.length > 0) {
// const result = []
// for (const doc of documentsYear) {
// await cozyClient.data.delete('com.grandlyon.grdf.year', doc)
// result.push(deleteResult)
// }
// log("debug", "NB OF DELETED OLD YEAR DATA : " + result.length)
// }
// return true
// }
// }
/**
* Parse data
* Remove existing data from DB using hydrateAndFilter
...
...
@@ -216,7 +190,7 @@ async function formateData(data) {
return
data
.
map
(
record
=>
{
let
date
=
moment
(
record
.
date_debut_consommation
,
'
YYYY/MM/DD h:mm:ss
'
)
let
load
=
record
.
energie
&&
record
.
energie
!==
0
record
.
energie
&&
record
.
energie
!==
0
?
record
.
energie
:
record
.
volume_brut
*
record
.
coeff_calcul
.
coeff_conversion
return
{
...
...
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