-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserDb.cs
More file actions
82 lines (68 loc) · 1.73 KB
/
UserDb.cs
File metadata and controls
82 lines (68 loc) · 1.73 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.ComponentModel;
internal class UserDb
{
internal class UserInfo
{
public int totalKarma = 0;
public int bestKarma = 0;
public HashSet<DateTime> dates = new HashSet<DateTime>();
}
Dictionary<string, UserInfo> userData = new Dictionary<string, UserInfo>();
public void Add(Post post)
{
AddSingle(post);
if (post.comments != null)
{
foreach (var elem in post.comments)
{
Add(elem);
}
}
}
private void AddSingle(Post post)
{
if (post.author == null)
{
return;
}
if (post.author == "[deleted]")
{
return;
}
var ui = userData.TryGetValue(post.author);
if (ui == null)
{
ui = new UserInfo();
userData[post.author] = ui;
}
ui.totalKarma += post.ups - 1; // don't count the self-vote
ui.bestKarma = Math.Max(ui.bestKarma, post.ups);
ui.dates.Add(post.created.Date);
}
public IEnumerable<string> AuthorizedUsers()
{
foreach (var kvp in userData)
{
int ct = 0;
if (kvp.Value.totalKarma >= Config.Global.validity_totalKarma)
{
++ct;
}
if (kvp.Value.bestKarma >= Config.Global.validity_bestKarma)
{
++ct;
}
if (kvp.Value.dates.Count >= Config.Global.validity_uniqueDates)
{
++ct;
}
if (ct != 3)
{
continue;
}
yield return kvp.Key;
}
}
}