Esempio n. 1
0
def get_plate_data_from_file_with_multiple_plates(path, c):
    return thread_first(
        path, open, file.read, (str.replace, '\r', ''),
        (str.split, c['plate_delimiter']), tail, map(StringIO),
        map(pd.read_csv(delimiter=c['delimiter'],
                        skiprows=c['skiprows'])), pd.concat,
        df.dropna(axis=1, how='all'), (drop_matching_columns, c['dropcols']),
        df.rename(columns=c['colrename']),
        (add_normalized_columns, c['normcols']))
def main():
	print("Calculating MAP for exercise 1")
	predictedSum = getPredictedSummariesEx1()
	relevantSum = getRelevantSummaries()
	MAP = map(predictedSum, relevantSum)
	print('Mean Average Precision:', MAP)

	print("Calculating MAP for exercise 2")
	predictedSum = getPredictedSummariesEx2()
	relevantSum = getRelevantSummaries()
	MAP = map(predictedSum, relevantSum)
	print('Mean Average Precision:', MAP)
Esempio n. 3
0
def get_plate_data_from_file_with_multiple_plates(path,c):
    return thread_first(path,
                        open,
                        file.read,
                        (str.replace,'\r',''),
                        (str.split,c['plate_delimiter']),
                        tail,
                        map(StringIO),
                        map(pd.read_csv(delimiter=c['delimiter'], skiprows=c['skiprows'])),
                        pd.concat,
                        df.dropna(axis=1,how='all'),
                        (drop_matching_columns,c['dropcols']),
                        df.rename(columns=c['colrename']),
                        (add_normalized_columns,c['normcols']))
Esempio n. 4
0
    def normalizePrices(self):
        highs = self.get('highs')
        lows = self.get('lows')
        closes = self.get('closes')
        opens = self.get('opens')
        new_highs = utils.map(highs, self.__flattenNonesPrice)
        new_lows = utils.map(lows, self.__flattenNonesPrice)
        new_opens = utils.map(opens, self.__flattenNonesPrice)
        new_closes = utils.map(closes, self.__flattenNonesPrice)

        self.set('highs', new_highs)
        self.set('lows', new_lows)
        self.set('opens', new_opens)
        self.set('closes', new_closes)
Esempio n. 5
0
 def setAvgVolume(self):
     volumes = self.get('volumes')
     new_vols = utils.map(volumes, self.__zeroNonesVol)
     self.set('volumes', new_vols)
     avg = utils.average(new_vols)
     self.set('avg_volume', avg)
     return avg
 def getIntensity(self, lampValues):
     """produce the values needed for each lamp"""
     returnList = []
     for value in lampValues:
         for propN, prop in enumerate(self.lightIntensityOn):
             returnList.append(utils.map(value, 0, 255, self.lightIntensityOff[propN], prop))
     return returnList
Esempio n. 7
0
def getCategoryList (q=None, shouldUpdateDb=True):
    "Query traditionally for multiple categorys.";
    q = q or {};
    assert type(q) is dict;
    adaptWrapper = lambda category: (                                       # A wrapper around `adapt`, aware of `shouldUpdateDb`.
        categoryAdp.adapt(category, shouldUpdateDb)#, # NO COMMA
    );
    return utils.map(adaptWrapper, db.categoryBox.find(q));
Esempio n. 8
0
def getDojoList(q=None, shouldUpdateDb=True):
    "Query traditionally for multiple dojos."
    q = q or {}
    assert type(q) is dict
    adaptWrapper = lambda dojo: (  # A wrapper around `adapt`, aware of `shouldUpdateDb`.
        dojoAdp.adapt(dojo, shouldUpdateDb)  #, # NO COMMA
    )
    return utils.map(adaptWrapper, db.dojoBox.find(q))
Esempio n. 9
0
def getUserList(q=None, shouldUpdateDb=True):
    "Query traditionally. No special treatment for emails."
    q = q or {}
    assert type(q) is dict
    adaptWrapper = lambda user: (  # A wrapper around `adapt`, aware of `shouldUpdateDb`.
        userAdp.adapt(user, shouldUpdateDb)  #, # NO COMMA
    )
    return utils.map(adaptWrapper, db.userBox.find(q))
