Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
web-et-numerique
LLLE_Project
grdf-konnector
Commits
7e588a1b
Commit
7e588a1b
authored
Nov 27, 2020
by
Yoan VALLET
Browse files
fix issue when load is unknown
parent
86dd2096
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/index.js
View file @
7e588a1b
...
...
@@ -54,8 +54,8 @@ 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", "Clean data retrieve by old scraping konnector")
//
await cleanOldData()
log
(
'
debug
'
,
'
Process grdf daily data
'
)
const
processedLoadData
=
await
processData
(
grdfData
,
...
...
@@ -132,42 +132,42 @@ async function getData(token, idPCE) {
* 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
}
}
//
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
...
...
@@ -208,9 +208,11 @@ 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
!==
0
record
.
energie
&&
record
.
energie
!==
0
?
record
.
energie
:
record
.
volume_brut
*
record
.
coeff_calcul
.
coeff_conversion
:
record
.
volume_brut
?
record
.
volume_brut
*
record
.
coeff_calcul
.
coeff_conversion
:
0
return
{
load
:
parseFloat
(
load
),
year
:
parseInt
(
date
.
format
(
'
YYYY
'
)),
...
...
Yoan VALLET
@yvallet
mentioned in commit
122d9b24
·
Nov 27, 2020
mentioned in commit
122d9b24
mentioned in commit 122d9b246b690e6d668cfceca2a50703b88f6356
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment