Source: site.view [edit]
Function name: cmdAddEducationFields
Arguments: person
Description: Adds education scores for a person. Currently: eduScore, schoolScore, degreeScore
Page type: webl
Render function:  
Module: skillsrank

Page source:

var schoolRankings;

var degreePoints = [. "aa" = 250,
    "b.s." = 500, "bs" = 500, "b.s" = 500, "b.a." = 500, "ba" = 500, "b.a" = 500, "be" = 500, "b.e." = 500,
    "m.s" = 700, "ms" = 700,"msee" = 700, "ms ee" = 700, "msc" = 700, "ma" = 700, "m.a." = 700,
    "mba" = 700, 
    "phd" = 1000, "ph.d." = 1000, "ph.d" = 1000 .];

var eduScoreToken = fun(eduScore)
   var token = "0";
   if (eduScore >= 1250) then
       token = "1250 1000 750 500 250"
   elsif (eduScore >= 1000) then
       token = "1000 750 500 250"
   elsif (eduScore >= 750) then
       token = "750"
   elsif (eduScore >= 500) then
       token = "500 250"
   elsif (eduScore >= 250) then
       token = "250"
   end;
   token
end;

var schoolScoreToken = fun(eduScore)
   var token = "0";
   if (eduScore >= 490) then
       token = "490"
   elsif (eduScore >= 450) then
       token = "450"
   elsif (eduScore >= 400) then
       token = "400"
   elsif (eduScore >= 300) then
       token = "300"
   elsif (eduScore >= 150) then
       token = "150"
   end;
   token
end;

var getSchoolRank = fun(schoolName)
   var res = 500;
   var school = schoolRankings[schoolName] ? nil;
   if school != nil then
      var i = Str_IndexOf("Rank", school.rank);
      if (i >= 0) then
         res = ToInt(Str_Trim(Select(school.rank, 5, Size(school.rank))));
      else
         res = 350
      end
   end;
   res
end;

var bestRank = 500;
var degreeScore = 0;
var educations = person.educations ? nil;

if (educations != nil) then
   schoolRankings = WubCall("cmdGetSchoolRankings", []);
   every school in educations do
      var rank = getSchoolRank(school["school-name"]);
      if rank < bestRank then
         bestRank = rank
      end;
      var ds = degreePoints[Str_ToLowerCase(school["degree"])] ? 0;
      if (ds > degreeScore) then
         degreeScore = ds
      end;
   end;

   var rankScore = 500 - bestRank;

   person.eduScore := rankScore + degreeScore;
   person.schoolScore := rankScore;
   person.degreeScore := degreeScore;
   person.qEduScore := eduScoreToken(person.eduScore);
   person.qSchoolScore := schoolScoreToken(rankScore);
else
   person.eduScore := 0;
   person.schoolScore := 0;
   person.degreeScore := 0;
   person.qEduScore := "0";
   person.qSchoolScore := "0";
end;

person;