Esempio n. 10
0
def getArticleList(q=None, shouldUpdateDb=True):
    "Query traditionally for multiple articles."
    q = q or {}
    assert type(q) is dict
    adaptWrapper = lambda article: (  # A wrapper around `adapt`, aware of `shouldUpdateDb`.
        articleAdp.adapt(article, shouldUpdateDb)  #, # NO COMMA
    )
    return utils.map(adaptWrapper, db.articleBox.find(q))
Esempio n. 11
0
def post_userCon_fetchUserList():
    sesh = auth.getSesh()
    userList = userMod.getUserList()
    #print("userList = ", userList);
    snippedUserList = utils.map(userList, userMod.snipUser)
    #print("snippedUserList = ", snippedUserList);
    return {
        "userList": snippedUserList
    }
def main():
    classifier = trainPerceptron()
    weightsList = []
    for weight in classifier.coef_[0]:
        weightsList.append(weight)

    predictedSum = getPredictedSummariesEx3(weightsList)
    relevantSum = getRelevantSummaries()
    MAP = map(predictedSum, relevantSum)
    print('Mean Average Precision:', MAP)
Esempio n. 13
0
 def generateOpenSimplex(self):
     self.generatePlain()
     for i in range(0, utils.chunk_size):
         for k in range(0, utils.chunk_size):
             value = utils.map(
                 utils.simplex2d(
                     (self.position.x * utils.chunk_size + i) * 0.025,
                     (self.position.z * utils.chunk_size + k) * 0.025), -1,
                 1, 0, utils.chunk_size)
             for j in range(0, int(value)):
                 self.placeBlockAt(i, j, k, BlockType.GRASS)
def get_article_urls(query='', page=0):
    yielded = []
    url = 'https://www.hmetro.com.my/search?s={}{}'.format(
        query, ''
        if page == 0 or not isinstance(page, int) else '&page={}'.format(page))
    for url in filter(
            map(filter(open_soup(url).find_all('a'), has_key('href')),
                get_key('href')), text_match(r'^/.+?/\d{4}/\d{2}/\d{6}/.+$')):
        url = 'https://www.hmetro.com.my{}'.format(url)
        if url in yielded: continue
        yielded.append(url)
        yield page, url, get_article(open_soup(url))
Esempio n. 15
0
def home():
    request.headers.environ["X_FORWARDED_FOR"] = "54.39.138.153"
    proxies = utils.map(request.headers.environ, http_headers)
    print(request.headers.environ.get("HTTP_USER_AGENT"))
    print("Are proxies enabled - " + str(proxies))
    print(request.headers)
    opened_ports = portscan.scan(request.headers.environ.get("REMOTE_ADDR"))
    return render_template(
        'index.html',
        using_proxies=proxies,
        user_agent=request.headers.environ.get("HTTP_USER_AGENT"),
        language=request.headers.environ.get("HTTP_ACCEPT_LANGUAGE"),
        opened_ports=opened_ports,
        title='Home Page',
        year=datetime.now().year,
    )
