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
7e588a1b
Commit
7e588a1b
authored
4 years ago
by
Yoan VALLET
Browse files
Options
Downloads
Patches
Plain Diff
fix issue when load is unknown
parent
86dd2096
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/index.js
+42
-40
42 additions, 40 deletions
src/index.js
with
42 additions
and
40 deletions
src/index.js
+
42
−
40
View file @
7e588a1b
...
@@ -54,8 +54,8 @@ async function start(fields) {
...
@@ -54,8 +54,8 @@ async function start(fields) {
const
grdfData
=
await
getData
(
fields
.
access_token
,
id_pce
)
const
grdfData
=
await
getData
(
fields
.
access_token
,
id_pce
)
if
(
grdfData
)
{
if
(
grdfData
)
{
log
(
"
debug
"
,
"
Clean data retrieve by old scraping konnector
"
)
//
log("debug", "Clean data retrieve by old scraping konnector")
await
cleanOldData
()
//
await cleanOldData()
log
(
'
debug
'
,
'
Process grdf daily data
'
)
log
(
'
debug
'
,
'
Process grdf daily data
'
)
const
processedLoadData
=
await
processData
(
const
processedLoadData
=
await
processData
(
grdfData
,
grdfData
,
...
@@ -132,42 +132,42 @@ async function getData(token, idPCE) {
...
@@ -132,42 +132,42 @@ async function getData(token, idPCE) {
* Get All actual daily data stored in the db
* Get All actual daily data stored in the db
* Return the list of daily data
* Return the list of daily data
*/
*/
async
function
cleanOldData
()
{
//
async function cleanOldData() {
if
(
moment
().
diff
(
moment
(
"
2020-12-02
"
,
"
DD/MM/YYYY
"
))
>
0
){
//
if(moment().diff(moment("2020-12-02", "DD/MM/YYYY")) > 0){
log
(
'
debug
'
,
'
No cleaning to do
'
)
//
log('debug', 'No cleaning to do')
return
false
//
return false
}
else
{
//
} else {
log
(
'
debug
'
,
'
Start cleaning old data
'
)
//
log('debug', 'Start cleaning old data')
const
documents
=
await
cozyClient
.
data
.
findAll
(
'
com.grandlyon.grdf.day
'
)
//
const documents = await cozyClient.data.findAll('com.grandlyon.grdf.day')
if
(
documents
&&
documents
.
length
>
0
)
{
//
if (documents && documents.length > 0) {
const
result
=
[]
//
const result = []
for
(
const
doc
of
documents
)
{
//
for (const doc of documents) {
const
deleteResult
=
await
cozyClient
.
data
.
delete
(
'
com.grandlyon.grdf.day
'
,
doc
)
//
const deleteResult = await cozyClient.data.delete('com.grandlyon.grdf.day', doc)
result
.
push
(
deleteResult
)
//
result.push(deleteResult)
}
//
}
log
(
"
debug
"
,
"
NB OF DELETED OLD DAY DATA :
"
+
result
.
length
)
//
log("debug", "NB OF DELETED OLD DAY DATA : " + result.length)
}
//
}
const
documentsMonth
=
await
cozyClient
.
data
.
findAll
(
'
com.grandlyon.grdf.month
'
)
//
const documentsMonth = await cozyClient.data.findAll('com.grandlyon.grdf.month')
if
(
documentsMonth
&&
documentsMonth
.
length
>
0
)
{
//
if (documentsMonth && documentsMonth.length > 0) {
const
result
=
[]
//
const result = []
for
(
const
doc
of
documentsMonth
)
{
//
for (const doc of documentsMonth) {
const
deleteResult
=
await
cozyClient
.
data
.
delete
(
'
com.grandlyon.grdf.month
'
,
doc
)
//
const deleteResult = await cozyClient.data.delete('com.grandlyon.grdf.month', doc)
result
.
push
(
deleteResult
)
//
result.push(deleteResult)
}
//
}
log
(
"
debug
"
,
"
NB OF DELETED OLD MONTH DATA :
"
+
result
.
length
)
//
log("debug", "NB OF DELETED OLD MONTH DATA : " + result.length)
}
//
}
const
documentsYear
=
await
cozyClient
.
data
.
findAll
(
'
com.grandlyon.grdf.year
'
)
//
const documentsYear = await cozyClient.data.findAll('com.grandlyon.grdf.year')
if
(
documentsYear
&&
documentsYear
.
length
>
0
)
{
//
if (documentsYear && documentsYear.length > 0) {
const
result
=
[]
//
const result = []
for
(
const
doc
of
documentsYear
)
{
//
for (const doc of documentsYear) {
await
cozyClient
.
data
.
delete
(
'
com.grandlyon.grdf.year
'
,
doc
)
//
await cozyClient.data.delete('com.grandlyon.grdf.year', doc)
result
.
push
(
deleteResult
)
//
result.push(deleteResult)
}
//
}
log
(
"
debug
"
,
"
NB OF DELETED OLD YEAR DATA :
"
+
result
.
length
)
//
log("debug", "NB OF DELETED OLD YEAR DATA : " + result.length)
}
//
}
return
true
//
return true
}
//
}
}
//
}
/**
/**
* Parse data
* Parse data
...
@@ -208,9 +208,11 @@ async function formateData(data) {
...
@@ -208,9 +208,11 @@ async function formateData(data) {
return
data
.
map
(
record
=>
{
return
data
.
map
(
record
=>
{
let
date
=
moment
(
record
.
date_debut_consommation
,
'
YYYY/MM/DD h:mm:ss
'
)
let
date
=
moment
(
record
.
date_debut_consommation
,
'
YYYY/MM/DD h:mm:ss
'
)
let
load
=
let
load
=
record
.
energie
!==
0
record
.
energie
&&
record
.
energie
!==
0
?
record
.
energie
?
record
.
energie
:
record
.
volume_brut
*
record
.
coeff_calcul
.
coeff_conversion
:
record
.
volume_brut
?
record
.
volume_brut
*
record
.
coeff_calcul
.
coeff_conversion
:
0
return
{
return
{
load
:
parseFloat
(
load
),
load
:
parseFloat
(
load
),
year
:
parseInt
(
date
.
format
(
'
YYYY
'
)),
year
:
parseInt
(
date
.
format
(
'
YYYY
'
)),
...
...
This diff is collapsed.
Click to expand it.
Yoan VALLET
@yvallet
mentioned in commit
122d9b24
·
4 years ago
mentioned in commit
122d9b24
mentioned in commit 122d9b246b690e6d668cfceca2a50703b88f6356
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