Skip to content

Commit

Permalink
New db-schema file
Browse files Browse the repository at this point in the history
added footer and updated error page
  • Loading branch information
mhekkel committed Sep 10, 2024
1 parent d8ed5f6 commit 4e10b78
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 81 deletions.
75 changes: 44 additions & 31 deletions db-schema.sql
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
-- drop table if exists public.p1_opname;
drop table if exists public.sessy_soc;
-- The table for the daily graph (status panel)

-- P1 status

create table
public.p1_opname (
tijd timestamp without time zone default now() not null,
verbruik_hoog numeric(9, 3),
verbruik_laag numeric(9, 3),
levering_hoog numeric(9, 3),
levering_laag numeric(9, 3)
);

alter table only public.p1_opname
add constraint p1_opname_pk primary key (tijd);

alter table public.p1_opname owner to "energie-admin";

-- Sessy state of charge

create table
public.sessy_soc (
tijd timestamp without time zone default now() not null,
nr integer not null,
soc numeric(4, 3)
);

alter table only public.sessy_soc
add constraint sessy_soc_pk primary key (tijd, nr);

alter table public.sessy_soc owner to "energie-admin";
drop table if exists public.daily_graph;

-- Status graph data

Expand All @@ -45,3 +16,45 @@ create table

alter table public.daily_graph owner to "energie-admin";

-- Tables for the history of energy usage

drop table if exists public.opname cascade;

create table public.opname (
id serial primary key,
tijd timestamp without time zone default now() not null
);

alter table public.opname owner to "energie-admin";
comment on table public.opname is 'een opname van meerdere tellerstanden';

create table public.teller (
id serial primary key,
naam character varying(32) not null,
naam_kort character varying(16) not null,
schaal integer not null,
teken integer
);

alter table public.teller owner to "energie-admin";
comment on table public.teller is 'de verschillende tellers';

create table public.tellerstand (
id serial primary key,
teller_id integer references public.teller,
stand numeric(8,3) not null,
opname_id integer references public.opname
);

alter table public.tellerstand owner to "energie-admin";
comment on table public.tellerstand is 'de stand van een teller';

-- some data

copy public.teller (id, naam, naam_kort, schaal, teken) from stdin;
1 Warmte Warmte 3 1
2 Electriciteit verbruik laag Verbruik laag 0 1
3 Electriciteit verbruik hoog Verbruik hoog 0 1
5 Electriciteit teruglevering hoog Teruglevering h 0 -1
4 Electriciteit teruglevering laag Teruglevering l 0 -1
\.
60 changes: 37 additions & 23 deletions docroot/error.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:z="http://www.hekkelman.com/libzeep/m2"
xml:lang="en" lang="en">
<head>
<title>Error</title>

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="Maarten L. Hekkelman" />
<meta name="generator" content="Japi" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<!DOCTYPE html SYSTEM "about:legacy-compat">

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:z2="http://www.hekkelman.com/libzeep/m2" lang="nl">

<head z2:replace="~{head::head(~{::title},~{::head/script})}">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />

<title>Energyd - Fout</title>
</head>

<body>
<div class="head">
<span z:if="${error.nr}" class="error-nr" z:text="${error.nr}"></span>
<span class="error-head-text" z:text="${error.head}"></span>
</div>
<div id="main">
<p class="error-main-text" z:text="${error.description}"></p>
<p z:if="${error.message}">Additional information: <span z:text="${error.message}"/></p>
</div>
<div id="footer">
<span z:if="${error.request.method}">Method: <em>${error.request.method}</em></span>
<span z:if="${error.request.uri}">URI: <em>${error.request.uri}</em></span>
<span z:if="${error.request.username}">Username: <em>${error.request.username}</em></span>
<nav z2:replace="~{menu :: navbar('token')}" />

<div class="container">

<div class="container-fluid mt-5">
<div class="alert alert-danger" role="alert">
<span z2:if="${error.nr}" class="error-nr" z2:text="${error.nr}"></span>
<span class="error-head-text" z2:text="${error.head}"></span>
</div>
</div>

<div class="container-fluid mt-5">
<p class="error-main-text" z2:text="${error.description}"></p>
<p z2:if="${error.message}" z2:text="${error.message}"></p>
</div>

<div class="container-fluid mt-5">
<ul class="error-info">
<li z2:if="${error.request.method}">Method: <em z2:text="${error.request.method}"></em></li>
<li z2:if="${error.request.uri}">URI: <em z2:text="${error.request.uri}"></em></li>
<li z2:if="${error.request.username}">Username: <em z2:text="${error.request.username}"></em></li>
</ul>
</div>
</div>

<footer z2:replace="~{footer::content}" />
</body>
</html>

</html>
8 changes: 8 additions & 0 deletions docroot/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE html>

<html xmlns:z2="http://www.hekkelman.com/libzeep/m2">
<body>
<footer z2:fragment="content">Developed by Maarten L. Hekkelman
<a href="https://www.hekkelman.com/">www.hekkelman.com</a></footer>
</body>
</html>
3 changes: 2 additions & 1 deletion docroot/invoer.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<nav z2:replace="menu :: navbar"></nav>

<div class="container-fluid" style="max-width: 30em;">
<div class="container-fluid container" style="max-width: 30em;">

<h3 class="mt-3">Meterstanden</h3>

