// 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"
}
Exemple #2
0
func processHandle(w http.ResponseWriter, r *http.Request, s *session.Session) {

	// Grab intervals since day start
	intervals := utils.Intervals()

	// Had some fancy math for peroidictiy. But
	// we could just brute force 100 per hour
	likes := int(utils.LIKES / utils.CALLS)
	utils.Limit(&likes, intervals, utils.LIKES)

	if !s.Usable() {
		fmt.Fprint(w, "Please set hashtags and authorize")
		return
	}

	// Follow ratio function where target is the desired
	// amount of followers.
	// e^(x*ln(magic)/target)
	// I wish could say there's some science behind why
	// we're doing this, but ultimately we just need a
	// decreasing function and some percentage of your
	// target feels right
	count := action.GetStatus(s)
	follows := int(utils.FollowerDecay(count.Followed_by, count.Follows, s.GetMagic(), s.GetTarget()))
	utils.Limit(&follows, intervals, utils.FOLLOWS)
	if follows < 0 {
		follows = 0
	}

	// Hang on channel otherwise jobs cut out
	done := make(chan bool)

	// Save status at midnight
	if intervals == 0 {
		go s.SetRecords(count.Followed_by, count.Follows)
	}
	if s.GetLearnt() {
		IntelligentDecision(s, follows, likes, intervals, done)
	} else {
		BasicDecision(s, follows, likes, intervals, done)
	}
	// Wait for finish. Defeats the purpose of aysnc, but only way to run in prod
	<-done
	fmt.Fprint(w, "Processing")
}