Home /Modules/advantage/SLGradeSet.sleela

SLGradeSet.sleela

lib/advantage/grading/SLGradeSet.sleela · 153 line(s) · sleela

<< lib/advantage/grading/SLGradeSet.sleela
   SLeeLa Standard Library Definition.
   Definition: A named set of graded modules (e.g. winning / losing / grader /
   absolute) with its own aggregate rating. >>
#sleela 3.0
material;
artifact;
pure;
gasoline;
< A grade set groups any collection of SLModuleGrade into a named bucket -- a >
< set of modules, winning modules, losing modules, grader modules, or absolute >
< modules -- and rates the SET as a whole: size, mean/best/worst score, and a >
< set-level 1..10 tier and letter derived from the mean. Holds the grades by >
< reference so the same module can appear in more than one set. >
class SLGradeSet {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 10551;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-11-08";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-11-08";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 8;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }

  String name;
  SLModuleGrade[] grades;
  int count;
  int cap;

  void configure(String nm, int capacity) {
    name = nm;
    cap = capacity;
    if (cap < 1) { cap = 1; }
    grades = new SLModuleGrade[cap];
    count = 0;
  }

  String getName() { return name; }
  int size() { return count; }

  void add(SLModuleGrade g) {
    if (count >= cap) { return; }
    grades[count] = g;
    count = count + 1;
  }

  SLModuleGrade at(int i) {
    if (i < 0) { return null; }
    if (i >= count) { return null; }
    return grades[i];
  }

  int totalScore() {
    int sum = 0;
    int i = 0;
    while (i < count) {
      SLModuleGrade g = grades[i];
      sum = sum + g.getScore();
      i = i + 1;
    }
    return sum;
  }

  < Mean score (integer; 0 if empty). >
  int meanScore() {
    if (count == 0) { return 0; }
    return totalScore() / count;
  }

  int bestScore() {
    if (count == 0) { return 0; }
    SLModuleGrade first = grades[0];
    int best = first.getScore();
    int i = 1;
    while (i < count) {
      SLModuleGrade g = grades[i];
      if (g.getScore() > best) { best = g.getScore(); }
      i = i + 1;
    }
    return best;
  }

  int worstScore() {
    if (count == 0) { return 0; }
    SLModuleGrade first = grades[0];
    int worst = first.getScore();
    int i = 1;
    while (i < count) {
      SLModuleGrade g = grades[i];
      if (g.getScore() < worst) { worst = g.getScore(); }
      i = i + 1;
    }
    return worst;
  }

  < Set-level tier 1..10 from the mean score (same scale as a module). >
  int tier() {
    int t = meanScore() / 10;
    if (t > 10) { t = 10; }
    if (t < 1) { t = 1; }
    return t;
  }

  String letter() {
    int t = tier();
    if (t >= 10) { return "S"; }
    if (t >= 9)  { return "A"; }
    if (t >= 8)  { return "B"; }
    if (t >= 6)  { return "C"; }
    if (t >= 4)  { return "D"; }
    return "F";
  }

  String describe() {
    return "set '" + name + "' size=" + count
         + " mean=" + meanScore() + " best=" + bestScore()
         + " worst=" + worstScore() + " rating=" + letter() + tier();
  }
}