github.com/prebid/prebid-server@v0.275.0/openrtb_ext/floors.go (about)

     1  package openrtb_ext
     2  
     3  // Defines strings for FetchStatus
     4  const (
     5  	FetchSuccess    = "success"
     6  	FetchTimeout    = "timeout"
     7  	FetchError      = "error"
     8  	FetchInprogress = "inprogress"
     9  	FetchNone       = "none"
    10  )
    11  
    12  // Defines strings for PriceFloorLocation
    13  const (
    14  	NoDataLocation  = "noData"
    15  	RequestLocation = "request"
    16  	FetchLocation   = "fetch"
    17  )
    18  
    19  // PriceFloorRules defines the contract for bidrequest.ext.prebid.floors
    20  type PriceFloorRules struct {
    21  	FloorMin           float64                `json:"floormin,omitempty"`
    22  	FloorMinCur        string                 `json:"floormincur,omitempty"`
    23  	SkipRate           int                    `json:"skiprate,omitempty"`
    24  	Location           *PriceFloorEndpoint    `json:"floorendpoint,omitempty"`
    25  	Data               *PriceFloorData        `json:"data,omitempty"`
    26  	Enforcement        *PriceFloorEnforcement `json:"enforcement,omitempty"`
    27  	Enabled            *bool                  `json:"enabled,omitempty"`
    28  	Skipped            *bool                  `json:"skipped,omitempty"`
    29  	FloorProvider      string                 `json:"floorprovider,omitempty"`
    30  	FetchStatus        string                 `json:"fetchstatus,omitempty"`
    31  	PriceFloorLocation string                 `json:"location,omitempty"`
    32  }
    33  
    34  // GetEnforcePBS will check if floors enforcement is enabled in request
    35  func (Floors *PriceFloorRules) GetEnforcePBS() bool {
    36  	if Floors != nil && Floors.Enforcement != nil && Floors.Enforcement.EnforcePBS != nil {
    37  		return *Floors.Enforcement.EnforcePBS
    38  	}
    39  	return true
    40  }
    41  
    42  // GetFloorsSkippedFlag will return  floors skipped flag
    43  func (Floors *PriceFloorRules) GetFloorsSkippedFlag() bool {
    44  	if Floors != nil && Floors.Skipped != nil {
    45  		return *Floors.Skipped
    46  	}
    47  	return false
    48  }
    49  
    50  // GetEnforceRate will return enforcement rate in request
    51  func (Floors *PriceFloorRules) GetEnforceRate() int {
    52  	if Floors != nil && Floors.Enforcement != nil {
    53  		return Floors.Enforcement.EnforceRate
    54  	}
    55  	return 0
    56  }
    57  
    58  // GetEnforceDealsFlag will return FloorDeals flag in request
    59  func (Floors *PriceFloorRules) GetEnforceDealsFlag() bool {
    60  	if Floors != nil && Floors.Enforcement != nil && Floors.Enforcement.FloorDeals != nil {
    61  		return *Floors.Enforcement.FloorDeals
    62  	}
    63  	return false
    64  }
    65  
    66  // GetEnabled will check if floors is enabled in request
    67  func (Floors *PriceFloorRules) GetEnabled() bool {
    68  	if Floors != nil && Floors.Enabled != nil {
    69  		return *Floors.Enabled
    70  	}
    71  	return true
    72  }
    73  
    74  type PriceFloorEndpoint struct {
    75  	URL string `json:"url,omitempty"`
    76  }
    77  
    78  type PriceFloorData struct {
    79  	Currency            string                 `json:"currency,omitempty"`
    80  	SkipRate            int                    `json:"skiprate,omitempty"`
    81  	FloorsSchemaVersion string                 `json:"floorsschemaversion,omitempty"`
    82  	ModelTimestamp      int                    `json:"modeltimestamp,omitempty"`
    83  	ModelGroups         []PriceFloorModelGroup `json:"modelgroups,omitempty"`
    84  	FloorProvider       string                 `json:"floorprovider,omitempty"`
    85  }
    86  
    87  type PriceFloorModelGroup struct {
    88  	Currency     string             `json:"currency,omitempty"`
    89  	ModelWeight  *int               `json:"modelweight,omitempty"`
    90  	ModelVersion string             `json:"modelversion,omitempty"`
    91  	SkipRate     int                `json:"skiprate,omitempty"`
    92  	Schema       PriceFloorSchema   `json:"schema,omitempty"`
    93  	Values       map[string]float64 `json:"values,omitempty"`
    94  	Default      float64            `json:"default,omitempty"`
    95  }
    96  
    97  func (mg PriceFloorModelGroup) Copy() PriceFloorModelGroup {
    98  	newMg := new(PriceFloorModelGroup)
    99  	newMg.Currency = mg.Currency
   100  	newMg.ModelVersion = mg.ModelVersion
   101  	newMg.SkipRate = mg.SkipRate
   102  	newMg.Default = mg.Default
   103  	if mg.ModelWeight != nil {
   104  		newMg.ModelWeight = new(int)
   105  		*newMg.ModelWeight = *mg.ModelWeight
   106  	}
   107  
   108  	newMg.Schema.Delimiter = mg.Schema.Delimiter
   109  	newMg.Schema.Fields = make([]string, len(mg.Schema.Fields))
   110  	copy(newMg.Schema.Fields, mg.Schema.Fields)
   111  	newMg.Values = make(map[string]float64, len(mg.Values))
   112  	for key, val := range mg.Values {
   113  		newMg.Values[key] = val
   114  	}
   115  	return *newMg
   116  }
   117  
   118  type PriceFloorSchema struct {
   119  	Fields    []string `json:"fields,omitempty"`
   120  	Delimiter string   `json:"delimiter,omitempty"`
   121  }
   122  
   123  type PriceFloorEnforcement struct {
   124  	EnforceJS     *bool `json:"enforcejs,omitempty"`
   125  	EnforcePBS    *bool `json:"enforcepbs,omitempty"`
   126  	FloorDeals    *bool `json:"floordeals,omitempty"`
   127  	BidAdjustment *bool `json:"bidadjustment,omitempty"`
   128  	EnforceRate   int   `json:"enforcerate,omitempty"`
   129  }
   130  
   131  type ImpFloorExt struct {
   132  	FloorRule      string  `json:"floorrule,omitempty"`
   133  	FloorRuleValue float64 `json:"floorrulevalue,omitempty"`
   134  	FloorValue     float64 `json:"floorvalue,omitempty"`
   135  }
   136  type Price struct {
   137  	FloorMin    float64 `json:"floormin,omitempty"`
   138  	FloorMinCur string  `json:"floormincur,omitempty"`
   139  }
   140  
   141  type ExtImp struct {
   142  	Prebid *ImpExtPrebid `json:"prebid,omitempty"`
   143  }
   144  
   145  type ImpExtPrebid struct {
   146  	Floors Price `json:"floors,omitempty"`
   147  }