Select Git revision
SmartGridModel.cpp 2.97 KiB
/// @file SmartGridModel.cpp
///
#include "SmartGridModel.hpp"
// #include "spdlog/spdlog.h"
SmartGridModel::SmartGridModel(HardwareControl &modell)
: m_modell(modell)
{
std::srand(std::time(nullptr));
update_states();
}
void SmartGridModel::update_wind()
{
auto base_wind = 500.0;
auto wind_by_sun = m_sun * 5.0;
auto random_wind = (((std::rand() * 1.0) / RAND_MAX) * 100.0) - 50.0;
m_wind = base_wind + wind_by_sun + random_wind;
}
void SmartGridModel::update_modell()
{
auto sun = m_sun * 3.5;
auto wind = m_wind / 9.3;
auto renewable = (sun + wind) / 1.5;
m_modell.set_solar_plant(sun);
m_modell.update_windmill_speed(wind);
m_modell.set_windmill_net(wind);
m_modell.set_renewable_net(renewable);
if (m_production.conventional > 0)
{
m_modell.set_power_plant(200);
m_modell.set_village_color(200, renewable);
}
else
{
m_modell.set_power_plant(0);
m_modell.set_village_color(0, renewable);
}
}
void SmartGridModel::update_power_production()
{
m_production.renewable.solar = m_sun * m_solar_size;
m_production.renewable.wind = m_wind * m_windpark_size;
if (m_usage.sum() > m_production.clean())
{
m_excess_power = 0.0;
m_production.conventional = m_usage.sum() - m_production.clean();
}
else
{
m_excess_power = m_production.clean() - m_usage.sum();
m_production.conventional = 0;
}
}
double SmartGridModel::calc_excess_power()
{
auto sum_prod = m_production.conventional + m_production.renewable.solar + m_production.renewable.wind;
auto sum_used = m_usage.industry + m_usage.village;
m_excess_power = sum_prod - sum_used;
return m_excess_power;
}
void SmartGridModel::update_power_consumption()
{
m_usage.village = village_consumption_at[m_time] * m_village_size;
if (m_producing == true)
{
m_usage.industry = MaxPower::industry;
}
else
{
m_usage.industry = 0.0;
}
}
void SmartGridModel::next_hour()
{
if (m_time < 23)
{
set_time(m_time + 1);
}
else
{
set_time(0);
}
update_states();
}
void SmartGridModel::update_sun()
{
m_sun = sunnshine_percentage[m_time] + 3;
}
void SmartGridModel::print_states()
{
// spdlog::debug("Time <{}> Sun <{}> Wind<{}>", m_time, m_sun, m_wind);
// spdlog::debug("Power Conv <{}> Solar <{}> Wind<{}>", m_production.conventional, m_production.renewable.solar, m_production.renewable.wind);
// spdlog::debug("Usage Village<{}> Industry<{}>", m_usage.village, m_usage.industry);
// spdlog::debug("excess_power<{}>", calc_excess_power());
}
void SmartGridModel::update_states()
{
update_sun();
update_wind();
update_power_consumption();
update_power_production();
update_modell();
print_states();
}
void SmartGridModel::set_time(int hour)
{
if ((hour >= 0) & (hour <= 23))
{
m_time = hour;
}
else
{
m_time = 0;
}
}