Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

104
LINES

< > BotCompany Repo | #1024794 // DynScoreMatrix - show results of multiple candidates tested against multiple tests

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (18845L/135K).

abstract sclass DynScoreMatrix extends DynObjectTable<DynScoreMatrix.Entry> {
  transient JTable tblDetails;
  transient Map<O, Double> detailsMap;
  
  transient O detailToMap = func(O test, double score) -> Map {
    Map map = litorderedmap(
      "Score" := str(score),
      "Test" := strOrNull(test));
    putAll(map, (Map) callOpt(test, 'extraColumns));
    ret map;
  };
  
  srecord noeq Entry(
    O candidate,
    double score,
    S comment,
    Map<O, Double> individualScores) {}

  start {
    itemToMap = func(Entry e) -> Map {
      long time = timeSum(keys(e.individualScores));
      O size = getOpt size(e.candidate);
      ret litorderedmap(
        "Candidate" := str(e.candidate),
        "Score" := formatDouble(e.score, 2),
        "Comment" := nullIfEmpty(e.comment),
        "Size" := size instanceof Long ? toK_str((Long) size) : size,
        "Time" := time == 0 ? null : renderElapsedTimePleasantly(time),
        "Tests performed" := nullIfZero(l(e.individualScores)));
    };
  }
  
  long timeSum(Iterable l) {
    ret longSum(collect time(l));
  }
  
  O comparator() { ret func(Entry a, Entry b) { cmp(b.score, a.score) }; }
  
  void add(Entry a) {
    syncAddToSortedList(comparator(), data, a);
    fireDataChanged();
    if (selected() == null) selectItem(first(data));
  }
  
  void setData(Cl<Entry> l) { super.setData(sorted(l, comparator()); }
  
  visualize {
    JComponent sup = super.visualize();
    popupMenuItem_top("Export structure", vf<Entry> exportStructure);
    onTableSelectionChanged(table, r { showDetails(selected()) });
    JComponent c = jvsplit(sup, detailsSection());
    
    onDoubleClickAndEnter(tblDetails, voidfunc(int row) {
      virtual TestResult item = _get(keysList(detailsMap), row);
      if (item == null) ret;
      thread {
        showDetails(item);
      }
    });
    
    ret c;
  }
  
  JComponent detailsSection() {
    ret jCenteredSection("Details (click on item above to show)", jscroll(tblDetails = sexyTable()));
  }
    
  void showDetails(Entry e) enter {
    if (e == null) {
      detailsMap = null;
      clearTable(tblDetails);
    } else {
      detailsMap = sortMapByValue(e.individualScores);
      dataToTable(tblDetails, map(detailsMap, detailToMap));
    }
  }
  
  void exportStructure(Entry e) {
    S s = wordWrappedStruct(e.candidate);
    showText(str(e.candidate) + " [" + nChars(s) + "]", s);
  }
  
  // override me
  void showDetails(virtual TestResult item) {
    callOpt(item, 'showDetails);
  }
  
  // API
  
  Entry newEntry(
    O candidate,
    double score,
    S comment,
    Map<O, Double> individualScores) {
    ret new Entry(candidate, score, comment, individualScores);
  }
  
  Entry newEntry(
    O candidate,
    double score,
    Map<O, Double> individualScores) {
    ret new Entry(candidate, score, null, individualScores);
  }
}

Author comment

Began life as a copy of #1024787

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1024794
Snippet name: DynScoreMatrix - show results of multiple candidates tested against multiple tests
Eternal ID of this version: #1024794/25
Text MD5: a684a5737930b510d3c2dd0e2afe9a50
Transpilation MD5: 432763ed314cef053baba8edfc1ccf83
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-11-21 14:28:53
Source code size: 2963 bytes / 104 lines
Pitched / IR pitched: No / No
Views / Downloads: 330 / 833
Version history: 24 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)