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

99
LINES

< > BotCompany Repo | #1010705 // Teach things on screen [don't use, doesn't use new comments system, also collects every 10]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 3874K of libraries. Click here for Pure Java version (15490L/111K).

!7

static int topTenSize = 1000, maxImages = 1000;
static MultiSetAndTopTen<S> mstt; // holds md5
static SS comments;

p-subst {
  autoRestart();
  comments = persistentHashMap("Comments");
  mstt = new MultiSetAndTopTen(
    l_persistentTreeMap("Images + count"),
    l_persistentList("Top Ten"));
  mstt.maxEntries = maxImages;
  mstt.setTopTenSize(topTenSize);
    
  thread "Collect" {
    repeat with sleep 10 {
      deleteUnusedImages();
      collectIt();
    }
  }
  
  showButtons(
    "Top " + topTenSize, f showTopTen,
    "Clear", rThread(f clearIt),
    "Current Screen", rThread(f currentScreen));
}

svoid collectIt {
  print("Collecting...");
  lock dbLock();
  long time = sysNow();
  BWImage img = shootScreenBW();
  L<Rect> segments = autoSegment(img);
  for (Rect r : segments) {
    RGBImage clip = img.clip(r).toRGB();
    S md5 = rgbMD5(clip);
    mstt.add(md5);
    File f = imgFile(md5);
    if (!f.exists())
      savePNG(f, clip);
  }
  
  print(n(segments, "segment") + " on screen. " + n(mstt.numEntries(), "image") + " in DB. " + n(mstt.numOccurrences(), "occurrence") + ". DB size: " + toM(guessClusteredDirSize(programDir())) + " MB");
  done2(time);
}

static File imgFile(S md5) {
  ret screenClipFileForMD5(md5);
}

svoid showTopTen {
  final L data = map(mstt.topTen(), func(S md5) {
    litorderedmap(
      "Image" := loadBufferedImageOpt(imgFile(md5)),
      "Comment" := unnull(comments.get(md5)),
      "MD5" := md5, "Occurrences" := mstt.get(md5))
  });
  
  final JTable table = setRowHeight(40, showTable(data, "Top " + l(data)));
  
  tablePopupMenuItemAndDoubleClick(table, "Comment...", voidfunc(final Int row) {
    fS md5 = getString(data.get(row), "MD5");
    final JTextField tf = jtextfield(comments.get(md5));
    showFormTitled("Comment image " + md5,
      //"MD5", md5,
      "Image", new ImageChooser(loadBufferedImage(imgFile(md5))),
      "Comment", tf,
      r {
        S text = getTextTrim(tf);
        comments.put(md5, nullIfEmpty(text));
        ((DefaultTableModel) table.getModel()).setValueAt(text, row, 1);
      });
  });
}

// Keep all images commented on & all in top 1000
svoid deleteUnusedImages {
  Set set = ciSet();
  set.addAll(mstt.entries());
  set.addAll(keys(comments));
  
  for (File f : filesEndingWith(screenClipsDir(), ".png"))
    if (!set.contains(toLower(dropSuffix(".png", f.getName())))) {
      print("Deleting " + f);
      f.delete();
    }
}

svoid clearIt {
  lock dbLock();
  mstt.clear();
}

svoid currentScreen {
  clearIt();
  collectIt();
  showTopTen();
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1010705
Snippet name: Teach things on screen [don't use, doesn't use new comments system, also collects every 10]
Eternal ID of this version: #1010705/52
Text MD5: ed6987e5631bbf8d9df2b3655e34558e
Transpilation MD5: bd588a8dec705687b1682b3dcf9d5207
Author: stefan
Category: javax / ocr
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-10 17:43:14
Source code size: 2658 bytes / 99 lines
Pitched / IR pitched: No / No
Views / Downloads: 540 / 2347
Version history: 51 change(s)
Referenced in: [show references]