Esempio n. 16
0
    def step(self, tick):
        # if self.target == self.master.ball.location:
        # 	self.master.ball.step(tick)
        # 	self.target = self.master.ball.location

        # if self.agent.team == 0: print(utils.steer(self.target, self.car), utils.angle2D(self.target, self.car), self.target.tuple, self.car.location.tuple)

        # self.controls.yaw = utils.steer(self.target, self.car)
        self.controls.throttle, self.controls.boost = utils.throttle(
            self.car, self.speed)

        turn_radius = utils.turn_radius(self.car, self.target)
        angle_to_target = utils.angle2D(self.target, self.car)

        point = utils.point_on_circle(self.car,
                                      utils.sign(angle_to_target) * math.pi /
                                      2, turn_radius)  #, self.car.rotation)
        circle = []
        for i in range(0, 366, 6):
            n = utils.point_on_circle(point, math.radians(i),
                                      turn_radius)  #, point.rotation)
            circle.append(n.tuple)
        self.agent.renderer.draw_polyline_3d(circle, self.agent.renderer.red())

        # ball_prediction = self.agent.get_ball_prediction_struct()
        # if ball_prediction is not None:
        # 	# for i in range(0, ball_prediction.num_slices):
        # 	if self.target == self.master.ball.location:
        # 		self.target = structs.Vector3(ball_prediction.slices[10].physics.location)
        # 		turn_radius = utils.turn_radius(self.car, self.target)

        # goal_to_ball_uv = (self.agent.game_info.their_goal.location - self.agent.game_info.ball.location).normalize()
        # yaw = math.atan2(goal_to_ball_uv.x, goal_to_ball_uv.z) #math.atan((goal_to_ball_uv.x/(-goal_to_ball_uv.y)))#
        # pitch = 0#math.atan(math.hypot(goal_to_ball_uv.x, goal_to_ball_uv.y)/goal_to_ball_uv.z)

        # target_ang = structs.Rotator(pitch, yaw, 0)

        # circle_point = utils.point_on_circle(self.target, math.pi/2, turn_radius, target_ang)
        # circle = []
        # for i in range(0, 366, 6):
        # 	n = utils.point_on_circle(circle_point, math.radians(i), turn_radius)
        # 	circle.append(n.tuple)
        # self.agent.renderer.draw_polyline_3d(circle, self.agent.renderer.black())

        # x1 = point.x
        # y1 = point.y
        # x2 = circle_point.x
        # y2 = circle_point.y

        # gamma = -math.atan((y2-y1)/(x2-x1))
        # beta = math.asin((turn_radius-turn_radius)/math.sqrt((x2-x1)**2 + (y2-y1)**2))
        # alpha = gamma-beta

        # x3 = x1 - turn_radius*math.cos((math.pi/2)-alpha)
        # y3 = y1 - turn_radius*math.sin((math.pi/2)-alpha)
        # x4 = x2 + turn_radius*math.cos((math.pi/2)-alpha)
        # y4 = y2 + turn_radius*math.sin((math.pi/2)-alpha)

        # tang1 = structs.Vector3(x3, y3, 100)
        # tang2 = structs.Vector3(x4, y4, 100)

        # if self.last_target_ang != target_ang:
        # 	print('ye')
        # 	self.cur_hit = 0
        # 	self.last_target_ang = target_ang

        # self.to_hit = [tang1, tang2, self.agent.game_info.ball.location]

        # self.agent.renderer.draw_rect_3d(self.to_hit[0].tuple, 20, 20, True, self.agent.renderer.black())
        # self.agent.renderer.draw_rect_3d(self.to_hit[1].tuple, 20, 20, True, self.agent.renderer.black())

        # point_to_target = utils.distance2D(self.target, point)
        # if point_to_target < turn_radius:
        # 	#inside circle
        # 	if abs(utils.angle2D(self.target, self.car)) < math.pi/2:
        # 		to_target = utils.localize(self.target, self.car).normalize(turn_radius)
        # 		self.target = self.car.location - to_target
        # 		self.controls.boost = 0
        # 		self.controls.throttle = 0
        # 	else:
        # 		to_target = utils.localize(self.target, self.car).normalize(turn_radius)
        # 		self.target = self.car.location - to_target
        # 		self.controls.boost = 0
        # 		self.controls.handbrake = 1

        # point2 = structs.Vector3(x,y,z)

        # self.agent.renderer.draw_rect_3d(point.tuple, 10, 10, True, self.agent.renderer.blue())

        if isinstance(self.master, states.quickShoot):
            if self.path:
                if not self.path.on_path(self.car.location):
                    # self.path = None
                    print('yes')
                else:
                    curvetarget = self.path.evaluate(0.1)
                    curvetarget = structs.Vector3(curvetarget[0],
                                                  curvetarget[1], 0)
                    self.controls.steer = utils.steer(curvetarget, self.car)
                    self.agent.renderer.draw_rect_3d(
                        curvetarget.tuple, 10, 10, True,
                        self.agent.renderer.blue())
            if not self.path:
                b_prediction = self.agent.get_ball_prediction_struct()

                target = utils.find_point_on_line(
                    self.agent.game_info.their_goal.location, self.target,
                    -.05)
                self.path = structs.Path(self.agent, [
                    self.car.location,
                    utils.point_on_circle(self.car, 0, 500), 'TP', target,
                    self.target
                ], utils.sign(angle_to_target), self.car.rotation, self.car)

                angletotarget = utils.map(
                    abs(utils.angle2D(self.target, self.car)), 0, math.pi, 0,
                    math.pi)
                curvetarget = self.path.evaluate(0.1)
                curvetarget = structs.Vector3(curvetarget[0], curvetarget[1],
                                              0)
                self.agent.renderer.draw_rect_3d(curvetarget.tuple, 10, 10,
                                                 True,
                                                 self.agent.renderer.blue())

                self.controls.steer = utils.steer(curvetarget, self.car)

        elif utils.distance2D(point, self.target) < turn_radius:
            to_target = utils.localize(self.target,
                                       self.car).normalize(turn_radius)
            self.target = self.car.location - to_target
            self.controls.boost = False
            self.controls.steer = utils.steer(self.target, self.car)

        else:
            self.controls.steer = utils.steer(self.target, self.car)

        if self.path:
            # print(self.path.on_path(self.car.location))
            self.agent.renderer.draw_polyline_3d(
                self.path.get_path_points(np.linspace(0, 1.0, 100)),
                self.agent.renderer.green())
        self.agent.renderer.draw_rect_3d(self.target.tuple, 10, 10, True,
                                         self.agent.renderer.red())
        self.agent.renderer.draw_line_3d(self.car.location.flatten().tuple,
                                         self.target.flatten().tuple,
                                         self.agent.renderer.green())

        self.expired = True
        return self.controls
