Esempio n. 1
0
    def testTraffic(self):
        try:
            df_File = pd.read_csv("List_of_Data_Set.csv")
            os.system('mkdir Result')
            for i in df_File.index:
                df = pd.read_csv(df_File["Input_File_Name"][i])
                t1 = df_File["Input_File_Name"][i].split('/')
                t3 = t1[-1].split('.')
                t4 = str(t3[0])
                path = os.path.join("Result/", t4)
                os.mkdir(path)
                # os.chdir(path)
                df["Speed (GPS)(km/h)"] = \
                    df["Speed (GPS)(km/h)"].astype("float")
                HC, MC, LC = Traffic.traffic(
                    df["Speed (GPS)(km/h)"].replace('-', 0),
                    df[' Latitude'], df[' Longitude'])
                t = df["Speed (GPS)(km/h)"]
                t2 = t.replace(to_replace='-', value=0)
                plt.figure(1)
                plt.plot(HC.loc[:, 'Longitude'], HC.loc[:, 'Latitude'], 'r.')
                plt.plot(MC.loc[:, 'Longitude'], MC.loc[:, 'Latitude'], 'b.')
                plt.plot(LC.loc[:, 'Longitude'], LC.loc[:, 'Latitude'], 'g.')
                plt.title("Congestion Location")
                plt.savefig(path + "/Congestion Location" + '.png')

                plt.figure(2)
                plt.plot(HC.loc[:, 'Speed'], HC.loc[:, 'Index'], 'r.')
                plt.plot(MC.loc[:, 'Speed'], MC.loc[:, 'Index'], 'b.')
                plt.plot(LC.loc[:, 'Speed'], LC.loc[:, 'Index'], 'g.')
                plt.title("Speed vs Index")
                plt.savefig(path + "/Speed vs Index" + '.png')

                plt.figure(3)
                """plt.plot(HC.loc[:, 'Latitude'], HC.loc[:, 'Index'], 'r.')
                plt.plot(MC.loc[:, 'Latitude'], MC.loc[:, 'Index'], 'b.')
                plt.plot(LC.loc[:, 'Latitude'], LC.loc[:, 'Index'], 'g.')"""
                plot1('Latitude','Longitude','r.',HC)
                plot1('Latitude','Longitude','b.',MC)
                plot1('Latitude','Longitude','g.',LC)
                plt.title("Latitude vs Index")
                plt.savefig(path + "/Latitude vs Index" + '.png')

                plt.figure(4)
                plt.plot(HC.loc[:, 'Longitude'], HC.loc[:, 'Index'], 'r.')
                plt.plot(MC.loc[:, 'Longitude'], MC.loc[:, 'Index'], 'b.')
                plt.plot(LC.loc[:, 'Longitude'], LC.loc[:, 'Index'], 'g.')
                plt.title("Longitude vs Index")
                plt.savefig(path + "/Longitude vs Index" + '.png')

        # os.system('cd..')

        except AssertionError as e:
            f = open("Difference_Report_Speed_Voilation", "a")
            f.write("TestCase_no_0:\n\t" + str(e) + " \n")
Esempio n. 2
0
    def __init__(self, w, h, title):
        prgm_start_time = time.time()

        super(myGame, self).__init__(w, h, title)

        self.cars = []
        self.traffics = Traffic.Traffic()

        self.from_bottom = [] # start_road == 0
        self.from_left = [] # start_raod == 1
        self.from_up = [] # start_road == 2
        self.from_right = [] # start_road == 3

        self.init_cars()
        self.init_traffics()

        self.avg_latency = 0
        self.traffic_times = 0
Esempio n. 3
0
    def do_source_sink(self, cmd):
        try:
            secs = int(cmd[1])
            if secs > MAX_SOURCESINK_TIME:
                secs = MAX_SOURCESINK_TIME
                self.wfile.write("warn Using test time %d instead of %s\n" %
                                 (secs, cmd[1]))
        except:
            raise ControlProtocolError("Bad %s arguments" % cmd[0])

        ts = Traffic.TrafficSock()
        self.test_start_time = time.time()
        self.kill_test = self.kill_source_sink
        self.kill_test_args = (ts, )
        if not self.test_list_add():
            self.kill_test = None
            self.kill_test_args = None
            return
        self.test_start_time = time.time(
        )  # don't short test their queueing time

        try:
            try:
                testrange_bind(ts.sock, self.request.getsockname()[0])
                ts.sock.listen(1)
                self.wfile.write("listen %s %d\n" %
                                 (ts.sock.getsockname()[0:2]))
            except Exception, e:
                self.wfile.write("warn While binding socket, got error: %s\n" %
                                 e)
                raise e

            try:
                ts.passive_open(self.client_address[0])
                if cmd[0] == "test_sink":
                    ts.sink(maxtime=secs)
                else:
                    ts.source(maxtime=secs)
                ts.sock.close()
            except:
                self.wfile.write("warn Got exception while running test\n")
            self.wfile.write("report none\n")
Esempio n. 4
0
import Traffic

