Source: site.view [edit]
Function name: getBabyNameInfo
Arguments: name
Description:
Page type: webl
Render function:  
Module: global

Page source:

var db = Wub_GetDB("namesDB");
var coll = Wub_GetCollection(db, "names");

var query = [. .];
if name != "" then
   query.name := name
end;
var dbobj = Wub_NewDBObject(query);

var list = Wub_QueryDB(coll, dbobj, 300); // 300 = max results

var f = 0;
var m = 0;
every elt in list do
   if elt.gender == "m" then
      m = m + 1
   elsif elt.gender == "f" then
      f = f + 1
   end;
end;
  
var gender = "";

if (f > m) then
   gender = "f"
else
   gender = "m"
end;

var pop = [];
var year = [];
every elt in list do
  if elt.gender == gender then
     if elt.year mod 10 == 8 then
        year = year + [ elt.year ];
        pop = pop + [ elt.rank ]
     end
  end;
end;

name = Str_ToUpperCase(Select(name, 0, 1)) + Select(name, 1, Size(name));

var   data = [. title="Popularity rank for " + name + "  (lower is better)",
      type="LINE", legend = "none",
      series=pop, 
      width=400,
      height=300,
      stitle= "Rank (lower is better)",
      categories= year,
      categoryorder = "reverse" .];

var desc = WubCall("firstNameDescription", [name]) ? "";
desc = Wub_ReplaceAll(desc, `"`, `'`);

[. chart = WubCall("chart", [data]), name=name, gender = gender, desc = desc .];