![]() |
RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
00001 /* auction_events.h -*- C++ -*- 00002 Jeremy Barnes, 30 May 2012 00003 Copyright (c) 2012 Datacratic. All rights reserved. 00004 00005 PAuctionEvent and related classes 00006 */ 00007 00008 00009 #pragma once 00010 00011 #include "jml/db/persistent.h" 00012 #include "soa/types/date.h" 00013 #include "soa/types/id.h" 00014 00015 #include "bids.h" 00016 #include "account_key.h" 00017 #include "auction.h" 00018 #include "bid_request.h" 00019 #include "currency.h" 00020 #include "json_holder.h" 00021 00022 00023 namespace RTBKIT { 00024 00025 /*****************************************************************************/ 00026 /* SUBMITTED AUCTION EVENT */ 00027 /*****************************************************************************/ 00028 00033 struct SubmittedAuctionEvent { 00034 Id auctionId; 00035 Id adSpotId; 00036 Date lossTimeout; 00037 JsonHolder augmentations; 00038 std::shared_ptr<BidRequest> bidRequest; 00039 std::string bidRequestStr; 00040 Auction::Response bidResponse; 00041 std::string bidRequestStrFormat; 00042 00043 void serialize(ML::DB::Store_Writer & store) const; 00044 void reconstitute(ML::DB::Store_Reader & store); 00045 }; 00046 00047 00048 /*****************************************************************************/ 00049 /* POST AUCTION EVENT TYPE */ 00050 /*****************************************************************************/ 00051 00052 enum PostAuctionEventType { 00053 PAE_INVALID, 00054 PAE_WIN, 00055 PAE_LOSS, 00056 PAE_CAMPAIGN_EVENT 00057 }; 00058 00059 const char * print(PostAuctionEventType type); 00060 00061 COMPACT_PERSISTENT_ENUM_DECL(PostAuctionEventType); 00062 00063 00064 /*****************************************************************************/ 00065 /* POST AUCTION EVENT */ 00066 /*****************************************************************************/ 00067 00073 struct PostAuctionEvent { 00074 PostAuctionEvent(); 00075 PostAuctionEvent(Json::Value const & json); 00076 00077 PostAuctionEventType type; 00078 std::string label; /* for campaign events */ 00079 Datacratic::Id auctionId; 00080 Datacratic::Id adSpotId; 00081 Datacratic::Date timestamp; 00082 JsonHolder metadata; 00083 AccountKey account; 00084 Amount winPrice; 00085 UserIds uids; 00086 SegmentList channels; 00087 Date bidTimestamp; 00088 00089 Json::Value toJson() const; 00090 00091 void serialize(ML::DB::Store_Writer & store) const; 00092 void reconstitute(ML::DB::Store_Reader & store); 00093 00094 std::string print() const; 00095 }; 00096 00097 std::ostream & 00098 operator << (std::ostream & stream, const PostAuctionEvent & event); 00099 00100 ML::DB::Store_Writer & operator 00101 << (ML::DB::Store_Writer & store, 00102 std::shared_ptr<PostAuctionEvent> event); 00103 ML::DB::Store_Reader & operator 00104 >> (ML::DB::Store_Reader & store, 00105 std::shared_ptr<PostAuctionEvent> & event); 00106 00107 00108 /******************************************************************************/ 00109 /* CAMPAIGN EVENTS */ 00110 /******************************************************************************/ 00111 00112 struct CampaignEvent 00113 { 00114 CampaignEvent(const std::string & label = "", Date time = Date(), 00115 const JsonHolder & meta = JsonHolder()) 00116 : label_(label), time_(time), meta_(meta) 00117 {} 00118 00119 Json::Value toJson() const; 00120 static CampaignEvent fromJson(const Json::Value & jsonValue); 00121 00122 void serialize(ML::DB::Store_Writer & store) const; 00123 void reconstitute(ML::DB::Store_Reader & store); 00124 00125 std::string label_; 00126 Date time_; 00127 JsonHolder meta_; 00128 }; 00129 00130 00131 struct CampaignEvents : public std::vector<CampaignEvent> 00132 { 00133 bool hasEvent(const std::string & label) const; 00134 void setEvent(const std::string & label, 00135 Date eventTime, 00136 const JsonHolder & eventMeta); 00137 00138 Json::Value toJson() const; 00139 static CampaignEvents fromJson(const Json::Value&); 00140 }; 00141 00142 00143 /******************************************************************************/ 00144 /* DELIVERY EVENTS */ 00145 /******************************************************************************/ 00146 00152 struct DeliveryEvent 00153 { 00154 std::string event; 00155 Date timestamp; 00156 00157 Id auctionId; 00158 Id spotId; 00159 int spotIndex; 00160 00161 std::shared_ptr<BidRequest> bidRequest; 00162 std::string augmentations; 00163 00164 00165 // \todo Annoyingly similar but cleaner version of Auction::Response 00166 struct Bid 00167 { 00168 Bid() : present(false) {} 00169 bool present; 00170 00171 Date time; 00172 00173 // Information about the actual bid 00174 Auction::Price price; 00175 int tagId; 00176 AccountKey account; 00177 bool test; 00178 00179 // Information about the agent who did the bidding 00180 std::string agent; 00181 Bids bids; 00182 std::string meta; 00183 00184 00185 int creativeId; 00186 std::string creativeName; 00187 00188 // Information about the status of the bid (what happened to it) 00189 Auction::WinLoss localStatus; 00190 00191 static Bid fromJson(const Json::Value&); 00192 Json::Value toJson() const; 00193 } bid; 00194 00195 00197 struct Win 00198 { 00199 Win() : present(false) {} 00200 bool present; 00201 00202 Date time; 00203 BidStatus reportedStatus; 00204 Amount price; 00205 std::string meta; 00206 00207 static Win fromJson(const Json::Value&); 00208 Json::Value toJson() const; 00209 } win; 00210 00211 00212 CampaignEvents campaignEvents; 00213 00214 Json::Value impressionToJson() const; 00215 Json::Value clickToJson() const; 00216 00217 00218 struct Visit 00219 { 00220 Date time; 00221 SegmentList channels; 00222 std::string meta; 00223 00224 static Visit fromJson(const Json::Value&); 00225 Json::Value toJson() const; 00226 }; 00227 00228 std::vector<Visit> visits; 00229 Json::Value visitsToJson() const; 00230 00231 static DeliveryEvent parse(const std::vector<std::string>&); 00232 }; 00233 00234 00235 } // namespace RTBKIT