예제 #1
0
    def showResults(self):
        #restore .m file from archive
        fileName = self.outfile
        self.restoreFromArchive(fileName)

        Visualizer.yScatterPlot(self.ensemble, self.outputs[0], self.x,
                                self.cmd, fileName)
예제 #2
0
def main():
    # parse arguments
    args = cli()

    # setup processor and visualizer
    processor = Processor(model=args['model'])
    visualizer = Visualizer()

    # fetch input
    print('image arg', args['image'])
    # img = cv2.imread('inputs/{}'.format(args['image']))
    input_image_paths = []
    folder_path = 'imgs'
    if os.path.isdir(folder_path):
        ls = os.listdir(folder_path)
        for file_name in sorted(ls, key=lambda x: str(x.split('.jpg')[0])):
            input_image_paths.append(os.path.join(folder_path, file_name))
    img_batch = []
    for input_image_path in input_image_paths:
        img_batch.append(input_image_path)
        if len(img_batch) == args['batch_size']:
            # inference
            output, image_raw_batch = processor.detect(img_batch)
            # final results
            boxes, confs, classes = processor.post_process(
                output,
                conf_thres=0.5,
                iou_thres=0.4,
                image_raw_batch=image_raw_batch)
            # print(boxes)
            for i in range(len(img_batch)):
                visualizer.draw_results_batch(i, image_raw_batch[i], boxes[i],
                                              confs[i], classes[i])
예제 #3
0
class MainWindow(QMainWindow):

    def __init__(self):

        super(MainWindow, self).__init__()

        self.scene = QGraphicsScene()

        # Scene is the parent of the view in order to show the graphical items.
        # the View must also be the parent of the scene in order to avoid
        # bizarre segmentation faults with GTK
        self.view = InteractiveView(self.scene)
        self.scene.setParent(self.view)

        self.setCentralWidget(self.view)
        self.view.setSceneRect(INT_MIN/2, INT_MIN/2, INT_MAX, INT_MAX)
        self.view.centerOn(0, 0)

        self.visualizer = Visualizer(self.scene)
        self.visualizer.update_processes_data()

        # Set a dark background color
        back_color = QColor(25, 20, 45)
        self.view.setBackgroundBrush(QBrush(back_color))

    def keyPressEvent(self, event):
        super(MainWindow, self).keyPressEvent(event)

        # Quit via escape key.
        if event.key() == Qt.Key_Escape:
            self.close()

        if event.key() == Qt.Key_R:
            self.visualizer.showRootTasks = not self.visualizer.showRootTasks
예제 #4
0
def main():
    # parse arguments
    args = cli()
    # setup processor and visualizer
    processor = Processor(model=args['model'])
    visualizer = Visualizer()

    # fetch input
    print('image arg', args['image'])
    # img = cv2.imread('inputs/{}'.format(args['image']))
    input_image_paths = []
    folder_path = args['image']
    if os.path.isdir(folder_path):
        ls = os.listdir(folder_path)
        for file_name in sorted(ls, key=lambda x: str(x.split('.jpg')[0])):
            input_image_paths.append(os.path.join(folder_path, file_name))
    for input_image_path in input_image_paths:
        img = cv2.imread(input_image_path)

        # inference
        output = processor.detect(img)

        # final results
        boxes, confs, classes = processor.post_process(output, conf_thres=0.3, iou_thres=0.4, origin_w=img.shape[1], origin_h=img.shape[0])
        visualizer.draw_results(img, boxes, confs, classes)
def elasticDistort(picture, sigma, alpha):
    dx, dy = generateDisplacementFields(sigma, alpha)
    distortion = np.zeros(Constants.pic_shape)

    Visualizer.plotNumber('dx', dx)
    Visualizer.plotNumber('dy', dy)

    # For each pixel use the displacement field to grab new pixel values
    # Hopefully it will be elastically distorted! :D

    # Bilinear interpolation
    for i in range(Constants.pic_height):
        for j in range(Constants.pic_width):
            x = i + dx[i, j]
            y = j + dy[i, j]

            # If the new location we're trying to grab is outside the picture
            # boundaries, then leave the pixel value as zero
            if x < 0 or x > (Constants.pic_width - 1):
                continue 
            if y < 0 or y > (Constants.pic_height - 1):
                continue

            distortion[i, j] = bilinearInterpolation(picture, x, y)

    return distortion
예제 #6
0
    def setUp(self):
        self.autoseed = random.randint(0, 9999999999)
        self.seed = self.RAND_SEED
        if not self.seed:
            self.seed = self.autoseed
        self.myRandom = random.Random(self.seed)

        self.peer_controller = None

        self.peers = [
            self.create_peer("P%d" % i, "127.0.0.1", 8500 + i)
            for i in range(self.NO_OF_PEERS)
        ]

        self.peer_controller = PeerController(self.peers,
                                              self.WORLD_SIZE,
                                              self.TOP_SPEED,
                                              self.MAX_SPEED_CHANGE,
                                              self.RADIO_RANGE,
                                              rand_seed=self.seed)

        #Start router
        self.router = Router("127.0.0.1", 8300, self.peers,
                             self.peer_controller, self.USE_TICKS)
        self.router.start()
        self.ensure_peers_ready(self.peers)
        self.router.activate_queue()

        if self.VISUALIZE:
            self.visualizer = Visualizer(self.peers, self.peer_controller)
            self.visualizer.visualize()
예제 #7
0
    def prepareLinkData(self, date='2009-02-13'):
        """ 
        Reads and returns a tuple of (linkData, segmentData). 
        
        linkData is a dictionary with one record for each link, containing 
        the data necessary for plotting. 
        
        segmentData is a dictionary with one record for each shape segment
        for use with the HoverTool. 
        
        Called once at the beginning to read in all the data. 
        
        date - string for the date's data to display
        """
        
        # read the highway network
        hwynet = HwyNetwork()
        hwynet.readDTANetwork(INPUT_DYNAMEQ_NET_DIR, INPUT_DYNAMEQ_NET_PREFIX, logging_dir=LOGGING_DIR) 
    
        # get the data
        v = Visualizer(hwynet, TAXI_OUTFILE)
        df = v.getLinkData(date=date)

        # convert to a dictionary.  
        # .to_dict() returns in a different structure that doesn't work. 
        linkData = {}
        for c in df.columns: 
            linkData[c] = df[c]
                
        # convert to segments
        segmentData = v.getSegmentRectangleData(df)
                                
        return (linkData, segmentData)
