Warning: session_start(): open(/var/lib/php/sessions/sess_tv4rib5eb842sssj0l8b9989io, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
static int topTenSize = 1000, maxImages = 1000;
static MultiSetAndTopTen mstt; // holds md5
static SS comments;
p {
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);
}
svoid collectIt {
print("Collecting...");
BWImage img = shootScreenBW();
L 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");
}
static File imgFile(S md5) {
ret getProgramFile(md5 + ".png");
}
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 = showTable(data, "Top " + l(data));
tablePopupMenuItem(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);
});
});
}
svoid deleteUnusedImages {
Set set = caseInsensitiveSet();
set.addAll(mstt.entries());
for (File f : filesEndingWith(programDir(), ".png"))
if (!mstt.contains(toLower(dropSuffix(".png", f.getName())))) {
print("Deleting " + f);
f.delete();
}
}