예제 #1
0
func BasicDecision(s *session.Session, follows int, likes int, intervals int, done chan bool) {
	// Round robin the hashtags. Allows for manual weighting eg: [#dog,#dog,#cute]
	posts := http.GetPosts(s, s.GetHashtag(intervals))

	// Go from end to reduce collision
	// Doesn't bother checking
	i := 19
	for (likes > 0 || follows > 0) && i >= 0 {

		// Process likes
		if likes > 0 {
			go http.LikePosts(s, posts.Data[i].Id)
			likes--

			// Doing this seperately reaches larger audience
			// Never exceeds 12/11 at a given time
		} else if follows > 0 {
			go http.FollowUser(s, posts.Data[i].Id)
			follows--
		}

		// Decrement
		i--
	}

	// Indicate doneness
	done <- true
}
예제 #2
0
// Async heapsort, hope it works
func sort(s *session.Session, next chan *group, follows, likes int, calls, total *int, done chan bool) {
	var instances []group
	count := 0
	x := 0
	min := math.Inf(1)
	for {
		select {
		case instance := <-next:

			x++
			// Catches up and thus done
			if x == *total && *calls == utils.MAXPOSTGRAB {
				i := 0
				for likes > 0 || follows > 0 {

					// Highest value for follows then do likes
					if follows > 0 {
						go http.FollowUser(s, instances[i].id)
						follows--
					} else if likes > 0 {
						go http.LikePosts(s, instances[i].id)
						likes--
					}
					i++
				}
				s.FlushCache()
				done <- true
				close(next)
				return
			}

			// We already have our fill and this value won't contribute
			if instance.id == "continue" || (instance.value <= min && count == follows+likes) {
				continue
			}

			if min < instance.value {
				if count == follows+likes {
					min = instance.value
				}
			} else {
				if count < follows+likes {
					min = instance.value
				}
			}

			if count < follows+likes {
				instances = append(instances, *instance)
				count += 1
			} else {
				// Replace end
				instances[count-1] = *instance
			}

			// Bubble sort
			for i := count - 2; i >= 0; i-- {
				if instance.value > instances[i].value {
					holder := instances[i]
					instances[i] = *instance
					instances[i+1] = holder
				} else {
					break
				}
			}
		}
	}
}