Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //foreach loop that returns an average excluding all 0's
- //I recommend a median version of this if possible to code, but it requires more work.
- //you would have to create an array that holds all values that are not 0'd, and then find's the median.
- function skillAvg (skill)
- {
- for (iterations in d.skill_rating(skill)
- {
- if (d.skill_rating == 0)
- {
- sum = sum + 0;
- count = count;
- }
- else
- {
- acount = count + 1;
- sum = sum + d.skill(rating(skill));
- }
- };
- return sum/count;
- }
- function median(list){
- function compare(a,b){
- return a-b;
- }
- list.sort(compare);
- var listlength = list.length;
- if (listlength % 2){
- var odd = (listlength / 2 - 0.5);
- alert("Median is:" + list[odd]);
- }else{
- var even = (list[listlength / 2]);
- even += (list[listlength / 2 + 1]);
- even = (even / 2);
- alert("Median is: " + even);
- }
- }
- function skillMedian (skill)
- {
- list[];
- count=0;
- //I hope this for starts at 0
- for (iterations in d.skill_rating(skill)
- {
- if (d.skill_rating == 0)
- {
- //do nothing;
- }
- else
- {
- list[count] = skill[iterations];
- count = count+1;
- }
- };
- return median(list);
- }
- //requires a d.skill_max() function
- //takes a d.skill_rating(skill) as skill parameter, takes either the return of skillAvg or skillMedian
- function skillPct (skill, avgOrMedian)
- {
- if (skill < avgOrMedian)
- {
- xpct = ((skill - avgOrMedian)/(avgOrMedian - d.skill_max(skill))+1)/2;
- }
- else if (skill >= avgOrMedian)
- {
- xpct = ((avgOrMedian - skill)/( (d.skill_max(skill) - skill) )+1)/2;
- }
- return xpct;
- }
- //requires a trait and a bin category (see below)
- function binTraitPercent (trait, category)
- {
- //minus traits
- if (category = 1)
- {
- bin1=0;
- bin2=9;
- bin3=22;
- bin4=36;
- bin5=57;
- bin6=73;
- bin7=90;
- if (trait < bin1) {
- xpct = 0 } //or... - (trait / bin1)}
- else if (trait >= bin1 && trait < bin2) {
- xpct = (((trait - bin1) / (bin2-bin1+1))*0.004)}
- else if (trait >= bin2 && trait < bin3) {
- xpct = (((x-bin2) / (bin3-bin2+1))*0.01375) + (0.004)}
- else if (trait >= bin3 && trait < bin4)) {
- xpct = (((x-bin3) / (bin4-bin3+1))*0.07775) + (0.01775)}
- else if (trait >= bin4 && trait < bin5)) {
- xpct = (((x-bin4) / (bin5-bin4+1))*0.7905) + (0.0955)}
- else if ((trait >= bin5 && trait < bin6)) {
- xpct = (((x-bin5) / (bin6-bin5+1)*0.08575) + (0.886) )}
- else if (trait >= bin6 && trait < bin7 ) {
- xpct = (((x-bin6) / (bin7-bin6+1)) *0.02425) + (0.97175)}
- else if (trait >= bin7) {
- xpct = (((x-bin7) / (100-bin7+1))*0.004) + (0.996) };
- return xpct;
- };
- //normal traits
- if (category = 2)
- {
- bin1=0;
- bin2=10;
- bin3=25;
- bin4=40;
- bin5=61;
- bin6=76;
- bin7=91;
- if (trait < bin1) {
- xpct = 0 } //or... - (x / bin1)}
- else if (trait >= bin1 && trait < bin2) {
- xpct = (((trait - bin1) / (bin2-bin1+1))*0.0038425926)}
- else if (trait >= bin2 && trait < bin3) {
- xpct = (((x-bin2) / (bin3-bin2+1))*0.0197592593) + (0.0038425926)}
- else if (trait >= bin3 && trait < bin4)) {
- xpct = (((x-bin3) / (bin4-bin3+1))*0.0857407407) + (0.0236018519)}
- else if (trait >= bin4 && trait < bin5)) {
- xpct = (((x-bin4) / (bin5-bin4+1))*0.7813148148) + (0.1093425926)}
- else if ((trait >= bin5 && trait < bin6)) {
- xpct = (((x-bin5) / (bin6-bin5+1)*0.0857407407) + (0.8906574074) )}
- else if (trait >= bin6 && trait < bin7 ) {
- xpct = (((x-bin6) / (bin7-bin6+1)) *0.0197592593) + (0.9763981481)}
- else if (trait >= bin7) {
- xpct = (((x-bin7) / (100-bin7+1))*0.0038425926) + (0.9961574074) };
- return xpct;
- };
- //plus traits
- if (category = 3)
- {
- bin1=0;
- bin2=11;
- bin3=27;
- bin4=44;
- bin5=65;
- bin6=78;
- bin7=92;
- if (trait < bin1) {
- xpct = 0 } //or... - (trait / bin1)}
- else if (trait >= bin1 && trait < bin2) {
- xpct = (((trait - bin1) / (bin2-bin1+1))*0.004)}
- else if (trait >= bin2 && trait < bin3) {
- xpct = (((x-bin2) / (bin3-bin2+1))*0.01375) + (0.004)}
- else if (trait >= bin3 && trait < bin4)) {
- xpct = (((x-bin3) / (bin4-bin3+1))*0.07775) + (0.01775)}
- else if (trait >= bin4 && trait < bin5)) {
- xpct = (((x-bin4) / (bin5-bin4+1))*0.7905) + (0.0955)}
- else if ((trait >= bin5 && trait < bin6)) {
- xpct = (((x-bin5) / (bin6-bin5+1)*0.08575) + (0.886) )}
- else if (trait >= bin6 && trait < bin7 ) {
- xpct = (((x-bin6) / (bin7-bin6+1)) *0.02425) + (0.97175)}
- else if (trait >= bin7) {
- xpct = (((x-bin7) / (100-bin7+1))*0.004) + (0.996) };
- return xpct;
- };
- };
- //Return's % relative to bin.
- //Two parameters are provided.
- //attribute is a attribute variable, such as d.strength()
- //category is a flag used to modify bin values
- function binAttributePercent (attribute, category)
- {
- //minus
- if (category = 1)
- {
- bin1=150;
- bin2=600;
- bin3=800;
- bin4=900;
- bin5=1000;
- bin6=1100;
- bin7=1500;
- };
- //normal, Physical
- if (category = 2)
- {
- bin1=200;
- bin2=700;
- bin3=900;
- bin4=1000;
- bin5=1100;
- bin6=1300;
- bin7=2000;
- };
- //normal, Mental
- if (category = 3)
- {
- bin1=200;
- bin2=800;
- bin3=900;
- bin4=1000;
- bin5=1100;
- bin6=1300;
- bin7=2000;
- };
- //plus
- if (category = 4)
- {
- bin1=450;
- bin2=950;
- bin3=1150;
- bin4=1250;
- bin5=1350;
- bin6=1550;
- bin7=2250;
- };
- //plus plus
- if (category = 5)
- {
- bin1=700;
- bin2=1200;
- bin3=1400;
- bin4=1500;
- bin5=1600;
- bin6=1800;
- bin7=2500;
- };
- //bottom 1% is reserved for below lowest bin
- //top 1% is reserved for above highest bin
- //bins now are 98% range of 100%
- //each bin is now 98/600 aka 16.33% vs 16.667%
- if (attribute < bin1) {
- xpct = (attribute/bin1)*.01}
- else if (attribute >= bin1 && attribute < bin2) {
- xpct = ((attribute/bin2)*(98/600)) + (0/6)+.01}
- else if (attribute >= bin2 && attribute < bin3) {
- xpct = (((x-bin2) / (bin3-bin2))*(98/600)) + ((98/600)+.01)}
- else if (attribute >= bin3 && attribute < bin4)) {
- xpct = (((x-bin3) / (bin4-bin3))*(98/600)) + ((196/600)+.01)}
- else if (attribute >= bin4 && attribute < bin5)) {
- xpct = (((x-bin4) / (bin5-bin4))*(98/600)) + ((294/600)+.01)}
- else if ((attribute >= bin5 && attribute < bin6)) {
- xpct = (((x-bin5) / (bin6-bin5))*(98/600)) + ((392/600)+.01)}
- else if (attribute >= bin6 && attribute < bin7 ) {
- xpct = (((x-bin6) / (bin7-bin6))*(98/600)) + ((490/600)+.01)}
- else if (attribute >= bin7) {
- xpct = (((x-bin7) / (5000-bin7))*.01) + ((588/600)+.01)}
- };
- return xpct;
- }
Advertisement
Add Comment
Please, Sign In to add comment