Percent package formatting

master
Mike Gerwitz 2015-11-02 15:59:36 -05:00 committed by Mike Gerwitz
parent 3a9ef76bea
commit af0862f1f1
2 changed files with 55 additions and 29 deletions

View File

@ -26,6 +26,7 @@
<import package="../base" /> <import package="../base" />
<!-- TODO: transitional; remove (used to contain _ptor_ and friends) --> <!-- TODO: transitional; remove (used to contain _ptor_ and friends) -->
<import package="percent" export="true" />
<!-- for template applications --> <!-- for template applications -->
<import package="common" export="true" /> <import package="common" export="true" />

View File

@ -140,12 +140,13 @@
<template name="_ptor-each_" desc="Each percent to real number"> <template name="_ptor-each_"
<param name="@name@" desc="Percentage to convert" /> desc="Each percent to real number">
<param name="@name@" desc="Percentage to convert" />
<param name="@generates@" desc="Value to generate into" /> <param name="@generates@" desc="Value to generate into" />
<param name="@difference@" desc="Whether to perform a percent <param name="@difference@"
difference (default false)"> desc="Whether to perform a percent difference">
<text>false</text> <text>false</text>
</param> </param>
@ -154,8 +155,11 @@
<text>false</text> <text>false</text>
</param> </param>
<rate yields="_{@generates@}"> <rate yields="_{@generates@}">
<c:sum of="@name@" index="k" generates="@generates@" desc="Real representation of {@name@}"> <c:sum of="@name@"
generates="@generates@" index="k"
desc="Real representation of {@name@}">
<t:ptor difference="@difference@" negate="@negate@" <t:ptor difference="@difference@" negate="@negate@"
name="@name@" index="k" /> name="@name@" index="k" />
</c:sum> </c:sum>
@ -165,13 +169,16 @@
<!-- <!--
Yields a total percent as an integer and rational number. The integer is Yields a total percent as an integer and rational number. The
useful for displaying a total percent (e.g. for credits/surcharges) and the integer is useful for displaying a total percent (e.g. for
rational number is useful for using for multiplication in an equation. credits/surcharges) and the rational number is useful for using
for multiplication in an equation.
Example: Example:
<t:total-percent class="foo" to_int="fooPercentTotal" to_rat="fooTotal" index="k"> <t:total-percent class="foo"
to_int="fooPercentTotal" to_rat="fooTotal"
index="k">
<with-param name="@values@"> <with-param name="@values@">
<c:value-of name="fooA" index="k" /> <c:value-of name="fooA" index="k" />
<c:value-of name="fooB" index="k" /> <c:value-of name="fooB" index="k" />
@ -184,7 +191,9 @@
- fooPercentTotal = -2 - fooPercentTotal = -2
- fooTotal = 0.98 - fooTotal = 0.98
--> -->
<template name="_total-percent_" desc="Generates a total percentage as an integer and a rational number"> <template name="_total-percent_"
desc="Generates a total percentage as an integer and a
rational number">
<!-- for use by @values@ --> <!-- for use by @values@ -->
<param name="@index@" desc="Index variable" /> <param name="@index@" desc="Index variable" />
@ -205,14 +214,17 @@
<!-- percent total (e.g. 7 for 7%) --> <!-- percent total (e.g. 7 for 7%) -->
<rate-each class="@class@" yields="@yields_int@" generates="@to_int@" index="@index@"> <rate-each class="@class@" yields="@yields_int@"
generates="@to_int@" index="@index@">
<c:sum> <c:sum>
<param-copy name="@values@" /> <param-copy name="@values@" />
</c:sum> </c:sum>
</rate-each> </rate-each>
<!-- as a rational number (to multiply by; e.g. 1.07 for 7%, 0.93 for -7%) --> <!-- as a rational number (to multiply by; e.g. 1.07 for 7%, 0.93 for -7%) -->
<rate-each class="@class@" yields="@yields_rat@" generates="@to_rat@" index="k"> <rate-each class="@class@" yields="@yields_rat@"
generates="@to_rat@" index="k">
<c:sum> <c:sum>
<c:const value="1" desc="Relative percent" /> <c:const value="1" desc="Relative percent" />
<t:ptor name="@to_int@" index="k" /> <t:ptor name="@to_int@" index="k" />
@ -223,21 +235,25 @@
<!-- <!--
This template is useful for, say, when a coverage is partially included, but This template is useful for, say, when a coverage is partially
additional coverage may be purchased. For example, if 10% of coverage X is included, but additional coverage may be purchased. For example,
included, but you can purchase more Y if 10% is insufficient, then we can if 10% of coverage X is included, but you can purchase more Y if
simply reduce coverage Y by 10% of coverage X. 10% is insufficient, then we can simply reduce coverage Y by 10%
of coverage X.
If the initial value is insufficient, then the value 0 will be produced. If the initial value is insufficient, then the value 0 will be
produced.
--> -->
<template name="_percent-reduction_" desc="Reduces a set of values by a percentage of another set of values"> <template name="_percent-reduction_"
desc="Reduces a set of values by a percentage of another set of values">
<param name="@index@" desc="Value index" /> <param name="@index@" desc="Value index" />
<param name="@reduce@" desc="Vector to reduce values of" /> <param name="@reduce@" desc="Vector to reduce values of" />
<param name="@percentof@" desc="Vector to reduce values by a percentage of" /> <param name="@percentof@" desc="Vector to reduce values by a percentage of" />
<param name="@percent@" desc="Percent reduction (as a float)" /> <param name="@percent@" desc="Percent reduction (as a float)" />
<param name="@minval@" desc="Minimum value to reduce by (optional)" /> <param name="@minval@" desc="Minimum value to reduce by (optional)" />
<param name="@condition@" desc="Boolean conditions (vector for each index) under which reduction should be applied" /> <param name="@condition@" desc="Boolean conditions (vector for
each index) under which reduction should be applied" />
<param name="@desc@" desc="Optional description"> <param name="@desc@" desc="Optional description">
<text>Percent to reduce by</text> <text>Percent to reduce by</text>
@ -257,18 +273,21 @@
<c:apply name="max" label="@label@"> <c:apply name="max" label="@label@">
<!-- if the reduction produces a value less than 0, then simply return 0 --> <!-- if the reduction produces a value less than 0, then simply return 0 -->
<c:arg name="max1"> <c:arg name="max1">
<c:const value="0" type="float" desc="0 will be returned if the reduction is too great" /> <c:const value="0"
desc="0 will be returned if the reduction is too great" />
</c:arg> </c:arg>
<c:arg name="max2"> <c:arg name="max2">
<c:sum> <c:sum>
<c:value-of name="@reduce@" index="@index@" label="Initial value" /> <c:value-of name="@reduce@" index="@index@"
label="Initial value" />
<c:let> <c:let>
<c:values> <c:values>
<c:value name="reduce" type="float" desc="Value to reduce by, should condition be met"> <c:value name="reduce" type="float"
desc="Value to reduce by, should condition be met">
<c:product> <c:product>
<c:const value="@percent@" type="float" desc="@desc@" /> <c:const value="@percent@" desc="@desc@" />
<c:value-of name="@percentof@" index="@index@" /> <c:value-of name="@percentof@" index="@index@" />
</c:product> </c:product>
</c:value> </c:value>
@ -287,7 +306,8 @@
<if name="@minval@"> <if name="@minval@">
<c:apply name="max" max1="reduce"> <c:apply name="max" max1="reduce">
<c:arg name="max2"> <c:arg name="max2">
<c:const value="@minval@" type="float" desc="Minimum value to reduce by" /> <c:const value="@minval@"
desc="Minimum value to reduce by" />
</c:arg> </c:arg>
</c:apply> </c:apply>
</if> </if>
@ -304,7 +324,8 @@
<template name="_percent-of-set_" desc="Returns the percent of a set of given values"> <template name="_percent-of-set_"
desc="Returns the percent of a set of given values">
<param name="@class@" desc="Class match" /> <param name="@class@" desc="Class match" />
<param name="@of@" desc="Vector of values to take the percent of" /> <param name="@of@" desc="Vector of values to take the percent of" />
<param name="@percent@" desc="Percent reduction (as a float)" /> <param name="@percent@" desc="Percent reduction (as a float)" />
@ -316,19 +337,23 @@
</param> </param>
<rate-each class="@class@" yields="@yields@" generates="@generates@" index="k"> <rate-each class="@class@" yields="@yields@"
generates="@generates@" index="k">
<c:apply name="round"> <c:apply name="round">
<c:arg name="roundval"> <c:arg name="roundval">
<c:apply name="max"> <c:apply name="max">
<!-- if the reduction produces a value less than 0, then simply return 0 --> <!-- if the reduction produces a value less than 0, then simply return 0 -->
<c:arg name="max1"> <c:arg name="max1">
<c:const value="0" type="float" desc="0 will be returned if the reduction is too great" /> <c:const value="0"
desc="0 will be returned if the reduction is too great" />
</c:arg> </c:arg>
<c:arg name="max2"> <c:arg name="max2">
<c:product label="Percent value"> <c:product label="Percent value">
<c:const value="@percent@" type="float" desc="Percent to reduce by" /> <c:const value="@percent@" desc="Percent to reduce by" />
<c:value-of name="@of@" index="k" label="Value to take percentage of" />
<c:value-of name="@of@" index="k"
label="Value to take percentage of" />
</c:product> </c:product>
</c:arg> </c:arg>
</c:apply> </c:apply>