laferrierejc

Bin Percents

Apr 2nd, 2012
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.02 KB | None | 0 0
  1. //foreach loop that returns an average excluding all 0's
  2. //I recommend a median version of this if possible to code, but it requires more work.
  3. //you would have to create an array that holds all values that are not 0'd, and then find's the median.
  4. function skillAvg (skill)
  5.  
  6. {
  7.  
  8. for (iterations in d.skill_rating(skill)
  9. {
  10. if (d.skill_rating == 0)
  11. {
  12. sum = sum + 0;
  13. count = count;
  14. }
  15. else
  16. {
  17. acount = count + 1;
  18. sum = sum + d.skill(rating(skill));
  19. }
  20. };
  21.  
  22. return sum/count;
  23. }
  24.  
  25. function median(list){
  26. function compare(a,b){
  27. return a-b;
  28. }
  29. list.sort(compare);
  30. var listlength = list.length;
  31. if (listlength % 2){
  32. var odd = (listlength / 2 - 0.5);
  33. alert("Median is:" + list[odd]);
  34. }else{
  35. var even = (list[listlength / 2]);
  36. even += (list[listlength / 2 + 1]);
  37. even = (even / 2);
  38. alert("Median is: " + even);
  39. }
  40. }
  41.  
  42. function skillMedian (skill)
  43. {
  44. list[];
  45. count=0;
  46.  
  47. //I hope this for starts at 0
  48. for (iterations in d.skill_rating(skill)
  49. {
  50. if (d.skill_rating == 0)
  51. {
  52. //do nothing;
  53. }
  54. else
  55. {
  56. list[count] = skill[iterations];
  57. count = count+1;
  58. }
  59. };
  60.  
  61. return median(list);
  62. }
  63.  
  64. //requires a d.skill_max() function
  65. //takes a d.skill_rating(skill) as skill parameter, takes either the return of skillAvg or skillMedian
  66. function skillPct (skill, avgOrMedian)
  67. {
  68. if (skill < avgOrMedian)
  69. {
  70. xpct = ((skill - avgOrMedian)/(avgOrMedian - d.skill_max(skill))+1)/2;
  71.  
  72. }
  73. else if (skill >= avgOrMedian)
  74. {
  75. xpct = ((avgOrMedian - skill)/( (d.skill_max(skill) - skill) )+1)/2;
  76. }
  77.  
  78. return xpct;
  79.  
  80. }
  81.  
  82. //requires a trait and a bin category (see below)
  83. function binTraitPercent (trait, category)
  84. {
  85. //minus traits
  86. if (category = 1)
  87. {
  88. bin1=0;
  89. bin2=9;
  90. bin3=22;
  91. bin4=36;
  92. bin5=57;
  93. bin6=73;
  94. bin7=90;
  95.  
  96. if (trait < bin1) {
  97. xpct = 0 } //or... - (trait / bin1)}
  98. else if (trait >= bin1 && trait < bin2) {
  99. xpct = (((trait - bin1) / (bin2-bin1+1))*0.004)}
  100. else if (trait >= bin2 && trait < bin3) {
  101. xpct = (((x-bin2) / (bin3-bin2+1))*0.01375) + (0.004)}
  102. else if (trait >= bin3 && trait < bin4)) {
  103. xpct = (((x-bin3) / (bin4-bin3+1))*0.07775) + (0.01775)}
  104. else if (trait >= bin4 && trait < bin5)) {
  105. xpct = (((x-bin4) / (bin5-bin4+1))*0.7905) + (0.0955)}
  106. else if ((trait >= bin5 && trait < bin6)) {
  107. xpct = (((x-bin5) / (bin6-bin5+1)*0.08575) + (0.886) )}
  108. else if (trait >= bin6 && trait < bin7 ) {
  109. xpct = (((x-bin6) / (bin7-bin6+1)) *0.02425) + (0.97175)}
  110. else if (trait >= bin7) {
  111. xpct = (((x-bin7) / (100-bin7+1))*0.004) + (0.996) };
  112.  
  113. return xpct;
  114. };
  115.  
  116. //normal traits
  117. if (category = 2)
  118. {
  119. bin1=0;
  120. bin2=10;
  121. bin3=25;
  122. bin4=40;
  123. bin5=61;
  124. bin6=76;
  125. bin7=91;
  126.  
  127. if (trait < bin1) {
  128. xpct = 0 } //or... - (x / bin1)}
  129. else if (trait >= bin1 && trait < bin2) {
  130. xpct = (((trait - bin1) / (bin2-bin1+1))*0.0038425926)}
  131. else if (trait >= bin2 && trait < bin3) {
  132. xpct = (((x-bin2) / (bin3-bin2+1))*0.0197592593) + (0.0038425926)}
  133. else if (trait >= bin3 && trait < bin4)) {
  134. xpct = (((x-bin3) / (bin4-bin3+1))*0.0857407407) + (0.0236018519)}
  135. else if (trait >= bin4 && trait < bin5)) {
  136. xpct = (((x-bin4) / (bin5-bin4+1))*0.7813148148) + (0.1093425926)}
  137. else if ((trait >= bin5 && trait < bin6)) {
  138. xpct = (((x-bin5) / (bin6-bin5+1)*0.0857407407) + (0.8906574074) )}
  139. else if (trait >= bin6 && trait < bin7 ) {
  140. xpct = (((x-bin6) / (bin7-bin6+1)) *0.0197592593) + (0.9763981481)}
  141. else if (trait >= bin7) {
  142. xpct = (((x-bin7) / (100-bin7+1))*0.0038425926) + (0.9961574074) };
  143.  
  144. return xpct;
  145. };
  146.  
  147. //plus traits
  148. if (category = 3)
  149. {
  150. bin1=0;
  151. bin2=11;
  152. bin3=27;
  153. bin4=44;
  154. bin5=65;
  155. bin6=78;
  156. bin7=92;
  157.  
  158. if (trait < bin1) {
  159. xpct = 0 } //or... - (trait / bin1)}
  160. else if (trait >= bin1 && trait < bin2) {
  161. xpct = (((trait - bin1) / (bin2-bin1+1))*0.004)}
  162. else if (trait >= bin2 && trait < bin3) {
  163. xpct = (((x-bin2) / (bin3-bin2+1))*0.01375) + (0.004)}
  164. else if (trait >= bin3 && trait < bin4)) {
  165. xpct = (((x-bin3) / (bin4-bin3+1))*0.07775) + (0.01775)}
  166. else if (trait >= bin4 && trait < bin5)) {
  167. xpct = (((x-bin4) / (bin5-bin4+1))*0.7905) + (0.0955)}
  168. else if ((trait >= bin5 && trait < bin6)) {
  169. xpct = (((x-bin5) / (bin6-bin5+1)*0.08575) + (0.886) )}
  170. else if (trait >= bin6 && trait < bin7 ) {
  171. xpct = (((x-bin6) / (bin7-bin6+1)) *0.02425) + (0.97175)}
  172. else if (trait >= bin7) {
  173. xpct = (((x-bin7) / (100-bin7+1))*0.004) + (0.996) };
  174.  
  175. return xpct;
  176. };
  177. };
  178.  
  179. //Return's % relative to bin.
  180. //Two parameters are provided.
  181. //attribute is a attribute variable, such as d.strength()
  182. //category is a flag used to modify bin values
  183. function binAttributePercent (attribute, category)
  184. {
  185. //minus
  186. if (category = 1)
  187. {
  188. bin1=150;
  189. bin2=600;
  190. bin3=800;
  191. bin4=900;
  192. bin5=1000;
  193. bin6=1100;
  194. bin7=1500;
  195. };
  196. //normal, Physical
  197. if (category = 2)
  198. {
  199. bin1=200;
  200. bin2=700;
  201. bin3=900;
  202. bin4=1000;
  203. bin5=1100;
  204. bin6=1300;
  205. bin7=2000;
  206. };
  207. //normal, Mental
  208. if (category = 3)
  209. {
  210. bin1=200;
  211. bin2=800;
  212. bin3=900;
  213. bin4=1000;
  214. bin5=1100;
  215. bin6=1300;
  216. bin7=2000;
  217. };
  218. //plus
  219. if (category = 4)
  220. {
  221. bin1=450;
  222. bin2=950;
  223. bin3=1150;
  224. bin4=1250;
  225. bin5=1350;
  226. bin6=1550;
  227. bin7=2250;
  228. };
  229. //plus plus
  230. if (category = 5)
  231. {
  232. bin1=700;
  233. bin2=1200;
  234. bin3=1400;
  235. bin4=1500;
  236. bin5=1600;
  237. bin6=1800;
  238. bin7=2500;
  239. };
  240.  
  241. //bottom 1% is reserved for below lowest bin
  242. //top 1% is reserved for above highest bin
  243. //bins now are 98% range of 100%
  244. //each bin is now 98/600 aka 16.33% vs 16.667%
  245. if (attribute < bin1) {
  246. xpct = (attribute/bin1)*.01}
  247. else if (attribute >= bin1 && attribute < bin2) {
  248. xpct = ((attribute/bin2)*(98/600)) + (0/6)+.01}
  249. else if (attribute >= bin2 && attribute < bin3) {
  250. xpct = (((x-bin2) / (bin3-bin2))*(98/600)) + ((98/600)+.01)}
  251. else if (attribute >= bin3 && attribute < bin4)) {
  252. xpct = (((x-bin3) / (bin4-bin3))*(98/600)) + ((196/600)+.01)}
  253. else if (attribute >= bin4 && attribute < bin5)) {
  254. xpct = (((x-bin4) / (bin5-bin4))*(98/600)) + ((294/600)+.01)}
  255. else if ((attribute >= bin5 && attribute < bin6)) {
  256. xpct = (((x-bin5) / (bin6-bin5))*(98/600)) + ((392/600)+.01)}
  257. else if (attribute >= bin6 && attribute < bin7 ) {
  258. xpct = (((x-bin6) / (bin7-bin6))*(98/600)) + ((490/600)+.01)}
  259. else if (attribute >= bin7) {
  260. xpct = (((x-bin7) / (5000-bin7))*.01) + ((588/600)+.01)}
  261. };
  262.  
  263. return xpct;
  264. }
Advertisement
Add Comment
Please, Sign In to add comment