Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
co2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
tools
co2
Commits
8407856a
Verified
Commit
8407856a
authored
11 months ago
by
Ruben van Dijk
Browse files
Options
Downloads
Patches
Plain Diff
Added ventilator data.
parent
62af2286
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#13363
passed
11 months ago
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
generate.py
+38
-25
38 additions, 25 deletions
generate.py
input/2024-05-14T15:09:59-ventilator.csv
+15
-0
15 additions, 0 deletions
input/2024-05-14T15:09:59-ventilator.csv
query.md
+13
-2
13 additions, 2 deletions
query.md
with
66 additions
and
27 deletions
generate.py
+
38
−
25
View file @
8407856a
...
...
@@ -6,7 +6,7 @@ import plotly.graph_objects as go
from
plotly.subplots
import
make_subplots
#"off":"dicht", 'on':"open"
all_files
=
glob
.
glob
(
os
.
path
.
join
(
"
input
"
,
"
*.csv
"
))
all_files
=
glob
.
glob
(
os
.
path
.
join
(
"
input
"
,
"
*.csv
"
))
li
=
[]
for
filename
in
all_files
:
df
=
pd
.
read_csv
(
filename
,
index_col
=
None
,
header
=
0
)
...
...
@@ -14,53 +14,66 @@ for filename in all_files:
df
=
pd
.
concat
(
li
,
axis
=
0
,
ignore_index
=
True
)
df
.
drop_duplicates
(
inplace
=
True
)
df
[
'
datetime
'
]
=
pd
.
to_datetime
(
df
[
'
datetime
'
])
raam
=
df
[
df
[
'
metadata_id
'
]
==
420
].
drop
(
columns
=
'
metadata_id
'
)
raam
=
raam
.
set_index
(
raam
[
'
datetime
'
])
raam
[
'
RaamOpen
'
]
=
raam
[
'
state
'
].
replace
({
"
off
"
:
False
,
'
on
'
:
True
})
raam
=
raam
[
'
RaamOpen
'
]
co2
=
df
[
df
[
'
metadata_id
'
]
==
2269
].
drop
(
columns
=
'
metadata_id
'
)
co2
[
'
state
'
]
=
co2
[
'
state
'
].
astype
(
int
)
co2
=
co2
.
set_index
(
co2
[
'
datetime
'
])
co2
=
co2
[
'
state
'
].
sort_index
()
if
raam
.
index
[
-
1
]
<
co2
.
index
[
-
1
]:
#extend raam to last co2 date
last_raam
=
raam
[
raam
.
index
[
-
1
]]
last_date
=
co2
.
index
[
-
1
]
raam
.
at
[
last_date
]
=
last_raam
fig
=
make_subplots
(
rows
=
2
,
cols
=
1
,
shared_xaxes
=
True
)
# Create traces
def
get_by_metadata
(
metadata_id
):
response
=
df
[
df
[
'
metadata_id
'
]
==
metadata_id
].
drop
(
columns
=
'
metadata_id
'
)
return
response
.
set_index
(
response
[
'
datetime
'
])[
'
state
'
]
co2
=
get_by_metadata
(
2269
).
astype
(
int
)
first_date
=
co2
.
index
[
0
]
last_date
=
co2
.
index
[
-
1
]
def
extendIndex
(
item
):
#extend data
if
item
.
index
[
-
1
]
<
last_date
:
last_item
=
item
[
item
.
index
[
-
1
]]
item
.
at
[
last_date
]
=
last_item
if
item
.
index
[
0
]
>
first_date
:
first_item
=
item
[
item
.
index
[
0
]]
item
.
at
[
first_date
]
=
first_item
booleans
=
{
'
raam
'
:
420
,
'
ventilator
'
:
2295
,
}
fig
=
make_subplots
(
rows
=
len
(
booleans
)
+
1
,
cols
=
1
,
shared_xaxes
=
True
)
co2_trace
=
go
.
Scatter
(
x
=
co2
.
index
,
y
=
co2
.
values
,
mode
=
'
lines
'
,
name
=
'
Co2
'
)
raam_trace
=
go
.
Scatter
(
x
=
raam
.
index
,
y
=
raam
.
values
.
astype
(
float
),
mode
=
'
lines
'
,
name
=
'
Raam Open
'
,
line_shape
=
'
hv
'
)
# Add traces to figure
fig
.
add_trace
(
co2_trace
,
row
=
1
,
col
=
1
)
fig
.
add_trace
(
raam_trace
,
row
=
2
,
col
=
1
)
for
index
,
key
in
enumerate
(
booleans
):
item
=
get_by_metadata
(
booleans
[
key
]).
replace
({
"
off
"
:
False
,
'
on
'
:
True
})
extendIndex
(
item
)
trace
=
go
.
Scatter
(
x
=
item
.
index
,
y
=
item
.
values
.
astype
(
float
),
mode
=
'
lines
'
,
name
=
key
,
line_shape
=
'
hv
'
)
fig
.
add_trace
(
trace
,
row
=
index
+
2
,
col
=
1
)
# Customize layout
fig
.
update_layout
(
xaxis
=
dict
(
tickmode
=
'
linear
'
,
tick0
=
co2
.
index
[
0
],
dtick
=
86400000
*
7
,
# milliseconds in a day * 7 (for weekly ticks)
dtick
=
86400000
*
7
,
# milliseconds in a day * 7 (for weekly ticks)
tickformat
=
'
%a %d %d
'
,
tickangle
=-
45
),
yaxis
=
dict
(
title
=
'
Co2
'
),
yaxis2
=
dict
(
title
=
'
Raam Open
'
),
autosize
=
True
,
margin
=
dict
(
l
=
50
,
r
=
50
,
t
=
50
,
b
=
50
),
height
=
600
,
)
for
index
,
key
in
enumerate
(
booleans
):
fig
.
update_yaxes
(
title_text
=
key
,
row
=
index
+
2
,
col
=
1
)
# Update shared axis settings
fig
.
update_layout
(
xaxis
=
dict
(
domain
=
[
0
,
1
],
rangeslider
=
dict
(
visible
=
False
)))
fig
.
update_xaxes
(
title_text
=
"
Date
"
,
row
=
2
,
col
=
1
)
start_index
=
max
(
co2
.
index
[
0
],
raam
.
index
[
0
])
fig
.
update_xaxes
(
range
=
[
start_index
,
co2
.
index
[
-
1
]],
row
=
2
,
col
=
1
)
fig
.
update_xaxes
(
range
=
[
co2
.
index
[
0
],
co2
.
index
[
-
1
]],
row
=
2
,
col
=
1
)
fig
.
write_html
(
"
output/all.html
"
)
This diff is collapsed.
Click to expand it.
input/2024-05-14T15:09:59-ventilator.csv
0 → 100644
+
15
−
0
View file @
8407856a
"metadata_id","state","datetime"
"2295","off","2024-05-12 16:29:55.106389"
"2295","on","2024-05-12 16:29:56.106389"
"2295","off","2024-05-12 16:30:05.012887"
"2295","on","2024-05-12 16:30:05.626596"
"2295","off","2024-05-12 16:31:07.716808"
"2295","on","2024-05-12 16:31:10.666773"
"2295","off","2024-05-12 16:31:10.916048"
"2295","on","2024-05-12 16:31:17.199450"
"2295","on","2024-05-12 16:56:24.332425"
"2295","off","2024-05-12 17:20:53.402442"
"2295","off","2024-05-12 18:50:33.241611"
"2295","on","2024-05-12 18:57:56.537290"
"2295","off","2024-05-12 18:57:57.955921"
"2295","off","2024-05-13 12:21:29.686283"
This diff is collapsed.
Click to expand it.
query.md
+
13
−
2
View file @
8407856a
...
...
@@ -3,7 +3,18 @@
Run this query on the MariaDB server of Home Assistant:
```
sql
SELECT
metadata_id
,
state
,
from_unixtime
(
last_updated_ts
)
as
datetime
FROM
`states`
where
metadata_id
in
(
select
metadata_id
from
states_meta
where
entity_id
=
'sensor.co2_woonkamer_co2'
or
entity_id
=
'binary_sensor.woonkamer_raam'
)
and
last_updated_ts
is
not
null
and
state
!=
'unknown'
and
state
!=
'unavailable'
and
from_unixtime
(
last_updated_ts
)
>
'2024-05-14T14:28:58'
order
by
datetime
;
SELECT
metadata_id
,
state
,
from_unixtime
(
last_updated_ts
)
as
datetime
FROM
`states`
where
metadata_id
in
(
select
metadata_id
from
states_meta
where
entity_id
=
'sensor.co2_woonkamer_co2'
or
entity_id
=
'binary_sensor.woonkamer_raam'
or
entity_id
=
'switch.ventilator_switch'
)
and
last_updated_ts
is
not
null
and
state
!=
'unknown'
and
state
!=
'unavailable'
and
from_unixtime
(
last_updated_ts
)
>
'2024-05-14T14:28:58'
order
by
datetime
;
```
Don't forget to modify the date!
Export it all as CSV, and place it in the
`input`
folder.
\ No newline at end of file
Export it all as CSV, and place it in the
`input`
folder.
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