Implement counting Online vs Offline

This commit is contained in:
Matti 2024-11-23 07:27:03 +01:00
parent 8af59118c2
commit e6fedd165e
2 changed files with 36 additions and 5 deletions

View File

@ -34,7 +34,7 @@ class MenuManager {
std::cout<<"Select Information to display" <<std::endl
<< "1. Profit per Metric" <<std::endl
<< "2. Cunt Sales of type X in a Region" <<std::endl
<< "2. Count Sales of type X in a Region" <<std::endl
<< "3. Most popular item type in country X" <<std::endl
<< "4. Online vs Offline Sales in country X" <<std::endl
<< "======" <<std::endl
@ -63,7 +63,7 @@ class MenuManager {
*selectedRegion = ShowPromptAndGetString("Enter The region to search in");
break;
case 3:
*selectedMetric = ShowPromptAndGetString("Enter The country to get most common type for");
*selectedRegion = ShowPromptAndGetString("Enter The country to get most common type for");
break;
case 4:
*selectedRegion = ShowPromptAndGetString("Select Country to count online vs offline purchases");

View File

@ -36,7 +36,6 @@ void deleteAllPointers(std::vector<ProductSale*> &allSales) {
}
void getMostPopularTypeIn(std::string country, std::vector<ProductSale*> &allSales) {
// TODO Add Map DataType
std::map<std::string, int>TypeCounter;
for (ProductSale* singelSale : allSales) {
@ -74,6 +73,38 @@ void getMostPopularTypeIn(std::string country, std::vector<ProductSale*> &allSal
}
void getOnlineVsOfflineIn(std::string country, std::vector<ProductSale*> &allSales) {
std::map<std::string, int>TypeCounter;
for (ProductSale* singelSale : allSales) {
// map.add(singleSale)
if (singelSale->country != country) {
continue;
}
bool alreadyExists = false;
for (auto element : TypeCounter) {
if (element.first == singelSale->salesChannel) {
element.second++;
alreadyExists = true;
break;
}
}
if (!alreadyExists) {
TypeCounter[singelSale->salesChannel] = 1;
}
}
int OnlineCounter = TypeCounter["Online"];
int OfflineCounter = TypeCounter["Offline"];
double ratio = (OfflineCounter==0) ? 100.0: OnlineCounter/OfflineCounter;
std::cout << "Online : " << OnlineCounter << std::endl << "Offline : " << OfflineCounter << std::endl;
std::cout << "Ratio : " << ratio << "% Online" << std::endl << std::endl;
}
void Aufg8Main() {
std::vector<ProductSale*> allSales;
std::string fileName = "../Aufg8/IO-Files/sales_records_small.csv";
@ -93,7 +124,7 @@ void Aufg8Main() {
std::string* PselectedType = &selectedType;
int* PcurrentMenu = &currentMenu;
MenuManager menu{PcurrentMenu, PselectedRegion, PselectedType};
MenuManager menu{PcurrentMenu, PselectedType, PselectedRegion};
menu.MainInteraction();
while (currentMenu) {
switch (currentMenu) { // TODO Finish these
@ -109,7 +140,7 @@ void Aufg8Main() {
getMostPopularTypeIn(selectedRegion, allSales);
break;
case 4:
// getOnlineVsOfflineIn(*selectedRegion);
getOnlineVsOfflineIn(selectedRegion, allSales);
break;
default:
std::cout << "You should not be able to reach this!";