-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScoreConfig.cs
98 lines (76 loc) · 3.44 KB
/
ScoreConfig.cs
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
namespace twot
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
internal class ScoreConfig
{
public ScoreConfig()
{
if (File.Exists("score.json"))
{
var properties = this.GetType().GetProperties();
var overridesJson = File.ReadAllText("score.json");
var overrides = JsonConvert.DeserializeObject<Dictionary<string, Score<object>>>(overridesJson);
foreach (var (key, score) in overrides)
{
var property = properties.FirstOrDefault(prop => prop.Name == key);
if (property != null)
{
switch (score.Value)
{
case bool b:
{
property.SetValue(this, new Score<bool>(b, score.Impact, score.Enabled));
break;
}
case long i:
{
property.SetValue(this, new Score<int>(
Convert.ToInt32(i),
score.Impact,
score.Enabled));
break;
}
default:
{
throw new Exception($"Unknown config type {score.Value.GetType()} for {key}");
}
}
}
}
}
}
public Score<bool> DefaultProfileImage { get; private set; } = new Score<bool>(true, 1);
public Score<int> DescriptionLength { get; private set; } = new Score<int>(0, 0.3);
public Score<int> Favourites { get; private set; } = new Score<int>(0, 0.8);
public Score<int> FriendsLessThan { get; private set; } = new Score<int>(20, 0.5);
public Score<int> LocationLength { get; private set; } = new Score<int>(0, 0.2);
public Score<int> FollowersLarge { get; private set; } = new Score<int>(10000, 0.2);
public Score<int> FollowersExtraLarge { get; private set; } = new Score<int>(25000, 0.7);
public Score<int> TweetsLessThan { get; private set; } = new Score<int>(10, 0.3);
public Score<int> ZeroTweets { get; private set; } = new Score<int>(0, 0.5);
public Score<bool> TweetedInLastWeek { get; private set; } = new Score<bool>(true, -0.4);
public Score<bool> TweetedMoreThan90Days { get; private set; } = new Score<bool>(true, 0.5);
public Score<bool> TweetedMoreThan1Year { get; private set; } = new Score<bool>(true, 1);
public Score<int> FollowingMoreThan { get; private set; } = new Score<int>(5000, 0.3);
public override string ToString()
{
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
}
internal class Score<T>
{
public Score(T value, double impact, bool enabled = true)
{
this.Enabled = enabled;
this.Value = value;
this.Impact = impact;
}
public bool Enabled { get; set; }
public T Value { get; set; }
public double Impact { get; set; }
}
}