예제 #8
0
    def prepareLinkData(self, date='2009-02-13'):
        """ 
        Reads and returns a tuple of (linkData, segmentData). 
        
        linkData is a dictionary with one record for each link, containing 
        the data necessary for plotting. 
        
        segmentData is a dictionary with one record for each shape segment
        for use with the HoverTool. 
        
        Called once at the beginning to read in all the data. 
        
        date - string for the date's data to display
        """

        # read the highway network
        hwynet = HwyNetwork()
        hwynet.readDTANetwork(INPUT_DYNAMEQ_NET_DIR,
                              INPUT_DYNAMEQ_NET_PREFIX,
                              logging_dir=LOGGING_DIR)

        # get the data
        v = Visualizer(hwynet, TAXI_OUTFILE)
        df = v.getLinkData(date=date)

        # convert to a dictionary.
        # .to_dict() returns in a different structure that doesn't work.
        linkData = {}
        for c in df.columns:
            linkData[c] = df[c]

        # convert to segments
        segmentData = v.getSegmentRectangleData(df)

        return (linkData, segmentData)
예제 #9
0
def main():
    # parse arguments
    args = cli()

    # setup processor and visualizer
    processor = Processor(model=args['model'])
    visualizer = Visualizer()

    # fetch input
    print('image arg', args['image'])
    img = cv2.imread('inputs/{}'.format(args['image']))

    # inference
    output = processor.detect(img)
    img = cv2.resize(img, (640, 640))

    # object visualization
    object_grids = processor.extract_object_grids(output)
    visualizer.draw_object_grid(img, object_grids, 0.1)

    # class visualization
    class_grids = processor.extract_class_grids(output)
    visualizer.draw_class_grid(img, class_grids, 0.01)

    # bounding box visualization
    boxes = processor.extract_boxes(output)
    visualizer.draw_boxes(img, boxes)

    # final results
    boxes, confs, classes = processor.post_process(output)
    visualizer.draw_results(img, boxes, confs, classes)
예제 #10
0
def RunDetection(TS_ID):
    #Get Data
    dfds = d.GetTimeSeries(TS_ID)
    targets = dfds['target'].unique()

    #Delete Output Data for TS_ID
    d._deleteTimeSeriesOutput(TS_ID)

    #Run detection
    for target in targets:
        try:
            titleName = TS_ID + '_' + target
            df = dfds[dfds['target'] == target]
            print(target)
            #Change Detection
            detector = ADetector(df)
            detector.Run()

            dfResults = detector.GetResults()
            dfResults['ts_id'] = TS_ID
            dfResults['target'] = target
            d.SaveResults(dfResults)

            visuals = Visualizer(dfResults,
                                 plt_ymin=min(df.y),
                                 plt_ymax=max(df.y))
            visuals.PlotChangePoints(Title=titleName, fileName=titleName)

        except Exception as ex:
            print("Error with {0}".format(TS_ID + " - " + target))
예제 #11
0
    def test2(self):
        useless = ['RegionID', 'resulttime', 'CellID', 'PRB_DL_Used_Rate']
        analyzer.drop_unnecessary_columns(useless)
        arguments = {"C": 0.3}
        analyzer.create_model(ModelType.logregression, arguments,
                              analyzer.data,
                              analyzer.data['cnt_averload_cell'])

        print("Cross variation score:\n" + str(analyzer.models[0].cv_score))
        # print("Feature importances:\n" + str(analyzer.models[0].model.feature_importances_))
        print(analyzer.models[0].feature_names)
        Visualizer.draw_class_scatter(analyzer.models[0])
def plot_polygon(m, polygons, limit_x, limit_y, title):
    for v in m.getVars():
        if v.x == 1:
            name = v.varName
            name = name.split(" ")
            i = int(name[0])
            point = [int(name[1]), int(name[2])]
            point[0] = point[0] - polygons[i][0][0]
            point[1] = point[1] - polygons[i][0][1]
            polygons[i] = Polygon.add_number_axis_x_y(polygons[i], point[0], point[1])
    polygons = Polygon.create_polygons_to_plot(polygons)
    visualiser = Visualizer(polygons, limit_x, limit_y, title)
    visualiser.plot_polygons()
예제 #13
0
def specialTurnGateTest():

    dic = DictionarySearcher(2)

    id = AQP.generateSpecialTurn(a=-1, b=0, dic=dic)
    Debug.debug(Visualizer.printPath(id, dic, deepEnd=False),
                DebugLevel.Result)
    Debug.debug(Visualizer.printCompress(id, dic), DebugLevel.Result)
    Debug.debug("\n" + str(dic.getGate(id).getMatrix()) + "\n\n",
                DebugLevel.Result)

    id = AQP.generateSpecialTurn(a=(1 / (math.sqrt(2))),
                                 b=(1 / (math.sqrt(2))),
                                 dic=dic)
    Debug.debug(Visualizer.printPath(id, dic, deepEnd=False),
                DebugLevel.Result)
    Debug.debug(Visualizer.printCompress(id, dic), DebugLevel.Result)
    Debug.debug("\n" + str(dic.getGate(id).getMatrix()) + "\n\n",
                DebugLevel.Result)

    dic = DictionarySearcher(3)

    id = AQP.generateSpecialTurn(a=1j, b=0, dic=dic)
    Debug.debug(Visualizer.printPath(id, dic, deepEnd=False),
                DebugLevel.Result)
    Debug.debug(Visualizer.printCompress(id, dic), DebugLevel.Result)
    Debug.debug(
        Visualizer.printCompress(id,
                                 dic,
                                 deepEnd=True,
                                 deep=1,
                                 autoReference=True), DebugLevel.Result)
    Debug.debug("\n" + str(dic.getGate(id).getMatrix()) + "\n\n",
                DebugLevel.Result)

    dic = DictionarySearcher(4)

    id = AQP.generateSpecialTurn(a=(1 / (math.sqrt(2))),
                                 b=(1j * (1 / (math.sqrt(2)))),
                                 dic=dic)
    Debug.debug(Visualizer.printPath(id, dic, deepEnd=False),
                DebugLevel.Result)
    Debug.debug(Visualizer.printCompress(id, dic), DebugLevel.Result)
    Debug.debug(
        Visualizer.printCompress(id,
                                 dic,
                                 deepEnd=True,
                                 deep=1,
                                 autoReference=True), DebugLevel.Result)
    Debug.debug("\n" + str(dic.getGate(id).getMatrix()) + "\n\n",
                DebugLevel.Result)
