Compare commits
10 Commits
bfd03a0bcb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c0fc5c61d | |||
| 5814fdd0cb | |||
| 90a16ddcb9 | |||
| e9accc56cc | |||
| 0d99c5aa35 | |||
| 6c3dc79f37 | |||
| 86b255a140 | |||
| 04c16b63ce | |||
| 6917793786 | |||
| 072f25cc0e |
@ -1,7 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.30)
|
||||
project(Sim_C__)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 26)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-static")
|
||||
add_executable(Sim_C__
|
||||
src/main.cpp
|
||||
src/model/Community.cpp
|
||||
@ -21,6 +22,30 @@ add_executable(Sim_C__
|
||||
src/services/Cost/TaxComponent.cpp
|
||||
src/services/Cost/TaxComponent.h
|
||||
src/helper/Curry.h
|
||||
src/Config.h
|
||||
src/services/Cost/NetworkProvider.cpp
|
||||
src/services/Cost/NetworkProvider.h
|
||||
src/services/Cost/CalculateFinalSums.cpp
|
||||
src/services/Cost/CalculateFinalSums.h
|
||||
src/services/Cost/GridCost/MeasurementServiceFee.cpp
|
||||
src/services/Cost/GridCost/MeasurementServiceFee.h
|
||||
src/services/Cost/GridCost/NetUsagePerformance.cpp
|
||||
src/services/Cost/GridCost/NetUsagePerformance.h
|
||||
src/services/Cost/BillCharge.cpp
|
||||
src/services/Cost/BillCharge.h
|
||||
src/services/CostHistory.cpp
|
||||
src/services/CostHistory.h
|
||||
src/services/Cost/ServiceCharge.cpp
|
||||
src/services/Cost/ServiceCharge.h
|
||||
src/helper/StringOperations.cpp
|
||||
src/helper/StringOperations.h
|
||||
src/helper/CsvBinary.cpp
|
||||
src/helper/CsvBinary.h
|
||||
tests/helper/test_CsvBinary.cpp
|
||||
src/helper/CalculateProfile.cpp
|
||||
src/helper/CalculateProfile.h
|
||||
src/singelton/UsageProfile.cpp
|
||||
src/singelton/UsageProfile.h
|
||||
)
|
||||
find_package(doctest CONFIG REQUIRED)
|
||||
find_package(spdlog CONFIG REQUIRED)
|
||||
|
||||
6
conandata.yml
Normal file
6
conandata.yml
Normal file
@ -0,0 +1,6 @@
|
||||
# This file is managed by Conan, contents will be overwritten.
|
||||
# To keep your changes, remove these comment lines, but the plugin won't be able to modify your requirements
|
||||
|
||||
requirements:
|
||||
- "doctest/2.4.11"
|
||||
- "spdlog/1.15.1"
|
||||
28
conanfile.py
Normal file
28
conanfile.py
Normal file
@ -0,0 +1,28 @@
|
||||
# This file is managed by Conan, contents will be overwritten.
|
||||
# To keep your changes, remove these comment lines, but the plugin won't be able to modify your requirements
|
||||
|
||||
from conan import ConanFile
|
||||
from conan.tools.cmake import cmake_layout, CMakeToolchain
|
||||
|
||||
class ConanApplication(ConanFile):
|
||||
package_type = "application"
|
||||
settings = "os", "compiler", "build_type", "arch"
|
||||
generators = "CMakeDeps"
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self)
|
||||
|
||||
def generate(self):
|
||||
tc = CMakeToolchain(self)
|
||||
tc.user_presets_path = False
|
||||
tc.cache_variables["CMAKE_FIND_LIBRARY_SUFFIXES"] = ".a;.lib" # Prefer static libraries
|
||||
tc.cache_variables["CMAKE_LINK_SEARCH_START_STATIC"] = "ON"
|
||||
tc.cache_variables["CMAKE_LINK_SEARCH_END_STATIC"] = "ON"
|
||||
tc.generate()
|
||||
|
||||
def requirements(self):
|
||||
requirements = self.conan_data.get('requirements', [])
|
||||
for requirement in requirements:
|
||||
self.requires(requirement)
|
||||
def configure(self):
|
||||
self.options["*"].shared = False
|
||||
21
src/Config.h
Normal file
21
src/Config.h
Normal file
@ -0,0 +1,21 @@
|
||||
//
|
||||
// Created by StanislausCichocki on 11.03.2025.
|
||||
//
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
#ifdef NDEBUG // Release mode
|
||||
#define LOG_DEBUG_INFO(...)
|
||||
#define LOG_DEBUG_ERROR(...)
|
||||
#else
|
||||
#define LOG_DEBUG_INFO(...) spdlog::info(__VA_ARGS__)
|
||||
#define LOG_DEBUG_ERROR(...) spdlog::error(__VA_ARGS__)
|
||||
#endif
|
||||
#define VALUE_COUNT ((size_t)(4 * 24 * 365))
|
||||
#define MAX_CONDITIONS 2560
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
typedef std::unique_ptr<std::vector<std::pair<std::string, std::vector<std::string>>>> usageProfile;
|
||||
|
||||
#endif //CONFIG_H
|
||||
95
src/helper/CalculateProfile.cpp
Normal file
95
src/helper/CalculateProfile.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
//
|
||||
// Created by stani on 3/14/2025.
|
||||
|
||||
#include "CalculateProfile.h"
|
||||
|
||||
#include <charconv>
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
|
||||
#include "../singelton/UsageProfile.h"
|
||||
#include <ranges>
|
||||
#include <tuple>
|
||||
|
||||
/**
|
||||
*
|
||||
* @param profileNameCon Name of the Consumption Profile e.g. G1
|
||||
* @param profileNameGen Name of the Generation Profile e.g. Solar
|
||||
* @param annualConsumption Annual Consumption value
|
||||
* @param annualGeneration Annual Consumption value
|
||||
* @return Tuple first element consumption vector, second generation Vector
|
||||
* @throws runtime_error if profileNameCon or profileNameGen is not loaded
|
||||
* @throws
|
||||
*/
|
||||
std::tuple<std::vector<float>, std::vector<float>> CalculateProfile::calculateProfile(
|
||||
const std::string& profileNameCon, const std::string& profileNameGen, const float annualConsumption,
|
||||
const float annualGeneration)
|
||||
{
|
||||
const UsageProfile* profiles = UsageProfile::getInstance();
|
||||
std::vector<float> calculatedConProfile;
|
||||
std::vector<float> calculatedGenProfile;
|
||||
const auto itCon = std::ranges::find_if(*profiles->ConsumptionProfile,
|
||||
[&profileNameCon](
|
||||
const std::pair<std::string, std::vector<std::string>>& pair)
|
||||
{
|
||||
return pair.first == profileNameCon;
|
||||
});
|
||||
const auto itGen = std::ranges::find_if(*profiles->GenerationProfile,
|
||||
[&profileNameGen](
|
||||
const std::pair<std::string, std::vector<std::string>>& pair)
|
||||
{
|
||||
return pair.first == profileNameGen;
|
||||
});
|
||||
if (itCon == profiles->ConsumptionProfile->end()) {
|
||||
throw std::runtime_error("Consumption profile not found: " + profileNameCon);
|
||||
}
|
||||
if (itGen == profiles->GenerationProfile->end()) {
|
||||
throw std::runtime_error("Consumption profile not found: " + profileNameGen);
|
||||
}
|
||||
const float sumCon = std::accumulate(itCon->second.begin(), itCon->second.end(), 0.0f,
|
||||
[](const float acc, const std::string& str)
|
||||
{
|
||||
float value;
|
||||
const auto result = std::from_chars(str.data(), str.data() + str.size(), value);
|
||||
if (result.ec != std::errc())
|
||||
{
|
||||
throw std::invalid_argument("Invalid number format: " + str);
|
||||
}
|
||||
return acc + value;
|
||||
});
|
||||
|
||||
const float sumGen = std::accumulate(itGen->second.begin(), itGen->second.end(), 0.0f,
|
||||
[](const float acc, const std::string& str)
|
||||
{
|
||||
float value = 0.0f;
|
||||
auto result = std::from_chars(str.data(), str.data() + str.size(), value);
|
||||
if (result.ec != std::errc())
|
||||
{
|
||||
throw std::invalid_argument("Invalid number format: " + str);
|
||||
}
|
||||
return acc + value;
|
||||
});
|
||||
|
||||
for (auto&& [consumption, generation] : std::views::zip(
|
||||
itCon->second,
|
||||
itGen->second
|
||||
))
|
||||
{
|
||||
float floatCon = 0.f;
|
||||
float floatGen = 0.f;
|
||||
const auto res1 = std::from_chars(consumption.data(), consumption.data() + consumption.size(), floatCon);
|
||||
const auto res2 = std::from_chars(generation.data(), generation.data() + generation.size(), floatGen);
|
||||
if (res1.ec == std::errc::invalid_argument || res2.ec == std::errc::invalid_argument)
|
||||
{
|
||||
throw std::invalid_argument("Not a float");
|
||||
}
|
||||
if (res1.ec == std::errc::result_out_of_range || res2.ec == std::errc::result_out_of_range)
|
||||
{
|
||||
throw std::out_of_range("Out fo range");
|
||||
}
|
||||
calculatedConProfile.push_back(floatCon * annualConsumption / sumCon);
|
||||
calculatedGenProfile.push_back(floatGen * annualGeneration / sumGen);
|
||||
}
|
||||
return make_tuple(std::move(calculatedConProfile),
|
||||
std::move(calculatedGenProfile));
|
||||
}
|
||||
20
src/helper/CalculateProfile.h
Normal file
20
src/helper/CalculateProfile.h
Normal file
@ -0,0 +1,20 @@
|
||||
//
|
||||
// Created by stani on 3/14/2025.
|
||||
//
|
||||
|
||||
#ifndef CALCULATEPROFILE_H
|
||||
#define CALCULATEPROFILE_H
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
class CalculateProfile
|
||||
{
|
||||
public:
|
||||
static std::tuple<std::vector<float>, std::vector<float>> calculateProfile(
|
||||
const std::string& profileNameCon, const std::string& profileNameGen, float annualConsumption,
|
||||
float annualGeneration);
|
||||
};
|
||||
|
||||
|
||||
#endif //CALCULATEPROFILE_H
|
||||
213
src/helper/CsvBinary.cpp
Normal file
213
src/helper/CsvBinary.cpp
Normal file
@ -0,0 +1,213 @@
|
||||
//
|
||||
// Created by stani on 3/14/25.
|
||||
//
|
||||
|
||||
#include "CsvBinary.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "../Config.h"
|
||||
|
||||
std::vector<std::string> CsvBinary::splitLine(const std::string& line, const char delimiter)
|
||||
{
|
||||
std::vector<std::string> tokens;
|
||||
std::stringstream ss(line);
|
||||
std::string token;
|
||||
while (std::getline(ss, token, delimiter))
|
||||
{
|
||||
tokens.push_back(token);
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
void CsvBinary::csvToBinary(const std::string& csvFile, const std::string& binFile)
|
||||
{
|
||||
std::ifstream inFile(csvFile);
|
||||
std::ofstream outFile(binFile, std::ios::binary);
|
||||
|
||||
if (!inFile.is_open() || !outFile.is_open())
|
||||
{
|
||||
LOG_DEBUG_ERROR("Failed opening file");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string line;
|
||||
bool isHeader = true;
|
||||
std::vector<std::string> header;
|
||||
|
||||
std::stringstream jsonHeader;
|
||||
jsonHeader << "{\"headers\":[";
|
||||
|
||||
while (std::getline(inFile, line))
|
||||
{
|
||||
std::vector<std::string> row = splitLine(line, ';');
|
||||
|
||||
if (isHeader)
|
||||
{
|
||||
header = row;
|
||||
|
||||
// Store header as JSON
|
||||
for (size_t i = 0; i < header.size(); ++i)
|
||||
{
|
||||
jsonHeader << "\"" << header[i] << "\"";
|
||||
if (i < header.size() - 1) jsonHeader << ",";
|
||||
}
|
||||
jsonHeader << "]}";
|
||||
|
||||
std::string jsonStr = jsonHeader.str();
|
||||
size_t jsonSize = jsonStr.size();
|
||||
|
||||
// Write JSON size and content at the beginning of the binary file
|
||||
outFile.write(reinterpret_cast<const char*>(&jsonSize), sizeof(size_t));
|
||||
outFile.write(jsonStr.c_str(), jsonSize);
|
||||
|
||||
isHeader = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const auto& field : row)
|
||||
{
|
||||
size_t length = field.size();
|
||||
outFile.write(reinterpret_cast<const char*>(&length), sizeof(size_t));
|
||||
outFile.write(field.c_str(), length);
|
||||
}
|
||||
}
|
||||
|
||||
inFile.close();
|
||||
outFile.close();
|
||||
|
||||
LOG_DEBUG_INFO("CSV converted to binary successfully.");
|
||||
}
|
||||
|
||||
void CsvBinary::binaryToCsv(const std::string& binFile, const std::string& csvFile)
|
||||
{
|
||||
std::ifstream inFile(binFile, std::ios::binary);
|
||||
std::ofstream outFile(csvFile);
|
||||
|
||||
if (!inFile.is_open() || !outFile.is_open())
|
||||
{
|
||||
LOG_DEBUG_ERROR("Failed opening file");
|
||||
return;
|
||||
}
|
||||
|
||||
// Read JSON metadata
|
||||
size_t jsonSize;
|
||||
inFile.read(reinterpret_cast<char*>(&jsonSize), sizeof(size_t));
|
||||
|
||||
std::string jsonStr(jsonSize, ' ');
|
||||
inFile.read(&jsonStr[0], jsonSize);
|
||||
|
||||
// Parse JSON to extract headers
|
||||
std::vector<std::string> header;
|
||||
size_t start = jsonStr.find("[") + 1;
|
||||
size_t end = jsonStr.find("]");
|
||||
std::string headersStr = jsonStr.substr(start, end - start);
|
||||
|
||||
std::stringstream ss(headersStr);
|
||||
std::string field;
|
||||
while (std::getline(ss, field, ','))
|
||||
{
|
||||
field.erase(std::remove(field.begin(), field.end(), '\"'), field.end()); // Remove quotes
|
||||
header.push_back(field);
|
||||
}
|
||||
|
||||
// Write header to CSV
|
||||
for (size_t i = 0; i < header.size(); ++i)
|
||||
{
|
||||
outFile << header[i];
|
||||
if (i < header.size() - 1) outFile << ";";
|
||||
}
|
||||
outFile << "\n";
|
||||
|
||||
while (!inFile.eof())
|
||||
{
|
||||
std::vector<std::string> row;
|
||||
for (size_t i = 0; i < header.size(); ++i)
|
||||
{
|
||||
size_t length;
|
||||
if (!inFile.read(reinterpret_cast<char*>(&length), sizeof(size_t))) break;
|
||||
|
||||
std::string field(length, ' ');
|
||||
inFile.read(&field[0], length);
|
||||
row.push_back(field);
|
||||
}
|
||||
if (!row.empty())
|
||||
{
|
||||
for (size_t i = 0; i < row.size(); ++i)
|
||||
{
|
||||
outFile << row[i];
|
||||
if (i < row.size() - 1) outFile << ";";
|
||||
}
|
||||
outFile << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
inFile.close();
|
||||
outFile.close();
|
||||
|
||||
LOG_DEBUG_INFO("Binary converted back to CSV successfully.");
|
||||
}
|
||||
|
||||
std::unique_ptr<std::vector<std::pair<std::string, std::vector<std::string>>>> CsvBinary::binaryToVector(
|
||||
const std::string& binFile)
|
||||
{
|
||||
std::ifstream inFile(binFile, std::ios::binary);
|
||||
auto data = std::make_unique<std::vector<std::pair<std::string, std::vector<std::string>>>>();
|
||||
|
||||
if (!inFile.is_open())
|
||||
{
|
||||
LOG_DEBUG_ERROR("Failed to open binary file");
|
||||
return data; // Return empty structure
|
||||
}
|
||||
|
||||
// Read JSON metadata size
|
||||
size_t jsonSize;
|
||||
inFile.read(reinterpret_cast<char*>(&jsonSize), sizeof(size_t));
|
||||
|
||||
// Read JSON metadata
|
||||
std::string jsonStr(jsonSize, ' ');
|
||||
inFile.read(&jsonStr[0], jsonSize);
|
||||
|
||||
// Extract headers from JSON
|
||||
std::vector<std::string> headers;
|
||||
size_t start = jsonStr.find("[") + 1;
|
||||
size_t end = jsonStr.find("]");
|
||||
std::string headersStr = jsonStr.substr(start, end - start);
|
||||
|
||||
std::stringstream ss(headersStr);
|
||||
std::string field;
|
||||
while (std::getline(ss, field, ','))
|
||||
{
|
||||
field.erase(std::remove(field.begin(), field.end(), '\"'), field.end()); // Remove quotes
|
||||
headers.push_back(field);
|
||||
}
|
||||
|
||||
// Initialize data structure for columns
|
||||
for (const auto& header : headers)
|
||||
{
|
||||
data->emplace_back(header, std::vector<std::string>());
|
||||
}
|
||||
|
||||
// Read row data and distribute into columns
|
||||
while (!inFile.eof())
|
||||
{
|
||||
for (size_t i = 0; i < headers.size(); ++i)
|
||||
{
|
||||
size_t length;
|
||||
if (!inFile.read(reinterpret_cast<char*>(&length), sizeof(size_t))) break;
|
||||
|
||||
std::string value(length, ' ');
|
||||
if (!inFile.read(&value[0], length)) break;
|
||||
|
||||
data->at(i).second.push_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inFile.close();
|
||||
return data;
|
||||
}
|
||||
|
||||
27
src/helper/CsvBinary.h
Normal file
27
src/helper/CsvBinary.h
Normal file
@ -0,0 +1,27 @@
|
||||
//
|
||||
// Created by stani on 3/14/25.
|
||||
//
|
||||
|
||||
#ifndef CSVTOBINARY_H
|
||||
#define CSVTOBINARY_H
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class CsvBinary
|
||||
{
|
||||
private:
|
||||
static std::vector<std::string> splitLine(const std::string& line, char delimiter);
|
||||
|
||||
public:
|
||||
static void csvToBinary(const std::string& csvFile, const std::string& binFile);
|
||||
|
||||
static void binaryToCsv(const std::string& binFile, const std::string& csvFile);
|
||||
|
||||
[[nodiscard]] static std::unique_ptr<std::vector<std::pair<std::string, std::vector<std::string>>>> binaryToVector(
|
||||
const std::string& binFile);
|
||||
};
|
||||
|
||||
|
||||
#endif //CSVTOBINARY_H
|
||||
@ -5,11 +5,9 @@
|
||||
#ifndef CURRY_H
|
||||
#define CURRY_H
|
||||
|
||||
template <typename Func1, typename Func2>
|
||||
auto curry(Func1 f1, Func2 f2)
|
||||
{
|
||||
return [=](auto... args)
|
||||
{
|
||||
template<typename Func1, typename Func2>
|
||||
auto curry(Func1 f1, Func2 f2) {
|
||||
return [=](auto... args) {
|
||||
auto result1 = f1(args...);
|
||||
return f2(result1);
|
||||
};
|
||||
|
||||
20
src/helper/StringOperations.cpp
Normal file
20
src/helper/StringOperations.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
//
|
||||
// Created by StanislausCichocki on 13.03.2025.
|
||||
//
|
||||
|
||||
#include "StringOperations.h"
|
||||
|
||||
void StringOperations::splitString(const std::string& input, const std::string& delimiter, std::string& before,
|
||||
std::string& after)
|
||||
{
|
||||
if (const size_t pos = input.find(delimiter); pos != std::string::npos)
|
||||
{
|
||||
before = input.substr(0, pos);
|
||||
after = input.substr(pos + delimiter.length());
|
||||
}
|
||||
else
|
||||
{
|
||||
before = input;
|
||||
after = "";
|
||||
}
|
||||
}
|
||||
17
src/helper/StringOperations.h
Normal file
17
src/helper/StringOperations.h
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by StanislausCichocki on 13.03.2025.
|
||||
//
|
||||
|
||||
#ifndef STRINGOPERATIONS_H
|
||||
#define STRINGOPERATIONS_H
|
||||
#include <string>
|
||||
|
||||
|
||||
class StringOperations {
|
||||
public:
|
||||
static void splitString(const std::string &input, const std::string &delimiter, std::string &before, std::string &after);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //STRINGOPERATIONS_H
|
||||
@ -1,15 +1,40 @@
|
||||
//
|
||||
// Created by stani on 3/10/2025.
|
||||
//
|
||||
|
||||
#ifndef ICOSTCOMPONENT_H
|
||||
#define ICOSTCOMPONENT_H
|
||||
#include "../model/Community.h"
|
||||
|
||||
class ICostComponent
|
||||
{
|
||||
#include <bitset>
|
||||
#include "../model/Community.h"
|
||||
#include "../Config.h"
|
||||
|
||||
class ICostComponent {
|
||||
protected:
|
||||
enum NET_LEVEL
|
||||
{
|
||||
NetLevel1,
|
||||
NetLevel2,
|
||||
NetLevel3,
|
||||
NetLevel4,
|
||||
NetLevel5,
|
||||
NetLevel6,
|
||||
NetLevel7mp,
|
||||
NetLevel7op,
|
||||
NetLevel7unt
|
||||
};
|
||||
enum MEASUREMENT_TYPE
|
||||
{
|
||||
NIEDER_WANDLERZAEHLER,
|
||||
MITTLE_WANDLERZAEHLER,
|
||||
DREHSTROM_ZEAHLUNG
|
||||
};
|
||||
public:
|
||||
std::bitset<MAX_CONDITIONS> applicableConditions;
|
||||
|
||||
template<typename... Conditions>
|
||||
explicit ICostComponent(Conditions... conditions) {
|
||||
}
|
||||
|
||||
virtual ~ICostComponent() = default;
|
||||
virtual double apply(std::vector<std::unique_ptr<Community>>& communities) const = 0;
|
||||
|
||||
virtual void apply(std::unique_ptr<Building::Base> &building, std::unique_ptr<Community> &community) = 0;
|
||||
};
|
||||
|
||||
#endif //ICOSTCOMPONENT_H
|
||||
|
||||
@ -4,149 +4,437 @@
|
||||
|
||||
#include "Building.h"
|
||||
|
||||
float Building::Cost::special_rate_consumption() const {
|
||||
#include <utility>
|
||||
|
||||
#include "../helper/CalculateProfile.h"
|
||||
|
||||
float Building::Metadata::special_rate_consumption() const
|
||||
{
|
||||
return SpecialRateConsumption;
|
||||
}
|
||||
|
||||
void Building::Cost::set_special_rate_consumption(float special_rate_consumption) {
|
||||
void Building::Metadata::set_special_rate_consumption(const float special_rate_consumption)
|
||||
{
|
||||
SpecialRateConsumption = special_rate_consumption;
|
||||
}
|
||||
|
||||
float Building::Cost::special_rate_generation() const {
|
||||
float Building::Metadata::special_rate_generation() const
|
||||
{
|
||||
return SpecialRateGeneration;
|
||||
}
|
||||
|
||||
void Building::Cost::set_special_rate_generation(float special_rate_generation) {
|
||||
void Building::Metadata::set_special_rate_generation(const float special_rate_generation)
|
||||
{
|
||||
SpecialRateGeneration = special_rate_generation;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<float> > &Building::Simulation_Values::community_coverage() {
|
||||
return CommunityCoverage;
|
||||
short Building::Metadata::grid_level() const
|
||||
{
|
||||
return GridLevel;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_grid_level(const short value)
|
||||
{
|
||||
GridLevel = value;
|
||||
}
|
||||
|
||||
std::string Building::Metadata::grid_operator()
|
||||
{
|
||||
return GridOperator;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_grid_operator(std::string value)
|
||||
{
|
||||
GridOperator = std::move(value);
|
||||
}
|
||||
|
||||
float Building::Metadata::consumption_net_price() const
|
||||
{
|
||||
return ConsumptionNetPrice;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_consumption_net_price(const float value)
|
||||
{
|
||||
ConsumptionNetPrice = value;
|
||||
}
|
||||
|
||||
float Building::Metadata::generation_net_price() const
|
||||
{
|
||||
return GenerationNetPrice;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_generation_net_price(const float value)
|
||||
{
|
||||
GenerationNetPrice = value;
|
||||
}
|
||||
|
||||
float Building::Metadata::total_cost_with() const
|
||||
{
|
||||
return TotalCostWith;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_total_cost_with(const float value)
|
||||
{
|
||||
TotalCostWith = value;
|
||||
}
|
||||
|
||||
float Building::Metadata::total_cost_without() const
|
||||
{
|
||||
return TotalCostWithout;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_total_cost_without(const float value)
|
||||
{
|
||||
TotalCostWithout = value;
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, float> Building::Metadata::total_by_category_with() const
|
||||
{
|
||||
return TotalByCategoryWith;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_total_by_category_with(std::unordered_map<std::string, float> value)
|
||||
{
|
||||
TotalByCategoryWith = std::move(value);
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, float> Building::Metadata::total_by_category_without() const
|
||||
{
|
||||
return TotalByCategoryWithout;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_total_by_category_without(std::unordered_map<std::string, float> value)
|
||||
{
|
||||
TotalByCategoryWithout = std::move(value);
|
||||
}
|
||||
|
||||
std::vector<float>& Building::Simulation_Values::generation_after_community()
|
||||
{
|
||||
return GenerationAfterCommunity;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::generation_after_community(const std::vector<float>& generation_after_community)
|
||||
{
|
||||
GenerationAfterCommunity = generation_after_community;
|
||||
}
|
||||
|
||||
std::vector<float>& Building::Simulation_Values::consumption_after_community()
|
||||
{
|
||||
return ConsumptionAfterCommunity;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::consumption_after_community(const std::vector<float>& consumption_after_community)
|
||||
{
|
||||
ConsumptionAfterCommunity = consumption_after_community;
|
||||
}
|
||||
|
||||
std::vector<float>& Building::Simulation_Values::generation_to_community()
|
||||
{
|
||||
return GenerationToCommunity;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::generation_to_community(const std::vector<float>& generation_to_community)
|
||||
{
|
||||
GenerationToCommunity = generation_to_community;
|
||||
}
|
||||
|
||||
std::vector<float>& Building::Simulation_Values::consumption_from_community()
|
||||
{
|
||||
return ConsumptionFromCommunity;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::consumption_from_community(const std::vector<float>& consumption_from_community)
|
||||
{
|
||||
ConsumptionFromCommunity = consumption_from_community;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::con_from_community_relative() const
|
||||
{
|
||||
return this->ConsumptionFromCommunityRelative;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_con_from_community_relative(const float x)
|
||||
{
|
||||
this->ConsumptionFromCommunityRelative = x;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::gen_to_community_relative() const
|
||||
{
|
||||
return this->GenerationToCommunityRelative;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_gen_to_community_relative(float x)
|
||||
{
|
||||
this->GenerationToCommunityRelative = x;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::consumption_after_own_coverage_sum() const
|
||||
{
|
||||
return ConsumptionAfterCommunitySum;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_consumption_after_own_coverage_sum(const float value)
|
||||
{
|
||||
ConsumptionFromCommunityRelative = value;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::own_usage_sum() const
|
||||
{
|
||||
return OwnUsageSum;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_own_usage_sum(const float value)
|
||||
{
|
||||
OwnUsageSum = value;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::needed_con_sum() const
|
||||
{
|
||||
return NeededConSum;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_needed_con_sum(const float value)
|
||||
{
|
||||
NeededConSum = value;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::needed_gen_sum() const
|
||||
{
|
||||
return NeededGenSum;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_needed_gen_sum(const float value)
|
||||
{
|
||||
NeededGenSum = value;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::consumption_after_community_sum() const
|
||||
{
|
||||
return ConsumptionAfterCommunitySum;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_consumption_after_community_sum(const float value)
|
||||
{
|
||||
ConsumptionAfterCommunitySum = value;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::generation_after_community_sum() const
|
||||
{
|
||||
return GenerationAfterCommunitySum;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_generation_after_community_sum(const float value)
|
||||
{
|
||||
GenerationAfterCommunitySum = value;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::consumption_from_community_sum() const
|
||||
{
|
||||
return ConsumptionFromCommunitySum;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_consumption_from_community_sum(const float value)
|
||||
{
|
||||
ConsumptionFromCommunitySum = value;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::generation_to_community_sum() const
|
||||
{
|
||||
return GenerationToCommunitySum;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_generation_to_community_sum(const float values)
|
||||
{
|
||||
GenerationToCommunitySum = values;
|
||||
}
|
||||
|
||||
std::vector<float>& Building::Simulation_Values::consumption_after_own_coverage()
|
||||
{
|
||||
return ConsumptionAfterOwnCoverage;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::
|
||||
set_community_coverage(std::vector<std::unique_ptr<float> > community_coverage) {
|
||||
CommunityCoverage = std::move(community_coverage);
|
||||
set_community_coverage(std::vector<float> community_coverage)
|
||||
{
|
||||
ConsumptionAfterOwnCoverage = std::move(community_coverage);
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<float> > &Building::Simulation_Values::own_usage() {
|
||||
std::vector<float>& Building::Simulation_Values::own_usage()
|
||||
{
|
||||
return OwnUsage;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_own_usage(std::vector<std::unique_ptr<float> > own_usage) {
|
||||
void Building::Simulation_Values::set_own_usage(std::vector<float> own_usage)
|
||||
{
|
||||
OwnUsage = std::move(own_usage);
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<float> > &Building::Simulation_Values::needed_con() {
|
||||
return Needed_con;
|
||||
std::vector<float>& Building::Simulation_Values::needed_con()
|
||||
{
|
||||
return NeededCon;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_needed_con(std::vector<std::unique_ptr<float> > needed_con) {
|
||||
Needed_con = std::move(needed_con);
|
||||
void Building::Simulation_Values::set_needed_con(std::vector<float> needed_con)
|
||||
{
|
||||
NeededCon = std::move(needed_con);
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<float> > &Building::Simulation_Values::needed_gen() {
|
||||
std::vector<float>& Building::Simulation_Values::needed_gen()
|
||||
{
|
||||
return NeededGen;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_needed_gen(std::vector<std::unique_ptr<float> > needed_gen) {
|
||||
void Building::Simulation_Values::set_needed_gen(std::vector<float> needed_gen)
|
||||
{
|
||||
NeededGen = std::move(needed_gen);
|
||||
}
|
||||
|
||||
std::string Building::Metadata::name() const {
|
||||
float Building::Simulation_Values::relativeSelfConsumption() const
|
||||
{
|
||||
return RelativeSelfConsumption;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_relativeSelfConsumption(float const relativeSelfConsumption)
|
||||
{
|
||||
this->RelativeSelfConsumption = relativeSelfConsumption;
|
||||
}
|
||||
|
||||
float Building::Simulation_Values::relativeSelfGeneration() const
|
||||
{
|
||||
return RelativeGeneration;
|
||||
}
|
||||
|
||||
void Building::Simulation_Values::set_relativeSelfGeneration(float const relativeSelfGeneration)
|
||||
{
|
||||
this->RelativeGeneration = relativeSelfGeneration;
|
||||
}
|
||||
|
||||
Building::Metadata::Metadata()
|
||||
{
|
||||
auto [con, gen] = CalculateProfile::calculateProfile(ConsumptionProfileName, GenerationProfileName,
|
||||
AnnualConsumption, AnnualConsumption);
|
||||
ConsumptionProfile = std::move(con);
|
||||
GenerationProfile = std::move(gen);
|
||||
}
|
||||
|
||||
std::string Building::Metadata::name() const
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_name(const std::string &name) {
|
||||
void Building::Metadata::set_name(const std::string& name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
float Building::Metadata::annual_consumption() const {
|
||||
float Building::Metadata::annual_consumption() const
|
||||
{
|
||||
return AnnualConsumption;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_annual_consumption(float annual_consumption) {
|
||||
void Building::Metadata::set_annual_consumption(float annual_consumption)
|
||||
{
|
||||
AnnualConsumption = annual_consumption;
|
||||
}
|
||||
|
||||
float Building::Metadata::annual_generation() const {
|
||||
float Building::Metadata::annual_generation() const
|
||||
{
|
||||
return AnnualGeneration;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_annual_generation(float annual_generation) {
|
||||
void Building::Metadata::set_annual_generation(float annual_generation)
|
||||
{
|
||||
AnnualGeneration = annual_generation;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<float> > &Building::Metadata::consumption_profile() {
|
||||
std::vector<float>& Building::Metadata::consumption_profile()
|
||||
{
|
||||
return ConsumptionProfile;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_consumption_profile(std::vector<std::unique_ptr<float> > consumption_profile) {
|
||||
void Building::Metadata::set_consumption_profile(std::vector<float> consumption_profile)
|
||||
{
|
||||
ConsumptionProfile = std::move(consumption_profile);
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<float> > &Building::Metadata::generation_profile() {
|
||||
std::vector<float>& Building::Metadata::generation_profile()
|
||||
{
|
||||
return GenerationProfile;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_generation_profile(std::vector<std::unique_ptr<float> > generation_profile) {
|
||||
void Building::Metadata::set_generation_profile(std::vector<float> generation_profile)
|
||||
{
|
||||
GenerationProfile = std::move(generation_profile);
|
||||
}
|
||||
|
||||
std::string Building::Metadata::consumption_profile_name() const {
|
||||
std::string Building::Metadata::consumption_profile_name() const
|
||||
{
|
||||
return ConsumptionProfileName;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_consumption_profile_name(const std::string &consumption_profile_name) {
|
||||
void Building::Metadata::set_consumption_profile_name(const std::string& consumption_profile_name)
|
||||
{
|
||||
ConsumptionProfileName = consumption_profile_name;
|
||||
}
|
||||
|
||||
std::string Building::Metadata::generation_profile_name() const {
|
||||
std::string Building::Metadata::generation_profile_name() const
|
||||
{
|
||||
return GenerationProfileName;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_generation_profile_name(const std::string &generation_profile_name) {
|
||||
void Building::Metadata::set_generation_profile_name(const std::string& generation_profile_name)
|
||||
{
|
||||
GenerationProfileName = generation_profile_name;
|
||||
}
|
||||
|
||||
short Building::Metadata::connection_power() const {
|
||||
short Building::Metadata::connection_power() const
|
||||
{
|
||||
return ConnectionPower;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_connection_power(short connection_power) {
|
||||
void Building::Metadata::set_connection_power(short connection_power)
|
||||
{
|
||||
ConnectionPower = connection_power;
|
||||
}
|
||||
|
||||
short Building::Metadata::grid_power() const {
|
||||
short Building::Metadata::grid_power() const
|
||||
{
|
||||
return GridPower;
|
||||
}
|
||||
|
||||
void Building::Metadata::set_grid_power(short grid_power) {
|
||||
void Building::Metadata::set_grid_power(short grid_power)
|
||||
{
|
||||
GridPower = grid_power;
|
||||
}
|
||||
|
||||
std::unique_ptr<Building::Cost> &Building::Base::cost() {
|
||||
return Cost;
|
||||
std::unique_ptr<Building::Cost>& Building::Base::cost()
|
||||
{
|
||||
return CostHistory;
|
||||
}
|
||||
|
||||
void Building::Base::set_cost(std::unique_ptr<Building::Cost> cost) {
|
||||
Cost = std::move(cost);
|
||||
void Building::Base::set_cost(std::unique_ptr<Building::Cost> cost)
|
||||
{
|
||||
CostHistory = std::move(cost);
|
||||
}
|
||||
|
||||
std::unique_ptr<Building::Simulation_Values> &Building::Base::values() {
|
||||
std::shared_ptr<Building::Simulation_Values>& Building::Base::values()
|
||||
{
|
||||
return Values;
|
||||
}
|
||||
|
||||
void Building::Base::set_values(std::unique_ptr<Simulation_Values> values) {
|
||||
void Building::Base::set_values(std::shared_ptr<Simulation_Values> values)
|
||||
{
|
||||
Values = std::move(values);
|
||||
}
|
||||
|
||||
std::unique_ptr<Building::Metadata> &Building::Base::metadata() {
|
||||
return Metadata;
|
||||
std::shared_ptr<Building::Metadata>& Building::Base::metadata()
|
||||
{
|
||||
return Data;
|
||||
}
|
||||
|
||||
void Building::Base::set_metadata(std::unique_ptr<Building::Metadata> metadata) {
|
||||
Metadata = std::move(metadata);
|
||||
void Building::Base::set_metadata(const std::shared_ptr<Building::Metadata>& metadata)
|
||||
{
|
||||
Data = metadata;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -4,122 +4,224 @@
|
||||
|
||||
#ifndef BUILDING_H
|
||||
#define BUILDING_H
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "Model.h"
|
||||
#include "../Config.h"
|
||||
#include "../services/CostHistory.h"
|
||||
|
||||
|
||||
namespace Building {
|
||||
class Cost {
|
||||
namespace Building
|
||||
{
|
||||
class Cost
|
||||
{
|
||||
private:
|
||||
float SpecialRateConsumption;
|
||||
float SpecialRateGeneration;
|
||||
std::shared_ptr<CostHistory> CostValuesWith{std::make_shared<CostHistory>()};
|
||||
std::shared_ptr<CostHistory> CostValuesWithOut{std::make_shared<CostHistory>()};
|
||||
|
||||
public:
|
||||
float special_rate_consumption() const;
|
||||
|
||||
void set_special_rate_consumption(float special_rate_consumption);
|
||||
|
||||
float special_rate_generation() const;
|
||||
|
||||
void set_special_rate_generation(float special_rate_generation);
|
||||
std::shared_ptr<CostHistory>& get_cost_values_with() { return CostValuesWith; }
|
||||
std::shared_ptr<CostHistory>& get_cost_values_without() { return CostValuesWithOut; }
|
||||
};
|
||||
|
||||
class Simulation_Values {
|
||||
class Simulation_Values
|
||||
{
|
||||
private:
|
||||
std::vector<std::unique_ptr<float> > CommunityCoverage;
|
||||
std::vector<std::unique_ptr<float> > OwnUsage;
|
||||
std::vector<std::unique_ptr<float> > Needed_con;
|
||||
std::vector<std::unique_ptr<float> > NeededGen;
|
||||
std::vector<float> ConsumptionAfterOwnCoverage = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> OwnUsage = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> NeededCon = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> NeededGen = std::vector(VALUE_COUNT, 0.0f);
|
||||
float RelativeSelfConsumption{0.0f};
|
||||
float RelativeGeneration{0.0f};
|
||||
std::vector<float> ConsumptionAfterCommunity = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> GenerationAfterCommunity = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> ConsumptionFromCommunity = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> GenerationToCommunity = std::vector(VALUE_COUNT, 0.0f);
|
||||
float ConsumptionFromCommunityRelative{0.0f};
|
||||
float GenerationToCommunityRelative{0.0f};
|
||||
|
||||
float ConsumptionAfterOwnCoverageSum{0.0f};
|
||||
float OwnUsageSum{0.0f};
|
||||
float NeededConSum{0.0f};
|
||||
float NeededGenSum{0.0f};
|
||||
float ConsumptionAfterCommunitySum{0.0f};
|
||||
float GenerationAfterCommunitySum{0.0f};
|
||||
float ConsumptionFromCommunitySum{0.0f};
|
||||
float GenerationToCommunitySum{0.0f};
|
||||
|
||||
public:
|
||||
std::vector<std::unique_ptr<float> > &community_coverage();
|
||||
Simulation_Values() = default;
|
||||
|
||||
void set_community_coverage(std::vector<std::unique_ptr<float> > community_coverage);
|
||||
std::vector<float>& consumption_after_own_coverage();
|
||||
|
||||
std::vector<std::unique_ptr<float> > &own_usage();
|
||||
void set_community_coverage(std::vector<float> community_coverage);
|
||||
|
||||
void set_own_usage(std::vector<std::unique_ptr<float> > own_usage);
|
||||
std::vector<float>& own_usage();
|
||||
|
||||
std::vector<std::unique_ptr<float> > &needed_con();
|
||||
void set_own_usage(std::vector<float> own_usage);
|
||||
|
||||
void set_needed_con(std::vector<std::unique_ptr<float> > needed_con);
|
||||
std::vector<float>& needed_con();
|
||||
|
||||
std::vector<std::unique_ptr<float> > &needed_gen();
|
||||
void set_needed_con(std::vector<float> needed_con);
|
||||
|
||||
void set_needed_gen(std::vector<std::unique_ptr<float> > needed_gen);
|
||||
std::vector<float>& needed_gen();
|
||||
|
||||
void set_needed_gen(std::vector<float> needed_gen);
|
||||
|
||||
[[nodiscard]] float relativeSelfConsumption() const;
|
||||
|
||||
void set_relativeSelfConsumption(float relativeSelfConsumption);
|
||||
|
||||
[[nodiscard]] float relativeSelfGeneration() const;
|
||||
|
||||
void set_relativeSelfGeneration(float relativeSelfGeneration);
|
||||
|
||||
std::vector<float>& generation_after_community();
|
||||
|
||||
void generation_after_community(const std::vector<float>& generation_after_community);
|
||||
|
||||
std::vector<float>& consumption_after_community();
|
||||
|
||||
void consumption_after_community(const std::vector<float>& consumption_after_community);
|
||||
|
||||
std::vector<float>& generation_to_community();
|
||||
|
||||
void generation_to_community(const std::vector<float>& generation_to_community);
|
||||
|
||||
std::vector<float>& consumption_from_community();
|
||||
|
||||
void consumption_from_community(const std::vector<float>& consumption_from_community);
|
||||
|
||||
[[nodiscard]] float con_from_community_relative() const;
|
||||
|
||||
void set_con_from_community_relative(float x);
|
||||
|
||||
[[nodiscard]] float gen_to_community_relative() const;
|
||||
|
||||
void set_gen_to_community_relative(float x);
|
||||
|
||||
[[nodiscard]] float consumption_after_own_coverage_sum() const;
|
||||
void set_consumption_after_own_coverage_sum(float value);
|
||||
[[nodiscard]] float own_usage_sum() const;
|
||||
void set_own_usage_sum(float value);
|
||||
[[nodiscard]] float needed_con_sum() const;
|
||||
void set_needed_con_sum(float value);
|
||||
[[nodiscard]] float needed_gen_sum() const;
|
||||
void set_needed_gen_sum(float value);
|
||||
[[nodiscard]] float consumption_after_community_sum() const;
|
||||
void set_consumption_after_community_sum(float value);
|
||||
[[nodiscard]] float generation_after_community_sum() const;
|
||||
void set_generation_after_community_sum(float value);
|
||||
[[nodiscard]] float consumption_from_community_sum() const;
|
||||
void set_consumption_from_community_sum(float value);
|
||||
[[nodiscard]] float generation_to_community_sum() const;
|
||||
void set_generation_to_community_sum(float values);
|
||||
};
|
||||
|
||||
class Metadata {
|
||||
class Metadata
|
||||
{
|
||||
private:
|
||||
std::string Name;
|
||||
float AnnualConsumption;
|
||||
float AnnualGeneration;
|
||||
std::vector<std::unique_ptr<float> > ConsumptionProfile;
|
||||
std::vector<std::unique_ptr<float> > GenerationProfile;
|
||||
std::string ConsumptionProfileName;
|
||||
std::string GenerationProfileName;
|
||||
short ConnectionPower;
|
||||
short GridPower;
|
||||
std::string Name{};
|
||||
float AnnualConsumption{0.0f};
|
||||
float AnnualGeneration{0.0f};
|
||||
std::vector<float> ConsumptionProfile;
|
||||
std::vector<float> GenerationProfile;
|
||||
std::string ConsumptionProfileName{};
|
||||
std::string GenerationProfileName{};
|
||||
short ConnectionPower{0};
|
||||
short GridPower{0};
|
||||
float SpecialRateConsumption{0.0f};
|
||||
float SpecialRateGeneration{0.0f};
|
||||
short GridLevel{0};
|
||||
std::string GridOperator;
|
||||
float ConsumptionNetPrice{0.0f};
|
||||
float GenerationNetPrice{0.0f};
|
||||
float TotalCostWith{0.0f};
|
||||
float TotalCostWithout{0.0f};
|
||||
std::unordered_map<std::string, float> TotalByCategoryWith{};
|
||||
std::unordered_map<std::string, float> TotalByCategoryWithout{};
|
||||
|
||||
public:
|
||||
std::string name() const;
|
||||
Metadata();
|
||||
|
||||
void set_name(const std::string &name);
|
||||
|
||||
float annual_consumption() const;
|
||||
[[nodiscard]] std::string name() const;
|
||||
void set_name(const std::string& name);
|
||||
|
||||
[[nodiscard]] float annual_consumption() const;
|
||||
void set_annual_consumption(float annual_consumption);
|
||||
|
||||
float annual_generation() const;
|
||||
|
||||
[[nodiscard]] float annual_generation() const;
|
||||
void set_annual_generation(float annual_generation);
|
||||
|
||||
std::vector<std::unique_ptr<float> > &consumption_profile();
|
||||
std::vector<float>& consumption_profile();
|
||||
void set_consumption_profile(std::vector<float> consumption_profile);
|
||||
|
||||
void set_consumption_profile(std::vector<std::unique_ptr<float> > consumption_profile);
|
||||
std::vector<float>& generation_profile();
|
||||
void set_generation_profile(std::vector<float> generation_profile);
|
||||
|
||||
std::vector<std::unique_ptr<float> > &generation_profile();
|
||||
[[nodiscard]] std::string consumption_profile_name() const;
|
||||
void set_consumption_profile_name(const std::string& consumption_profile_name);
|
||||
|
||||
void set_generation_profile(std::vector<std::unique_ptr<float> > generation_profile);
|
||||
|
||||
std::string consumption_profile_name() const;
|
||||
|
||||
void set_consumption_profile_name(const std::string &consumption_profile_name);
|
||||
|
||||
std::string generation_profile_name() const;
|
||||
|
||||
void set_generation_profile_name(const std::string &generation_profile_name);
|
||||
|
||||
short connection_power() const;
|
||||
[[nodiscard]] std::string generation_profile_name() const;
|
||||
void set_generation_profile_name(const std::string& generation_profile_name);
|
||||
|
||||
[[nodiscard]] short connection_power() const;
|
||||
void set_connection_power(short connection_power);
|
||||
|
||||
short grid_power() const;
|
||||
|
||||
[[nodiscard]] short grid_power() const;
|
||||
void set_grid_power(short grid_power);
|
||||
|
||||
[[nodiscard]] float special_rate_consumption() const;
|
||||
void set_special_rate_consumption(float special_rate_consumption);
|
||||
|
||||
[[nodiscard]] float special_rate_generation() const;
|
||||
void set_special_rate_generation(float special_rate_generation);
|
||||
|
||||
[[nodiscard]] short grid_level() const;
|
||||
void set_grid_level(short value);
|
||||
|
||||
std::string grid_operator();
|
||||
void set_grid_operator(std::string value);
|
||||
|
||||
[[nodiscard]] float consumption_net_price() const;
|
||||
void set_consumption_net_price(float value);
|
||||
|
||||
[[nodiscard]] float generation_net_price() const;
|
||||
void set_generation_net_price(float value);
|
||||
|
||||
[[nodiscard]] float total_cost_with() const;
|
||||
void set_total_cost_with(float value);
|
||||
|
||||
[[nodiscard]] float total_cost_without() const;
|
||||
void set_total_cost_without(float value);
|
||||
|
||||
[[nodiscard]] std::unordered_map<std::string, float> total_by_category_with() const;
|
||||
void set_total_by_category_with(std::unordered_map<std::string, float> value);
|
||||
|
||||
[[nodiscard]] std::unordered_map<std::string, float> total_by_category_without() const;
|
||||
void set_total_by_category_without(std::unordered_map<std::string, float> value);
|
||||
};
|
||||
|
||||
class Base : public Model<Base> {
|
||||
class Base : public Model<Base>
|
||||
{
|
||||
private:
|
||||
std::unique_ptr<Cost> Cost;
|
||||
std::unique_ptr<Simulation_Values> Values;
|
||||
std::unique_ptr<Metadata> Metadata;
|
||||
std::unique_ptr<Cost> CostHistory{std::make_unique<Building::Cost>()};
|
||||
std::shared_ptr<Simulation_Values> Values{std::make_unique<Building::Simulation_Values>()};
|
||||
std::shared_ptr<Metadata> Data{std::make_unique<Building::Metadata>()};
|
||||
|
||||
public:
|
||||
std::unique_ptr<Building::Cost> &cost();
|
||||
std::unique_ptr<Building::Cost>& cost();
|
||||
|
||||
void set_cost(std::unique_ptr<Building::Cost> cost);
|
||||
|
||||
std::unique_ptr<Simulation_Values> &values();
|
||||
std::shared_ptr<Building::Simulation_Values>& values();
|
||||
|
||||
void set_values(std::unique_ptr<Simulation_Values> values);
|
||||
void set_values(std::shared_ptr<Simulation_Values> values);
|
||||
|
||||
std::unique_ptr<Building::Metadata> &metadata();
|
||||
std::shared_ptr<Building::Metadata>& metadata();
|
||||
|
||||
void set_metadata(std::unique_ptr<Building::Metadata> metadata);
|
||||
void set_metadata(const std::shared_ptr<Building::Metadata>& metadata);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -1,44 +1,86 @@
|
||||
#include "Community.h"
|
||||
|
||||
#include "../helper/Curry.h"
|
||||
|
||||
std::string Community::name() const {
|
||||
std::string Community::name() const
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
void Community::set_name(const std::string &name) {
|
||||
void Community::set_name(const std::string& name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Building::Base> > &Community::buildings() {
|
||||
std::vector<std::unique_ptr<Building::Base>>& Community::buildings()
|
||||
{
|
||||
return Buildings;
|
||||
}
|
||||
|
||||
// Use move semantics for efficiency
|
||||
void Community::set_buildings(std::vector<std::unique_ptr<Building::Base> > buildings) {
|
||||
void Community::set_buildings(std::vector<std::unique_ptr<Building::Base>> buildings)
|
||||
{
|
||||
Buildings = std::move(buildings);
|
||||
}
|
||||
|
||||
Energy_Tariff Community::energy_tariff() const {
|
||||
Energy_Tariff Community::energy_tariff() const
|
||||
{
|
||||
return energy_Tariff;
|
||||
}
|
||||
|
||||
void Community::set_energy_tariff(const Energy_Tariff &energy_tariff) {
|
||||
void Community::set_energy_tariff(const Energy_Tariff& energy_tariff)
|
||||
{
|
||||
energy_Tariff = energy_tariff;
|
||||
}
|
||||
|
||||
auto Community::iterateBuildings(
|
||||
std::vector<std::unique_ptr<Community> > &Communities) -> std::function<std::function<void(
|
||||
const std::function<void(Building::Base &)> &)>(const std::function<void(Community &)> &)> {
|
||||
return [&](const std::function<void(Community &)> &func1) {
|
||||
return [&, func1](const std::function<void(Building::Base &)> &func2) {
|
||||
iterateVector(Communities, func1);
|
||||
std::vector<float>& Community::generation_available()
|
||||
{
|
||||
return GenerationAvailable;
|
||||
}
|
||||
|
||||
iterateVector(Communities, [&](Community &community) {
|
||||
for (auto &building: community.buildings()) {
|
||||
func2(*building);
|
||||
void Community::set_generation_available(std::vector<float>& generationAvailable)
|
||||
{
|
||||
this->GenerationAvailable = generationAvailable;
|
||||
}
|
||||
|
||||
std::vector<float>& Community::consumption_available()
|
||||
{
|
||||
return ConsumptionAvailable;
|
||||
}
|
||||
|
||||
void Community::set_consumption_available(std::vector<float>& consumptionAvailable)
|
||||
{
|
||||
this->ConsumptionAvailable = consumptionAvailable;
|
||||
}
|
||||
|
||||
std::vector<bool>& Community::is_gen_bigger_than_con()
|
||||
{
|
||||
return IsGenBiggerThanCon;
|
||||
}
|
||||
|
||||
void Community::set_is_gen_bigger_than_con(std::vector<bool>& isGenBiggerThanCon)
|
||||
{
|
||||
this->IsGenBiggerThanCon = isGenBiggerThanCon;
|
||||
}
|
||||
|
||||
auto Community::iterateBuildings(
|
||||
std::vector<std::unique_ptr<Community>>& Communities)
|
||||
-> std::function<std::function<void(const std::function<void(Community&, Building::Base&)>&)>(
|
||||
const std::function<void(Community&)>&)>
|
||||
{
|
||||
return [&](const std::function<void(Community&)>& func1)
|
||||
{
|
||||
return [&, func1](const std::function<void(Community&, Building::Base&)>& func2)
|
||||
{
|
||||
for (auto& community : Communities)
|
||||
{
|
||||
func1(*community);
|
||||
for (auto& building : community->buildings())
|
||||
{
|
||||
func2(*community, *building);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -4,34 +4,57 @@
|
||||
|
||||
#ifndef COMMUNITY_H
|
||||
#define COMMUNITY_H
|
||||
#include <bitset>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "../Config.h"
|
||||
#include "Building.h"
|
||||
#include "Energy_Tariff.h"
|
||||
|
||||
|
||||
class Community : public Model<Community> {
|
||||
class Community : public Model<Community>
|
||||
{
|
||||
public:
|
||||
std::string name() const;
|
||||
float total{0.f};
|
||||
|
||||
void set_name(const std::string &name);
|
||||
[[nodiscard]] std::string name() const;
|
||||
|
||||
std::vector<std::unique_ptr<Building::Base> > &buildings();
|
||||
void set_name(const std::string& name);
|
||||
|
||||
void set_buildings(std::vector<std::unique_ptr<Building::Base> > buildings);
|
||||
std::vector<std::unique_ptr<Building::Base>>& buildings();
|
||||
|
||||
Energy_Tariff energy_tariff() const;
|
||||
void set_buildings(std::vector<std::unique_ptr<Building::Base>> buildings);
|
||||
|
||||
void set_energy_tariff(const Energy_Tariff &energy_tariff);
|
||||
[[nodiscard]] Energy_Tariff energy_tariff() const;
|
||||
|
||||
static std::function<std::function<void(const std::function<void(Building::Base &)> &)>
|
||||
(const std::function<void(Community &)> &)>
|
||||
iterateBuildings(std::vector<std::unique_ptr<Community> > &Communities);
|
||||
void set_energy_tariff(const Energy_Tariff& energy_tariff);
|
||||
|
||||
std::vector<float>& generation_available();
|
||||
|
||||
void set_generation_available(std::vector<float>& generationAvailable);
|
||||
|
||||
std::vector<float>& consumption_available();
|
||||
|
||||
void set_consumption_available(std::vector<float>& consumptionAvailable);
|
||||
|
||||
std::vector<bool>& is_gen_bigger_than_con();
|
||||
|
||||
void set_is_gen_bigger_than_con(std::vector<bool>& isGenBiggerThanCon);
|
||||
|
||||
static std::function<std::function<void(const std::function<void(Community&, Building::Base&)>&)>(const std::
|
||||
function<void(
|
||||
Community&)>&)>
|
||||
iterateBuildings(std::vector<std::unique_ptr<Community>>& Communities);
|
||||
|
||||
private:
|
||||
std::string Name;
|
||||
std::vector<std::unique_ptr<Building::Base> > Buildings;
|
||||
std::vector<std::unique_ptr<Building::Base>> Buildings;
|
||||
std::vector<float> GenerationAvailable = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<float> ConsumptionAvailable = std::vector(VALUE_COUNT, 0.0f);
|
||||
std::vector<bool> IsGenBiggerThanCon = std::vector(VALUE_COUNT, false);
|
||||
|
||||
|
||||
Energy_Tariff energy_Tariff;
|
||||
};
|
||||
|
||||
|
||||
@ -7,6 +7,11 @@
|
||||
|
||||
|
||||
class Energy_Tariff {
|
||||
public:
|
||||
float consumption_tariff{0.0f};
|
||||
float generation_tariff{0.0f};
|
||||
float bill_charge{0.0f};
|
||||
float service_charge{0.0f};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -5,15 +5,12 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
template <class T>
|
||||
class Model
|
||||
{
|
||||
template<class T>
|
||||
class Model {
|
||||
public:
|
||||
static void iterateVector(std::vector<std::unique_ptr<T>>& vector,
|
||||
const std::function<void(T&)>& function)
|
||||
{
|
||||
for (auto& item : vector)
|
||||
{
|
||||
static void iterateVector(std::vector<std::unique_ptr<T> > &vector,
|
||||
const std::function<void(T &)> &function) {
|
||||
for (auto &item: vector) {
|
||||
function(*item);
|
||||
}
|
||||
}
|
||||
|
||||
11
src/services/Cost/BillCharge.cpp
Normal file
11
src/services/Cost/BillCharge.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
//
|
||||
// Created by stani on 3/12/2025.
|
||||
//
|
||||
|
||||
#include "BillCharge.h"
|
||||
|
||||
void BillCharge::apply(std::unique_ptr<Building::Base>& building, std::unique_ptr<Community>& community)
|
||||
{
|
||||
const std::shared_ptr<CostHistory>& valuesWith = building->cost()->get_cost_values_with();
|
||||
valuesWith->add_cost_point("Bill charge",1.0f,community->energy_tariff().bill_charge);
|
||||
}
|
||||
17
src/services/Cost/BillCharge.h
Normal file
17
src/services/Cost/BillCharge.h
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by stani on 3/12/2025.
|
||||
//
|
||||
|
||||
#ifndef BILLCHARGE_H
|
||||
#define BILLCHARGE_H
|
||||
#include "../../interfaces/ICostComponent.h"
|
||||
|
||||
|
||||
class BillCharge : public ICostComponent
|
||||
{
|
||||
public:
|
||||
void apply(std::unique_ptr<Building::Base>& building, std::unique_ptr<Community>& community) override;
|
||||
};
|
||||
|
||||
|
||||
#endif //BILLCHARGE_H
|
||||
18
src/services/Cost/CalculateFinalSums.cpp
Normal file
18
src/services/Cost/CalculateFinalSums.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
//
|
||||
// Created by stani on 3/13/2025.
|
||||
//
|
||||
|
||||
#include "CalculateFinalSums.h"
|
||||
|
||||
void CalculateFinalSums::apply(std::unique_ptr<Building::Base>& building, std::unique_ptr<Community>& community)
|
||||
{
|
||||
const std::shared_ptr<CostHistory>& valuesWith = building->cost()->get_cost_values_with();
|
||||
const std::shared_ptr<CostHistory>& valuesWithout = building->cost()->get_cost_values_without();
|
||||
const auto& metadata = building->metadata();
|
||||
metadata->set_total_cost_with(valuesWith->total_cost());
|
||||
metadata->set_total_by_category_with(valuesWith->calculateCategories());
|
||||
|
||||
metadata->set_total_cost_without(valuesWithout->total_cost());
|
||||
metadata->set_total_by_category_without(valuesWithout->calculateCategories());
|
||||
community->total += valuesWithout->total_cost();
|
||||
}
|
||||
17
src/services/Cost/CalculateFinalSums.h
Normal file
17
src/services/Cost/CalculateFinalSums.h
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by stani on 3/13/2025.
|
||||
//
|
||||
|
||||
#ifndef CALCULATEFINALSUMS_H
|
||||
#define CALCULATEFINALSUMS_H
|
||||
#include "../../interfaces/ICostComponent.h"
|
||||
|
||||
|
||||
class CalculateFinalSums : public ICostComponent
|
||||
{
|
||||
public:
|
||||
void apply(std::unique_ptr<Building::Base>& building, std::unique_ptr<Community>& community) override;
|
||||
};
|
||||
|
||||
|
||||
#endif //CALCULATEFINALSUMS_H
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
#include "CostPipeline.h"
|
||||
|
||||
|
||||
void CostPipeline::addCostComponent(const std::shared_ptr<ICostComponent>& components)
|
||||
{
|
||||
this->components.push_back(components);
|
||||
@ -11,8 +12,27 @@ void CostPipeline::addCostComponent(const std::shared_ptr<ICostComponent>& compo
|
||||
|
||||
void CostPipeline::calculateFinalCost()
|
||||
{
|
||||
for (auto& component : this->components)
|
||||
for (size_t i = 0; i < this->components.size() - 1; i++)
|
||||
{
|
||||
component->apply(this->communities);
|
||||
iterateCommunity(this->components[i]);
|
||||
}
|
||||
// Ensure CalculateFinalSums is last
|
||||
iterateCommunity(this->components.back());
|
||||
}
|
||||
|
||||
|
||||
void CostPipeline::iterateCommunity(std::shared_ptr<ICostComponent>& component) const
|
||||
{
|
||||
for (auto& community : this->communities)
|
||||
{
|
||||
iterateBuilding(community, component);
|
||||
}
|
||||
}
|
||||
|
||||
void CostPipeline::iterateBuilding(std::unique_ptr<Community>& community, std::shared_ptr<ICostComponent>& component)
|
||||
{
|
||||
for (auto& building : community->buildings())
|
||||
{
|
||||
component->apply(building, community);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,21 +6,26 @@
|
||||
#define COSTPIPELINE_H
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "../../interfaces/ICostComponent.h"
|
||||
#include "../../model/Community.h"
|
||||
|
||||
class CostPipeline
|
||||
{
|
||||
std::vector<std::unique_ptr<Community>>& communities;
|
||||
std::vector<std::shared_ptr<ICostComponent>> components;
|
||||
class CostPipeline {
|
||||
std::vector<std::unique_ptr<Community> > &communities;
|
||||
std::vector<std::shared_ptr<ICostComponent> > components;
|
||||
|
||||
public:
|
||||
CostPipeline(std::vector<std::unique_ptr<Community>>& communities) : communities(communities)
|
||||
{
|
||||
explicit CostPipeline(std::vector<std::unique_ptr<Community> > &communities) : communities(communities) {
|
||||
}
|
||||
|
||||
void addCostComponent(const std::shared_ptr<ICostComponent>& components);
|
||||
void addCostComponent(const std::shared_ptr<ICostComponent> &components);
|
||||
|
||||
void calculateFinalCost();
|
||||
|
||||
void iterateCommunity(std::shared_ptr<ICostComponent> &component) const;
|
||||
|
||||
|
||||
static void iterateBuilding(std::unique_ptr<Community> &community, std::shared_ptr<ICostComponent> &component);
|
||||
};
|
||||
|
||||
|
||||
|
||||
35
src/services/Cost/GridCost/MeasurementServiceFee.cpp
Normal file
35
src/services/Cost/GridCost/MeasurementServiceFee.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
//
|
||||
// Created by stani on 3/13/2025.
|
||||
//
|
||||
|
||||
#include "MeasurementServiceFee.h"
|
||||
|
||||
void MeasurementServiceFee::apply(std::unique_ptr<Building::Base>& building, std::unique_ptr<Community>& community)
|
||||
{
|
||||
const auto& valuesWith = building->cost()->get_cost_values_with();
|
||||
const auto& valuesWithout = building->cost()->get_cost_values_without();
|
||||
const short grid_level = building->metadata()->grid_level();
|
||||
|
||||
//TODO use actual value
|
||||
float measurement_cost = 1.f;
|
||||
const short measurementType = getMeasurementServiceFeeType(grid_level);
|
||||
|
||||
valuesWith->add_cost_point("Messentgelt",measurement_cost,1.f);
|
||||
valuesWithout->add_cost_point("Messentgelt",measurement_cost,1.f);
|
||||
}
|
||||
|
||||
short MeasurementServiceFee::getMeasurementServiceFeeType(const short grid_level)
|
||||
{
|
||||
switch (grid_level)
|
||||
{
|
||||
case NetLevel6:
|
||||
case NetLevel7mp:
|
||||
return MITTLE_WANDLERZAEHLER;
|
||||
case NetLevel7op:
|
||||
case NetLevel7unt:
|
||||
return DREHSTROM_ZEAHLUNG;
|
||||
default:
|
||||
return NIEDER_WANDLERZAEHLER;
|
||||
}
|
||||
}
|
||||
|
||||
18
src/services/Cost/GridCost/MeasurementServiceFee.h
Normal file
18
src/services/Cost/GridCost/MeasurementServiceFee.h
Normal file
@ -0,0 +1,18 @@
|
||||
//
|
||||
// Created by stani on 3/13/2025.
|
||||
//
|
||||
|
||||
#ifndef MEASUREMENTSERVICEFEE_H
|
||||
#define MEASUREMENTSERVICEFEE_H
|
||||
#include "../../../interfaces/ICostComponent.h"
|
||||
|
||||
|
||||
class MeasurementServiceFee : public ICostComponent{
|
||||
public:
|
||||
void apply(std::unique_ptr<Building::Base>& building, std::unique_ptr<Community>& community) override;
|
||||
[[nodiscard]] short getMeasurementServiceFeeType(short grid_level);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //MEASUREMENTSERVICEFEE_H
|
||||
22
src/services/Cost/GridCost/NetUsagePerformance.cpp
Normal file
22
src/services/Cost/GridCost/NetUsagePerformance.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by stani on 3/13/2025.
|
||||
//
|
||||
|
||||
#include "NetUsagePerformance.h"
|
||||
|
||||
void NetUsagePerformance::apply(std::unique_ptr<Building::Base>& building, std::unique_ptr<Community>& community)
|
||||
{
|
||||
const auto& valuesWith = building->cost()->get_cost_values_with();
|
||||
const auto& valuesWithout = building->cost()->get_cost_values_without();
|
||||
const auto& data = building->metadata();
|
||||
float connectionPower = 1;
|
||||
//TODO use actual value
|
||||
float netznutzungLeistungspreis = 1.f;
|
||||
|
||||
if (data->grid_level()!=NetLevel7op)
|
||||
{
|
||||
connectionPower=data->connection_power();
|
||||
}
|
||||
valuesWith->add_cost_point("Netznutzungs Leistungspreis",netznutzungLeistungspreis*connectionPower,1.f);
|
||||
valuesWithout->add_cost_point("Netznutzungs Leistungspreis",netznutzungLeistungspreis*connectionPower,1.f);
|
||||
}
|
||||
17
src/services/Cost/GridCost/NetUsagePerformance.h
Normal file
17
src/services/Cost/GridCost/NetUsagePerformance.h
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by stani on 3/13/2025.
|
||||
//
|
||||
|
||||
#ifndef NETWORKUSAGEPERFORMANCE_H
|
||||
#define NETWORKUSAGEPERFORMANCE_H
|
||||
#include "../../../interfaces/ICostComponent.h"
|
||||
|
||||
|
||||
class NetUsagePerformance : public ICostComponent{
|
||||
public:
|
||||
void apply(std::unique_ptr<Building::Base>& building, std::unique_ptr<Community>& community) override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //NETWORKUSAGEPERFORMANCE_H
|
||||
23
src/services/Cost/NetworkProvider.cpp
Normal file
23
src/services/Cost/NetworkProvider.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
//
|
||||
// Created by StanislausCichocki on 12.03.2025.
|
||||
//
|
||||
|
||||
#include "NetworkProvider.h"
|
||||
|
||||
|
||||
void NetworkProvider::apply(std::unique_ptr<Building::Base>& building, std::unique_ptr<Community>& community)
|
||||
{
|
||||
const std::shared_ptr<CostHistory>& valuesWith = building->cost()->get_cost_values_with();
|
||||
const std::shared_ptr<CostHistory>& valuesWithout = building->cost()->get_cost_values_without();
|
||||
const std::shared_ptr<Building::Metadata>& metadata = building->metadata();
|
||||
const std::shared_ptr<Building::Simulation_Values>& values = building->values();
|
||||
//With Community
|
||||
valuesWith->add_cost_point("Net Consumption",metadata->consumption_net_price(),values->consumption_after_community_sum());
|
||||
valuesWith->add_cost_point("Net Generation",metadata->consumption_net_price(),values->consumption_after_community_sum());
|
||||
valuesWith->add_cost_point("Community Consumption", community->energy_tariff().consumption_tariff, values->consumption_after_community_sum());
|
||||
valuesWith->add_cost_point("Generation Consumption", -community->energy_tariff().generation_tariff, values->generation_after_community_sum());
|
||||
|
||||
//Without Community
|
||||
valuesWithout->add_cost_point("Net Consumption",metadata->consumption_net_price(),values->needed_con_sum());
|
||||
valuesWithout->add_cost_point("Net Generation",metadata->generation_net_price(),values->needed_gen_sum());
|
||||
}
|
||||
19
src/services/Cost/NetworkProvider.h
Normal file
19
src/services/Cost/NetworkProvider.h
Normal file
@ -0,0 +1,19 @@
|
||||
//
|
||||
// Created by StanislausCichocki on 12.03.2025.
|
||||
//
|
||||
|
||||
#ifndef NETWORKPROVIDER_H
|
||||
#define NETWORKPROVIDER_H
|
||||
#include "../../interfaces/ICostComponent.h"
|
||||
|
||||
|
||||
class NetworkProvider : public ICostComponent {
|
||||
public:
|
||||
NetworkProvider(): ICostComponent() {
|
||||
}
|
||||
|
||||
void apply(std::unique_ptr<Building::Base> &building, std::unique_ptr<Community> &community) override;
|
||||
};
|
||||
|
||||
|
||||
#endif //NETWORKPROVIDER_H
|
||||
12
src/services/Cost/ServiceCharge.cpp
Normal file
12
src/services/Cost/ServiceCharge.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
//
|
||||
// Created by StanislausCichocki on 13.03.2025.
|
||||
//
|
||||
|
||||
#include "ServiceCharge.h"
|
||||
|
||||
void ServiceCharge::apply(std::unique_ptr<Building::Base> &building, std::unique_ptr<Community> &community) {
|
||||
const std::shared_ptr<CostHistory>& valuesWith = building->cost()->get_cost_values_with();
|
||||
const std::shared_ptr<Building::Simulation_Values>& values = building->values();
|
||||
|
||||
valuesWith->add_cost_point("Service Charge",values->consumption_from_community_sum(),community->energy_tariff().service_charge);
|
||||
}
|
||||
17
src/services/Cost/ServiceCharge.h
Normal file
17
src/services/Cost/ServiceCharge.h
Normal file
@ -0,0 +1,17 @@
|
||||
//
|
||||
// Created by StanislausCichocki on 13.03.2025.
|
||||
//
|
||||
|
||||
#ifndef SERVICECHARGE_H
|
||||
#define SERVICECHARGE_H
|
||||
#include "../../interfaces/ICostComponent.h"
|
||||
|
||||
|
||||
class ServiceCharge : public ICostComponent{
|
||||
public:
|
||||
void apply(std::unique_ptr<Building::Base> &building, std::unique_ptr<Community> &community) override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //SERVICECHARGE_H
|
||||
@ -4,12 +4,6 @@
|
||||
|
||||
#include "TaxComponent.h"
|
||||
|
||||
void TaxComponent::applyCost(std::vector<std::unique_ptr<Community>>& communities)
|
||||
{
|
||||
Community::iterateVector(communities, [&](Community& community)
|
||||
{
|
||||
Building::Base::iterateVector(community.buildings(), [&](Building::Base& building)
|
||||
{
|
||||
});
|
||||
});
|
||||
void apply(std::unique_ptr<Building::Base> &building, std::unique_ptr<Community> &community) {
|
||||
|
||||
}
|
||||
|
||||
@ -12,11 +12,11 @@ class TaxComponent : public ICostComponent
|
||||
double taxRate;
|
||||
|
||||
public:
|
||||
TaxComponent(double rate) : taxRate(rate)
|
||||
explicit TaxComponent(const double rate) : ICostComponent(), taxRate(rate)
|
||||
{
|
||||
}
|
||||
|
||||
void applyCost(std::vector<std::unique_ptr<Community>>& communities);
|
||||
void apply(std::unique_ptr<Building::Base>& building, std::unique_ptr<Community>& community) override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
5
src/services/CostHistory.cpp
Normal file
5
src/services/CostHistory.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by stani on 3/12/2025.
|
||||
//
|
||||
|
||||
#include "CostHistory.h"
|
||||
71
src/services/CostHistory.h
Normal file
71
src/services/CostHistory.h
Normal file
@ -0,0 +1,71 @@
|
||||
//
|
||||
// Created by stani on 3/12/2025.
|
||||
//
|
||||
|
||||
#ifndef COSTHISTORY_H
|
||||
#define COSTHISTORY_H
|
||||
#include <numeric>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
class CostHistory
|
||||
{
|
||||
private:
|
||||
struct CostPoint
|
||||
{
|
||||
std::string name;
|
||||
float value{0.0f};
|
||||
float amount{0.f};
|
||||
|
||||
CostPoint(std::string name, const float value, const float amount)
|
||||
: name(std::move(name)), value(value), amount(amount)
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] float total() const
|
||||
{
|
||||
return value * amount;
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<CostPoint> costPoints{};
|
||||
std::unordered_map<std::string, float> TotalByCategory{};
|
||||
|
||||
public:
|
||||
void add_cost_point(const std::string& name, float value, float amount)
|
||||
{
|
||||
if (amount == 0.0) return;
|
||||
costPoints.emplace_back(name, value, amount);
|
||||
}
|
||||
|
||||
float total_cost() const
|
||||
{
|
||||
return std::accumulate(costPoints.begin(), costPoints.end(), 0.0f,
|
||||
[](const float sum, const CostPoint& point)
|
||||
{
|
||||
return sum + point.total();
|
||||
});
|
||||
}
|
||||
|
||||
const std::vector<CostPoint>& get_cost_points() const
|
||||
{
|
||||
return costPoints;
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, float> calculateCategories()
|
||||
{
|
||||
TotalByCategory.clear();
|
||||
if (costPoints.empty()) return {};
|
||||
for (const CostPoint& point : costPoints)
|
||||
{
|
||||
const size_t pos = point.name.find(' ');
|
||||
std::string result = (pos != std::string::npos) ? point.name.substr(0, pos) : point.name;
|
||||
TotalByCategory[result] += point.total();
|
||||
}
|
||||
return TotalByCategory;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif //COSTHISTORY_H
|
||||
@ -1,72 +1,216 @@
|
||||
//
|
||||
// Created by StanislausCichocki on 10.03.2025.
|
||||
//
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#ifdef NDEBUG // Release mode
|
||||
#define LOG_DEBUG_INFO(...)
|
||||
#define LOG_DEBUG_ERROR(...)
|
||||
#else
|
||||
#define LOG_DEBUG_INFO(...) spdlog::info(__VA_ARGS__)
|
||||
#define LOG_DEBUG_ERROR(...) spdlog::error(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#include "Surplus.h"
|
||||
#include "../model/Building.h"
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <ranges>
|
||||
#include <numeric>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
void Surplus::CalculateSurplus() {
|
||||
void Surplus::CalculateSurplus()
|
||||
{
|
||||
auto iterateFunc = Community::iterateBuildings(communities);
|
||||
auto modifyCommunity = [](Community &c) {
|
||||
LOG_DEBUG_INFO("Calculating Surplus for Community: {}", c.name());
|
||||
};
|
||||
auto modifyBuilding = [this](Building::Base &building) {
|
||||
LOG_DEBUG_INFO("Calculating Surplus for Community: {}", building.metadata()->name());
|
||||
CalculateBuildingSurplus(building);
|
||||
};
|
||||
iterateFunc(modifyCommunity)(modifyBuilding);
|
||||
|
||||
//TODO Calculate Relative Values
|
||||
auto modifyCommunity = [this](const Community& c)
|
||||
{
|
||||
this->consumptionAvailable = std::vector<float>(VALUE_COUNT, 0.f);
|
||||
this->generationAvailable = std::vector<float>(VALUE_COUNT, 0.f);
|
||||
|
||||
assert(!c.name().empty() && "Community name is empty!");
|
||||
};
|
||||
|
||||
|
||||
auto modifyBuildingSurplus = [this](Community& community, Building::Base& building)
|
||||
{
|
||||
CalculateBuildingSurplus(community, building);
|
||||
|
||||
community.set_consumption_available(this->consumptionAvailable);
|
||||
community.set_generation_available(this->generationAvailable);
|
||||
};
|
||||
|
||||
iterateFunc(modifyCommunity)(modifyBuildingSurplus);
|
||||
|
||||
auto calculateCommunitySurplus = [this](Community& community)
|
||||
{
|
||||
std::vector<bool> isGenBiggerThanCon;
|
||||
std::ranges::transform(
|
||||
consumptionAvailable, generationAvailable,
|
||||
std::back_inserter(isGenBiggerThanCon),
|
||||
[](const float a, const float b) { return a < b; }
|
||||
);
|
||||
community.set_is_gen_bigger_than_con(isGenBiggerThanCon);
|
||||
};
|
||||
|
||||
auto calculateDistribution = [this](Community& community, Building::Base& building)
|
||||
{
|
||||
CalculateSurplusCommunity(community, building);
|
||||
};
|
||||
|
||||
iterateFunc(calculateCommunitySurplus)(calculateDistribution);
|
||||
}
|
||||
|
||||
void Surplus::CalculateBuildingSurplus(Building::Base &building) {
|
||||
std::vector<std::unique_ptr<float> > ownCoverage;
|
||||
std::vector<std::unique_ptr<float> > neededConsumption;
|
||||
std::vector<std::unique_ptr<float> > neededGeneration;
|
||||
std::vector<std::unique_ptr<float> > ownUsage;
|
||||
void Surplus::CalculateBuildingSurplus(Community& community, Building::Base& building)
|
||||
{
|
||||
auto ownCoverage = std::vector(VALUE_COUNT, 0.0f);
|
||||
auto neededConsumption = std::vector(VALUE_COUNT, 0.0f);
|
||||
auto neededGeneration = std::vector(VALUE_COUNT, 0.0f);
|
||||
auto ownUsage = std::vector(VALUE_COUNT, 0.0f);
|
||||
|
||||
const auto &consumption = building.metadata()->consumption_profile();
|
||||
const auto &generation = building.metadata()->generation_profile();
|
||||
assert(building.metadata() != nullptr && "Building metadata is null!");
|
||||
|
||||
ownCoverage.reserve(consumption.size());
|
||||
neededConsumption.reserve(consumption.size());
|
||||
neededGeneration.reserve(consumption.size());
|
||||
ownUsage.reserve(consumption.size());
|
||||
const auto& consumption = building.metadata()->consumption_profile();
|
||||
const auto& generation = building.metadata()->generation_profile();
|
||||
|
||||
std::transform(consumption.begin(), consumption.end(),
|
||||
generation.begin(), std::back_inserter(ownCoverage),
|
||||
[&](const std::unique_ptr<float> &c, const std::unique_ptr<float> &g) {
|
||||
auto own_cov = std::make_unique<float>((c ? *c : 0.0f) - (g ? *g : 0.0f));
|
||||
ownCoverage.push_back(std::make_unique<float>(*own_cov));
|
||||
size_t i = 0; // Fixed static variable issue
|
||||
std::ranges::for_each(consumption, [&](auto c_ptr)
|
||||
{
|
||||
const float c = c_ptr ? c_ptr : 0.0f;
|
||||
const float g = i < generation.size() ? generation[i] : 0.0f;
|
||||
const float c_community = (i < consumptionAvailable.size()) ? consumptionAvailable[i] : 0.0f;
|
||||
const float g_community = (i < generationAvailable.size()) ? generationAvailable[i] : 0.0f;
|
||||
|
||||
neededConsumption.push_back(std::make_unique<float>(c && *c > 0.0f ? *c : 0.0f));
|
||||
neededGeneration.push_back(std::make_unique<float>(g && *g < 0.0f ? -*g : 0.0f));
|
||||
ownUsage.push_back(std::make_unique<float>((c ? *c : 0.0f) - *neededConsumption.back()));
|
||||
const auto ownCov = (c - g);
|
||||
const auto neededCons = ((c > 0.0f) ? c : 0.0f);
|
||||
const auto neededGen = ((g < 0.0f) ? -g : 0.0f);
|
||||
const auto ownUs = (c - neededCons);
|
||||
|
||||
const auto communityConsumption = c_community + neededCons;
|
||||
const auto generationConsumption = g_community + neededGen;
|
||||
|
||||
ownCoverage[i] = ownCov;
|
||||
neededConsumption[i] = neededCons;
|
||||
neededGeneration[i] = neededGen;
|
||||
ownUsage[i] = ownUs;
|
||||
if (i < consumptionAvailable.size()) this->consumptionAvailable[i] = communityConsumption;
|
||||
if (i < generationAvailable.size()) this->generationAvailable[i] = generationConsumption;
|
||||
++i;
|
||||
});
|
||||
|
||||
return std::move(own_cov);
|
||||
});
|
||||
building.values()->set_community_coverage(std::move(ownCoverage));
|
||||
building.values()->set_needed_con(std::move(neededGeneration));
|
||||
building.values()->set_needed_con(std::move(neededConsumption));
|
||||
building.values()->set_needed_gen(std::move(neededGeneration));
|
||||
building.values()->set_own_usage(std::move(ownUsage));
|
||||
|
||||
const float totalConsumption = std::accumulate(building.metadata()->consumption_profile().begin(),
|
||||
building.metadata()->consumption_profile().end(), 0.0f);
|
||||
const float totalGeneration = std::accumulate(building.metadata()->generation_profile().begin(),
|
||||
building.metadata()->generation_profile().end(), 0.0f);
|
||||
|
||||
std::transform(generationAvailable.begin(), generationAvailable.end(), consumptionAvailable.begin(),
|
||||
isGenBigger.begin(), [&](const float a, const float b) { return a > b; });
|
||||
if (totalConsumption > 0.0f)
|
||||
{
|
||||
building.values()->set_relativeSelfConsumption(
|
||||
std::accumulate(building.values()->own_usage().begin(), building.values()->own_usage().end(), 0.0f) /
|
||||
totalConsumption);
|
||||
}
|
||||
else
|
||||
{
|
||||
building.values()->set_relativeSelfConsumption(0.0f);
|
||||
}
|
||||
|
||||
if (totalGeneration > 0.0f)
|
||||
{
|
||||
building.values()->set_relativeSelfGeneration(
|
||||
std::accumulate(building.values()->own_usage().begin(), building.values()->own_usage().end(), 0.0f) /
|
||||
totalGeneration);
|
||||
}
|
||||
else
|
||||
{
|
||||
building.values()->set_relativeSelfGeneration(0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void Surplus::CalculateSurplusCommunity(Community& community, Building::Base& base)
|
||||
{
|
||||
const size_t neededGenSize = base.values()->needed_gen().size();
|
||||
const size_t neededConSize = base.values()->needed_con().size();
|
||||
const size_t consumptionAfterCommunitySize = base.values()->consumption_after_community().size();
|
||||
const size_t generationAfterCommunitySize = base.values()->generation_after_community().size();
|
||||
const size_t generationToCommunitySize = base.values()->generation_to_community().size();
|
||||
const size_t consumptionFromCommunitySize = base.values()->consumption_from_community().size();
|
||||
const size_t communityConsumptionSize = community.consumption_available().size();
|
||||
const size_t communityGenerationSize = community.generation_available().size();
|
||||
|
||||
if (neededGenSize != neededConSize ||
|
||||
neededGenSize != consumptionAfterCommunitySize ||
|
||||
neededGenSize != generationAfterCommunitySize ||
|
||||
neededGenSize != generationToCommunitySize ||
|
||||
neededGenSize != consumptionFromCommunitySize ||
|
||||
neededGenSize != communityConsumptionSize ||
|
||||
neededGenSize != communityGenerationSize)
|
||||
{
|
||||
std::cerr << "Size mismatch detected in CalculateSurplusCommunity():\n";
|
||||
std::cerr << "neededGenSize: " << neededGenSize << "\n";
|
||||
std::cerr << "neededConSize: " << neededConSize << "\n";
|
||||
std::cerr << "consumptionAfterCommunitySize: " << consumptionAfterCommunitySize << "\n";
|
||||
std::cerr << "generationAfterCommunitySize: " << generationAfterCommunitySize << "\n";
|
||||
std::cerr << "generationToCommunitySize: " << generationToCommunitySize << "\n";
|
||||
std::cerr << "consumptionFromCommunitySize: " << consumptionFromCommunitySize << "\n";
|
||||
std::cerr << "communityConsumptionSize: " << communityConsumptionSize << "\n";
|
||||
std::cerr << "communityGenerationSize: " << communityGenerationSize << "\n";
|
||||
|
||||
throw std::runtime_error("Mismatch in vector sizes for CalculateSurplusCommunity()");
|
||||
}
|
||||
|
||||
|
||||
for (auto&& [needed_g, needed_c, con_after,gen_after,con_from,gen_to, con_available, gen_available, isGenBigger] :
|
||||
std::views::zip(
|
||||
base.values()->needed_gen(),
|
||||
base.values()->needed_con(),
|
||||
base.values()->consumption_after_community(),
|
||||
base.values()->generation_after_community(),
|
||||
base.values()->generation_to_community(),
|
||||
base.values()->consumption_from_community(),
|
||||
community.consumption_available(),
|
||||
community.generation_available(),
|
||||
community.is_gen_bigger_than_con()
|
||||
))
|
||||
{
|
||||
if (isGenBigger)
|
||||
{
|
||||
con_from = needed_g;
|
||||
gen_to = needed_g / gen_available * con_available;
|
||||
}
|
||||
else
|
||||
{
|
||||
con_from = needed_c / con_available * gen_available;
|
||||
gen_to = needed_c;
|
||||
}
|
||||
con_after = needed_c - con_from;
|
||||
gen_after = needed_g - gen_to;
|
||||
}
|
||||
CalculateSums(base);
|
||||
if (base.metadata()->annual_consumption() != 0)
|
||||
{
|
||||
base.values()->set_con_from_community_relative(
|
||||
std::accumulate(base.values()->consumption_from_community().begin(),
|
||||
base.values()->consumption_from_community().end(),
|
||||
0.0f) / base.metadata()->annual_consumption());
|
||||
}
|
||||
if (base.metadata()->annual_generation() != 0)
|
||||
{
|
||||
base.values()->set_gen_to_community_relative(
|
||||
std::accumulate(base.values()->generation_to_community().begin(),
|
||||
base.values()->generation_to_community().end(),
|
||||
0.0f) / base.metadata()->annual_generation());
|
||||
}
|
||||
}
|
||||
|
||||
void Surplus::CalculateSums(Building::Base& base)
|
||||
{
|
||||
const auto& values = base.values();
|
||||
values->set_consumption_after_own_coverage_sum(std::accumulate(values->consumption_after_own_coverage().begin(),
|
||||
values->consumption_after_own_coverage().end(),
|
||||
0.f));
|
||||
values->set_own_usage_sum(std::accumulate(values->own_usage().begin(), values->own_usage().end(), 0.f));
|
||||
values->set_needed_con_sum(std::accumulate(values->needed_con().begin(), values->needed_con().end(), 0.f));
|
||||
values->set_needed_gen_sum(std::accumulate(values->needed_gen().begin(), values->needed_gen().end(), 0.f));
|
||||
values->set_consumption_after_community_sum(std::accumulate(values->consumption_after_community().begin(),
|
||||
values->consumption_after_community().end(), 0.f));
|
||||
values->set_generation_after_community_sum(std::accumulate(values->generation_after_community().begin(),
|
||||
values->generation_after_community().end(), 0.f));
|
||||
values->set_consumption_from_community_sum(std::accumulate(values->consumption_from_community().begin(),
|
||||
values->consumption_from_community().end(), 0.f));
|
||||
values->set_generation_to_community_sum(std::accumulate(values->generation_to_community().begin(),
|
||||
values->generation_to_community().end(), 0.f));
|
||||
}
|
||||
|
||||
@ -4,31 +4,34 @@
|
||||
|
||||
#ifndef SURPLUS_H
|
||||
#define SURPLUS_H
|
||||
#define VALUE_COUNT (4*24*365)
|
||||
#include <memory>
|
||||
|
||||
#include "../model/Community.h"
|
||||
#include "../Config.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
|
||||
class Community;
|
||||
|
||||
class Surplus {
|
||||
class Surplus
|
||||
{
|
||||
private:
|
||||
std::vector<std::unique_ptr<Community> > &communities;
|
||||
std::vector<std::unique_ptr<Community>>& communities;
|
||||
std::vector<float> consumptionAvailable;
|
||||
std::vector<float> generationAvailable;
|
||||
std::vector<bool> isGenBigger;
|
||||
|
||||
public:
|
||||
Surplus(std::vector<std::unique_ptr<Community> > &communities) : communities(communities),
|
||||
consumptionAvailable(VALUE_COUNT, 0.0f),
|
||||
generationAvailable(VALUE_COUNT, 0.0f),
|
||||
isGenBigger(VALUE_COUNT, false) {
|
||||
explicit Surplus(std::vector<std::unique_ptr<Community>>& communities) : communities(communities),
|
||||
consumptionAvailable(VALUE_COUNT, 0.0f),
|
||||
generationAvailable(VALUE_COUNT, 0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
void CalculateSurplus();
|
||||
|
||||
void CalculateBuildingSurplus(Building::Base &);
|
||||
void CalculateBuildingSurplus(Community& community, Building::Base&);
|
||||
|
||||
void CalculateSurplusCommunity(Community& community, Building::Base& base);
|
||||
|
||||
void CalculateSums(Building::Base& base);
|
||||
};
|
||||
|
||||
|
||||
|
||||
9
src/singelton/UsageProfile.cpp
Normal file
9
src/singelton/UsageProfile.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
//
|
||||
// Created by stani on 3/14/2025.
|
||||
//
|
||||
|
||||
#include "UsageProfile.h"
|
||||
|
||||
|
||||
std::mutex UsageProfile::mtx;
|
||||
UsageProfile* UsageProfile::instance = nullptr;
|
||||
49
src/singelton/UsageProfile.h
Normal file
49
src/singelton/UsageProfile.h
Normal file
@ -0,0 +1,49 @@
|
||||
//
|
||||
// Created by stani on 3/14/2025.
|
||||
//
|
||||
|
||||
#ifndef USAGEPROFILE_H
|
||||
#define USAGEPROFILE_H
|
||||
#include <mutex>
|
||||
#include "../Config.h"
|
||||
#include "../helper/CsvBinary.h"
|
||||
|
||||
class UsageProfile
|
||||
{
|
||||
public:
|
||||
static UsageProfile* getInstance()
|
||||
{
|
||||
std::lock_guard lock(mtx);
|
||||
if (!instance)
|
||||
{
|
||||
instance = new UsageProfile();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
static void destroyInstance()
|
||||
{
|
||||
delete instance;
|
||||
instance = nullptr;
|
||||
}
|
||||
|
||||
UsageProfile(const UsageProfile&) = delete;
|
||||
UsageProfile& operator=(const UsageProfile&) = delete;
|
||||
|
||||
usageProfile ConsumptionProfile;
|
||||
usageProfile GenerationProfile;
|
||||
|
||||
private:
|
||||
UsageProfile(): ConsumptionProfile(CsvBinary::binaryToVector("Verbrauchsprofile.bin")),
|
||||
GenerationProfile(CsvBinary::binaryToVector("ErzeugerProfile.bin"))
|
||||
{
|
||||
};
|
||||
|
||||
~UsageProfile() = default;
|
||||
|
||||
static UsageProfile* instance;
|
||||
static std::mutex mtx;
|
||||
};
|
||||
|
||||
|
||||
#endif //USAGEPROFILE_H
|
||||
24
tests/helper/test_CsvBinary.cpp
Normal file
24
tests/helper/test_CsvBinary.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by stani on 3/14/25.
|
||||
//
|
||||
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include <numeric>
|
||||
#include <doctest/doctest.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "../../src/Config.h"
|
||||
#include "../../src/helper/CsvBinary.h"
|
||||
|
||||
TEST_CASE("Test Csv to binary and back") {
|
||||
CsvBinary::csvToBinary("Verbrauchsprofile.csv","Verbrauchsprofil.bin");
|
||||
auto verbrauchsProfil = CsvBinary::binaryToVector("Verbrauchsprofil.bin");
|
||||
for (const auto & [fst, snd]: *verbrauchsProfil) {
|
||||
LOG_DEBUG_INFO("Sum from {}: {}",fst ,std::accumulate(
|
||||
snd.begin(), snd.end(), 0.f,
|
||||
[](const float sum, const std::string& val) {
|
||||
return sum + std::stof(val); // Convert string to float before addition
|
||||
}
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,7 @@
|
||||
#include "../../src/model/Building.h"
|
||||
#include "../../src/model/Community.h"
|
||||
#include "../../src/model/Energy_Tariff.h"
|
||||
#include "../../src/Config.h"
|
||||
|
||||
namespace Building {
|
||||
class Cost;
|
||||
@ -15,29 +16,23 @@ namespace Building {
|
||||
|
||||
class Factory {
|
||||
public:
|
||||
std::unique_ptr<Building::Cost> static create_test_cost() {
|
||||
auto cost = std::make_unique<Building::Cost>();
|
||||
cost->set_special_rate_consumption(0.15f);
|
||||
cost->set_special_rate_generation(0.10f);
|
||||
return cost;
|
||||
}
|
||||
|
||||
std::unique_ptr<Building::Simulation_Values> static create_test_simulation_values() {
|
||||
auto values = std::make_unique<Building::Simulation_Values>();
|
||||
|
||||
auto communityCoverage = std::vector<std::unique_ptr<float> >();
|
||||
auto ownUsage = std::vector<std::unique_ptr<float> >();
|
||||
auto neededCon = std::vector<std::unique_ptr<float> >();
|
||||
auto neededGen = std::vector<std::unique_ptr<float> >();
|
||||
auto communityCoverage = std::vector<float>();
|
||||
auto ownUsage = std::vector<float>();
|
||||
auto neededCon = std::vector<float>();
|
||||
auto neededGen = std::vector<float>();
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
// Populate with test values
|
||||
communityCoverage.push_back(std::make_unique<float>(i * 10.0f));
|
||||
ownUsage.push_back(std::make_unique<float>(i * 5.0f));
|
||||
neededCon.push_back(std::make_unique<float>(i * 3.0f));
|
||||
neededGen.push_back(std::make_unique<float>(i * 2.0f));
|
||||
communityCoverage.push_back(static_cast<float>(i) * 10.0f);
|
||||
ownUsage.push_back(static_cast<float>(i) * 5.0f);
|
||||
neededCon.push_back(static_cast<float>(i) * 3.0f);
|
||||
neededGen.push_back(static_cast<float>(i) * 2.0f);
|
||||
}
|
||||
|
||||
|
||||
values->set_community_coverage(std::move(communityCoverage));
|
||||
values->set_own_usage(std::move(ownUsage));
|
||||
values->set_needed_con(std::move(neededCon));
|
||||
@ -49,20 +44,26 @@ public:
|
||||
std::unique_ptr<Building::Metadata> static create_test_metadata() {
|
||||
auto metadata = std::make_unique<Building::Metadata>();
|
||||
metadata->set_name("Test Building");
|
||||
metadata->set_annual_consumption(12000.0f);
|
||||
metadata->set_annual_generation(5000.0f);
|
||||
metadata->set_annual_consumption(3000.0f);
|
||||
metadata->set_annual_generation(0.0f);
|
||||
metadata->set_consumption_profile_name("Profile_1");
|
||||
metadata->set_generation_profile_name("Profile_2");
|
||||
metadata->set_connection_power(100);
|
||||
metadata->set_connection_power(1);
|
||||
metadata->set_grid_power(50);
|
||||
metadata->set_consumption_net_price(0.10f);
|
||||
metadata->set_generation_net_price(0.12f);
|
||||
|
||||
auto consumptionProfile = std::vector<std::unique_ptr<float> >();
|
||||
auto generationProfile = std::vector<std::unique_ptr<float> >();
|
||||
metadata->set_special_rate_consumption(0.15f);
|
||||
metadata->set_special_rate_generation(0.10f);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
auto consumptionProfile = std::vector<float>();
|
||||
auto generationProfile = std::vector<float>();
|
||||
|
||||
for (int i = 0; i < VALUE_COUNT; i++) {
|
||||
// Populate with test values
|
||||
consumptionProfile.push_back(std::make_unique<float>(i * 100.0f));
|
||||
generationProfile.push_back(std::make_unique<float>(i * 50.0f));
|
||||
consumptionProfile.push_back(static_cast<float>(i) * (VALUE_COUNT % 100));
|
||||
|
||||
generationProfile.push_back(static_cast<float>(i) * (VALUE_COUNT % 50));
|
||||
}
|
||||
|
||||
metadata->set_consumption_profile(std::move(consumptionProfile));
|
||||
@ -74,7 +75,6 @@ public:
|
||||
std::unique_ptr<Building::Base> static create_test_building() {
|
||||
auto building = std::make_unique<Building::Base>();
|
||||
|
||||
building->set_cost(create_test_cost());
|
||||
building->set_values(create_test_simulation_values());
|
||||
building->set_metadata(create_test_metadata());
|
||||
|
||||
@ -88,9 +88,8 @@ public:
|
||||
std::unique_ptr<Community> static create_test_community() {
|
||||
auto community = std::make_unique<Community>();
|
||||
community->set_name("Test Community");
|
||||
|
||||
std::vector<std::unique_ptr<Building::Base> > buildings;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
buildings.push_back(create_test_building());
|
||||
}
|
||||
|
||||
|
||||
@ -1,15 +1,38 @@
|
||||
//
|
||||
// Created by StanislausCichocki on 10.03.2025.
|
||||
//
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "../../src/services/Surplus.h"
|
||||
#include "../../src/services/Cost/BillCharge.h"
|
||||
#include "../../src/services/Cost/CalculateFinalSums.h"
|
||||
#include "../../src/services/Cost/CostPipeline.h"
|
||||
#include "../../src/services/Cost/NetworkProvider.h"
|
||||
#include "../../src/services/Cost/ServiceCharge.h"
|
||||
#include "../../src/services/Cost/GridCost/MeasurementServiceFee.h"
|
||||
#include "../../src/services/Cost/GridCost/NetUsagePerformance.h"
|
||||
#include "doctest/doctest.h"
|
||||
#include "../model/Factory.h"
|
||||
#include "../../src/Config.h"
|
||||
|
||||
TEST_CASE("Testing add function") {
|
||||
std::vector<std::unique_ptr<Community> > communities;
|
||||
communities.push_back(Factory::create_test_community());
|
||||
Surplus surplus(communities);
|
||||
surplus.CalculateSurplus();
|
||||
CHECK(true);
|
||||
std::vector<std::unique_ptr<Community> > communities;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
communities.push_back(Factory::create_test_community());
|
||||
}
|
||||
Surplus surplus(communities);
|
||||
surplus.CalculateSurplus();
|
||||
|
||||
LOG_DEBUG_INFO("Add components");
|
||||
CostPipeline costPipeline(communities);
|
||||
costPipeline.addCostComponent(std::make_shared<NetworkProvider>());
|
||||
costPipeline.addCostComponent(std::make_shared<BillCharge>());
|
||||
costPipeline.addCostComponent(std::make_shared<MeasurementServiceFee>());
|
||||
costPipeline.addCostComponent(std::make_shared<NetUsagePerformance>());
|
||||
costPipeline.addCostComponent(std::make_shared<ServiceCharge>());
|
||||
costPipeline.addCostComponent(std::make_shared<CalculateFinalSums>());
|
||||
costPipeline.calculateFinalCost();
|
||||
|
||||
LOG_DEBUG_INFO("{}",communities[0]->total);
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user