-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimpression.cpp
More file actions
101 lines (63 loc) · 1.43 KB
/
impression.cpp
File metadata and controls
101 lines (63 loc) · 1.43 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
Impression - ID (PK), timestamp, cost
Click - TimeStamp, ImpressionID (FK)
How much I am spending on the clicks?
ClickEvent -> Click from WebPage/ Phone etc
Redirection
1. Impressions one Ad/ couple of seconds
2. One cost per impression
*/
#include <map>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
class Impression
{
public:
// Impression();
//~Impression() {};
long long ID;
int timestamp;
double cost;
};
class ClickEvent {
public:
int timeStamp;
long long ID;
};
class ImpressionManager {
public:
map<long long, Impression> impressionMap;
};
ImpressionManager iManager;
double ComputeCost(vector<ClickEvent> clickEvents){
double retVal = 0;
for (int i = 0; i < clickEvents.size(); ++ i){
ClickEvent c = clickEvents[i];
auto impressionIter = iManager.impressionMap.find(c.ID);
if (impressionIter != iManager.impressionMap.end() ) {
Impression imp = (*impressionIter).second;
retVal += imp.cost;
}
}
return retVal;
}
int main() {
Impression i1;
i1.ID = 1;
i1.cost = 5.0;
Impression i2;
i2.ID = 2;
i2.cost = 7.0;
ClickEvent c1;
c1.ID = 2;
ClickEvent c2;
c2.ID = 1;
iManager.impressionMap[i1.ID] = i1;
iManager.impressionMap[i2.ID] = i2;
std::vector<ClickEvent> v1;
v1.push_back(c1);
v1.push_back(c2);
cout<<ComputeCost(v1)<<endl;
}