• My Pages
  • Comments
  • Add Link
  • Subscribe
  • Subscribe User
  • Edit (GUI)
  • Edit (Text)
  • Rename Page
  • Copy Page
  • Load Page
  • Save Page
  • Delete Page
  • Attachments
  • Check Spelling
  • Diffs
  • Info
  • Revert to this revision
  • XML
  • Render as Docbook
  • Print View
  • Raw Text
  • Delete Cache
  • Like Pages
  • Local Site Map
  • Remove Spam
  • Package Pages
  • Sync Pages
    • Diff for "SortingMemberList"
    Differences between revisions 1 and 2
    Revision 1 as of 2014-04-22 16:30:36
    Size: 747
    Editor: Inanna
    Comment:
    Revision 2 as of 2015-02-16 14:43:16
    Size: 749
    Editor: tech
    Comment:
    Deletions are marked like this. Additions are marked like this.
    Line 5: Line 5:
    execute "members = [ " + $result.replace(/^(".*?"),(".*?"),"(.*?)","(.*?)",(".*?"),"(.*?)","(.*?)".*?$/gm, "{ lord:$1, position:$2,prestige:$3,honor:$4,lastlogin:date($5),cities:$6,population:$7 }").split("\n").splice(1).join(",\n") + " ]" execute "members = [ " + $result.replace(/^(".*?"),(".*?"),"(.*?)","(.*?)",(".*?"),"(.*?)","(.*?)".*?$/gm, "\{ lord:$1, position:$2,prestige:$3,honor:$4,lastlogin:date($5),cities:$6,population:$7 \}").split("\n").splice(1).join(",\n") + " ]"

    This is an example of how to convert CSV output ("members" command in this case) to an array of objects. It also shows how you can process numeric/string/date fields differently and easily sort them.

    command "members"
    execute "members = [ " + $result.replace(/^(".*?"),(".*?"),"(.*?)","(.*?)",(".*?"),"(.*?)","(.*?)".*?$/gm, "\{ lord:$1, position:$2,prestige:$3,honor:$4,lastlogin:date($5),cities:$6,population:$7 \}").split("\n").splice(1).join(",\n") + " ]"
    
    top = members.sortOn("prestige", 18)[0]
    echo "Highest prestige member is " + top.lord + ", prestige=" + FormatNumber(top.prestige)
    
    last = members.sortOn("lastlogin", 18)[0]
    echo "Most recent login is " + last.lord + ", login=" + last.lastlogin


    ScriptExamples

    SortingMemberList (last edited 2015-02-16 14:43:16 by tech)