this is the header file .h:, note the std::string& means to modify the string value, while removing the ampersand meaning you create a copy to modify. note 2, std::vector<std::string> means the type is vector and components are string, the components are always angle bracketed, another example // Modern C++ std::vector<std::vector<int>>
#pragma once
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <DataFrame/DataFrame.h>
class GlobalMonopoly {
public:
global Monopoly(const std::string& start_date, int periods);
void processMonopolies();
void saveToExcel(const std::string& filename);
void verifyData();
private:
struct MonopolyData {
DataFrame<double> market_share;
DataFrame<double> monopolies;
};
std::vector<std::string> dates;
std::vector<std::string> leel_list{"L6", "L5"};
std::unordered_map<std::string, std::map<std::string, MonopolyData>> history_dfs;
std::map<std::string, MonopolyData> monopoly_dfs;
DataFrame<double> getMarketShareData(const std::srting& day, const std::string& level);
DataFrame<double> getApiData(const std::vector<std::string>& idList, const std::string& day);
void capWeight(DataFrame<double>& df, double cap);
std::vector<std::string> generateDates(const std::string& start_date, int periods);
};
here is the cpp source files: note when to use curly bracket in C++? curly brackets {} are used for initialization in several common scenarios. Initializer Lists – Direct initialization of arrays, vectors, or other containers, for example std::vector<std::string> level_list{“L6”, “L5”}; // Modern C++ style or Class/Struct Member Initialization: struct Person {std::string name{“John”}; // Default member initialization int age{25}; };
#include "global_monopoly.h"
#include <iostream>
#include <iomanip>
#include <cmath>
#include <xlnt/xlnt.hpp> // Using xlnt for Excel operations
GlobalMonopoly:: globalMonopoly(const std::string& start_date, int periods) {
dates = generateDates(start_date, periods);
}
void GlobalMonopoly::processMonopolies() {
for (const auto& day : dates) {
std::map<std::string, MonopolyData> day_monopolies;
for (const auto& level : level_list) {
std::cout << "Processing " << day << " and " << level << std::endl;
//get market share data
auto market_share_df = getMarketShareData(day, level);
//store results
day_monopolies[level] = MonopolyData{market_share_df, monopolies_df};
std::cout << "number of monopolies in"" << level << ": "
<< monopolies_df.rows() << std::endl;
}
history_dfs[day] = day_monopolies;
if (day == dates.back()) {
monopoly_dfs = day_monopolies;
}
}
}
void globalMonopoly::saveToExccel(const std::string& filename) {
xlnt::workbook wb;
std::map<std::string DataFrame<double>> histories;
for (const auto& level : {"L6", "L5"}) {
DataFrame<double> history_df;
for (const auto& date : dates) {
auto df = history_dfs[date][level].monopolies;
}
histories[level[ = history_df;
//create worksheet and write data
auto ws = wb.create_sheet("Level " + std::string(level));
}
wb.save(filename);
}
void GlobalMonopoly::verifyData() {
for (const auto& [level, history_df] : histories) {
std::cout << "\nchecking " << level << " history:\n";
//check size