예제 #14
0
def basicTurnGateTest():

    dic = DictionarySearcher(2)

    id = AQP.generateBasicTurn(target=1,
                               angle=math.pi,
                               turnType=TurnType.Z,
                               dic=dic)
    Debug.debug(Visualizer.printPath(id, dic), DebugLevel.Result)
    Debug.debug(Visualizer.printCompress(id, dic), DebugLevel.Result)
    Debug.debug("\n" + str(dic.getGate(id).getMatrix()) + "\n\n",
                DebugLevel.Result)

    id = AQP.generateBasicTurn(target=0,
                               angle=math.pi / 2,
                               turnType=TurnType.Z,
                               dic=dic)
    Debug.debug(Visualizer.printPath(id, dic), DebugLevel.Result)
    Debug.debug(Visualizer.printCompress(id, dic), DebugLevel.Result)
    Debug.debug("\n" + str(dic.getGate(id).getMatrix()) + "\n\n",
                DebugLevel.Result)

    id = AQP.generateBasicTurn(target=1,
                               angle=math.pi / 4,
                               turnType=TurnType.X,
                               dic=dic)
    Debug.debug(Visualizer.printPath(id, dic), DebugLevel.Result)
    Debug.debug(Visualizer.printCompress(id, dic), DebugLevel.Result)
    Debug.debug("\n" + str(dic.getGate(id).getMatrix()) + "\n\n",
                DebugLevel.Result)

    dic = DictionarySearcher(4)

    id = AQP.generateBasicTurn(target=3,
                               angle=math.pi / 4,
                               turnType=TurnType.Z,
                               dic=dic)
    Debug.debug(Visualizer.printPath(id, dic), DebugLevel.Result)
    Debug.debug(Visualizer.printCompress(id, dic), DebugLevel.Result)
    Debug.debug("\n" + str(dic.getGate(id).getMatrix()) + "\n\n",
                DebugLevel.Result)

    id = AQP.generateBasicTurn(target=1,
                               angle=math.pi / 4,
                               turnType=TurnType.Z,
                               dic=dic)
    Debug.debug(Visualizer.printPath(id, dic), DebugLevel.Result)
    Debug.debug(Visualizer.printCompress(id, dic), DebugLevel.Result)
    Debug.debug("\n" + str(dic.getGate(id).getMatrix()) + "\n\n",
                DebugLevel.Result)
예제 #15
0
    def test3(self):
        classifier = "DL_MCS_64QAM"
        # TODO: redo it, so it doesn't delete the classifier from the dataset, what if you want to reuse it?
        classifier_values = analyzer.data[classifier]
        arguments = {"C": 0.8, "kernel": 'linear'}
        useless = [
            'RegionID', 'resulttime', 'CellID', 'cnt_averload_cell', classifier
        ]
        analyzer.drop_unnecessary_columns(useless)
        analyzer.create_model(ModelType.svc, arguments, analyzer.data,
                              classifier_values)

        print("Cross variation score:\n" + str(analyzer.models[0].cv_score))
        # print("Feature importances:\n" + str(analyzer.models[0].model.feature_importances_))
        print(analyzer.models[0].feature_names)
        Visualizer.draw_class_scatter(analyzer.models[0])
예제 #16
0
    def __init__(self, train, test):
        print("ObjectOrientedTitanic object created")
        self.testPassengerID = test['PassengerId']
        self.number_of_train = train.shape[0]

        self.y_train = train['Survived']
        self.train = train.drop('Survived', axis=1)
        self.test = test

        self.all_data = self._get_all_data()

        # Create instance of objects
        self._info = Information()
        self.preprocessStrategy = PreprocessStrategy()
        self.visualizer = Visualizer()
        self.gridSearchHelper = GridSearchHelper()
예제 #17
0
    def action(self):
        def order_review():
            #print('Passed')
            return True

        order_review()
        #self.selected_data_engine   = Selector(self.order.data_engine).task_submit()
        self.data_profiling_result = Analyst(
            self.order.df, self.order.df_name,
            self.order.path_to_output).task_submit()
        print(self.data_profiling_result)
        self.data_auditing_result = Auditor(
            self.data_profiling_result, self.order.auditing_config,
            self.order.path_to_output).task_submit()
        self.Visualizing_result = Visualizer(
            self.data_profiling_result, self.data_auditing_result,
            self.order.path_to_output, self.order.report_config,
            self.order.auditing_config).task_submit()

        result = {}
        result['data_profile'] = self.data_profiling_result
        result['data_auditing'] = self.data_auditing_result
        result['data_viz'] = self.Visualizing_result

        return result
예제 #18
0
    def showResults(self):
        cmd = 'rs%d' % len(self.inputs)
        mfile = 'matlab' + cmd + '.m'
        self.restoreFromArchive(mfile)

        ngrid = 0
        if len(self.inputs) == 2:
            ngrid = 256  # select grid resolution (32-256)
        elif len(self.inputs) == 3:
            ngrid = 32  # select grid resolution (16-32)

        inNames = self.ensemble.getInputNames()
        x = [index + 1 for index in self.inputs]

        Visualizer.showRSPlot(self.ensemble, self.outputs[0], x,
                              len(self.inputs), ngrid, self.responseSurface,
                              self.minVal, self.maxVal, mfile)
예제 #19
0
 def write_frames_from_log(self, logfile):
     stuff = np.load(logfile)
     filename = str(stuff['name']) + '.mp4'
     self.visualizer = Visualizer(int(stuff['ego_id']),
                                  stuff['LengthWidth'][:, 0],
                                  stuff['LengthWidth'][:, 1],
                                  int(stuff['num_cars']), self.road)
     metadata = dict(title=str(stuff['name']), artist='Pseudo', comment='')
     writer = FFMpegWriter(fps=2 * int(1. / Vehicle.DEL_T),
                           codec='libx264',
                           metadata=metadata,
                           extra_args=['-pix_fmt', 'yuv420p'])
     with writer.saving(self.visualizer.fig, filename,
                        self.visualizer.fig.dpi):
         for state in stuff['State_record']:
             self.visualizer.update(state[:, :3])
             writer.grab_frame()
     Scenario.flip_video(filename)
예제 #20
0
def grover4AATest():

    dic = DictionarySearcher(4)
    matrix = QuantumMath.getAmplitudAmplifier(4)
    id = AQP.generateSpecial(matrix=matrix, name="grover4AA", dic=dic)

    Debug.debug(Visualizer.printCompress(id, dic), DebugLevel.Result)
    Debug.debug("\n" + str(dic.getGate(id).getMatrix()) + "\n\n",
                DebugLevel.Result)
예제 #21
0
def main():
    # parse arguments
    args = cli()

    # setup processor and visualizer
    processor = Processor(model=args['model'])
    visualizer = Visualizer()

    # fetch input
    print('image arg', args['image'])
    #img = cv2.imread('inputs/{}'.format(args['image']))
    img = cv2.imread("/home/jiqing/jq/bottle/33/3 (3).jpg")
    cap = cv2.VideoCapture(0)
    while 1:
        ret, frame = cap.read()
        #print(type(img))

        # inference
        #output = processor.detect(img)
        #img = cv2.resize(img, (640, 640))

        output = processor.detect(frame)
        img = cv2.resize(frame, (640, 640))

        # object visualization
        object_grids = processor.extract_object_grids(output)
        #visualizer.draw_object_grid(img, object_grids, 0.1)

        # class visualization
        class_grids = processor.extract_class_grids(output)
        #visualizer.draw_class_grid(img, class_grids, 0.01)

        # bounding box visualization
        boxes = processor.extract_boxes(output)
        #visualizer.draw_boxes(img, boxes)

        # final results
        boxes, confs, classes = processor.post_process(output)
        #print(classes)

        #label = f'{names[int(classes)]} {confs:.2f}'
        visualizer.draw_results(img, boxes, confs, classes)
 def show_current_policy_and_map(self):
     """
     For visualization of the maze and policy when using the A* planner.
     :return: None
     """
     vis = Visualizer(self.maze_map.dim)
     vis.draw_maze(Maze('known_maze.txt'))
     vis.draw_policy(reversed(self.planner.policy), self.location, self.heading)
     vis.show_window()