Esempio n. 17
0
import json

# PIP:
import bottle

# LOC:
import bu
from appDef import app
from constants import K
import utils
import emailer

# Install required netloc:
utils.map(app.install, [
    bu.mkPlugin_enforeSchemeAndNetloc(K.APP_SCHEME, K.APP_NETLOC),
    bu.plugin_frameDeny,
    bu.plugin_timer,
])

# Static routing (front/) & templating (views/):
for dirPath in K.STATIC_DIR_PATHS:
    bu.addStaticFolder(app, dirPath)
for dirPath in K.VIEW_DIR_PATHS:
    bu.addTemplateFolder(dirPath)
    # General, not app-specific.

# Add shortcuts:
bu.addShortcuts(app, K.SHORTCUT_MAP)

# Configure bottle-related:
bu.setMemfileMax(K.MEMFILE_MAX)
def get_article(soup):
    attribs = {'class': 'field-item even', 'property': 'content:encoded'}
    return '\n\n'.join(
        filter(map(soup.find('div', attribs).find_all('p'), lambda x: x.text),
               is_part_of_article))
    try:
        with open('latest_page.log', 'r') as file:
            latest_page = int(file.read())
    except:
        latest_page = 0  # 23

    with open('dbconfig.json', 'r') as file:
        config = json.loads(file.read())
    conn = mysql_connect(**config)

    for page, url, article in scrap(page=latest_page):
        # utama/2019/10/505232/datuk-red-enggan-cerai-adira
        match = find_matches(
            r'^https://www\.hmetro\.com\.my/(.+?)/(\d{4})/(\d{2})/(\d+?)/(.+)$',
            url)
        c, y, m, id, title = map(range(1, 6),
                                 lambda x: try_cast(match.group(x), int))
        cid = get_id_by_category(c)

        with open('article.txt', 'a', encoding='utf-8') as file:
            file.write('{}\n\n'.format(article))

        print('Got article from page {}: {}'.format(page, url))

        # ID, category_id, year, month, title, content
        # insert_into(
        # 	conn,
        # 	'INSERT INTO article (ID,category_id,year,month,title,content) VALUES (%s, %s, %s, %s, %s, %s)',
        # 	id, cid, y, m, title, article
        # )

        last_page = page
Esempio n. 20
0
def map(message):
    if message.chat.id != config.group_id:
        config.the_bot.forward_message(config.group_id, message.chat.id,
                                       message.message_id)
    utils.map(message.chat.id)
