Rate a policy with three vehicles
Save the rater asfleet/rater.rsl:
Complete example: fleet/rater.rsl
Complete example: fleet/rater.rsl
fleet/rater.rsl
explain gives one row for each calculation of each vehicle, named by its position in the request.
The three vehicle premiums add up to 3,096. The charges of 40, 100 and 150 bring the annual premium to 3,386.
Declare the list
Declare the item as its own record, with its inputs:keyed by numbernames the input that identifies each vehicle. Each vehicle in a request has its ownnumber.len(self) in [1, 20]states how many vehicles a policy rates.unique(self as v, v.plate)states that a second input is distinct across the list.- Each rule carries the code, the message and the citation of its refusal.
Rate each item in its own step
Write the calculations of one vehicle in theVehicle record. self is that vehicle:
vehicles[1].premium is 800 × 1.8 = 1440.
Read a policy value from an item
A vehicle reads a value of its policy by the record’s name, as inPolicy.fleet_factor:
fleet_factor once, from the length of the list:
Add the items up
sum binds a name to each item and adds one value for each:
sumof an empty list is 0.max,minandavgtake the same two parts and need a list with one item or more.- The length rule
[1, 20]gives the check that proof. On a list that accepts zero items, these three getE-EMPTY-FOLD.
Write a rule over the list total
A rule on the record reads a fold over its list. Write it after the record’s closing brace:self is the policy, so the fold reads self.vehicles. The rater checks the rule before it rates:
reason is the message alone.
Count and test the items
count, exists and all take the list and a condition on one item:
The example has one heavy vehicle, so the heavy charge is 40. The box truck lacks telematics, so
all_telematics is false.
Pick one item
argmax gives the item with the greatest score. The manual names the vehicle with the greatest cost new as the lead vehicle:
- The result is an option:
Someitem, orNonefor an empty list.matchreads it, and both arms are required. then [cite: manual:p3]: v.model_yearis the filed tie-breaker: of two vehicles with the same cost, the newer one leads.- The list key breaks each remaining tie: the vehicle with the lowest
numberleads. argmingives the item with the least score in the same way.
find gives the first item, in key order, that meets a condition:
None arm.
A selection needs a keyed list. argmax, argmin, find, topn or rank on a list that lacks keyed by gets
E-SELECT-TIE.
Related
- Lists in the function reference covers
filter,topn,rank,indexandavg. - Work with dates counts the incidents in a look-back window.
- Refusals lists the reason codes a rater returns for a list.