Predicates
From KynetxDocs
Contents |
Predicate Expressions
- You can use conjunction (&&) and disjunction (||) in rules.
- Negation is done using the keyword not
- Expressions can parenthesized for grouping.
The following are examples of valid predicates:
city("Orem") || city("Provo")
not(city("Orem") || city("Provo"))
state("UT") && not city("Provo")
More examples can be found in Predicate Expression Examples
Testing for Equality
You can build predicate expressions that test for equality and inequality.
For numbers you can use <, >, <=, >=, ==, and !=
For strings you can use eq, neq, and like. like takes a regular expression as its second argument and returns true if it matches the string given as it's first argument.
Arguments can be any valid expression including arithmetic expressions, datasources (see Declarations), constants, page variables (see Page Variables), URL variables, or variables declared in the pre block (see Declarations).
The following are all valid tests for equality:
c == 5
page:var("city") eq "Blackfoot"
"Orem" neq location:city()
weather:curr_temp() < 90
location:city() + ", WA" eq city
5 * (weather:curr_temp() - 32) / 9 < 0
Predicates
The following predicates are available for use in rules. If you think of others we ought to have, just ask.
The predicates are grouped by data source.
Location Predicates
city(<arg>)</dt>- returns true when <arg> matches the customer city. </dd>
outside_city(<arg>)</dt>- returns true when <arg> does not match the customer city. </dd>
state(<arg>)</dt>- returns true when <arg> matches the customer state. </dd>
outside_state(<arg>)</dt>- returns true when <arg> does not match the customer state. </dd>
country(<arg>)</dt>- returns true when <arg> matches the customer county. <arg> must be a valid two-digit country code. Use GB for United Kingdom. </dd>
outside_country(<arg>)</dt>- returns true when <arg> does not match the customer country. <arg> must be a valid two-digit country code. Use GB for United Kingdom. </dd>
international()</dt>- returns true when the customer country is not 'US'. </dd>
Media Market Predicates
media_market_rank_grater_than(<arg>)</dt>- returns true when media market rank is greater then <arg>. </dd>
media_market_rank_less_than(<arg>)</dt>- returns true when media market rank is less then <arg>. </dd>
dma_is(<arg>)</dt>-
returns true when <arg> is your DMA Media Market Code.
</dd>
Demographic Predicates
The data used by this data source is from the 2000 US Census. Demographic data is only available for US households at present. For median income, it is useful to keep this table of median income distributions by zipcode in mind:
Income Range Number of Zips Percent $0 - $10000 127 0.40% $10000 - $20000 1256 3.91% $20000 - $30000 6916 21.55% $30000 - $40000 11564 36.03% $40000 - $50000 6247 19.46% $50000 - $60000 2933 9.14% $60000 - $70000 1484 4.62% $70000 - $80000 711 2.22% $80000 - $90000 385 1.20% $90000 - $100000 186 0.58% $100000 - $110000 132 0.41% $110000 - $120000 61 0.19% $120000 - $130000 35 0.11% $130000 - $140000 14 0.04% $140000 - $150000 15 0.05% $150000 - $160000 13 0.04% $160000 - $170000 2 0.01% $170000 - $180000 3 0.01% $180000 - $190000 2 0.01% $190000 - $200000 1 0.00% Above $200000 11 0.03% Note that less than 20% of US zip codes have a median income above $50000. Also note that the median income of many work locations is lower than you might think, so you might want to combine the median income predicates with the
at_homepredicate (to be implemented).A zip code is classified as "urban" if more than 70% of total population lives in an urban setting and "rural" if more than 70% of total population lives in an rural setting. Note that with this definition, "not urban" isn't the same as "rural". The classification "mixed" applied to zip codes that are neither urban nor rural. The following table shows the overall number of zip codes and percentages classified as rural, urban, or mixed:
Type Number of Zips Percent Urban 10131 30.53% Rural 18496 55.74% Mixed 4553 13.72% Note that even though the majority of zip codes are rural, according to the classification given above, 75% of the population lives in an urban setting as shown in the following table:
Type Population Percent Urban 214461186 75.19% Rural 33122004 11.61% Mixed 37647326 13.20%
median_income_above(<arg>)</dt>- returns true when the median income of the zip code the customer is in is greater than the number given in <arg> </dd>
median_income_below(<arg>)</dt>- returns true when the median income of the zip code the custom is in is less than the number given in <arg> </dd>
median_income_between(<low>,<high>)</dt>- returns true when the median income of the zip code the custom is in is between <low> and <high> </dd>
urban()</dt>- returns true when the customer is in an urban location. </dd>
rural()</dt>- returns true when the customer is in an rural location. </dd>
Weather Predicates
All predicates are relative to local weather. That is weather where the customer is.
warmer_than(<arg>)</dt>- Is the current temperature warmer than <arg> </dd>
colder_than(<arg>)</dt>- Is the current temperature colder than <arg> </dd>
tomorrow_cond(<arg>)</dt>- Is <arg> the condition code for tomorrow's weather? </dd>
today_showers()</dt>- Is rain forecast today? </dd>
tomorrow_showers()</dt>- Is rain forecast tomorrow? </dd>
today_cloudy()</dt>- Is cloudy weather forecast for today? </dd>
tomorrow_cloudy()</dt>- Is cloudy weather forecast for tomorrow? </dd>
today_snow()</dt>- Is snow forecast for today/ </dd>
tomorrow_snow()</dt>- Is snow forecast for tomorrow? </dd>
today_windy()</dt>- Is wind forecast for today/ </dd>
tomorrow_windy()</dt>- Is wind forecast for tomorrow? </dd>
today_sunny()</dt>- Is sunny weather forecast for today/ </dd>
tomorrow_sunny()</dt>- Is sunny weather forecast for tomorrow? </dd>
Time Predicates
All of the following predicates are referenced to the users local time. All times are 24-hour clock.
timezone(<arg>)</dt>- <arg> is the name of a timezone in a timezone code like "America/Denver" </dd>
daytime()</dt>- Is it daytime (between sunrise and sunset)? </dd>
nighttime()</dt>- Is it nighttime (between sunset and sunrise)? </dd>
morning()</dt>- Between 0600 and 1200 </dd>
afternoon()</dt>- Between 1200 and 1700 </dd>
evening()</dt>- Between 1700 and 2000 </dd>
night()</dt>- Between 2000 and 2400 </dd>
lunch_time()</dt>- Between 1130 and 1300 </dd>
late_morning()</dt>- Between 1000 and 1200 </dd>
early_afternoon()</dt>- Between 1200 and 1500 </dd>
late_afternoon()</dt>- Between 1500 and 1700 </dd>
time_between(<start_hour>, <start_minute>, <end_hour>, <end_minute>)</dt>- Local time is between the times given. </dd>
date_between(<start_month>, <start_day>, <start_year>, <end_month>, <end_day>, <end_year>)</dt>- Local time is between the dates given (midnight) </dd>
date_start(<start_month>, <start_day>, <start_year>)</dt>- Date is on or after the indicated month, day, and year </dd>
day_of_week(<day name>)</dt>- Checks if the current day of the week has the name (capitalized) given as an argument </dd>
today_is(<sun>, <mon>, <tue>, <wed>, <thur>, <fri>, <sat>)</dt>- Each argument is a 1 or 0 indicating whether to chek if today is that day. </dd>
weekday()</dt>- is today a weekday? </dd>
weekend()</dt>- Is today a weekend? </dd>
</dt>-
</dd>
Economic Indicator Predicates
djia_up_more_than(<arg>)</dt>-
</dd>
djia_down_more_than(<arg>)</dt>-
</dd>
Referer Predicates
search_engine_referer()</dt>- Is referer a search engine? </dd>
referer_domain(<arg>)</dt>- Is the referer domain equal to <arg> </dd>
remote_referer()</dt>- Did the user come to this page from another Web site? Note: only domain names are checked, not ports or protocols. </dd>
local_referer()</dt>- Did the user come to this page from within the same Web site? Note: only domain names are checked, not ports or protocols. </dd>
Browser Predicates
using_ie()</dt>- returns true when the browser type is Internet Explorer. </dd>
using_firefox()</dt>- returns true when the browser type is Firefox. </dd>
Misc Predicates
truth()</dt>- returns true unconditionally</dd>
