diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-09-07 13:19:28 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-09-07 13:19:28 +0900 |
| commit | e891b34d6160ff3e3357e75cbe065812be636982 (patch) | |
| tree | bda4fbb04cc520a76e0dd312a35ee4feec37047a /src/tools/analysis/predict-user-interst.ts | |
| parent | Add analysis script (diff) | |
| download | misskey-e891b34d6160ff3e3357e75cbe065812be636982.tar.gz misskey-e891b34d6160ff3e3357e75cbe065812be636982.tar.bz2 misskey-e891b34d6160ff3e3357e75cbe065812be636982.zip | |
Rename
Diffstat (limited to 'src/tools/analysis/predict-user-interst.ts')
| -rw-r--r-- | src/tools/analysis/predict-user-interst.ts | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/tools/analysis/predict-user-interst.ts b/src/tools/analysis/predict-user-interst.ts new file mode 100644 index 0000000000..99bdfa4206 --- /dev/null +++ b/src/tools/analysis/predict-user-interst.ts @@ -0,0 +1,45 @@ +import Post from '../../api/models/post'; +import User from '../../api/models/user'; + +export async function predictOne(id) { + console.log(`predict interest of ${id} ...`); + + // TODO: repostなども含める + const recentPosts = await Post.find({ + user_id: 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); + }); +} |