예제 #23
0
 def __init__(self, parent):
     self.ch_tracks = dict()
     self.parent = parent
     self.parsed = False
     self.listWidget = self.parent.GetTracksList()
     self.Visualizer = Visualizer.getInstance()
     self.last_id = -1e3
     self.np_tracks = np.zeros(0)
     self.clothes = dict()
     self.tracks_path = ""
     self.clothes_path = ""
예제 #24
0
def memoryTest():

    # inicializa un diccionario para 4 qubits
    dic = DictionarySearcher(nQubits=4)

    # genera una puerta de giro condicionado multiple y las subpuertas necesarias
    gateId = AQP.generateMultipleTurn(sources=[0, 1, 2],
                                      target=3,
                                      angle=math.pi / 2,
                                      turnType=TurnType.Z,
                                      dic=dic)

    # imprime por pantalla el path
    print(
        Visualizer.printCompress(gateId,
                                 dic,
                                 deepEnd=True,
                                 deep=1,
                                 autoReference=False))

    # genera el fichero .qasm para crear esta puerta
    WriterAsm.writeAsm(gateId, dic, "multiConditionalGate.qasm", reset=True)

    Debug.debug(Visualizer.printCompress(
        id,
        dic,
    ), DebugLevel.Result)
    Debug.debug(
        Visualizer.printCompress(id,
                                 dic,
                                 deepEnd=True,
                                 deep=1,
                                 autoReference=True), DebugLevel.Result)
    Debug.debug(
        Visualizer.printCompress(id,
                                 dic,
                                 deepEnd=True,
                                 deep=2,
                                 autoReference=True), DebugLevel.Debug)
    Debug.debug("\n" + str(dic.getGate(id).getMatrix()) + "\n\n",
                DebugLevel.Result)
예제 #25
0
    def calcScore(self):
        i = 0
        visualizer = Visualizer()
        totalScore = 0
        iterations = 200
        if (self.visualization == 1):
            iterations = 200


        while(i < iterations): #frontierController.hasData()):
            self.frontierController.tick(self.workingNN)
            #print self.frontierController.agentLocations
            totalScore += self.agents[self.workingNN].getScore()
            self.globalScore += self.scorer.getGlobalScore()
            if (self.visualization == 1):
                visualizer.vis(self.frontierController.frontierData, self.frontierController.agentLocations)
#                print self.frontierController.agentLocations
                time.sleep(.03)
            i = i + 1

        return totalScore
예제 #26
0
    def analyze(self):
        Common.initFolder(Visualizer.dname)

        data = self.ensemble
        data = data.getValidSamples(
        )  # filter out samples that have no output results

        fname = Common.getLocalFileName(Visualizer.dname,
                                        data.getModelName().split()[0], '.dat')
        index = ResponseSurfaces.getEnumValue(self.responseSurface)
        fixedAsVariables = index == ResponseSurfaces.USER
        data.writeToPsuade(fname, fixedAsVariables=fixedAsVariables)
        rsdim = len(self.inputs)

        inNames = data.getInputNames()
        plotInNames = [inNames[i - 1] for i in self.inputs]
        if self.legendreOrder is not None:
            mfile = Visualizer.showRS(
                fname,
                self.outputs[0],
                plotInNames,
                rsdim,
                self.responseSurface,
                vmin=self.minVal,
                vmax=self.maxVal,
                rsOptions=self.rsOptions,
                userRegressionFile=self.userRegressionFile)
        else:
            mfile = Visualizer.showRS(
                fname,
                self.outputs[0],
                plotInNames,
                rsdim,
                self.responseSurface,
                vmin=self.minVal,
                vmax=self.maxVal,
                userRegressionFile=self.userRegressionFile)
        if mfile is not None:
            self.archiveFile(mfile)
        return mfile
예제 #27
0
    def __init__(self):

        self.run_mode = Runmode.BUILD
        self.event_stream = []
        self.fps = conf["simulation"]["fps"]
        env_conf = conf["environment"]
        tile_size = env_conf["tile_size"]

        self.clock = pygame.time.Clock()
        default_obstacles, default_robot = self.get_default_environment()
        self.environment = RoomEnvironment(env_conf["width"],
                                           env_conf["height"], tile_size,
                                           default_obstacles, default_robot)
        self.visualizer = Visualizer(self.environment, self.clock,
                                     self.environment.initial_events)
        self.algorithms = {
            "random": RandomBounceWalkAlgorithm(),
            "spiral": SpiralWalkAlgorithm(),
            "swalk": SWalkAlgorithm()
        }

        self.algorithm = self.algorithms[self.get_algorithm_name()]
예제 #28
0
    def RunBackpropagation(self,
                           minPeriods=30,
                           chartTitle="Trend",
                           metric='AlgoOutlierDetected'):
        AS_OF_DATES = self.df['ds'].unique()

        for i, toDate in enumerate(AS_OF_DATES):
            print(toDate)
            dfSource = self.df[self.df['ds'] <= toDate]

            #need at least 10 records to run model
            if dfSource.shape[0] > minPeriods:
                detector = ADetector(dfSource)
                detector.Run()

                dfResults = detector.GetResults()
                dfResults['AsOfDate'] = toDate

                #Prepare for Visualization (including future dates with 0's)
                xDates = self.df['ds'].values
                y = list(dfResults['y'].values)
                changepointChanges = list(dfResults[metric].values)
                while len(y) < len(xDates):
                    y.append(0)
                    changepointChanges.append(0)

                d = {'ds': xDates, 'y': y, metric: changepointChanges}

                dfResultsCharting = pd.DataFrame(d)

                #Save Image
                visuals = Visualizer(dfResultsCharting,
                                     plt_ymin=min(self.df.y),
                                     plt_ymax=max(self.df.y))
                visuals.PlotChangePoints(Title=chartTitle,
                                         fileName=str(i),
                                         folderName="seqimg",
                                         metric=metric)
예제 #29
0
 def __init__(self, path, queue_size=128):
     self.stream = cv2.VideoCapture(path)
     self.stopped = False
     self.queue_size = queue_size
     self.path = path
     self.Q = Queue(maxsize=queue_size)
     self.thread = threading.Thread(target=self.update, args=())
     # self.thread.daemon = True
     self.allreaded = False
     self.pause_cond = threading.Condition(threading.Lock())
     self.paused = False
     self.Visualizer = Visualizer.getInstance()
     self.Visualizer.setStream(self)
     self.frame_id = 0
