Billinghistory Categories
This commit is contained in:
@ -28,6 +28,10 @@ add_executable(Sim_C__
|
|||||||
src/services/Cost/BillCharge.h
|
src/services/Cost/BillCharge.h
|
||||||
src/services/CostHistory.cpp
|
src/services/CostHistory.cpp
|
||||||
src/services/CostHistory.h
|
src/services/CostHistory.h
|
||||||
|
src/services/Cost/ServiceCharge.cpp
|
||||||
|
src/services/Cost/ServiceCharge.h
|
||||||
|
src/helper/StringOperations.cpp
|
||||||
|
src/helper/StringOperations.h
|
||||||
)
|
)
|
||||||
find_package(doctest CONFIG REQUIRED)
|
find_package(doctest CONFIG REQUIRED)
|
||||||
find_package(spdlog CONFIG REQUIRED)
|
find_package(spdlog CONFIG REQUIRED)
|
||||||
|
|||||||
16
src/helper/StringOperations.cpp
Normal file
16
src/helper/StringOperations.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//
|
||||||
|
// 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
|
||||||
@ -10,7 +10,8 @@ class Energy_Tariff {
|
|||||||
public:
|
public:
|
||||||
float consumption_tariff{0.0f};
|
float consumption_tariff{0.0f};
|
||||||
float generation_tariff{0.0f};
|
float generation_tariff{0.0f};
|
||||||
float bill_charge;
|
float bill_charge{0.0f};
|
||||||
|
float service_charge{0.0f};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -7,5 +7,5 @@
|
|||||||
void BillCharge::apply(std::unique_ptr<Building::Base>& building, std::unique_ptr<Community>& community)
|
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();
|
const std::shared_ptr<CostHistory>& valuesWith = building->cost()->get_cost_values_with();
|
||||||
valuesWith->add_cost_point("Bill charge",1.0,community->energy_tariff().bill_charge);
|
valuesWith->add_cost_point("Bill charge",1.0f,community->energy_tariff().bill_charge);
|
||||||
}
|
}
|
||||||
|
|||||||
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
|
||||||
@ -7,35 +7,35 @@
|
|||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include "../helper/StringOperations.h"
|
||||||
|
|
||||||
class CostHistory {
|
class CostHistory {
|
||||||
public:
|
private:
|
||||||
struct CostPoint {
|
struct CostPoint {
|
||||||
std::string name;
|
std::string name;
|
||||||
double value;
|
float value;
|
||||||
double amount;
|
float amount;
|
||||||
|
|
||||||
CostPoint(std::string name, double value, double amount)
|
CostPoint(std::string name, const float value, const float amount)
|
||||||
: name(std::move(name)), value(value), amount(amount) {}
|
: name(std::move(name)), value(value), amount(amount) {}
|
||||||
|
|
||||||
double total() const {
|
float total() const {
|
||||||
return value * amount;
|
return value * amount;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
std::vector<CostPoint> costPoints{};
|
||||||
private:
|
std::unordered_map<std::string, float> TotalByCategory{};
|
||||||
std::vector<CostPoint> costPoints;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void add_cost_point(const std::string &name, double value, double amount) {
|
void add_cost_point(const std::string &name, float value, float amount) {
|
||||||
if (amount==0.0) return;
|
if (amount==0.0) return;
|
||||||
costPoints.emplace_back(name, value, amount);
|
costPoints.emplace_back(name, value, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
double total_cost() const {
|
float total_cost() const {
|
||||||
return std::accumulate(costPoints.begin(), costPoints.end(), 0.0,
|
return std::accumulate(costPoints.begin(), costPoints.end(), 0.0f,
|
||||||
[](double sum, const CostPoint &point) {
|
[](const float sum, const CostPoint &point) {
|
||||||
return sum + point.total();
|
return sum + point.total();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -43,6 +43,16 @@ public:
|
|||||||
const std::vector<CostPoint> &get_cost_points() const {
|
const std::vector<CostPoint> &get_cost_points() const {
|
||||||
return costPoints;
|
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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user