Ejemplo n.º 1
0
    def POST(self):
        auth = web.ctx.env.get('HTTP_AUTHORIZATION')
        authreq = False

        if auth is None:
            authreq = True
        else:
            auth = re.sub('^Basic ', '', auth)
            username, password = base64.decodestring(auth).split(':')

            if (username, password) in allowed:
                web.header('Content-Type', 'application/json')
                data = json.loads(web.data())
                feedTime = data["time"]
                feed = Feeder(float(feedTime))
                result = feed.feed()
                successDate = feed.getDate()
                jsonResponse = {'result': result, 'date': successDate}
                return json.dumps(jsonResponse)
            else:
                authreq = True

        if authreq:
            web.header('WWW-Authenticate', 'Basic realm="Cat Feeder"')
            web.ctx.status = '401 Unauthorized'
            return
Ejemplo n.º 2
0
def simulate(in_runs, in_pairs, in_visitors):
	target = [ [2,2,0],[2,2,1],[2,2,2] ]
	genes  = [ [1,1,0],[1,2,0],[2,0,0],[2,1,0] ] # simulating t110 x t110
	probs  = [ 4/9,    2/9,    1/9,    2/9     ] # 25/12.5/6.25/12.5
	genemap = len(probs)
	pairs_results = []
	turtle_results = []

	for run in range(in_runs):
		turtle_day = -1
		pairs_day = -1
		turtle = Field("turtle", turtle_layout)
		pairs  = Field("pairs", pairs_layout)
		pairer = PairBreeder()
		feeder = Feeder(genes, probs, visit=in_visitors, pairs=in_pairs)
		for day in range(1, 365):
			# get the days flowers
			feed = feeder.feed()
			# print("day",day,feed)

			# check for output from the pairer, put them into the pairs field
			for new_pair in pairer.breed():
				pairs.place(new_pair[0], new_pair[1])

			# add the day's feed into the pairer and the turtle
			for new_flower in feed:
				pairer.place(new_flower)
				turtle.place(new_flower)

			# everything above this point technically "runs" the day before
			# run the fields
			if pairs_day == -1:
				harvest  = pairs.run()
				# print("pairs:",  pairs_harvest)
				for flower in harvest:
					if flower.get_genes() in target:
						pairs_day = day
			if turtle_day == -1:
				harvest = turtle.run()
				# print("turtle:", turtle_harvest)
				for flower in harvest:
					if flower.get_genes() in target:
						turtle_day = day

			# break out if they both finish
			if turtle_day != -1 and pairs_day != -1:
				break
		if turtle_day != -1 and pairs_day != -1:
			# print("run", run, "ended on day", day, "turtle", turtle_day, "pairs", pairs_day)
			pairs_results.append(pairs_day)
			turtle_results.append(turtle_day)

	print("{}\t{}\tpairs\t{}\t{}\t{}\t{}\t{}".format(in_visitors, in_pairs, np.amin(pairs_results), np.amax(pairs_results), np.mean(pairs_results), np.median(pairs_results), np.percentile(pairs_results, 95)))
	print("{}\t{}\tturtle\t{}\t{}\t{}\t{}\t{}".format(in_visitors, in_pairs, np.amin(turtle_results), np.amax(turtle_results), np.mean(turtle_results), np.median(turtle_results), np.percentile(turtle_results, 95)))
	return
Ejemplo n.º 3
0
from feeder import Feeder
from datetime import datetime, timedelta

datetime_object = datetime.strptime(Feeder.getDate(), '%Y-%m-%d %H:%M:%S')

if datetime_object < datetime.now() - timedelta(hours=4):
    feed = Feeder()
    feed.feed()