Difference between revisions of "Template:SetTextPropertyCompletionRate"
m |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
<noinclude> | <noinclude> | ||
− | This template is called from within other ''category'' templates (e.g. Author, Topic, Theory) to store the completion rate of a given textual property. The template checks whether the text has the required length and given in <code><nowiki>|requiredwordcount=</nowiki></code>. If the minimal word count is reached, then a completion rate of 100% is assigned to a property <code><nowiki>CR_{{{ | + | This template is called from within other ''category'' templates (e.g. Author, Topic, Theory) to store the completion rate of a given textual property. The template checks whether the text has the required length and given in <code><nowiki>|requiredwordcount=</nowiki></code>. If the minimal word count is reached, then a completion rate of 100% is assigned to a property <code><nowiki>CR_{{{propertyname}}}</nowiki></code>. Otherwise, the exact rate of completion is stored in that property. |
'''NOTE:''' As any "set" template, it doesn't print anything on the page, but merely sets the appropriate values. | '''NOTE:''' As any "set" template, it doesn't print anything on the page, but merely sets the appropriate values. | ||
+ | |||
+ | '''NOTE:''' Because there doesn't seem to be a function to get the number of words in a string, this template works with the number of characters multiplied by 6. Six is chosen as a multiplier, since the average number of letters in an English word is 5.1; plus we have to factor in spaces between the words. | ||
'''Parameters:''' | '''Parameters:''' | ||
* <code><nowiki>|propertyname=</nowiki></code> - the name of the property for which a completion rate is to be calculated. | * <code><nowiki>|propertyname=</nowiki></code> - the name of the property for which a completion rate is to be calculated. | ||
− | * <code><nowiki>|propertyvalue=</nowiki></code> - the string value of the property; this is to be passed as a parameter, since not all properties are stored and, thus, not all properties are | + | * <code><nowiki>|propertyvalue=</nowiki></code> - the string value of the property; this is to be passed as a parameter, since not all properties are stored and, thus, not all properties are retrievable. |
* <code><nowiki>|requiredwordcount=</nowiki></code> - the minimal number of words to qualify as 100% complete. | * <code><nowiki>|requiredwordcount=</nowiki></code> - the minimal number of words to qualify as 100% complete. | ||
+ | * <code><nowiki>|returnvalue=</nowiki></code> - if nonempty, the calculated value is returned. | ||
</noinclude><includeonly><!-- | </noinclude><includeonly><!-- | ||
+ | -->{{#vardefine: varCR|0}}<!-- start from 0 as the completion rate | ||
-->{{#ifexpr: {{#len: {{{propertyvalue|}}} }} > ({{{requiredwordcount|1}}} * 6)<!-- | -->{{#ifexpr: {{#len: {{{propertyvalue|}}} }} > ({{{requiredwordcount|1}}} * 6)<!-- | ||
-->|<!-- if: store the value as complete | -->|<!-- if: store the value as complete | ||
− | -->{{# | + | -->{{#vardefine: varCR|100}}<!-- |
--><!-- | --><!-- | ||
-->|<!-- else: store the percentage | -->|<!-- else: store the percentage | ||
− | -->{{# | + | -->{{#vardefine: varCR|{{#expr: (100/({{{requiredwordcount|1}}} * 6) * {{#len: {{{propertyvalue|}}} }} ) round 0}} }}<!-- |
--><!-- | --><!-- | ||
-->}}<!-- if length is greater than required word count | -->}}<!-- if length is greater than required word count | ||
+ | --><!-- store the value | ||
+ | -->{{#set: CR_{{{propertyname}}}={{#var: varCR}} }}<!-- | ||
+ | --><!-- return the value if necessary | ||
+ | -->{{#if: {{{returnvalue|}}}|{{#var: varCR}}|}}<!-- | ||
--></includeonly> | --></includeonly> |
Latest revision as of 12:41, 10 June 2017
This template is called from within other category templates (e.g. Author, Topic, Theory) to store the completion rate of a given textual property. The template checks whether the text has the required length and given in |requiredwordcount=
. If the minimal word count is reached, then a completion rate of 100% is assigned to a property CR_{{{propertyname}}}
. Otherwise, the exact rate of completion is stored in that property.
NOTE: As any "set" template, it doesn't print anything on the page, but merely sets the appropriate values.
NOTE: Because there doesn't seem to be a function to get the number of words in a string, this template works with the number of characters multiplied by 6. Six is chosen as a multiplier, since the average number of letters in an English word is 5.1; plus we have to factor in spaces between the words.
Parameters:
|propertyname=
- the name of the property for which a completion rate is to be calculated.|propertyvalue=
- the string value of the property; this is to be passed as a parameter, since not all properties are stored and, thus, not all properties are retrievable.|requiredwordcount=
- the minimal number of words to qualify as 100% complete.|returnvalue=
- if nonempty, the calculated value is returned.