Esempio n. 21
0
		print Arduino.cue()
		while True:
			sender = []
			output =  Arduino.readSequence()
			print output
			for i in output:
				sender.append(int(i) * 83)
			EntTec.sendLights(pins,sender)
	elif mode == "boulez":
		IRCAM = IRCAM()
		IRCAM.connect('0.0.0.0',7007)
		while True:
			message = IRCAM.getMessage()
			if message != None:
				print "in" + str(message)
				message = map(message, 0, 90, 0, 63)
				#messages = [0] * 64
				for cN,channel in enumerate(messages):
					if channel != 0:
						messages[cN] -= 2
				message = clamp(message, 0, 63)
				messages[message] = 20
				#EntTec.senddmx(range(1,65),messages)
				EntTec.senddmx(range(1,65),messages)
	elif mode == "test":
		while True:
			IRCAM = IRCAM()
			IRCAM.connect('0.0.0.0',7007)

	elif mode == "test2":
		while True:
def engine_game(screen, get_data, decrease_lives):
    """
    This function handles the 'wheelie' minigame.
    - screen: pygame.display to draw to.
    - get_data: get_data function to retrieve data
                from the microbit.
    """
    global angle
    global angle_opponent
    global X
    global Y
    global car
    global background

    blow_points = 0
    old_blow_points = 0
    stage = 0

    # Load car sprite
    car = pygame.image.load("engine_files" + utils.sep +
                            "car.png").convert_alpha()

    # Car sprite's coordinates
    X = 600
    Y = utils.height - 20 - 320  # 320 is the sprite's height

    # Init engine temperature sprite
    temp_indicator = engine_files.engine_temp.EngineTemp()
    indicator_sprites = pygame.sprite.Group()
    indicator_sprites.add(temp_indicator)

    # Init smoke sprite
    smoke = engine_files.smoke.Smoke()
    smoke_sprites = pygame.sprite.Group()
    smoke_sprites.add(smoke)

    # Load backgound image
    background = pygame.image.load("engine_files" + utils.sep +
                                   "background.png").convert_alpha()

    # Game
    pygame.mixer.music.load("engine_files" + utils.sep + "music.ogg")
    pygame.mixer.music.play(1)  # Do not loop the song, play it once
    seconds_counter = time.time()
    utils.text_colour = (190, 150, 200)
    while True:
        old_blow_points = blow_points

        if stage == 5:
            pygame.mixer.music.stop()
            end_anim(screen, True)
            utils.time_remaining = 0  # Make sure the game stops

        if time.time() - seconds_counter > 1:
            utils.time_remaining -= 1
            seconds_counter = time.time()

        if utils.time_remaining > 0:
            utils.run_in_thread(get_data)
            utils.check_data_integrity(screen)
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    pygame.quit()
                    sys.exit()
            screen.fill((0, 0, 0))

            # Map the data coming from the microbit to a
            # scale of 0 to 100.
            # If the engine is not spinning, the pin is floating
            # due to the diode protection. Might need adjustement.
            blow = utils.map(utils.data[3], 80, 560, 0, 100)
            if blow > 70:
                blow_points += 0.02

            if int(blow_points) > int(old_blow_points):
                stage += 1
                utils.points += 1
                temp_indicator.change_temp(stage)

            smoke.animate()

            screen.blit(background, (0, 0))
            indicator_sprites.draw(screen)
            screen.blit(car, (X, Y))
            smoke_sprites.draw(screen)
            smoke_sprites.update()
            indicator_sprites.update()

            # Info
            utils.draw_text(screen, "Blow on the fan!", utils.width / 2, 322)
            utils.draw_points(screen)
            utils.draw_time(screen, utils.time_remaining)
            utils.run_in_thread(utils.draw_volume(screen))

            pygame.display.flip()
            utils.clock.tick(60)
        else:
            pygame.mixer.music.stop()
            if stage < 5:
                decrease_lives()
                end_anim(screen, False)

            utils.minigame_end(screen, get_data)
            break
    return