예제 #30
0
def basicGateTest():

    dic = DictionarySearcher(2)

    id = AQP.generateBasic(standarGate=StandarGate.X, targets=[0], dic=dic)
    Debug.debug(Visualizer.printPath(id, dic), DebugLevel.Result)
    Debug.debug(Visualizer.printCompress(id, dic), DebugLevel.Result)
    Debug.debug("\n" + str(dic.getGate(id).getMatrix()) + "\n\n",
                DebugLevel.Result)

    id = AQP.generateBasic(standarGate=StandarGate.X, targets=[0, 1], dic=dic)
    Debug.debug(Visualizer.printPath(id, dic), DebugLevel.Result)
    Debug.debug(Visualizer.printCompress(id, dic), DebugLevel.Result)
    Debug.debug("\n" + str(dic.getGate(id).getMatrix()) + "\n\n",
                DebugLevel.Result)

    id = AQP.generateBasic(standarGate=StandarGate.H, targets=[0, 1], dic=dic)
    Debug.debug(Visualizer.printPath(id, dic), DebugLevel.Result)
    Debug.debug(Visualizer.printCompress(id, dic), DebugLevel.Result)
    Debug.debug("\n" + str(dic.getGate(id).getMatrix()) + "\n\n",
                DebugLevel.Result)

    dic = DictionarySearcher(4)

    id = AQP.generateBasic(standarGate=StandarGate.X,
                           targets=[1, 2, 3],
                           dic=dic)
    Debug.debug(Visualizer.printPath(id, dic), DebugLevel.Result)
    Debug.debug(Visualizer.printCompress(id, dic), DebugLevel.Result)
    Debug.debug("\n" + str(dic.getGate(id).getMatrix()) + "\n\n",
                DebugLevel.Result)

    id = AQP.generateBasic(standarGate=StandarGate.H, targets=[2], dic=dic)
    Debug.debug(Visualizer.printPath(id, dic), DebugLevel.Result)
    Debug.debug(Visualizer.printCompress(id, dic), DebugLevel.Result)
    Debug.debug("\n" + str(dic.getGate(id).getMatrix()) + "\n\n",
                DebugLevel.Result)
예제 #31
0
class ObjectOrientedTitanic():
    def __init__(self, train, test):
        print("ObjectOrientedTitanic object created")
        self.testPassengerID = test['PassengerId']
        self.number_of_train = train.shape[0]

        self.y_train = train['Survived']
        self.train = train.drop('Survived', axis=1)
        self.test = test

        self.all_data = self._get_all_data()

        # Create instance of objects
        self._info = Information()
        self.preprocessStrategy = PreprocessStrategy()
        self.visualizer = Visualizer()
        self.gridSearchHelper = GridSearchHelper()

    def _get_all_data(self):
        return pd.concat([self.train, self.test])

    def information(self):
        self._info.info(self.all_data)

    def preprocessing(self, strategy_type):
        self.strategy_type = strategy_type

        self.all_data = self.preprocessStrategy.strategy(
            self._get_all_data(), strategy_type)

    def visualize(self, visualizer_type, number_of_features=None):
        self._get_train_and_test()

        if visualizer_type == "RadViz":
            self.visualizer.RandianViz(X=self.X_train,
                                       y=self.y_train,
                                       number_of_features=number_of_features)

    def machine_learning(self):
        self._get_train_and_test()

        self.gridSearchHelper.fit_predict_save(self.X_train, self.X_test,
                                               self.y_train,
                                               self.testPassengerID,
                                               self.strategy_type)

    def _get_train_and_test(self):
        self.X_train = self.all_data[:self.number_of_train]
        self.X_test = self.all_data[self.number_of_train:]
def main():
    from Visualizer import Visualizer
    #data = np.genfromtxt('Data/train.csv', delimiter=',') # Why does numpy break? Nobody knows...
    print 'Reading data'
    data = pd.read_csv('Data/train.csv') 

    print 'Reshaping data'
    row = 0
    label = data.iloc[row, 0]
    picture = np.reshape(data.iloc[row, 1:], Constants.pic_shape)
    
    print 'Plotting number'

    Visualizer.plotNumber(str(label), picture)

    print 'Transforming'
    sigma = 4
    alpha = 8
    elasticDistort(picture, sigma, alpha)
    return
    # distortion = elasticDistort(picture, sigma, alpha)
    print distortion
    print 'Plotting zoom'
    Visualizer.plotNumber(str(label), distortion)
예제 #33
0
    def analyze(self):
        data = self.ensemble.getValidSamples()
        Common.initFolder(Visualizer.dname)

        fname = Common.getLocalFileName(Visualizer.dname,
                                        data.getModelName().split()[0], '.dat')
        data.writeToPsuade(fname)

        #perform screening
        mfile = Visualizer.yScatter(fname, self.outputs[0], self.x, self.cmd)

        #archive file
        if mfile is not None:
            self.archiveFile(mfile)
        return mfile
예제 #34
0
class SimRobotControl():
    def __init__(self, callback, rate, errorPercent):
        pyglet.clock.schedule_interval(callback, rate)
        ob = ObstacleGenerator()
        ob.generate()
        self.vis = Visualizer(ob.cornerarray, errorPercent)

    #A manual function for overriding the Model control
    def setMotorSpeed(self, motorIndex, speed):
        raise Exception("Not implemented")

    #Sets all the speeds of all the motors
    def setAllMotorSpeeds(self, motor0, motor1, motor2, motor3):
        raise Exception("Not implemented")

    #Gets the probable point
    def getProbablePoint(self):
        return [self.vis.robit.x, self.vis.robit.y]

    #Gets the probable theta
    def getProbableTheta(self):
        return self.vis.robit.theta

    #Moves the robot forward a distance at a certain speed
    def move(self, meters, speed):
        self.vis.moveForward(meters)

    #Rotates the robot by degrees at speed
    def rotate(self, degrees, speed):
        self.vis.setΘReltive(degrees) 

    def getSensorData(self):
        return self.vis.getSensorData()

    def tick(self, function):
        function(self)
예제 #35
0
    def __init__(self, D: DataCI, embedding_size: int = 200, optimizer: str = 'Adam',
                 negative_ratio=1, nb_epochs: int = 10, batch_size: int = 1, classification: bool = False,
                 kfolds: int = 10, model_file: str = 'model.h5', load: bool = False, save: bool = False):
        """
        NNEmbeddings Class initialization.
        :param D:
        :param model_file:
        :param embedding_size:
        :param optimizer:
        :param save:
        :param load:
        """
        Model.__init__(self)
        Metrics.__init__(self)
        Visualizer.__init__(self)
        self.Data = D

        # Parameter Grid
        self.param_grid = {'embedding_size': embedding_size,
                           'negative_ratio': negative_ratio,
                           'batch_size': batch_size,
                           'nb_epochs': nb_epochs,
                           'classification': classification,
                           'optimizer': optimizer
                           }

        self.model_file = model_file
        self.nr_revision = len(self.Data.pairs)

        if load:
            self.model = keras.models.load_model(self.model_file)
        else:
            self.model = self.build_model()
            print(self.crossValidation(k_folds=kfolds))
            if save:
                self.model.save(self.model_file)
