File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,22 @@ pub struct PricingBounds {
102
102
pub click : Option < Pricing > ,
103
103
}
104
104
105
+ impl PricingBounds {
106
+ pub fn to_vec ( & self ) -> Vec < ( & str , Pricing ) > {
107
+ let mut vec = Vec :: new ( ) ;
108
+
109
+ if let Some ( pricing) = self . impression . as_ref ( ) {
110
+ vec. push ( ( "IMPRESSION" , pricing. clone ( ) ) ) ;
111
+ }
112
+
113
+ if let Some ( pricing) = self . click . as_ref ( ) {
114
+ vec. push ( ( "CLICK" , pricing. clone ( ) ) )
115
+ }
116
+
117
+ vec
118
+ }
119
+ }
120
+
105
121
#[ derive( Serialize , Deserialize , Debug , Clone ) ]
106
122
#[ serde( rename_all = "camelCase" ) ]
107
123
pub struct ChannelSpec {
Original file line number Diff line number Diff line change 1
- use crate :: BigNum ;
1
+ use crate :: { BigNum , Channel } ;
2
2
use std:: collections:: HashMap ;
3
3
4
4
pub use eval:: * ;
@@ -139,6 +139,25 @@ pub struct Output {
139
139
pub price : HashMap < String , BigNum > ,
140
140
}
141
141
142
+ impl From < & Channel > for Output {
143
+ fn from ( channel : & Channel ) -> Self {
144
+ let price = match & channel. spec . pricing_bounds {
145
+ Some ( pricing_bounds) => pricing_bounds
146
+ . to_vec ( )
147
+ . into_iter ( )
148
+ . map ( |( key, price) | ( key. to_string ( ) , price. min ) )
149
+ . collect ( ) ,
150
+ _ => Default :: default ( ) ,
151
+ } ;
152
+
153
+ Self {
154
+ show : true ,
155
+ boost : 1.0 ,
156
+ price,
157
+ }
158
+ }
159
+ }
160
+
142
161
#[ cfg( test) ]
143
162
mod test {
144
163
use super :: * ;
You can’t perform that action at this time.
0 commit comments