-
Notifications
You must be signed in to change notification settings - Fork 14
/
sentience.go
88 lines (72 loc) · 1.99 KB
/
sentience.go
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
package bot
import(
"log"
"bot/jobs"
"bot/session"
"bot/utils"
"bot/http"
)
// Supervised learning -
//// Ideal person is a follower
//// Non ideal person is someone we follow, but doesn't follow back
// Might be worth putting a defer in here incase a job breaks
// I.E to Clean up is processing
func Learn(s *session.Session) string{
if s.SetLearning(){
// New
log.Println("Set up learning")
status := http.GetStatus(s)
s.SetLimits(int(status.Follows), int(status.Followed_by))
}
if !s.SetProcessing() {
// Show we're still working
return " *"
}
switch s.GetLearningStep() {
case utils.APPRAISE:
jobs.MinePeople(s)
return StatusBar(s,"Mining Followers")
case utils.SCORN:
jobs.MinePeople(s)
return StatusBar(s,"Mining Following")
case utils.BUILD:
// Logistic Regression
// Get records and run
go jobs.LogisticRegression(s)
s.IncrementStep()
return "* Running Logistic Regression"
case utils.GOODTAGS:
go jobs.CrawlTags(s, true)
return StatusBar(s,"Finding Good Tags")
case utils.BADTAGS:
go jobs.CrawlTags(s, false)
return StatusBar(s,"Finding Bad Tags")
case utils.COMPUTETAGS:
go jobs.WeightTags(s)
return "* Ranking Tags"
case utils.SHARE:
go s.Share()
s.IncrementStep()
s.StopProcessing()
return "Sharing"
}
return "Stop"
}
// Build a little status bar for debug and ./toolbelt -l purposes
func StatusBar(s *session.Session, title string) (bar string) {
bar = " " + title + ":"
BARSIZE := 100 - len(title)
i := int(BARSIZE * s.GetState()/s.GetLimit())
j := BARSIZE - i
for i + j > 0 {
if i > 0 {
i--
bar += "*"
}else {
j--
bar += "-"
}
}
bar += utils.IntToString(s.GetState()) + "/" + utils.IntToString(s.GetLimit())
return
}