Predicates

From KynetxDocs

Jump to: navigation, search

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 RangeNumber of ZipsPercent
$0 - $100001270.40%
$10000 - $2000012563.91%
$20000 - $30000691621.55%
$30000 - $400001156436.03%
$40000 - $50000624719.46%
$50000 - $6000029339.14%
$60000 - $7000014844.62%
$70000 - $800007112.22%
$80000 - $900003851.20%
$90000 - $1000001860.58%
$100000 - $1100001320.41%
$110000 - $120000610.19%
$120000 - $130000350.11%
$130000 - $140000140.04%
$140000 - $150000150.05%
$150000 - $160000130.04%
$160000 - $17000020.01%
$170000 - $18000030.01%
$180000 - $19000020.01%
$190000 - $20000010.00%
Above $200000110.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_home predicate (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:

TypeNumber of ZipsPercent
Urban1013130.53%
Rural1849655.74%
Mixed455313.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:

TypePopulationPercent
Urban21446118675.19%
Rural3312200411.61%
Mixed3764732613.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>


Personal tools