예제 #36
0
 def finish_scene(self):
     if (not self.write_log) and (not self.write_frames):
         return
     if self.join_index_and_run_in_log:
         name = self.frame_prefix + '%06d' % (self.index + self.run)
     else:
         name = self.frame_prefix + '%03d_%03d' % (self.index, self.run)
     # save log
     if self.write_log:
         filename = name + '.npz'
         with open(filename, 'wb') as file:
             np.savez_compressed(file,
                                 State_record=np.asarray(self.State_record),
                                 ego_id=self.ego_id,
                                 LengthWidth=self.LengthWidth,
                                 num_cars=self.num_cars,
                                 index=self.index,
                                 run=self.run,
                                 name=name)
     # make movie
     if self.write_frames:
         filename = name + '.mp4'
         self.visualizer = Visualizer(self.ego_id, self.LengthWidth[:, 0],
                                      self.LengthWidth[:, 1], self.num_cars,
                                      self.road)
         metadata = dict(title=name, artist='Pseudo', comment='')
         writer = FFMpegWriter(fps=2 * int(1. / Vehicle.DEL_T),
                               codec='libx264',
                               metadata=metadata,
                               extra_args=['-pix_fmt', 'yuv420p'])
         with writer.saving(self.visualizer.fig, filename,
                            self.visualizer.fig.dpi):
             for state in self.State_record:
                 self.visualizer.update(state[:, :3])
                 writer.grab_frame()
         Scenario.flip_video(filename)
예제 #37
0
    def __init__(self):

        super(MainWindow, self).__init__()

        self.scene = QGraphicsScene()

        # Scene is the parent of the view in order to show the graphical items.
        # the View must also be the parent of the scene in order to avoid
        # bizarre segmentation faults with GTK
        self.view = InteractiveView(self.scene)
        self.scene.setParent(self.view)

        self.setCentralWidget(self.view)
        self.view.setSceneRect(INT_MIN/2, INT_MIN/2, INT_MAX, INT_MAX)
        self.view.centerOn(0, 0)

        self.visualizer = Visualizer(self.scene)
        self.visualizer.update_processes_data()

        # Set a dark background color
        back_color = QColor(25, 20, 45)
        self.view.setBackgroundBrush(QBrush(back_color))
예제 #38
0
    def setUp(self):
        self.autoseed = random.randint(0, 9999999999)
        self.seed = self.RAND_SEED
        if not self.seed:
            self.seed = self.autoseed
        self.myRandom = random.Random(self.seed)

        self.peer_controller = None

        self.peers = [self.create_peer("P%d" % i, "127.0.0.1", 8500 + i) for i in range(self.NO_OF_PEERS)]

        self.peer_controller = PeerController(
            self.peers, self.WORLD_SIZE, self.TOP_SPEED, self.MAX_SPEED_CHANGE, self.RADIO_RANGE, rand_seed=self.seed
        )

        # Start router
        self.router = Router("127.0.0.1", 8300, self.peers, self.peer_controller, self.USE_TICKS)
        self.router.start()
        self.ensure_peers_ready(self.peers)
        self.router.activate_queue()

        if self.VISUALIZE:
            self.visualizer = Visualizer(self.peers, self.peer_controller)
            self.visualizer.visualize()
예제 #39
0
class PeerController():
    """The purpose of the class is to emulate a physical space to test range and effect of wireless communication.
    Average walking speed will be 1.4, which corresponds to 5 km/h. Maximal speed in this configuration is 7.12km/h"""

    def __init__(self, peers, worldSize, topSpeed, maxSpeedChange, radioRange, rand_seed = None):
        if not rand_seed:
            rand_seed = random.randint(0,9999999999)

        self.myRandom = random.Random(rand_seed)

        self.peers = peers
        self.peerLock = Lock()
        self.worldSize = worldSize
        self.TOP_SPEED, self.MAX_SPEED_CHANGE, self.RADIO_RANGE = topSpeed, maxSpeedChange, radioRange
        self.visualizer = None

        for peer in self.peers:
            peer.setLocation(self.generateNewPeerLocation())
            peer.setPeerController(self)

    def addPeer(self, peer):
        self.peers.append(peer)
        self.revisualize()

    def removePeer(self, peer):
        self.peers.remove(peer)
        if self.visualizer:
            self.visualizer.removePeer(peer)
        self.revisualize()

    def endVisualize(self):
        self.visualizer.close = True

    def revisualize(self):
        if self.visualizer:
            self.visualizer.redraw = True


    def visualize(self, block=True):
        if block:
            self._do_visualize()
        else:
            thread = threading.Thread(name="visualize", target=self._do_visualize, args=[])
            thread.setDaemon(True)
            thread.start()

    def _do_visualize(self):
        self.visualizer = Visualizer(self.peers, self)
        self.visualizer.visualize()

        
    def replacePeer(self, i, peer):
        with self.peerLock:
            oldPeer = self.peers[i]
            self.peers[i] = peer
        if self.visualizer:
            self.visualizer.removePeer(oldPeer)
        self.revisualize()

    def generateNewPeerLocation(self):
        x = self.myRandom.uniform(0, self.worldSize['width'])          # x coord of peer spawn
        y = self.myRandom.uniform(0, self.worldSize['height'])         # y coord of peer spawn
        vecX = self.myRandom.uniform(-self.TOP_SPEED, self.TOP_SPEED)  # x coord of peer speed vector
        vecY = self.myRandom.uniform(-self.TOP_SPEED, self.TOP_SPEED)  # y coord of peer speed vector
        return x, y, vecX, vecY

    def movePeers(self):
        with self.peerLock:
            for peer in self.peers:
                # Check the world bounds and flip the vector to avoid collision
                if peer.x + peer.vecX > self.worldSize['width'] or peer.x + peer.vecX < 0:
                    peer.vecX = -peer.vecX
                if peer.y + peer.vecY > self.worldSize['height'] or peer.y + peer.vecY < 0:
                    peer.vecY = -peer.vecY

                # Move
                peer.x += peer.vecX
                peer.y += peer.vecY

                # Change the vector to change speed and direction of peer
                peer.vecX = self.myRandom.uniform(
                    -self.TOP_SPEED if peer.vecX < -self.TOP_SPEED + self.MAX_SPEED_CHANGE else peer.vecX - self.MAX_SPEED_CHANGE,
                    self.TOP_SPEED if peer.vecX > self.TOP_SPEED - self.MAX_SPEED_CHANGE else peer.vecX + self.MAX_SPEED_CHANGE)
                peer.vecY = self.myRandom.uniform(
                    -self.TOP_SPEED if peer.vecY < -self.TOP_SPEED + self.MAX_SPEED_CHANGE else peer.vecY - self.MAX_SPEED_CHANGE,
                    self.TOP_SPEED if peer.vecY > self.TOP_SPEED - self.MAX_SPEED_CHANGE else peer.vecY + self.MAX_SPEED_CHANGE)
        self.revisualize()

    def findPeersInRange(self, peer):
        with self.peerLock:
            # print()
            # if peer.color:
            #     print('Finding peers in range of ' + peer.name + '(' + peer.color + ')')
            # else:
            #     print('Finding peers in range of ' + peer.name)
            peersInRange = []
            meX = peer.x
            meY = peer.y
            for opeer in self.peers:
                if opeer:
                    if math.pow(meX - opeer.x, 2) + math.pow(meY - opeer.y, 2) < math.pow(self.RADIO_RANGE, 2):
                        #if opeer.color:
                            #    print(opeer.name + '(' + opeer.color + ') is in range')
                        #else:
                        #    print(opeer.name + ' is in range')
                        peersInRange.append(opeer)

            return peersInRange

    def findPeersInRangeOutputToTerm(self, peer):
        with self.peerLock:
            print()
            if peer.color:
                print('Finding peers in range of ' + peer.name + '(' + peer.color + ')')
            else:
                print('Finding peers in range of ' + peer.name)
            peersInRange = []
            meX = peer.x
            meY = peer.y
            for opeer in self.peers:
                if opeer:
                    if math.pow(meX - opeer.x, 2) + math.pow(meY - opeer.y, 2) < math.pow(self.RADIO_RANGE, 2):
                        if opeer.color:
                            print(opeer.name + '(' + opeer.color + ') is in range')
                        else:
                            print(opeer.name + ' is in range')
                        peersInRange.append(opeer)
            return peersInRange
