bayes: better prefs ui/stats

This commit is contained in:
Andrew Dolgov 2015-06-17 21:40:44 +03:00
parent 47cd0bd551
commit 308c55c0f1
2 changed files with 46 additions and 6 deletions

View File

@ -26,6 +26,7 @@ function bayesClearDatabase() {
parameters: query, parameters: query,
onComplete: function (transport) { onComplete: function (transport) {
notify(transport.responseText); notify(transport.responseText);
bayesUpdateUI();
} }
}); });
} }
@ -35,3 +36,19 @@ function bayesClearDatabase() {
} }
} }
function bayesUpdateUI() {
try {
var query = "backend.php?op=pluginhandler&plugin=af_sort_bayes&method=renderPrefsUI";
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function (transport) {
dijit.byId("af_sort_bayes_prefs").attr("content", transport.responseText);
}
});
} catch (e) {
exception_error("showTrgmRelated", e);
}
}

View File

@ -201,18 +201,16 @@ class Af_Sort_Bayes extends Plugin {
$this->dbh->query("COMMIT"); $this->dbh->query("COMMIT");
} }
function hook_prefs_tab($args) { function renderPrefsUI() {
if ($args != "prefPrefs") return;
print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Bayesian classifier (af_sort_bayes)')."\">";
$result = $this->dbh->query("SELECT category, probability, word_count, $result = $this->dbh->query("SELECT category, probability, word_count,
(SELECT COUNT(id) FROM {$this->sql_prefix}_references WHERE (SELECT COUNT(id) FROM {$this->sql_prefix}_references WHERE
category_id = {$this->sql_prefix}_categories.id) as doc_count category_id = {$this->sql_prefix}_categories.id) as doc_count
FROM {$this->sql_prefix}_categories WHERE owner_uid = " . $_SESSION["uid"]); FROM {$this->sql_prefix}_categories WHERE owner_uid = " . $_SESSION["uid"]);
print "<h3>" . __("Statistics") . "</h3>";
print "<table>"; print "<table>";
print "<tr><th>Category</th><th>Probability</th><th>Word count</th><th>Article count</th></tr>"; print "<tr><th>Category</th><th>Probability</th><th>Words</th><th>Articles</th></tr>";
while ($line = $this->dbh->fetch_assoc($result)) { while ($line = $this->dbh->fetch_assoc($result)) {
print "<tr>"; print "<tr>";
@ -226,10 +224,35 @@ class Af_Sort_Bayes extends Plugin {
print "</table>"; print "</table>";
print "<h3>" . __("Last matched articles") . "</h3>";
$result = $this->dbh->query("SELECT te.title, category, tf.title AS feed_title
FROM ttrss_entries AS te, ttrss_user_entries AS tu, ttrss_feeds AS tf, {$this->sql_prefix}_references AS tr, {$this->sql_prefix}_categories AS tc
WHERE tf.id = tu.feed_id AND tu.ref_id = te.id AND tc.id = tr.category_id AND tr.document_id = te.guid ORDER BY te.id DESC LIMIT 20");
print "<ul class=\"browseFeedList\" style=\"border-width : 1px\">";
while ($line = $this->dbh->fetch_assoc($result)) {
print "<li>" . $line["category"] . ": " . $line["title"] . " (" . $line["feed_title"] . ")</li>";
}
print "</ul>";
print "<button dojoType=\"dijit.form.Button\" onclick=\"return bayesUpdateUI()\">".
__('Refresh')."</button> ";
print "<button dojoType=\"dijit.form.Button\" onclick=\"return bayesClearDatabase()\">". print "<button dojoType=\"dijit.form.Button\" onclick=\"return bayesClearDatabase()\">".
__('Clear database')."</button> "; __('Clear database')."</button> ";
// //
}
function hook_prefs_tab($args) {
if ($args != "prefPrefs") return;
print "<div id=\"af_sort_bayes_prefs\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Bayesian classifier (af_sort_bayes)')."\">";
$this->renderPrefsUI();
print "</div>"; print "</div>";
} }