Compare commits
7 Commits
8af59118c2
...
b99e0b45ad
Author | SHA1 | Date | |
---|---|---|---|
|
b99e0b45ad | ||
|
00b4e196da | ||
|
a0f05d9130 | ||
|
bff9cf5935 | ||
|
9321ec8d71 | ||
|
dbdd4ade8e | ||
|
e6fedd165e |
@ -8,6 +8,7 @@
|
|||||||
#include "Aufg5/Mastermind.h"
|
#include "Aufg5/Mastermind.h"
|
||||||
#include "Aufg6/MineSweeper.h"
|
#include "Aufg6/MineSweeper.h"
|
||||||
#include "Aufg7/SegFault.h"
|
#include "Aufg7/SegFault.h"
|
||||||
|
#include "Aufg8/SalesStatMain.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// Aufg1Main();
|
// Aufg1Main();
|
||||||
@ -16,5 +17,6 @@ int main() {
|
|||||||
// Aufg4Main();
|
// Aufg4Main();
|
||||||
// Aufg5Main();
|
// Aufg5Main();
|
||||||
// Aufg6Main();
|
// Aufg6Main();
|
||||||
Aufg7Main();
|
// Aufg7Main();
|
||||||
|
Aufg8Main();
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class MenuManager {
|
|||||||
|
|
||||||
std::cout<<"Select Information to display" <<std::endl
|
std::cout<<"Select Information to display" <<std::endl
|
||||||
<< "1. Profit per Metric" <<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
|
<< "3. Most popular item type in country X" <<std::endl
|
||||||
<< "4. Online vs Offline Sales in country X" <<std::endl
|
<< "4. Online vs Offline Sales in country X" <<std::endl
|
||||||
<< "======" <<std::endl
|
<< "======" <<std::endl
|
||||||
@ -63,7 +63,7 @@ class MenuManager {
|
|||||||
*selectedRegion = ShowPromptAndGetString("Enter The region to search in");
|
*selectedRegion = ShowPromptAndGetString("Enter The region to search in");
|
||||||
break;
|
break;
|
||||||
case 3:
|
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;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
*selectedRegion = ShowPromptAndGetString("Select Country to count online vs offline purchases");
|
*selectedRegion = ShowPromptAndGetString("Select Country to count online vs offline purchases");
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "MenuManager.h"
|
#include "MenuManager.h"
|
||||||
#include "ProductSale.h"
|
#include "ProductSale.h"
|
||||||
|
#include "../Aufg1/forLoop.h"
|
||||||
|
|
||||||
std::string readFile(std::string &fileName, std::vector<ProductSale*> &allSales) {
|
std::string readFile(std::string &fileName, std::vector<ProductSale*> &allSales) {
|
||||||
std::string content;
|
std::string content;
|
||||||
@ -29,35 +30,126 @@ std::string readFile(std::string &fileName, std::vector<ProductSale*> &allSales)
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void printAllSales(std::vector<ProductSale*> &allSales) {
|
||||||
|
for (int i = 0; i < allSales.size(); ++i) {
|
||||||
|
std::cout << allSales[i]->toString() << std::endl;
|
||||||
|
std::cout << "==============" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void deleteAllPointers(std::vector<ProductSale*> &allSales) {
|
void deleteAllPointers(std::vector<ProductSale*> &allSales) {
|
||||||
for (auto it = allSales.begin(); it != allSales.end(); it++) {
|
for (auto it = allSales.begin(); it != allSales.end(); it++) {
|
||||||
delete (*it);
|
delete (*it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void getMostPopularTypeIn(std::string country, std::vector<ProductSale*> &allSales) {
|
void getTotalProfitFor(std::string metric, std::vector<ProductSale*> &allSales) {
|
||||||
// TODO Add Map DataType
|
std::map<std::string, long long> TotalPerMetric;
|
||||||
std::map<std::string, int>TypeCounter;
|
|
||||||
|
|
||||||
for (ProductSale* singelSale : allSales) {
|
if (metric == "Region") {
|
||||||
// map.add(singleSale)
|
for(auto sale : allSales) {
|
||||||
if (singelSale->country != country) {
|
TotalPerMetric[sale->region] += sale->totalProfit;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
} else if (metric == "Country") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
TotalPerMetric[sale->country] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
} else if (metric=="Item_Type") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
TotalPerMetric[sale->itemType] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric=="Sales_Channel") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
TotalPerMetric[sale->salesChannel] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Order_Priority") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
TotalPerMetric[sale->orderPriority] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Order_Date") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
TotalPerMetric[sale->orderDate] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Order_ID") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
TotalPerMetric[sale->orderId] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Ship_Date") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
TotalPerMetric[sale->shipDate] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Units_Sold") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
std::string key = std::to_string(sale->unitsSold);
|
||||||
|
TotalPerMetric[key] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Unit_Price") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
std::string key = std::to_string(sale->unitPrice);
|
||||||
|
TotalPerMetric[key] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric=="Unit_Cost") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
std::string key = std::to_string(sale->unitCost);
|
||||||
|
TotalPerMetric[key] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Total_Revenue") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
std::string key = std::to_string(sale->totalRevenue);
|
||||||
|
TotalPerMetric[key] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Total_Cost") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
std::string key = std::to_string(sale->totalCost);
|
||||||
|
TotalPerMetric[key] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else if (metric == "Total_Profit") {
|
||||||
|
for(auto sale : allSales) {
|
||||||
|
std::string key = std::to_string(sale->totalProfit);
|
||||||
|
TotalPerMetric[key] += sale->totalProfit;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
std::cout << "Unknown metric :" << metric << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool alreadyExists = false;
|
for (auto entry : TotalPerMetric) {
|
||||||
for (auto element : TypeCounter) {
|
std::cout << entry.first << " : " << entry.second << std::endl;
|
||||||
if (element.first == singelSale->itemType) {
|
}
|
||||||
element.second++;
|
std::cout << std::endl;
|
||||||
alreadyExists = true;
|
}
|
||||||
break;
|
|
||||||
|
void getSaleCount(std::string itemType, std::string country, std::vector<ProductSale*> &allSales) {
|
||||||
|
long totalSales;
|
||||||
|
long salesOfTypeX;
|
||||||
|
|
||||||
|
for (auto singleSale : allSales) {
|
||||||
|
if (singleSale->country == country) {
|
||||||
|
totalSales += singleSale->unitsSold;
|
||||||
|
|
||||||
|
if (singleSale->itemType == itemType) {
|
||||||
|
salesOfTypeX += singleSale->unitsSold;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!alreadyExists) {
|
|
||||||
TypeCounter[singelSale->itemType] = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double ratio = (totalSales == 0) ? 100.0 : static_cast<double>(salesOfTypeX) / totalSales * 50.0;
|
||||||
|
std::cout << "There were " << totalSales << " total sales in " << country << std::endl;
|
||||||
|
std::cout << itemType << " were " << salesOfTypeX << " of them in " << country << std::endl;
|
||||||
|
std::cout << "that's " << ratio << "%" << std::endl << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void getMostPopularTypeIn(std::string country, std::vector<ProductSale*> &allSales) {
|
||||||
|
std::map<std::string, int>TypeCounter;
|
||||||
|
|
||||||
|
// Filter out wrong countries
|
||||||
|
for (ProductSale* singleSale : allSales) {
|
||||||
|
if (singleSale->country != country) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TypeCounter[singleSale->itemType]++;
|
||||||
|
}
|
||||||
|
|
||||||
// return map.getMostCommon
|
// return map.getMostCommon
|
||||||
std::string mostPopularType;
|
std::string mostPopularType;
|
||||||
@ -74,16 +166,35 @@ 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* singleSale : allSales) {
|
||||||
|
if (singleSale->country != country) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increment the counter for the sales channel directly
|
||||||
|
TypeCounter[singleSale->salesChannel]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int OnlineCounter = TypeCounter["Online"];
|
||||||
|
int OfflineCounter = TypeCounter["Offline"];
|
||||||
|
double ratio = (OfflineCounter == 0) ? 100.0 : static_cast<double>(OnlineCounter) / OfflineCounter * 50.0;
|
||||||
|
|
||||||
|
std::cout << "Online : " << OnlineCounter << std::endl << "Offline : " << OfflineCounter << std::endl;
|
||||||
|
std::cout << "Ratio : " << ratio << "% Online" << std::endl << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void Aufg8Main() {
|
void Aufg8Main() {
|
||||||
std::vector<ProductSale*> allSales;
|
std::vector<ProductSale*> allSales;
|
||||||
std::string fileName = "../Aufg8/IO-Files/sales_records_small.csv";
|
std::string fileName = "../Aufg8/IO-Files/sales_records_small.csv";
|
||||||
|
fileName = "../Aufg8/IO-Files/DANGER-1500000SalesRecords.csv";
|
||||||
|
|
||||||
readFile(fileName, allSales);
|
readFile(fileName, allSales);
|
||||||
|
|
||||||
for (int i = 0; i < allSales.size(); ++i) {
|
// printAllSales(allSales);
|
||||||
std::cout << allSales[i]->toString() << std::endl;
|
|
||||||
std::cout << "==============" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string selectedRegion;
|
std::string selectedRegion;
|
||||||
std::string selectedType;
|
std::string selectedType;
|
||||||
@ -93,24 +204,24 @@ void Aufg8Main() {
|
|||||||
std::string* PselectedType = &selectedType;
|
std::string* PselectedType = &selectedType;
|
||||||
int* PcurrentMenu = ¤tMenu;
|
int* PcurrentMenu = ¤tMenu;
|
||||||
|
|
||||||
MenuManager menu{PcurrentMenu, PselectedRegion, PselectedType};
|
MenuManager menu{PcurrentMenu, PselectedType, PselectedRegion};
|
||||||
menu.MainInteraction();
|
menu.MainInteraction();
|
||||||
while (currentMenu) {
|
while (currentMenu) {
|
||||||
switch (currentMenu) { // TODO Finish these
|
switch (currentMenu) { // TODO Finish these
|
||||||
case 0:
|
case 0:
|
||||||
return;
|
return; // To quit the programm
|
||||||
case 1:
|
case 1:
|
||||||
// getTotalProfitFor(*selectedType);
|
getTotalProfitFor(selectedType, allSales);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// getSaleCount(*selectedType, *selectedRegion);
|
getSaleCount(selectedType, selectedRegion, allSales);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
getMostPopularTypeIn(selectedRegion, allSales);
|
getMostPopularTypeIn(selectedRegion, allSales);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
// getOnlineVsOfflineIn(*selectedRegion);
|
getOnlineVsOfflineIn(selectedRegion, allSales);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
std::cout << "You should not be able to reach this!";
|
std::cout << "You should not be able to reach this!";
|
||||||
}
|
}
|
||||||
|
@ -6,4 +6,6 @@
|
|||||||
- Aufgabe 3 (Telefonbuch mit Speichern in Datei) ☎️
|
- Aufgabe 3 (Telefonbuch mit Speichern in Datei) ☎️
|
||||||
- Aufgabe 4 (Auswertung großer Verbrecher-CSV) 🕵️♂️
|
- Aufgabe 4 (Auswertung großer Verbrecher-CSV) 🕵️♂️
|
||||||
- Aufgabe 5 (Mastermind Code-Guessing-Game) 👺
|
- Aufgabe 5 (Mastermind Code-Guessing-Game) 👺
|
||||||
- Aufgabe 6 (Minesweeper Board Generator) 💣
|
- Aufgabe 6 (Minesweeper Board Generator) 💣
|
||||||
|
- Aufgabe 7 (SEGV. und Signal-Handling) 🤖
|
||||||
|
- Aufgabe 8 (Auswertung riesiger Sales-Datei) 🍇
|
Loading…
Reference in New Issue
Block a user