Esempio n. 23
0
	def action(self):
		"""Runs a loop within a thread, different action depending on input_device"""
		sys.stdout.write("%s thread initiated\n" % self.input_device)
		while True:

			if self.playThread:

			# Arduino Mode
				if self.mode == 'Arduino':
					#print "Start Arduino"
					ArduinoLights = [57, 49, 41, 33, 25, 17, 9, 1] # Mapping of the 8 arduono lights
					#ArduinoLights = [1, 2, 3, 4, 5, 6, 7, 8]
					ArduinoLights.reverse()
					step = 0
					self.input_device.cue() # Send a start command to the Arduino over serial

					# This loop waits for each step from the arduino then it passes the values to the DMX device
					# It only ends when the user presses the button to set playThread False
					while True:
						if self.input_device.isConnected() == False:
							print "Arduino Not connected"
							self.playThread = False
						else:
							ArduinoStep = [] # New empty list for the DMX send
							output = self.input_device.readSequence() # this blocks until it can return a value
							step += 1
							#app.cueNumber.set(step)
							# string to list > this could be done more efficiently using list()?
							for i in output:
								ArduinoStep.append(self.rangeMapper(int(i), 0, 3, 0, 255))
							# Send list to DMX output
							if step >= 0: # <=466
								self.output_device.sendLights(ArduinoLights,ArduinoStep)
							elif step == 465:
								self.output_device.all(0)
							else:
								self.output_device.all(255)
							# Stop playing if end of sequence
							if step >= 2131:
								self.playThread = False

						# Terminate when button sets playThread False, closes port
						if not self.playThread:
							# print "Stopping Arduino"
							self.input_device.stop()
							self.output_device.all(0)
							#app.cueNumber.set('0')
							break

			# IRCAM Mode
				elif self.mode == "IRCAM":
					self.cue = 0
					print "Listening for IRCAM"
					messages = [0] * 65
					lastMessages = []
					lastspat = None
					lastpitch = None
					self.output_device.sendLights(all64Lights,messages)
					while True:

						message = self.input_device.getMessage()

						print message

						if message.get('cue', None) != None:
							#app.cueNumber.set(message['cue'])
							self.cue = message['cue']

						elif self.cue >= 22 and self.cue <= 31:
							fade = 51
							if message.get('spat', None) != None:

								message = message['spat']
								message = map(message, 0, 360, 0, 64)
								message = clamp(message, 1, 64)
								messages[message] = 255

						elif self.cue >= 209:
							fade = 15
							if message.get('pitch', None) != None:

								message = message['pitch']
								message = clamp(message, 50, 100)
								message = map(message, 50, 100, 4, 64)
								#message = clamp(message, 1, 64)
								messages[message] = 255
								#print "pitch %d " % message

						else:
							self.output_device.all(0)


						for cN,channel in enumerate(messages):
							if channel != 0:
								messages[cN] -= fade

						if messages != lastMessages:
							lastMessages = messages[:]
							self.output_device.sendLights(all64Lights,messages)

						if not self.playThread:
							print "Stopping IRCAM"
							self.output_device.all(0)
							# self.input_device.disconnect()
							#app.cueNumber.set('0')
							break

			# testCircle Mode
				elif self.mode == "testCircle":
					while True:
						output = self.input_device.circle()
						if output == 1:
							last_output = 64
						else:
							last_output = output - 1
						self.output_device.sendLights([last_output, output],[0, 255])
						#app.cueNumber.set(str(output))



						if not self.playThread:
							print "Stopping Circle test"
							#app.cueNumber.set('0')
							self.input_device.reset()
							self.output_device.all(0)

							break

			# testAll Mode
				elif self.mode == "testAll":
					while True:
						if self.playThread:
							self.output_device.sendLights(all64Lights, [255]*64)
						elif not self.playThread:
							print 'stop'
							self.output_device.sendLights(all64Lights, [0]*64)
							break
						sleep(0.1)

			# fadeAll Mode
				elif self.mode == "fadeAll":
							while True:
								output = self.input_device.fade()
								#app.cueNumber.set(str(output))
								self.output_device.sendLights(all64Lights,[output]*64)

								if not self.playThread:
									print "Stopping fade test"
									#app.cueNumber.set('0')
									self.input_device.reset()
									self.output_device.all(0)
									break

			sleep(0.1)