Parametric filters
Parametric filters assign parametric models to data items.
PFilter
dataclass
Bases: CoreItem
, BoundedItem
Construct parametric models to items associations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter_class | str | Specifies the fields of the target item that are inspected upon filtering matching. | required |
filter_content | str | The content to be matched | required |
pmodel_id | str | A pointer (identifier) to the model which stores the set of parameters that we want to assign | required |
Following examples explain how to associate pmodels to markets and flights. In these cases, there is a hierachy that is obeyed when multiple models match multiple filtering criteria for a given category item.
Examples:
Assigning customers models to citysectors and cityroutes
Customers models can be assigned either to:
citysectors: A city pair with defined directionality (eg: a CitySector with ID CityA->CityB).
cityroutes: A city pair with undefined directionality (eg: a CityRoute with ID CityA<>CityB).
Following examples show different filters to associate a given my_customers_model.json
to:
All citysectors:
pf = ParametricFilter(
filter_class="network",
filter_content="",
pmodel_id="my_customers_model.json")
A cityroute with ID CityA<>CityB
:
pf = ParametricFilter(
filter_class="network",
filter_content="CityA<>CityB",
pmodel_id="my_customers_model.json")
Assigning pricing models models to flights
First, note that:
A schedule represents a set of flights departing within a date period, referring to a given airline and sector.
A sector represents a pair of airports with defined directionality (AirportA-> AirportB). We use IATA coding to identify them (eg AAABBB)
A route represents a pair of airports with undefined directionality (AirportA <> AirportB). We use <>-separated IATA coding to identify them (eg AAA<>BBB)
Following examples show how to create parametric filters to associate a given my_pricing_model.json
to:
All flights of all schedules:
pf = ParametricFilter(
filter_class="network",
filter_content="",
pmodel_id="my_pricing_model.json")
All flights of cityroute CityA<>CityB
:
pf = ParametricFilter(
filter_class="cityroute",
filter_content="CityA<>CityB",
pmodel_id="my_pricing_model.json")
All flights of citysector CityA->CityB
:
pf = ParametricFilter(
filter_class="cityroute",
filter_content="CityA->CityB",
pmodel_id="my_pricing_model.json")
All flights of route AAA<>BBB
:
pf = ParametricFilter(
filter_class="route",
filter_content="AAA<>BBB",
pmodel_id="my_pricing_model.json")
All flights of sector AAABBB
:
pf = ParametricFilter(
filter_class="sector",
filter_content="AAABBB",
pmodel_id="my_pricing_model.json")
All flights of airline MyAirline
:
pf = ParametricFilter(
filter_class="airline",
filter_content="MyAirline",
pmodel_id="my_pricing_model.json")
All flights with flight number 2744
:
pf = ParametricFilter(
filter_class="flight_number",
filter_content="2744",
pmodel_id="my_pricing_model.json")
All flights whose departure dates are fully contained within a given period 2022/05/24-2022/12/31
:
pf = ParametricFilter(
filter_class="in_period",
filter_content="20220524-20221231",
pmodel_id="my_pricing_model.json")
All flights sharing several attributes:
- whose departure dates are fully contained within a given period
2022/05/24-2022/12/31
- belonging to an airline
MyAirline
- covering citysector
CityA->CityB
pf = ParametricFilter(
filter_class=["in_period", "airline", "citysector"],
filter_content=["20220524-20221231", "MyAirline", "CityA->CityB"],
pmodel_id="my_pricing_model.json")
All previous examples work as json representations too:
{
"filter_class": "String",
"filter_content": "String",
"pmodel_id": "String"
}
Source code in src/rmlab/data/parametric/filter.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
make_parametric_filters_from_json(filename_or_list)
Make a parametric filter instance from a json representation (from file or list).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename_or_list | Union[str, list] | JSON filename or list of dictionaries in json format | required |
Example from file: my_parametric_filters.json
[
{
"filter_class": "network",
"filter_content": "",
"pmodel_id": "pricing_range.sample.json"
},
{
"filter_class": "in_period",
"filter_content": "20220524-20221231",
"pmodel_id": "pricing_behavior.sample.json"
},
{
"filter_class": "airline",
"filter_content": "MyAirline",
"pmodel_id": "pricing_optimizer.sample.json"
},
{
"filter_class": "citysector",
"filter_content": "CityA->CityB",
"pmodel_id": "customers_request.poisson_bl1.json"
},
{
"filter_class": "sector",
"filter_content": "CCCDDD",
"pmodel_id": "customers_choice.mnl_bl1.json"
}
]
my_filters = make_parametric_filters_from_json("my_parametric_filters.json")
Source code in src/rmlab/data/parametric/filter.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|