예제 #40
0
 def _do_visualize(self):
     self.visualizer = Visualizer(self.peers, self)
     self.visualizer.visualize()
예제 #41
0
from socket import *
from Visualizer import Visualizer

def socketHandler(client, addr, vis):
    pass

if __name__ == '__main__':
    HOST = 'localhost'
    PORT = 1234
    BUFSIZE = 1024
    serversock = socket(AF_INET, SOCK_STREAM)
    serversock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
    serversock.bind((HOST, PORT))
    serversock.listen(1)

    print 'Waiting for client'
    clientsock, addr = serversock.accept()
    print 'Client connected from:', addr

    vis = Visualizer(clientsock)
    vis.start()
    
    # does it ever get here
    print 'Closing socket connection.'
    serversock.shutdown(1)
    serversock.close()
예제 #42
0
def train(network, minibatch_size=5000, data_size=50000, n_epochs=60, shapeInput=(7, 7), data_iterator=DataLoader.iterate_cifar, load_previous=False):
    visualizer = Visualizer()
    errors_train = []
    errors_train_vector = []
    errors_test = []
    errors_test_vector = []
    sparsity_train = []
    sparsity_test = []
    currenti = 0
    if load_previous:
        try:
            state = pickle.load(open('network_state.pkl', 'rb'))
            network.weights = state[0]
            currenti = state[1] + 1
            errors_train = state[2]
            errors_train_vector = state[3]
            sparsity_train = state[4]
            errors_test = state[5]
            errors_test_vector = state[6]
            sparsity_test =  state[7]
            np.random.set_state(state[8])
            network.learning_rate = state[9]
            network.output_average = state[10]
            network.norm_limit = state[11]
            print('Reloading previous state')
        except:
            print('Starting from random weights')
    queue_train, queue_test = data_loading(minibatch_size, data_iterator, shapeInput, n_epochs-currenti)
    for i in range(currenti, n_epochs):
        print("----Epoch %i----" % i)
        total_error_train = 0
        total_error_train_vector = np.zeros_like(network.get_reconstruction_error_vector())
        total_sparsity_train = 0
        total_error_test = 0
        total_error_test_vector = np.zeros_like(network.get_reconstruction_error_vector())
        total_sparsity_test = 0
        t1 = time.time()
        j = 0
        for k in range(data_size/minibatch_size):
            new_input = queue_train.get()
            new_input_test = queue_test.get()
            for m in range(new_input.shape[0]):
                j += 1
                # train, update network
                network.update(new_input[m], train=True)
                # update statistics train
                total_error_train += network.get_reconstruction_error()
                total_error_train_vector += network.get_reconstruction_error_vector()
                total_sparsity_train += network.get_sparsity_error_term()
                # test, not modify weights
                network.update(new_input_test[m], train=False)
                # update statistics test
                total_error_test += network.get_reconstruction_error()
                total_error_test_vector += network.get_reconstruction_error_vector()
                total_sparsity_test += network.get_sparsity_error_term()

            print(i, j, total_error_train / j, total_sparsity_train / float(j))
            visualizer.saveNetworkPlots(network, i, calc_error_surface=False)
        if i % 1 == 0:  # measure only sometimes
            errors_train += [total_error_train / j]
            errors_train_vector += [total_error_train_vector / j]
            sparsity_train += [total_sparsity_train / float(j)]
            errors_test += [total_error_test / j]
            errors_test_vector += [total_error_test_vector / j]
            sparsity_test += [total_sparsity_test / float(j)]
            print(i, total_error_train / j, total_sparsity_train / float(j))
        print(time.time()-t1)
        if i % 1 == 0:
            pickle.dump((network.weights, i, errors_train, errors_train_vector, sparsity_train, errors_test,
                         errors_test_vector, sparsity_test, np.random.get_state(), network.learning_rate, network.output_average,
                         network.norm_limit), open('network_state.pkl', 'wb'))
            visualizer.saveFinalPlots(errors_train, errors_test, sparsity_train, sparsity_test, errors_train_vector, errors_test_vector, epoch=i)
            visualizer.saveNetworkPlots(network, i, calc_error_surface=True)
        if i > 0: # update learning rate
            previous_error = errors_train[i-1]
            if not errors_train[i]*1.01 < previous_error:
                network.learning_rate*=0.9
                print('New learning rate: ', network.learning_rate)

    print("Training END")
예제 #43
0
from MazeMap import MazeMap
from AStarPlanner import AStarPlanner
from Visualizer import Visualizer
from Position import Position
from Direction import Direction
from maze import Maze
import sys
from GoalHeuristic import GoalHeuristic

if __name__ == '__main__':
    file_path = str(sys.argv[1])
    maze_map = MazeMap(file_path=file_path)
    maze = Maze(file_path)
    planner = AStarPlanner(maze_map, GoalHeuristic(maze.dim))
    vis = Visualizer(maze_map.dim)
    start_pos = Position(0,0)
    start_head = Direction(0)
    planner.replan(start_pos, start_head)
    vis.draw_maze(maze)
    vis.draw_policy(reversed(planner.policy), start_pos, start_head)
    print "Number of moves: ", len(planner.policy)
    vis.show_window()
 def run(self):
     drawer = Visualizer()
     while True:
         for key in self.robots:
             robot = self.robots[key]
             if self.running:
                 print "update"
                 self.update_robot(robot, delta)
                 self.send_updated_position(robot)
             drawer.draw_robot(robot)
         if self.running:
             self.update_ball()
         drawer.draw_ball(self.ball)
         drawer.plot_field()
         drawer.draw()
         time.sleep(0.1)
         drawer.clear()
