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).

1  
abstract sclass DynScoreMatrix extends DynObjectTable<DynScoreMatrix.Entry> {
2  
  transient JTable tblDetails;
3  
  transient Map<O, Double> detailsMap;
4  
  
5  
  transient O detailToMap = func(O test, double score) -> Map {
6  
    Map map = litorderedmap(
7  
      "Score" := str(score),
8  
      "Test" := strOrNull(test));
9  
    putAll(map, (Map) callOpt(test, 'extraColumns));
10  
    ret map;
11  
  };
12  
  
13  
  srecord noeq Entry(
14  
    O candidate,
15  
    double score,
16  
    S comment,
17  
    Map<O, Double> individualScores) {}
18  
19  
  start {
20  
    itemToMap = func(Entry e) -> Map {
21  
      long time = timeSum(keys(e.individualScores));
22  
      O size = getOpt size(e.candidate);
23  
      ret litorderedmap(
24  
        "Candidate" := str(e.candidate),
25  
        "Score" := formatDouble(e.score, 2),
26  
        "Comment" := nullIfEmpty(e.comment),
27  
        "Size" := size instanceof Long ? toK_str((Long) size) : size,
28  
        "Time" := time == 0 ? null : renderElapsedTimePleasantly(time),
29  
        "Tests performed" := nullIfZero(l(e.individualScores)));
30  
    };
31  
  }
32  
  
33  
  long timeSum(Iterable l) {
34  
    ret longSum(collect time(l));
35  
  }
36  
  
37  
  O comparator() { ret func(Entry a, Entry b) { cmp(b.score, a.score) }; }
38  
  
39  
  void add(Entry a) {
40  
    syncAddToSortedList(comparator(), data, a);
41  
    fireDataChanged();
42  
    if (selected() == null) selectItem(first(data));
43  
  }
44  
  
45  
  void setData(Cl<Entry> l) { super.setData(sorted(l, comparator()); }
46  
  
47  
  visualize {
48  
    JComponent sup = super.visualize();
49  
    popupMenuItem_top("Export structure", vf<Entry> exportStructure);
50  
    onTableSelectionChanged(table, r { showDetails(selected()) });
51  
    JComponent c = jvsplit(sup, detailsSection());
52  
    
53  
    onDoubleClickAndEnter(tblDetails, voidfunc(int row) {
54  
      virtual TestResult item = _get(keysList(detailsMap), row);
55  
      if (item == null) ret;
56  
      thread {
57  
        showDetails(item);
58  
      }
59  
    });
60  
    
61  
    ret c;
62  
  }
63  
  
64  
  JComponent detailsSection() {
65  
    ret jCenteredSection("Details (click on item above to show)", jscroll(tblDetails = sexyTable()));
66  
  }
67  
    
68  
  void showDetails(Entry e) enter {
69  
    if (e == null) {
70  
      detailsMap = null;
71  
      clearTable(tblDetails);
72  
    } else {
73  
      detailsMap = sortMapByValue(e.individualScores);
74  
      dataToTable(tblDetails, map(detailsMap, detailToMap));
75  
    }
76  
  }
77  
  
78  
  void exportStructure(Entry e) {
79  
    S s = wordWrappedStruct(e.candidate);
80  
    showText(str(e.candidate) + " [" + nChars(s) + "]", s);
81  
  }
82  
  
83  
  // override me
84  
  void showDetails(virtual TestResult item) {
85  
    callOpt(item, 'showDetails);
86  
  }
87  
  
88  
  // API
89  
  
90  
  Entry newEntry(
91  
    O candidate,
92  
    double score,
93  
    S comment,
94  
    Map<O, Double> individualScores) {
95  
    ret new Entry(candidate, score, comment, individualScores);
96  
  }
97  
  
98  
  Entry newEntry(
99  
    O candidate,
100  
    double score,
101  
    Map<O, Double> individualScores) {
102  
    ret new Entry(candidate, score, null, individualScores);
103  
  }
104  
}

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: 261 / 745
Version history: 24 change(s)
Referenced in: [show references]