Skip to content

Commit e133934

Browse files
committed
fixes, formatting and clippy around:
- changes on targeting input - Event ad_unit & ad_slot - analytics
1 parent e7ed972 commit e133934

File tree

12 files changed

+175
-141
lines changed

12 files changed

+175
-141
lines changed

adview-manager/serve/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::sync::Arc;
22

33
use adex_primitives::{
4+
sentry::IMPRESSION,
45
supermarket::units_for_slot,
56
targeting::{input::Global, Input},
67
test_util::{DUMMY_CAMPAIGN, DUMMY_IPFS},
@@ -77,11 +78,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
7778
targeting_input_base: Input {
7879
ad_view: None,
7980
global: Global {
80-
ad_slot_id: options.market_slot.to_string(),
81+
ad_slot_id: options.market_slot,
8182
ad_slot_type: "".into(),
8283
publisher_id: publisher_addr,
8384
country: Some("Bulgaria".into()),
84-
event_type: "IMPRESSION".into(),
85+
event_type: IMPRESSION,
8586
seconds_since_epoch: Utc::now(),
8687
user_agent_os: None,
8788
user_agent_browser_family: None,

primitives/src/ad_slot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{targeting::Rule, ValidatorId, IPFS, Address, UnifiedNum};
1+
use crate::{targeting::Rule, Address, UnifiedNum, ValidatorId, IPFS};
22
use chrono::{
33
serde::{ts_milliseconds, ts_milliseconds_option},
44
DateTime, Utc,

primitives/src/sentry.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,8 @@ mod postgres {
924924
};
925925
use crate::{
926926
analytics::{AnalyticsQuery, Metric},
927-
validator::{messages::Type as MessageType, MessageTypes}, IPFS,
927+
validator::{messages::Type as MessageType, MessageTypes},
928+
IPFS,
928929
};
929930
use bytes::BytesMut;
930931
use chrono::{DateTime, Timelike, Utc};

primitives/src/targeting/eval_test.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use chrono::{TimeZone, Utc};
22

33
use super::*;
44
use crate::{
5+
sentry::IMPRESSION,
56
targeting::input,
67
test_util::{DUMMY_CAMPAIGN, DUMMY_IPFS, LEADER},
78
UnifiedMap,
@@ -17,11 +18,11 @@ fn get_default_input() -> Input {
1718
navigator_language: "bg".to_string(),
1819
}),
1920
global: input::Global {
20-
ad_slot_id: "ad_slot_id Value".to_string(),
21+
ad_slot_id: DUMMY_IPFS[0],
2122
ad_slot_type: "ad_slot_type Value".to_string(),
2223
publisher_id: *LEADER,
2324
country: Some("bg".to_string()),
24-
event_type: "IMPRESSION".to_string(),
25+
event_type: IMPRESSION,
2526
seconds_since_epoch: Utc.ymd(2020, 11, 6).and_hms(12, 0, 0),
2627
user_agent_os: Some("os".to_string()),
2728
user_agent_browser_family: Some("family".to_string()),
@@ -95,6 +96,8 @@ mod rules_test {
9596
}
9697

9798
mod dsl_test {
99+
use crate::sentry::CLICK;
100+
98101
use super::*;
99102

100103
#[test]
@@ -270,20 +273,28 @@ mod dsl_test {
270273

271274
#[test]
272275
fn test_set_eval() {
273-
use crate::campaign::{Pricing, PricingBounds};
276+
use crate::campaign::Pricing;
274277
use crate::test_util::DUMMY_CAMPAIGN;
275278

276279
let mut campaign = DUMMY_CAMPAIGN.clone();
277-
campaign.pricing_bounds = Some(PricingBounds {
278-
impression: Some(Pricing {
279-
min: 1_000.into(),
280-
max: 2_000.into(),
281-
}),
282-
click: Some(Pricing {
283-
min: 3_000.into(),
284-
max: 4_000.into(),
285-
}),
286-
});
280+
campaign.pricing_bounds = vec![
281+
(
282+
IMPRESSION,
283+
Pricing {
284+
min: 1_000.into(),
285+
max: 2_000.into(),
286+
},
287+
),
288+
(
289+
CLICK,
290+
Pricing {
291+
min: 3_000.into(),
292+
max: 4_000.into(),
293+
},
294+
),
295+
]
296+
.into_iter()
297+
.collect();
287298

288299
let input = get_default_input();
289300
let mut output = Output::from(&campaign);

primitives/src/targeting/input.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use self::campaign::FullCampaign;
22

33
use super::{Error, Value};
4-
use crate::{Address, IPFS, sentry::EventType};
4+
use crate::{sentry::EventType, Address, IPFS};
55
use chrono::{serde::ts_seconds, DateTime, Utc};
66
use serde::{Deserialize, Serialize};
77

@@ -51,7 +51,7 @@ impl Input {
5151
pub fn with_campaign(mut self, campaign: crate::Campaign) -> Self {
5252
self.campaign = Some(Get::Getter(FullCampaign {
5353
campaign,
54-
event_type: self.global.event_type.clone(),
54+
event_type: self.global.event_type,
5555
}));
5656

5757
self
@@ -210,7 +210,9 @@ pub mod campaign {
210210
use serde::Deserialize;
211211

212212
use super::{field, Get, GetField, Value};
213-
use crate::{targeting::get_pricing_bounds, Address, CampaignId, ToHex, UnifiedNum, sentry::EventType};
213+
use crate::{
214+
sentry::EventType, targeting::get_pricing_bounds, Address, CampaignId, ToHex, UnifiedNum,
215+
};
214216

215217
pub type GetCampaign = Get<FullCampaign, Values>;
216218

@@ -370,7 +372,10 @@ pub mod balances {
370372
#[cfg(test)]
371373
mod test {
372374
use super::*;
373-
use crate::{test_util::{LEADER, PUBLISHER}, sentry::IMPRESSION};
375+
use crate::{
376+
sentry::IMPRESSION,
377+
test_util::{LEADER, PUBLISHER},
378+
};
374379
pub use crate::{
375380
test_util::{DUMMY_CAMPAIGN as CAMPAIGN, DUMMY_IPFS as IPFS},
376381
AdUnit, UnifiedMap,

sentry/src/access.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ mod test {
172172
config::GANACHE_CONFIG,
173173
event_submission::{RateLimit, Rule},
174174
sentry::Event,
175-
test_util::{DUMMY_CAMPAIGN, FOLLOWER, IDS, PUBLISHER_2},
175+
test_util::{DUMMY_CAMPAIGN, DUMMY_IPFS, FOLLOWER, IDS, PUBLISHER_2},
176176
Config, EventSubmission,
177177
};
178178

@@ -206,8 +206,8 @@ mod test {
206206
(0..count)
207207
.map(|_| Event::Impression {
208208
publisher: *PUBLISHER_2,
209-
ad_unit: None,
210-
ad_slot: None,
209+
ad_unit: DUMMY_IPFS[0],
210+
ad_slot: DUMMY_IPFS[1],
211211
referrer: None,
212212
})
213213
.collect()

sentry/src/db/analytics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn analytics_query_params(
6969
allowed_keys: &HashSet<AllowedKey>,
7070
) -> (Vec<String>, Vec<Box<(dyn ToSql + Sync + Send)>>) {
7171
let mut where_clauses = vec!["\"time\" >= $1".to_string()];
72-
let mut params: Vec<Box<(dyn ToSql + Sync + Send)>> = vec![Box::new(query.time.start.clone())];
72+
let mut params: Vec<Box<(dyn ToSql + Sync + Send)>> = vec![Box::new(query.time.start)];
7373

7474
// for all allowed keys of this query
7575
// insert parameter into the SQL if there is a value set for it
@@ -93,10 +93,10 @@ fn analytics_query_params(
9393

9494
if let Some(end_date) = &query.time.end {
9595
where_clauses.push(format!("\"time\" <= ${}", params.len() + 1));
96-
params.push(Box::new(end_date.clone()));
96+
params.push(Box::new(*end_date));
9797
}
9898
where_clauses.push(format!("event_type = ${}", params.len() + 1));
99-
params.push(Box::new(query.event_type.clone()));
99+
params.push(Box::new(query.event_type));
100100

101101
where_clauses.push(format!("{} IS NOT NULL", query.metric.column_name()));
102102

sentry/src/db/campaign.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,7 @@ pub async fn units_for_slot_get_campaigns(
236236
// Deposit assets
237237
match deposit_assets {
238238
Some(assets) if !assets.is_empty() => {
239-
let assets_vec = assets
240-
.into_iter()
241-
.map(|address| *address)
242-
.collect::<Vec<_>>();
239+
let assets_vec = assets.iter().copied().collect::<Vec<_>>();
243240

244241
where_clauses.push("channels.token IN ($3)".into());
245242
params.push(Box::new(assets_vec))
@@ -583,7 +580,7 @@ mod test {
583580
campaign,
584581
campaign::Validators,
585582
event_submission::{RateLimit, Rule},
586-
sentry::campaign_modify::ModifyCampaign,
583+
sentry::{campaign_modify::ModifyCampaign, CLICK, IMPRESSION},
587584
targeting::Rules,
588585
test_util::{
589586
ADVERTISER, ADVERTISER_2, CREATOR, DUMMY_AD_UNITS, DUMMY_CAMPAIGN,
@@ -650,16 +647,26 @@ mod test {
650647
budget: Some(new_budget),
651648
validators: None,
652649
title: Some("Modified Campaign".to_string()),
653-
pricing_bounds: Some(campaign::PricingBounds {
654-
impression: Some(campaign::Pricing {
655-
min: 1.into(),
656-
max: 10.into(),
657-
}),
658-
click: Some(campaign::Pricing {
659-
min: 0.into(),
660-
max: 0.into(),
661-
}),
662-
}),
650+
pricing_bounds: Some(
651+
vec![
652+
(
653+
IMPRESSION,
654+
campaign::Pricing {
655+
min: 1.into(),
656+
max: 10.into(),
657+
},
658+
),
659+
(
660+
CLICK,
661+
campaign::Pricing {
662+
min: 0.into(),
663+
max: 0.into(),
664+
},
665+
),
666+
]
667+
.into_iter()
668+
.collect(),
669+
),
663670
event_submission: Some(EventSubmission { allow: vec![rule] }),
664671
ad_units: Some(DUMMY_AD_UNITS.to_vec()),
665672
targeting_rules: Some(Rules::new()),

sentry/src/payout.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn get_payout(
5050
ad_slot_type: ad_unit.map(|u| u.ad_type.clone()).unwrap_or_default(),
5151
publisher_id: *publisher,
5252
country: session.country.clone(),
53-
event_type: event_type.clone(),
53+
event_type: event_type,
5454
seconds_since_epoch: Utc::now(),
5555
user_agent_os: session.os.clone(),
5656
user_agent_browser_family: None,
@@ -93,10 +93,9 @@ pub fn get_payout(
9393
mod test {
9494
use super::*;
9595
use primitives::{
96-
campaign::{Pricing, PricingBounds},
96+
campaign::Pricing,
9797
sentry::{CLICK, IMPRESSION},
9898
test_util::{discard_logger, DUMMY_CAMPAIGN, DUMMY_IPFS, LEADER, PUBLISHER},
99-
IPFS,
10099
};
101100

102101
#[test]

0 commit comments

Comments
 (0)