예제 #45
0
파일: Sim.py 프로젝트: osurdml/flame2.0
#Frontier simulator 
from FrontierController import FrontierController
from TestAgent import TestAgent
from FarsiteProducer import FarsiteProducer
from TestScorer import TestScorer
from Visualizer import Visualizer
from HotspotFilter import HotspotFilter
from FovFilter import FovFilter
import time

agent1 = TestAgent()
agent2 = TestAgent()
frontierFilter = HotspotFilter()
agentFilter = FovFilter()

frontierProducer = FarsiteProducer()
scorer = TestScorer()
i = 0
frontierController = FrontierController(scorer,frontierProducer,[agent1, agent2], [frontierFilter, agentFilter])
visualizer = Visualizer()

while(i < 10000): #frontierController.hasData()):
    frontierController.tick()
    visualizer.vis(frontierController.frontierData, frontierController.agentLocations) # ,frontierController.fov, frontierController.AgentLoc)
    i = i +1
예제 #46
0
try:
	opts, args = getopt.getopt(sys.argv[1:], "hcsv", \
                 ["help", "calculate", "simulate", "visualize"])
except getopt.GetoptError:
	usage()
	sys.exit(2)

if len(sys.argv) == 1:
	usage()
	sys.exit()

for opt, arg in opts:
	if opt in ("-h", "--help"):
		usage()
		sys.exit()
	elif opt in("-c", "--calculate"):
		try:
			call("pypy Simulation.py", shell = True)
		except: #pypy not found I guess
			Simulate().start_calculation()
	elif opt in("-s", "--simulate"):
		vis = Visualizer()
		vis.show_real_time()
	elif opt in("-v", "--visualize"):
		vis = Visualizer()
		vis.show_from_file()
	else:
		usage()
		sys.exit()
예제 #47
0
        taxiHelper.setDebugCabTripIds(TRAJ_DEBUG_SPECS)
        taxiHelper.createTrajectories(hwynet, TAXI_OUTFILE, 'trip_points', 'trajectories') 
        taxiHelper.closeDebugFile()
        print 'Finished creating taxi trajectories in ', (datetime.datetime.now() - startTime)

    # calculate means and such
    if 'timeAgg' in STEPS_TO_RUN: 
        startTime = datetime.datetime.now()   
        taxiHelper.aggregateLinkTravelTimes(TAXI_OUTFILE, 'trajectories', 'link_tt')            
        print 'Finished aggregating link travel times in ', (datetime.datetime.now() - startTime)

    # create network vizualizations
    if 'viz' in STEPS_TO_RUN:
        startTime = datetime.datetime.now()  
        if (hwynet==None): 
            hwynet = HwyNetwork()
            hwynet.readDTANetwork(INPUT_DYNAMEQ_NET_DIR, INPUT_DYNAMEQ_NET_PREFIX, logging_dir=LOGGING_DIR) 
        vizualizer = Visualizer(hwynet, TAXI_OUTFILE)
        
        # network speed maps
        vizualizer.createNetworkPlot(VIZ_OUTFILE, date=VIZ_DATE, hour=VIZ_HOUR)  
        
        # individual trajectory plots
        vizualizer.plotTrajectories(TRAJ_VIZ_OUTFILE, trajSpecs=TRAJ_VIZ_SPECS)  
          
        print 'Finished vizualizing data in ', (datetime.datetime.now() - startTime)
        
    
    print 'Run complete!  Time for a pint!'
    # Alex is doing something funny.  Blame him when it breaks. 
    
예제 #48
0
class P2PTestCase(unittest.TestCase):
    NO_OF_PEERS = 1
    VISUALIZE = False

    # Simulation params
    TOP_SPEED = 140
    MAX_SPEED_CHANGE = 50
    RADIO_RANGE = 500
    WORLD_SIZE = {"width": 2000, "height": 2000}  # in centimeters
    USE_TICKS = False
    CLOCK_SYNC = False
    MANUAL_OVERRIDE = True
    RAND_SEED = None

    def setUp(self):
        self.autoseed = random.randint(0, 9999999999)
        self.seed = self.RAND_SEED
        if not self.seed:
            self.seed = self.autoseed
        self.myRandom = random.Random(self.seed)

        self.peer_controller = None

        self.peers = [self.create_peer("P%d" % i, "127.0.0.1", 8500 + i) for i in range(self.NO_OF_PEERS)]

        self.peer_controller = PeerController(
            self.peers, self.WORLD_SIZE, self.TOP_SPEED, self.MAX_SPEED_CHANGE, self.RADIO_RANGE, rand_seed=self.seed
        )

        # Start router
        self.router = Router("127.0.0.1", 8300, self.peers, self.peer_controller, self.USE_TICKS)
        self.router.start()
        self.ensure_peers_ready(self.peers)
        self.router.activate_queue()

        if self.VISUALIZE:
            self.visualizer = Visualizer(self.peers, self.peer_controller)
            self.visualizer.visualize()

    def tearDown(self):
        for peer in self.peers:
            peer.kill()
        self.router.shutdown()

        # print("SEED: " + str(self.seed))

    def tick(self, num_msgs=1):
        self.router.tick(num_msgs)

    def wait_nw_idle(self):
        self.router.wait_queue_empty()

    def assertContains(self, msg, msg_part):
        try:
            self.assertTrue(msg_part in msg)
        except AssertionError:
            raise AssertionError("Msg: %s does not contain %s" % (msg, msg_part))

    def assertNotContains(self, msg, msg_part):
        try:
            self.assertFalse(msg_part in msg)
        except AssertionError:
            raise AssertionError("Msg: %s does  contain %s" % (msg, msg_part))

    def create_peer(self, name, host, port):
        peer = PeerHandler(name, host, port, self.MANUAL_OVERRIDE, self.CLOCK_SYNC)
        if self.peer_controller:  # Not set on first setup
            peer.setLocation(self.peer_controller.generateNewPeerLocation())
            peer.setPeerController(self.peer_controller)

        if peer.process.returncode is not None:
            raise Exception("Peer " + peer.name + " quit immediately ")
        return peer

    def ensure_peers_ready(self, peers):
        for peer in peers:
            peer.expect_ready(20)

    def has_song_with_votes_in_playlist(self, playlist, song):
        for playlistitem in playlist:
            if playlistitem["song_name"] == song:
                if len(playlistitem["votes"]) > 0:
                    return True
                return False
        return False

    def assert_song_in_playlist(self, playlist, song):
        self.assertTrue(
            self.has_song_with_votes_in_playlist(playlist, song), "Song " + song + " was expected in playlist"
        )