Traffic.start()
Esempio n. 5
0
def game(screen):

	background = pygame.Surface(screen.get_size())
	background = background.convert_alpha()
	background.fill((26, 26, 26))
	font = pygame.font.Font(None, 24)


	done = False
	clock = pygame.time.Clock()
	player = Player()
	camera = Camera()


	player_s 	= pygame.sprite.Group() # Handles player movements and updates
	map_s 		= pygame.sprite.Group() # Handles map movements
	traffic_s 	= pygame.sprite.Group()
	police_s 	= pygame.sprite.Group()

	for i in range(0, 5):
		traffic_s.add(Traffic())
		police_s.add(Police())


	# Load map files
	for tile in range(0, len(Map.map_tiles)):
		Map.map_files.append(pygame.image.load('resources/' + Map.map_tiles[tile]))
	# Create map
	for x in range(0, 10):
		for y in range(0, 10):
			map_s.add(Map.Map(Map.map_1[x][y], x * 1000, y * 1000, Map.map_1_rot[x][y]))


	player_s.add(player)
	camera.setCam(player.x, player.y)

	w_center = int(pygame.display.Info().current_w/2)
	h_center = int(pygame.display.Info().current_h/2)

	initTraf(w_center, h_center)

	while not done:
		for event in pygame.event.get(): # User did something
			if event.type == pygame.QUIT: # If user clicked close
				done=True	

		screen.blit(background, (0,0))


		map_s.update(camera.x, camera.y)
		map_s.draw(screen)

		# Check driving surface
		carGround = screen.get_at((w_center, h_center))
		player.handle_keys()	
		player.update_player(carGround)
		camera.setCam(player.x, player.y)

		player_s.update(camera.x, camera.y)
		player_s.draw(screen)

		traffic_s.update(camera.x, camera.y)
		traffic_s.draw(screen)

		police_s.update(camera.x, camera.y)
		police_s.draw(screen)


		text_fps = font.render('FPS: ' + str(int(clock.get_fps())), 1, (224, 16, 16))
		textpos_fps = text_fps.get_rect(centery=25, centerx=60)
		screen.blit(text_fps, textpos_fps)
		
		text_boost = font.render('BOOST: ', 1, (0, 0, 250))
		textpos_boost = text_boost.get_rect(centery=pygame.display.Info().current_h-65, centerx=pygame.display.Info().current_w-235)
		screen.blit(text_boost, textpos_boost)
		pygame.draw.rect(screen, (0, 0, 250), player.boostBar())

		text_speed = font.render("SPEED: " + str(player.velocity), 1, (224, 16, 16))
		textpos_speed = text_speed.get_rect(centery=40, centerx=60)
		screen.blit(text_speed, textpos_speed)



		pygame.display.flip()

		clock.tick(50)
Esempio n. 6
0
 def __init__(self):
     self.traffic = Traffic.QNTraffic()
Esempio n. 7
0
#DIAEngineAnalysis.LoadAnalysis(EngineLoad,EngineRPM,VehicleSpeed, TripTime)

# Feature 2
print("\nFeature 2 :")
Lean, Rich, Nrml = DIAFuelMixture.FuelMixture(O2_Volts)
print("No. of instances of Lean mixture: ", Lean.size / 2)
print("No. of instances of Rich mixture: ", Rich.size / 2)
print("No. of instances of Nrml mixture: ", Nrml.size / 2)
#.plot(Lean)
#DistAvg.AverageDistance(Distance, Fuel, Kmpl)

# Feature 3
print("\nFeature 3 : Shown in plots")
Pothole.pothole()
SpeedBreaker.pothole()

# Feature 4
print("\nFeature 4 :")
SpeedVoilation = DIASpeedVoilation.SpeedVoilation(VehicleSpeed, Latitude,
                                                  Longitude, ThresholdSpeed)
print("\nSpeed violations have occurred at the following locations: ")
print(SpeedVoilation)

# Feature 5
print("\nFeature 5 :")
Traffic.traffic(VehicleSpeed, Latitude, Longitude)

# Feature 6
print("\nFeature 6 :")
DIARashDriving.detect_rash_driving(df, pos_d, pos_e, Threshold_Rash_driving)
Esempio n. 8
0
        print("Thread test start %s (queue time %d)" % (relative, qtime))

        # open a per run logfile
        logf = open(log_file + ".out", "w")
        logf.write("Start")

        pid = -1
        try:

            (r, w) = os.pipe()
            pid = os.fork()
            if pid == 0:
                try:
                    # Create a socket on an ephemeral port for pathdiag
                    # we do this first, so print goes to the shared log
                    ts = Traffic.TrafficSock()
                    testrange_bind(ts.sock, self.request.getsockname()[0])

                    # Set up stdout/err to the pipe.  All further output goes to the cleint
                    os.dup2(w, 1)
                    os.dup2(w, 2)
                    os.close(w)

                    # listen and tell the client
                    ts.sock.listen(1)
                    self.wfile.write("listen %s %d\n" %
                                     (ts.sock.getsockname()[0:2]))
                    ts.passive_open(self.client_address[0])

                    # don't hold the listen FD in case we are going to be restarted
                    #					os.close(self.socket.fileno())