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
Project 'web-et-numerique/llle_project/grdf-konnector' was moved to 'web-et-numerique/factory/llle_project/grdf-konnector'. Please update any links and bookmarks that may still have the old path.
Commit
7e588a1b
authored
4 years ago
by
Yoan VALLET
Browse files
Options
Downloads
Patches
Plain Diff
fix issue when load is unknown
parent
86dd2096
Branches
Branches containing commit
Tags
Tags containing commit
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) {
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
'
)),
...
...
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