add user stats & store db/classifier on updates
This commit is contained in:
parent
b420e1608d
commit
0e17ff90e6
3 changed files with 12 additions and 12 deletions
File diff suppressed because one or more lines are too long
17
src/main.rs
17
src/main.rs
|
@ -101,15 +101,6 @@ impl UserData {
|
|||
}
|
||||
|
||||
impl Db {
|
||||
fn new() -> Db {
|
||||
Db {
|
||||
users: HashMap::new(),
|
||||
is_spam: HashMap::new(),
|
||||
tokens: HashMap::new(),
|
||||
score: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn recompute_tokens(&mut self) {
|
||||
for (id, user) in &self.users {
|
||||
self.tokens.insert(*id, user.to_tokens());
|
||||
|
@ -462,8 +453,13 @@ async fn index(data: web::Data<AppState>) -> impl Responder {
|
|||
users.sort_by_key(|(_, _, score)| 1000 - (score * 1000.) as u64);
|
||||
users.truncate(50);
|
||||
|
||||
let users_count = db.users.len();
|
||||
let classified_count = db.is_spam.len();
|
||||
|
||||
let mut context = tera::Context::new();
|
||||
context.insert("users", &users);
|
||||
context.insert("unclassified_users_count", &(users_count - classified_count));
|
||||
context.insert("total_users_count", &users_count);
|
||||
eprintln!("rendering template...");
|
||||
let page = TEMPLATES.render("index.html", &context).unwrap();
|
||||
eprintln!("done");
|
||||
|
@ -487,6 +483,9 @@ async fn apply(
|
|||
|
||||
set_spam(db, classifier, &updates);
|
||||
|
||||
db.store_to_path(Path::new("db.json")).unwrap();
|
||||
classifier.save(&mut File::create(Path::new("model.json")).unwrap(), false).unwrap();
|
||||
|
||||
HttpResponse::SeeOther()
|
||||
.insert_header(("Location", "/"))
|
||||
.finish()
|
||||
|
|
|
@ -109,8 +109,10 @@
|
|||
<body>
|
||||
<form method="post">
|
||||
<div class="main">
|
||||
<div class="stats">
|
||||
Users: unclassified: {{unclassified_users_count}} | total: {{total_users_count}}
|
||||
</div>
|
||||
<div class="users">
|
||||
|
||||
{% for id_user_score in users %}
|
||||
{% set user_id = id_user_score[0] %}
|
||||
{% set user = id_user_score[1] %}
|
||||
|
|
Loading…
Reference in a new issue