blob: a101f2010e58bf0c3f93415235695ff0bf14098f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import Post from '../../server/api/models/post';
import User from '../../server/api/models/user';
export async function predictOne(id) {
console.log(`predict interest of ${id} ...`);
// TODO: repostなども含める
const recentPosts = await Post.find({
userId: id,
category: {
$exists: true
}
}, {
sort: {
_id: -1
},
limit: 1000,
fields: {
_id: false,
category: true
}
});
const categories = {};
recentPosts.forEach(post => {
if (categories[post.category]) {
categories[post.category]++;
} else {
categories[post.category] = 1;
}
});
}
export async function predictAll() {
const allUsers = await User.find({}, {
fields: {
_id: true
}
});
allUsers.forEach(user => {
predictOne(user._id);
});
}
|