Skip to content

Commit

Permalink
Remove storing p1_opname and soc_status
Browse files Browse the repository at this point in the history
  • Loading branch information
mhekkel committed Sep 10, 2024
1 parent 05e1493 commit 7339ed4
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 115 deletions.
62 changes: 0 additions & 62 deletions src/data-service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,68 +91,6 @@ void DataService_v2::reset_connection()
s_connection.reset(nullptr);
}

void DataService_v2::store(const P1Opname &opname)
{
if (m_read_only)
return;

bool first_reset = true;
do
{
try
{
pqxx::transaction tx(get_connection());

tx.exec("INSERT INTO p1_opname (verbruik_hoog, verbruik_laag, levering_hoog, levering_laag) VALUES (" +
tx.quote(opname.verbruik_hoog) + ", " +
tx.quote(opname.verbruik_laag) + ", " +
tx.quote(opname.levering_hoog) + ", " +
tx.quote(opname.levering_laag) + ")");
tx.commit();
}
catch (const pqxx::broken_connection &e)
{
if (first_reset)
{
first_reset = false;
reset_connection();
continue;
}
std::cerr << "Failed to write opname: " << e.what() << '\n';
}
} while (false);
}

void DataService_v2::store(const SessySOC &soc)
{
if (m_read_only)
return;

bool first_reset = true;
do
{
try
{
pqxx::transaction tx(get_connection());

tx.exec("INSERT INTO sessy_soc (nr, soc) VALUES (" +
tx.quote(soc.nr) + ", " +
tx.quote(soc.sessy.state_of_charge) + ")");
tx.commit();
}
catch (const pqxx::broken_connection &e)
{
if (first_reset)
{
first_reset = false;
reset_connection();
continue;
}
std::cerr << "Failed to write opname: " << e.what() << '\n';
}
} while (false);
}

void DataService_v2::store(const GrafiekPunt &pt)
{
if (m_read_only)
Expand Down
2 changes: 0 additions & 2 deletions src/data-service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ class DataService_v2
public:
static DataService_v2 &instance();

void store(const P1Opname &opname);
void store(const SessySOC &soc);
void store(const GrafiekPunt &pt);

void reset_connection();
Expand Down
16 changes: 0 additions & 16 deletions src/p1-service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,6 @@ void P1Service::run()
{
using namespace std::literals;

using namespace date;
using namespace std::chrono;

using quarters = std::chrono::duration<int64_t, std::ratio<60 * 15>>;

auto now = std::chrono::system_clock::now();
auto next = ceil<quarters>(now);

for (;;)
{
try
Expand All @@ -88,14 +80,6 @@ void P1Service::run()
m_opname = opname;
m_status = status;
}

now = std::chrono::system_clock::now();
if (now < next)
continue;

DataService_v2::instance().store(m_opname);

next = ceil<quarters>(now);
}
catch (const std::exception &e)
{
Expand Down
30 changes: 0 additions & 30 deletions src/sessy-service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,43 +55,13 @@ SessyService &SessyService::instance()
SessyService::SessyService(boost::asio::io_context &io_context)
: m_io_context(io_context)
{
m_current = read();
m_thread = std::thread(std::bind(&SessyService::run, this));
}

std::vector<SessySOC> SessyService::get_soc() const
{
return read();
}

void SessyService::run()
{
using namespace std::literals;

using namespace date;
using namespace std::chrono;

using quarters = std::chrono::duration<int64_t, std::ratio<60 * 15>>;

for (;;)
{
try
{
auto now = std::chrono::system_clock::now();
std::this_thread::sleep_until(ceil<quarters>(now));

m_current = read();

for (auto &soc : m_current)
DataService_v2::instance().store(soc);
}
catch (const std::exception &e)
{
std::cerr << e.what() << '\n';
}
}
}

std::vector<SessySOC> SessyService::read() const
{
auto &config = mcfp::config::instance();
Expand Down
5 changes: 0 additions & 5 deletions src/sessy-service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,8 @@ class SessyService
private:
SessyService(boost::asio::io_context &io_context);

void run();

std::vector<SessySOC> read() const;

boost::asio::io_context &m_io_context;
std::thread m_thread;
std::vector<SessySOC> m_current;

static std::unique_ptr<SessyService> s_instance;
};

0 comments on commit 7339ed4

Please sign in to comment.