def start(): root = Tk() test = Controller(root) test.run() test.analytics() test.updateUsers() test.runvisuals()
def start(): root = Tk() test = Controller(parent=root) progress_bar["value"] = 0 #root.overrideredirect(True) progress_bar.start() root.mainloop()
def test_get_survey(): MySurveys = Controller() MySurveys.CreateSurvey("Survey Test") MySurveys.CreateSurvey("Survey Test 2") assert MySurveys.GetSurvey("Survey Test").name == "Survey Test" assert MySurveys.GetSurvey("Survey Test 2").name == "Survey Test 2" assert MySurveys.GetSurvey("No survey") == "Survey not found"
def main(): evm = EventManager() shared_obj_registry = {} controller = Controller( evm ) model = Model(evm) view = View(evm) serverController = NetworkServerController( evm ) serverView = NetworkServerView( evm, shared_obj_registry ) try: controller.tick() except Exception, ex: print 'got exception (%s)' % ex, 'killing reactor' import logging logging.basicConfig() logging.exception(ex) serverView.disconnect()
def test_get_surveys(): MySurveys = Controller() surveys = MySurveys.GetSurveys() assert len(surveys) == 0 MySurveys.CreateSurvey("Survey Test 3") MySurveys.CreateSurvey("Survey Test 4") surveys = MySurveys.GetSurveys() assert len(surveys) == 2 MySurveys.CreateSurvey("Survey Test 5") MySurveys.CreateSurvey("Survey Test 6") surveys = MySurveys.GetSurveys() assert len(surveys) == 4
def test_create_survey(): MySurveys = Controller() surveys = MySurveys.GetSurveys() assert len(surveys) == 0 assert MySurveys.CreateSurvey("Survey Test 7") == None surveys = MySurveys.GetSurveys() assert len(surveys) == 1 assert surveys[0].name == "Survey Test 7" assert MySurveys.CreateSurvey("Survey Test 8") == None surveys = MySurveys.GetSurveys() assert len(surveys) == 2 assert surveys[1].name == "Survey Test 8"
def test_Controller_check_last_day_of_month(self): c = Controller() d = datetime(year=2015, month=2, day=28) rs = c.check_last_day_of_month(d) self.assertTrue(rs) d = datetime(year=2015, month=2, day=27) rs = c.check_last_day_of_month(d) self.assertFalse(rs) d = datetime(year=2016, month=2, day=29) rs = c.check_last_day_of_month(d) self.assertTrue(rs) d = datetime(year=2015, month=11, day=30) rs = c.check_last_day_of_month(d) self.assertTrue(rs) d = datetime(year=2015, month=12, day=1) rs = c.check_last_day_of_month(d) self.assertFalse(rs) d = datetime.now() rs = c.check_last_day_of_month(d)
def run(self): if self.state == self.Init: # Listen for message # If message recieved and this message belongs to this controller: # if this message is a route message # Get the start and target states from the route message # Update state into Ready # Send okay message ??TODO re-think if this message is necessary # else we are in wrong state, do nothing data = self.socket.recv(self.BUFFER_SIZE) message = Message.create(data.decode()) if message and message.type == Message.RouteMessageType: self.start = message.start self.target = message.target self.state = self.Ready self.socket.send(Message.createOkMessage().__str__().encode()) else: pass elif self.state == self.Ready: # Listen for message # If message recieved and this message belongs to this controller: # if this message is a start message # Update state into Running # init controller object with start and first target state # else do nothing data = self.socket.recv(self.BUFFER_SIZE) message = Message.create(data.decode()) if message and message.type == Message.StartMessageType: self.state = self.Running self.goalIndex = 0 Controller.__init__(self, self.start, self.target[self.goalIndex]) else: pass elif self.state == self.Running: # if all goals achieved and there is no more target # then send a end message to brain # set state to init # else # send get location message to the brain # listen for message # If message recieved and this message belongs to this controller: # if this message is a location message # iterate the PID controller using the current location and the routes # else do nothing, pass # else: # update self.goal and reset errors. # set state to iterating, if self.goalIndex == len(self.target): reply = Message.createEndMessage() self.socket.send(reply.__str__().encode()) self.close() else: self.goal = self.target[self.goalIndex] self.E = 0 self.old_e = 0 self.state = self.Iterating elif self.state == self.Iterating: # if the goal accuired # then set the goal index to next # set the state to running. # else: # send get location message to the brain # listen for message # If message recieved and this message belongs to this controller: # if this message is a location message # iterate the PID controller using the current location and the routes # else # do nothing, pass if self.isArrived(): self.goalIndex = self.goalIndex + 1 self.state = self.Running #print("Goal arrived, heading to next goal") else: msg = Message.createGetLocationMessage() self.socket.send(msg.__str__().encode()) data = self.socket.recv(self.BUFFER_SIZE) message = Message.create(data.decode()) if message and message.type == Message.LocationMessageType: self.current = message.location v, w = self.iteratePID() #print(v,w) self.makeAction(v, w) else: pass else: pass
class GoForFiveHundred(Bot): def set_dice_aside(self): while (self.round_score + self.round_rollover) < 500: return self.round_used_in_score return [True, True, True, True, True, True] class GoForTwoGrand(Bot): def set_dice_aside(self): while (self.round_score + self.round_rollover) < 2000: return self.round_used_in_score return [True,True,True,True,True,True] from main import Controller from farkle_bots import Bot scoreDevice = Controller(1, 1, [], 0) class BruteForceOdds(Bot): def set_dice_aside(self): stop_score = self.round_score + self.round_rollover if self.game_scores[self.index] + stop_score > max(self.game_scores + [self.end_score]): # Take the win return [True, True, True, True, True, True] using = self.round_used_in_score[:] if self.round_dice.count(5) < 3: for i in range(len(using)): if self.round_dice[i] == 5 and not self.round_set_aside[i] and using.count(True) > self.round_set_aside.count(True)+1: using[i] = False if self.round_dice.count(1) < 3: for i in range(len(using)):
from hog import HOG import numpy as np import cv2 from main import Controller from canny import Canny positive = Controller().load_batch("./Test_positive/") negative = Controller().load_batch("./Test_negative/") print(len(positive)) positive = Controller().grascale(positive) negative = Controller().grascale(negative) print(len(positive)) i = 0 for image in positive: i += 1 grad_x, grad_y = Canny().gradient_generation(image) egde_mag = Canny().edge_magnitude(grad_x, grad_y) cv2.imwrite("./results/Postive" + str(i) + ".jpg", egde_mag) i = 0 for image in negative: i += 1 grad_x, grad_y = Canny().gradient_generation(image) egde_mag = Canny().edge_magnitude(grad_x, grad_y) cv2.imwrite("./results/Negative" + str(i) + ".jpg", egde_mag) image = cv2.imread("./Train_positive/crop001278a.bmp") image = 0.114 * image[:, :, 0] + 0.587 * image[:, :, 1] + 0.299 * image[:, :, 2] descriptor = HOG().generate_hog_features(image, (8, 8), 2)
def test_add_response(): firstUser = 1 secondUser = 2 MySurveys = Controller() MySurveys.CreateSurvey("Survey Test 11") assert len(MySurveys.GetSurvey("Survey Test 11").responses) == 0 assert MySurveys.AddResponse("Survey Test 11", 2, firstUser) == "No question for this answer" assert MySurveys.AddResponse("Survey Test 11", "invalid response", firstUser) == "Invalid answer" assert MySurveys.AddResponse("Survey Test 11", 10, firstUser) == "Invalid answer" assert MySurveys.AddResponse("Survey Test 11", 0, firstUser) == "Invalid answer" assert MySurveys.AddQuestion("Survey Test 11", "This is a question for survey 1") == None assert len(MySurveys.GetSurvey("Survey Test 11").questions) == 1 assert MySurveys.AddResponse("Unknow Survey 2", 4, firstUser) == "Survey not found" assert MySurveys.AddResponse("Survey Test 11", 4, firstUser) == None assert len(MySurveys.GetSurvey("Survey Test 11").responses) == 1 assert MySurveys.GetSurvey("Survey Test 11").responses[0].answer[0] == 4 assert MySurveys.AddResponse("Survey Test 11", 4, firstUser) == "No question for this answer" assert MySurveys.AddQuestion("Survey Test 11", "This is a question 2 for survey 1") == None assert len(MySurveys.GetSurvey("Survey Test 11").questions) == 2 assert MySurveys.AddResponse("Survey Test 11", 1, firstUser) == None assert len(MySurveys.GetSurvey("Survey Test 11").responses[0].answer) == 2 assert MySurveys.GetSurvey("Survey Test 11").responses[0].answer[1] == 1 assert MySurveys.AddResponse("Survey Test 11", 3, secondUser) == None assert len(MySurveys.GetSurvey("Survey Test 11").responses) == 2 assert len(MySurveys.GetSurvey("Survey Test 11").responses[1].answer) == 1 assert len(MySurveys.GetSurvey("Survey Test 11").responses[0].answer) == 2 assert MySurveys.GetSurvey("Survey Test 11").responses[1].answer[0] == 3 assert MySurveys.AddResponse("Survey Test 11", 4, secondUser) == None assert len(MySurveys.GetSurvey("Survey Test 11").responses) == 2 assert len(MySurveys.GetSurvey("Survey Test 11").responses[1].answer) == 2 assert len(MySurveys.GetSurvey("Survey Test 11").responses[0].answer) == 2 assert MySurveys.GetSurvey("Survey Test 11").responses[1].answer[1] == 4 MySurveys.CreateSurvey("Survey Test 12") assert MySurveys.AddQuestion("Survey Test 12", "This is a question for survey 1") == None assert len(MySurveys.GetSurvey("Survey Test 12").questions) == 1 assert MySurveys.AddResponse("Survey Test 12", 2, firstUser) == None assert len(MySurveys.GetSurvey("Survey Test 11").responses) == 2 assert len(MySurveys.GetSurvey("Survey Test 11").responses[1].answer) == 2 assert len(MySurveys.GetSurvey("Survey Test 11").responses[0].answer) == 2 assert MySurveys.GetSurvey("Survey Test 11").responses[1].answer[1] == 4 assert len(MySurveys.GetSurvey("Survey Test 12").responses[0].answer) == 1 assert MySurveys.GetSurvey("Survey Test 12").responses[0].answer[0] == 2
def test_add_question(): MySurveys = Controller() MySurveys.CreateSurvey("Survey Test 9") assert len(MySurveys.GetSurvey("Survey Test 9").questions) == 0 assert MySurveys.AddQuestion("Survey Test 9", "This is a question") == None assert MySurveys.AddQuestion("Survey Test 9", "This is a question") == "Question already exist if this survey" assert len(MySurveys.GetSurvey("Survey Test 9").questions) == 1 assert MySurveys.GetSurvey("Survey Test 9").questions[0] == "This is a question" assert MySurveys.AddQuestion("Survey Test 9", "This is a question 2") == None assert len(MySurveys.GetSurvey("Survey Test 9").questions) == 2 assert MySurveys.GetSurvey("Survey Test 9").questions[1] == "This is a question 2" assert MySurveys.AddQuestion("Unknow Survey", "This is a question") == "Survey not found" MySurveys.CreateSurvey("Survey Test 10") assert MySurveys.AddQuestion("Survey Test 10", "This is a question for survey 2") == None assert len(MySurveys.GetSurvey("Survey Test 9").questions) == 2 assert len(MySurveys.GetSurvey("Survey Test 10").questions) == 1 assert MySurveys.GetSurvey("Survey Test 10").questions[0] == "This is a question for survey 2" assert MySurveys.AddQuestion("Survey Test 10", "This is a question 10 for survey 10") == None assert MySurveys.AddQuestion("Survey Test 10", "This is a question 101 for survey 10") == None assert MySurveys.AddQuestion("Survey Test 10", "This is a question 102 for survey 10") == None assert MySurveys.AddQuestion("Survey Test 10", "This is a question 103 for survey 10") == None assert MySurveys.AddQuestion("Survey Test 10", "This is a question 104 for survey 10") == None assert MySurveys.AddQuestion("Survey Test 10", "This is a question 105 for survey 10") == None assert MySurveys.AddQuestion("Survey Test 10", "This is a question 106 for survey 10") == None assert MySurveys.AddQuestion("Survey Test 10", "This is a question 107 for survey 10") == None assert MySurveys.AddQuestion("Survey Test 10", "This is a question 108 for survey 10") == None assert MySurveys.AddQuestion("Survey Test 10", "This is a question 109 for survey 10") == "Limit of 10 questions reached"
def test_get_survey_question_stat(): firstUser = 1 secondUser = 2 MySurveys = Controller() MySurveys.CreateSurvey("Survey Test 14") assert MySurveys.AddQuestion("Survey Test 14", "This is a question for survey 1") == None assert MySurveys.AddQuestion("Survey Test 14", "This is a question 2 for survey 1") == None assert len(MySurveys.GetSurvey("Survey Test 14").questions) == 2 assert MySurveys.GetSurveyQuestionStat("Unknow Survey", "This is a question for survey 1") == "Survey not found" assert MySurveys.GetSurveyQuestionStat("Survey Test 14", "Unknow question") == "Survey Question not found" questionStat = MySurveys.GetSurveyQuestionStat("Survey Test 14", "This is a question for survey 1") assert questionStat == {} assert MySurveys.AddResponse("Survey Test 14", 4, firstUser) == None assert MySurveys.AddResponse("Survey Test 14", 5, firstUser) == None questionStat = MySurveys.GetSurveyQuestionStat("Survey Test 14", "This is a question for survey 1") assert questionStat["max"] == 4 assert questionStat["min"] == 4 assert questionStat["average"] == 4 questionStat = MySurveys.GetSurveyQuestionStat("Survey Test 14", "This is a question 2 for survey 1") assert questionStat["max"] == 5 assert questionStat["min"] == 5 assert questionStat["average"] == 5 assert MySurveys.AddResponse("Survey Test 14", 2, secondUser) == None questionStat = MySurveys.GetSurveyQuestionStat("Survey Test 14", "This is a question 2 for survey 1") assert questionStat["max"] == 5 assert questionStat["min"] == 5 assert questionStat["average"] == 5 assert MySurveys.AddResponse("Survey Test 14", 1, secondUser) == None questionStat = MySurveys.GetSurveyQuestionStat("Survey Test 14", "This is a question for survey 1") assert questionStat["max"] == 4 assert questionStat["min"] == 2 assert questionStat["average"] == 3 assert questionStat["stand_dev"] == 1.4142135623730951 questionStat = MySurveys.GetSurveyQuestionStat("Survey Test 14", "This is a question 2 for survey 1") assert questionStat["max"] == 5 assert questionStat["min"] == 1 assert questionStat["average"] == 3 assert questionStat["stand_dev"] == 2.8284271247461903
def test_get_survey_stat(): firstUser = 1 secondUser = 2 MySurveys = Controller() MySurveys.CreateSurvey("Survey Test 13") assert MySurveys.AddQuestion("Survey Test 13", "This is a question for survey 1") == None assert MySurveys.AddQuestion("Survey Test 13", "This is a question 2 for survey 1") == None assert len(MySurveys.GetSurvey("Survey Test 13").questions) == 2 surveyStat = MySurveys.GetSurveyStat("Survey Test 13") assert MySurveys.GetSurveyStat("Unknow Survey") == "Survey not found" assert surveyStat == {} assert MySurveys.AddResponse("Survey Test 13", 4, firstUser) == None assert MySurveys.AddResponse("Survey Test 13", 2, firstUser) == None surveyStat = MySurveys.GetSurveyStat("Survey Test 13") assert surveyStat["max"] == 6 assert surveyStat["min"] == 6 assert surveyStat["average"] == 6 assert MySurveys.AddResponse("Survey Test 13", 1, secondUser) == None assert MySurveys.AddResponse("Survey Test 13", 2, secondUser) == None surveyStat = MySurveys.GetSurveyStat("Survey Test 13") assert surveyStat["max"] == 6 assert surveyStat["min"] == 3 assert surveyStat["average"] == 4.5 assert surveyStat["stand_dev"] == 2.1213203435596424 MySurveys.CreateSurvey("Survey Test 14") assert MySurveys.AddQuestion("Survey Test 14", "This is a question for survey 1") == None assert MySurveys.AddQuestion("Survey Test 14", "This is a question 2 for survey 1") == None assert len(MySurveys.GetSurvey("Survey Test 14").questions) == 2 assert MySurveys.AddResponse("Survey Test 14", 4, firstUser) == None assert MySurveys.AddResponse("Survey Test 14", 2, firstUser) == None surveyStat = MySurveys.GetSurveyStat("Survey Test 13") assert surveyStat["max"] == 6 assert surveyStat["min"] == 3 assert surveyStat["average"] == 4.5 assert surveyStat["stand_dev"] == 2.1213203435596424 surveyStat = MySurveys.GetSurveyStat("Survey Test 14") assert surveyStat["max"] == 6 assert surveyStat["min"] == 6 assert surveyStat["average"] == 6
def test_get_survey_responses(): firstUser = 1 secondUser = 2 thirdUser = 3 MySurveys = Controller() MySurveys.CreateSurvey("Survey Test new") assert MySurveys.AddQuestion("Survey Test new", "This is a question for survey new") == None assert MySurveys.AddQuestion("Survey Test new", "This is a question 2 for survey new") == None assert len(MySurveys.GetSurvey("Survey Test new").questions) == 2 assert MySurveys.AddResponse("Survey Test new", 4, firstUser) == None assert MySurveys.AddResponse("Survey Test new", 2, firstUser) == None assert MySurveys.GetSurveyResponses("Unknow") == "Survey not found" responses = MySurveys.GetSurveyResponses("Survey Test new") assert len(responses) == 1 assert len(responses[0]) == 2 assert responses[0][0] == 4 assert responses[0][1] == 2 assert MySurveys.AddResponse("Survey Test new", 1, secondUser) == None responses = MySurveys.GetSurveyResponses("Survey Test new") assert len(responses) == 2 assert len(responses[0]) == 2 assert responses[0][0] == 4 assert responses[0][1] == 2 assert len(responses[1]) == 1 assert responses[1][0] == 1 assert MySurveys.AddResponse("Survey Test new", 5, secondUser) == None responses = MySurveys.GetSurveyResponses("Survey Test new") assert len(responses) == 2 assert len(responses[0]) == 2 assert responses[0][0] == 4 assert responses[0][1] == 2 assert len(responses[1]) == 2 assert responses[1][0] == 1 assert responses[1][1] == 5 assert MySurveys.AddResponse("Survey Test new", 2, thirdUser) == None assert MySurveys.AddResponse("Survey Test new", 3, thirdUser) == None responses = MySurveys.GetSurveyResponses("Survey Test new") assert len(responses) == 3 assert len(responses[0]) == 2 assert responses[0][0] == 4 assert responses[0][1] == 2 assert len(responses[1]) == 2 assert responses[1][0] == 1 assert responses[1][1] == 5 assert len(responses[2]) == 2 assert responses[2][0] == 2 assert responses[2][1] == 3