Expand All @@ -42,6 +42,7 @@ <h3 class="mt-3">Meterstanden</h3>
</form>
</div>

<footer z2:replace="~{footer::content}" />
</body>

</html>
3 changes: 1 addition & 2 deletions docroot/opnames.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
</head>

<body>

<nav z2:replace="menu :: navbar"></nav>

<div class="container">
Expand Down Expand Up @@ -91,7 +90,7 @@ <h5 class="modal-title" id="dialog-label">Tellerstand registratie</h5>
</div>
</div>


<footer z2:replace="~{footer::content}" />
</body>

</html>
2 changes: 2 additions & 0 deletions docroot/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,7 @@ <h1 class="mt-2">Grafiek</h1>
</div>

</div>

<footer z2:replace="~{footer::content}" />
</body>
</html>
57 changes: 36 additions & 21 deletions src/energyd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,9 @@ std::vector<DataPunt> e_rest_controller::get_grafiek(grafiek_type type, aggregat

StandMap sm = DataService::instance().get_stand_map(type);

if (sm.empty())
return {};

auto nu = floor<std::chrono::days>(std::chrono::system_clock::now());
auto jaar = year_month_day{ floor<days>(nu) }.year();

Expand Down Expand Up @@ -744,22 +747,28 @@ zeep::http::reply e_web_controller::opname(const zeep::http::scope &scope)
to_element(tellers, u);
sub.put("tellers", tellers);

// huidige stand
// huidige stand, if any

auto huidig = DataService::instance().get_last_opname();
huidig.id.clear();
huidig.datum = {};
try
{
auto huidig = DataService::instance().get_last_opname();
huidig.id.clear();
huidig.datum = {};

auto p1_w = P1Service::instance().get_current();
auto p1_w = P1Service::instance().get_current();

huidig.standen["2"] = p1_w.verbruik_laag;
huidig.standen["3"] = p1_w.verbruik_hoog;
huidig.standen["4"] = p1_w.levering_laag;
huidig.standen["5"] = p1_w.levering_hoog;
huidig.standen["2"] = p1_w.verbruik_laag;
huidig.standen["3"] = p1_w.verbruik_hoog;
huidig.standen["4"] = p1_w.levering_laag;
huidig.standen["5"] = p1_w.levering_hoog;

zeep::json::element opname;
to_element(opname, huidig);
sub.put("huidig", opname);
zeep::json::element opname;
to_element(opname, huidig);
sub.put("huidig", opname);
}
catch (const std::exception &e)
{
}

return get_template_processor().create_reply_from_template("opnames", sub);
}
Expand All @@ -775,16 +784,22 @@ void e_web_controller::invoer(const zeep::http::request &request, const zeep::ht
std::string id = request.get_parameter("id", "");
if (id.empty())
{
o = DataService::instance().get_last_opname();
o.id.clear();
o.datum = {};
try
{
o = DataService::instance().get_last_opname();
o.id.clear();
o.datum = {};

auto p1_w = P1Service::instance().get_current();
auto p1_w = P1Service::instance().get_current();

o.standen["2"] = p1_w.verbruik_laag;
o.standen["3"] = p1_w.verbruik_hoog;
o.standen["4"] = p1_w.levering_laag;
o.standen["5"] = p1_w.levering_hoog;
o.standen["2"] = p1_w.verbruik_laag;
o.standen["3"] = p1_w.verbruik_hoog;
o.standen["4"] = p1_w.levering_laag;
o.standen["5"] = p1_w.levering_hoog;
}
catch (const std::exception &e)
{
}
}
else
o = DataService::instance().get_opname(id);
Expand Down Expand Up @@ -956,7 +971,7 @@ Command should be either:
}

zeep::http::daemon server([&]()
{
{
auto s = new zeep::http::server(sc.get(), "docroot");

if (config.has("context"))
Expand Down
56 changes: 53 additions & 3 deletions webapp/style.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,58 @@
// @use "sass:math";
@use "sass:math";

// (Required) Import Bootstrap
@import "bootstrap/scss/_functions";
@import "bootstrap/scss/_variables";
@import "bootstrap/scss/_mixins";

.alert {
border: 1px solid;
}

@import "bootstrap/scss/_alert";

$card-box-shadow: $box-shadow;

// (Required) Import Bootstrap
@import "bootstrap/scss/bootstrap";
@import "~bootstrap-icons/font/bootstrap-icons.css";

// Generic layout, forcing a footer at the bottom
body {
display: flex;
min-height: 100vh;
height: 100%;
flex-direction: column;

header,
footer {
flex: none;
}

footer {
clear: both;
border-top: 1px solid #888;
padding: 0.5em;
margin-top: 2em;
font-size: small;
color: #555;
white-space: pre;
}

&>div.container {
flex: 1 0 auto;
padding: var(--space) var(--space) 0;
width: 100%;

&::after {
content: '\00a0';
/* &nbsp; */
display: block;
margin-top: var(--space);
height: 0px;
visibility: hidden;
}
}
}

/* * {
font-family: sans-serif;
Expand Down Expand Up @@ -37,7 +88,6 @@ g.tick line {
opacity: 0.7;
}


.head {
display: block;
height: 5em;
Expand Down

0 comments on commit 4e10b78

Please sign in to comment.