-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataContainer.cpp
More file actions
50 lines (45 loc) · 1.73 KB
/
DataContainer.cpp
File metadata and controls
50 lines (45 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "DataContainer.h"
#include <exception>
const std::string DataContainer::place_id = "6";
const std::string DataContainer::sell_id = "1";
void DataContainer::addCNT(const std::string& aCode, const std::string& aEvent_id) {
event_list.push_back(EventInfo(aCode, aEvent_id));
}
void DataContainer::addSEL(const std::string& aCode, const std::string& aBanner_id, double aPrice) {
if( !price_hashmap.insert({aCode, PriceInfo(aBanner_id, aPrice)}).second) {
throw std::runtime_error("Bad data: same code twice for event 6");
}
auto banner_it = banner_hashmap.find(aBanner_id);
if(banner_it!=banner_hashmap.end())
{
auto place_it = banner_it->second.eventInfo_map.find(place_id);
place_it->second++;
}
else {
banner_hashmap.insert({aBanner_id,BannerInfo(place_id)});
}
}
void DataContainer::prepareToOutput(){
for(const auto& event:event_list){
auto it_priceInfo = price_hashmap.find(event.code);
if(it_priceInfo != price_hashmap.end()) {
auto it_banner = banner_hashmap.find(it_priceInfo->second.banner_id);
if(it_banner != banner_hashmap.end()) {
BannerInfo& banner = it_banner->second;
if(event.event_id == sell_id) {
banner.money_earned += it_priceInfo->second.price;
}
auto it_event = banner.eventInfo_map.find(event.event_id);
if(it_event != banner.eventInfo_map.end()){
it_event->second++;
}
else {
banner.eventInfo_map.insert(std::make_pair(event.event_id,1));
}
}
}
}
}
const TBannerHashMap& DataContainer::getResults() const {
return banner_hashmap;
}