Skip to content

Commit fc4c2c9

Browse files
authored
Merge pull request #345 from AdExNetwork/issue-340-re-think-targeting-input
Issue #340 re-think targeting input
2 parents e77c08a + aed253b commit fc4c2c9

File tree

13 files changed

+1116
-740
lines changed

13 files changed

+1116
-740
lines changed

Cargo.lock

Lines changed: 135 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

adview-manager/src/lib.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use adex_primitives::{
55
supermarket::units_for_slot,
66
supermarket::units_for_slot::response::{AdUnit, Campaign},
7-
targeting::{self, input, Value},
7+
targeting::{self, input},
88
BigNum, ChannelId, SpecValidators, ValidatorId, IPFS,
99
};
1010
use async_std::{sync::RwLock, task::block_on};
@@ -323,10 +323,9 @@ impl Manager {
323323
})
324324
.unwrap_or(u64::MAX);
325325

326-
input.set_ad_view(input::AdView {
326+
input.ad_view = Some(input::AdView {
327327
seconds_since_campaign_impression,
328328
has_custom_preferences: false,
329-
// TODO: Check this empty default!
330329
navigator_language: self.options.navigator_language.clone().unwrap_or_default(),
331330
});
332331

@@ -435,17 +434,12 @@ impl Manager {
435434
let units_for_slot = self.get_market_demand_resp().await?;
436435
let campaigns = &units_for_slot.campaigns;
437436
let fallback_unit = units_for_slot.fallback_unit;
438-
let targeting_input = input::Getter {
439-
base: units_for_slot.targeting_input_base,
440-
ad_unit: None,
441-
channel: None,
442-
last_approved: None,
443-
deposit_asset: None,
444-
};
437+
let targeting_input = units_for_slot.targeting_input_base;
445438

446439
let hostname = targeting_input
447-
.try_get("adSlot.hostname")
448-
.and_then(Value::try_string)
440+
.ad_slot
441+
.as_ref()
442+
.map(|ad_slot| ad_slot.hostname.clone())
449443
.unwrap_or_default();
450444

451445
// Stickiness is when we keep showing an ad unit for a slot for some time in order to achieve fair impression value
@@ -474,15 +468,16 @@ impl Manager {
474468
if block_on(self.is_campaign_sticky(campaign.channel.id)) {
475469
return vec![];
476470
}
477-
let mut campaign_input = targeting_input.clone();
471+
478472
let campaign_id = campaign.channel.id;
479-
campaign_input.channel = Some(campaign.channel.clone());
473+
474+
let mut unit_input = targeting_input.clone().with_market_channel(campaign.channel.clone());
480475

481476
campaign
482477
.units_with_price
483478
.iter()
484479
.filter(|unit_with_price| {
485-
campaign_input.ad_unit = Some(unit_with_price.unit.clone());
480+
unit_input.ad_unit_id = Some(unit_with_price.unit.id.clone());
486481

487482
let mut output = targeting::Output {
488483
show: true,
@@ -496,7 +491,7 @@ impl Manager {
496491

497492
targeting::eval_with_callback(
498493
&campaign.targeting_rules,
499-
&input::Input::Getter(campaign_input.clone()),
494+
&unit_input,
500495
&mut output,
501496
Some(on_type_error)
502497
);

primitives/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ serde = { version = "^1.0", features = ['derive'] }
1313
serde_json = "1.0"
1414
serde-hex = "0.1.0"
1515
serde_millis = "0.1.1"
16+
# Used prefixes on field for targeting::Input
17+
serde_with = "1.5"
1618
# Configuration
1719
toml = "0.5"
1820
# Logging
@@ -23,6 +25,8 @@ slog-async = "^2.3.0"
2325
thiserror = "^1.0"
2426
chrono = { version = "0.4", features = ["serde"] }
2527
time = "0.1.42"
28+
# Macro for easier derive of Display & FromStr
29+
parse-display = "^0.3"
2630
# CID & multihash / multibase
2731
cid = "0.5"
2832
hex = "0.4"
@@ -47,3 +51,6 @@ futures = "0.3"
4751
async-trait = "0.1.40"
4852
# Other
4953
lazy_static = "1.4.0"
54+
55+
[dev-dependencies]
56+
pretty_assertions = "^0.6"

primitives/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub mod merkle_tree;
1818
pub mod sentry;
1919
pub mod supermarket;
2020
pub mod targeting;
21-
pub mod targeting_tag;
2221

2322
pub mod util {
2423
pub mod tests {
@@ -48,7 +47,6 @@ pub use self::channel::{Channel, ChannelId, ChannelSpec, SpecValidator, SpecVali
4847
pub use self::config::Config;
4948
pub use self::event_submission::EventSubmission;
5049
pub use self::ipfs::IPFS;
51-
pub use self::targeting_tag::TargetingTag;
5250
pub use self::validator::{ValidatorDesc, ValidatorId};
5351

5452
#[derive(Debug, PartialEq, Eq)]

primitives/src/supermarket.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub mod units_for_slot {
4444
pub mod response {
4545

4646
use crate::{
47-
targeting::{Map, Rule},
47+
targeting::{Input, Rule},
4848
BigNum, ChannelId, ChannelSpec, SpecValidators, ValidatorId, IPFS,
4949
};
5050
use chrono::{
@@ -57,7 +57,7 @@ pub mod units_for_slot {
5757
#[derive(Debug, Serialize, Deserialize, PartialEq)]
5858
#[serde(rename_all = "camelCase")]
5959
pub struct Response {
60-
pub targeting_input_base: Map,
60+
pub targeting_input_base: Input,
6161
pub accepted_referrers: Vec<Url>,
6262
pub fallback_unit: Option<AdUnit>,
6363
pub campaigns: Vec<Campaign>,

0 commit comments

Comments
 (0)