def main(): args = build_parser().parse_args() with open(args.data_path) as file: data = file.read().splitlines() points = pts.get_points(data) minx, miny, maxx, maxy = pts.get_point_bounds(points) _, set_counts = get_counts(points, minx, maxx, miny, maxy) _, big_counts = get_counts(points, 0, maxx + 50, 0, maxy + 50) print(max(np.take(set_counts, np.where(set_counts - big_counts == 0)[0])))
def _main(): from path import get_zip_file from points import get_points # from expert_verified import get_seg_image from shapenet.core.meshes import get_mesh_dataset # import matplotlib.pyplot as plt from mayavi import mlab cat_id = '02691156' # example_id = '1a04e3eab45ca15dd86060f189eb133' # example_id = '1a6ad7a24bb89733f412783097373bdc' example_id = '1a9b552befd6306cc8f2d5fe7449af61' with get_zip_file() as f: points = get_points(f, cat_id, example_id) labels = get_point_labels(f, cat_id, example_id) names = get_segmentation_names(cat_id) # image = get_seg_image(f, cat_id, example_id) print(len(points)) names = ['unlabelled'] + names clouds = [] for i, name in enumerate(names): cloud = points[labels == i] clouds.append(cloud) print('%s: %d' % (name, len(cloud))) with get_mesh_dataset(cat_id) as mesh_ds: example = mesh_ds[example_id] vertices, faces = (np.array(example[k]) for k in ('vertices', 'faces')) x, z, y = vertices.T mlab.triangular_mesh(x, y, z, faces, color=(1, 1, 1)) mlab.triangular_mesh(x, y, z, faces, color=(0, 0, 0), representation='wireframe') colors = np.random.uniform(size=(np.max(labels) + 1, 3)) for color, cloud in zip(colors, clouds): x, z, y = cloud.T mlab.points3d(x, y, z, color=tuple(color), opacity=0.8, scale_factor=0.02) print(np.min(points, axis=0), np.max(points, axis=0)) print(np.min(vertices, axis=0), np.max(vertices, axis=0)) # plt.imshow(image) # plt.show(block=False) mlab.show()
def main(): args = build_parser().parse_args() with open(args.data_path) as file: data = file.read().splitlines() points = pts.get_points(data) minx, miny, maxx, maxy = pts.get_point_bounds(points) max_distance = args.max_distance area = 0 for x, y in product(range(minx, maxx + 1), range(miny, maxy + 1)): distance = sum( pts.manhattan_distance([x, y], point) for point in points) if distance < max_distance: area += 1 print(area)
def points_roulette(text, user): if text.split()[0] == "roulette": gamble_point_amount = int(text.split()[1]) user_point_amount = points.get_points()[users_id[user]] if gamble_point_amount <= user_point_amount and gamble_point_amount >= 0: w_or_l = random.randint(0, 1) if w_or_l == 1: user_point_amount += gamble_point_amount database.put('members/'+users_id[user]+'/points', user_point_amount) post_message(users_id[user].title() + " vandt " + str(gamble_point_amount) + " point! :feelsgoodman:") # Doesn't currently work - database.get() returns a NoneType for some reason # winnings = database.get('members/' + users_id[user] + 'roulette/winnings') # print type(winnings) # winnings += gamble_point_amount # database.put('members/' + users_id[user] + 'roulette/winnings', winnings) # # wins = database.get('members/' + users_id[user] + 'roulette/wins') # wins = wins + 1 # database.put('members/' + users_id[user] + 'roulette/winnings', wins) elif w_or_l == 0: user_point_amount -= gamble_point_amount database.put('members/'+users_id[user]+'/points', user_point_amount) post_message(users_id[user].title() + " tabte " + str(gamble_point_amount) + " point... :feelsbadman:") # Doesn't currently work - database.get() returns a NoneType for some reason # winnings = database.get('members/' + users_id[user] + 'roulette/winnings') # print type(winnings) # winnings -= gamble_point_amount # database.put('members/' + users_id[user] + 'roulette/winnings', winnings) # # losses = database.get('members/' + users_id[user] + 'roulette/losses') # losses += 1 # database.put('members/' + users_id[user] + 'roulette/losses', losses) else: print "Gamble amount", gamble_point_amount print "Users points", user_point_amount post_message("Der opstod en fejl :feelsbadman:")
def __getitem__(self, key): return get_points(self._file, self._cat_id, key)
async def on_message(message): author = message.author user_id = message.author.id # We do not want the bot to reply to itself if message.author == client.user: return # Shutdown if message.content.startswith('$shutdown'): if author.server_permissions.administrator: await client.send_message(message.channel, ':wave: Bye :wave: bye!') points.save() await client.close() else: await client.send_message( message.channel, 'You do not have permissions to do that.') # Guessing game for guessing the network address of an IP # $subnet-network if message.content.startswith('$subnet-network'): ip = ip_address.IPAddress() question = "What is the Network address of **{}**?\n\n Format your answer as " \ "xxx.xxx.xxx.xxx/xx".format(ip.formatted_ip_address) answer = ip.ip_network embed_question = discord.Embed( title="Subnetting: Finding Network Addresses", description=question, color=0x00FF00 # Green ) embed_timeout = discord.Embed( title="Subnetting: Finding Network Addresses", description='Sorry {}, you took too long. It was **{}**'.format( author.mention, answer), color=0xFF0000 # Red ) embed_correct = discord.Embed( title="Subnetting: Finding Network Addresses", description='Correct {}! +10 Points!'.format(author.mention), color=0x00FF00 # Green ) embed_wrong = discord.Embed( title="Subnetting: Finding Network Addresses", description='Sorry {}. It is actually **{}**. -5 Points'.format( author.mention, answer), color=0xFF0000) await client.send_message(message.channel, embed=embed_question) current_channel = message.channel def check(msg): if msg.channel != current_channel: return False try: ipaddress.IPv4Network(msg.content, strict=False) return True except ipaddress.AddressValueError: return False guess = await client.wait_for_message(channel=message.channel, timeout=60.0, check=check) # If the user enters nothing if guess is None: await client.send_message(message.channel, embed=embed_timeout) return # Correct answer given if ipaddress.IPv4Network(guess.content, strict=False) == answer: await client.send_message(message.channel, embed=embed_correct) points.set_points(user_id, points.get_points(user_id) + 10) points.save() # Wrong answer given else: await client.send_message(message.channel, embed=embed_wrong) points.set_points(user_id, points.get_points(user_id) - 5) points.save() # Guessing game for guessing the broadcast address of an IP # $subnet-broadcast if message.content.startswith('$subnet-broadcast'): ip = ip_address.IPAddress() question = 'What is the Broadcast address of **{}**?'.format( ip.formatted_ip_address) answer = ip.ip_network.broadcast_address embed_question = discord.Embed( title="Subnetting: Finding Broadcast Addresses", description=question, color=0x00FF00 # Green ) embed_timeout = discord.Embed( title="Subnetting: Finding Broadcast Addresses", description='Sorry {}, you took too long. It was **{}**'.format( author.mention, answer), color=0xFF0000 # Red ) embed_correct = discord.Embed( title="Subnetting: Finding Broadcast Addresses", description='Correct {}! +10 Points!'.format(author.mention), color=0x00FF00 # Green ) embed_wrong = discord.Embed( title="Subnetting: Finding Broadcast Addresses", description='Sorry {}. It is actually **{}**. -5 Points'.format( author.mention, answer), color=0xFF0000 # Red ) await client.send_message(message.channel, embed=embed_question) current_channel = message.channel def check(msg): if msg.channel != current_channel: return False try: ipaddress.IPv4Network(msg.content, strict=False) return True except ipaddress.AddressValueError: return False guess = await client.wait_for_message(timeout=30.0, check=check) # If the user enters nothing if guess is None: await client.send_message(message.channel, embed=embed_timeout) return # Correct answer given if guess.content == answer: await client.send_message(message.channel, embed=embed_correct) points.set_points(user_id, points.get_points(user_id) + 10) points.save() # Wrong answer given else: await client.send_message(message.channel, embed=embed_wrong) points.set_points(user_id, points.get_points(user_id) - 5) points.save() # Guessing game for guessing the subnets of an IP # $subnet-subnet # if message.content.startswith('$subnet-subnet'): # ip = ip_address.IPAddress() # question = 'What are the subnets of **{}**?\n\n Format your answer as \ # xxx.xxx.xxx.xxx/xx and separate subnets with a space'.format(ip.formatted_ip_address) # answer = [] # for subnet in ip.subnets: # answer.append(subnet) # print(subnet) # # print(answer) # # embed_question = discord.Embed( # title="Subnetting: Finding Subnets", # description=question, # color=0x00FF00 # Green # ) # # embed_timeout = discord.Embed( # title="Subnetting: Finding Subnets", # description='Sorry {}, you took too long. It was **{}**'.format(author.mention, answer[0:]), # color=0xFF0000 # Red # ) # # embed_correct = discord.Embed( # title="Subnetting: Finding Subnets", # description='Correct {}! +10 Points!'.format(author.mention), # color=0x00FF00 # Green # ) # # embed_wrong = discord.Embed( # title="Subnetting: Finding Subnets", # description='Sorry {}. It is actually **{}**. -5 Points'.format(author.mention, answer), # color=0xFF0000 # Red # ) # # await client.send_message(message.channel, embed=embed_question) # # guess = await client.wait_for_message(channel=message.channel, timeout=60.0) # # Split the guess into an array separated by a comma # guess_split = set(guess.content.split(',')) # print(guess_split) # Debugging # # # If the user enters nothing # if guess is None: # await client.send_message(message.channel, embed=embed_timeout) # return # # Correct answer given # if guess_split.issubset(answer): # await client.send_message(message.channel, embed=embed_correct) # points.set_points(user_id, points.get_points(user_id) + 10) # points.save() # # Wrong answer given # else: # await client.send_message(message.channel, embed=embed_wrong) # points.set_points(user_id, points.get_points(user_id) - 5) # points.save() if message.content.startswith("$power"): power = random.randint(1, 16) question = "What is the answer: **2^{}**".format(power) answer = 2**power embed_question = discord.Embed( title="Powers: Base 2", description=question, color=0x00FF00 # Green ) embed_timeout = discord.Embed( title="Powers: Base 2", description='Sorry {}, you took too long. It was **{}**'.format( author.mention, answer), color=0xFF0000 # Red ) embed_correct = discord.Embed( title="Powers: Base 2", description='Correct {}! +10 Points!'.format(author.mention), color=0x00FF00 # Green ) embed_wrong = discord.Embed( title="Powers: Base 2", description='Sorry {}. It is actually **{}**. -5 Points'.format( author.mention, answer), color=0xFF0000 # Red ) await client.send_message(message.channel, embed=embed_question) current_channel = message.channel def is_int(msg): try: int(msg) return True except ValueError: return False def check(msg): return msg.channel == current_channel and is_int(msg.content) guess = await client.wait_for_message(channel=message.channel, timeout=10.0, check=check) # If the user enters nothing if guess is None: await client.send_message(message.channel, embed=embed_timeout) return # Correct answer given if guess.content == str(answer): await client.send_message(message.channel, embed=embed_correct) points.set_points(user_id, points.get_points(user_id) + 10) points.save() # Wrong answer given else: await client.send_message(message.channel, embed=embed_wrong) points.set_points(user_id, points.get_points(user_id) - 5) points.save() # Get user's points from the json file # $points if message.content.startswith('$points'): points_embed = discord.Embed( title='{}\'s Points'.format(author), description='You have **{}** points'.format( points.get_points(user_id)), color=0xFFFF00 # Yellow ) await client.send_message(message.channel, embed=points_embed) # Display the leaderboard if message.content.startswith('$leaderboard'): leaderboard_embed = discord.Embed( title="Subnetting Leaderboard", description='The Top 10 Subnetting Masters!', color=0xFFFF00, # Yellow ) # Enumerate through get_leaderboard() # Set position to 1 + index # Set name to be a mention when it formats in Discord # points = value (couldn't use the same name) for index, item in enumerate(points.get_leaderboard()): position = index + 1 name = '<@' + str(item[0]) + '>' value = item[1] leaderboard_embed.add_field(name='Position', value='**{0}.**'.format(position), inline=True) leaderboard_embed.add_field(name='Name', value='{0}'.format(name), inline=True) leaderboard_embed.add_field(name='Points', value='{0}'.format(value), inline=True) await client.send_message(message.channel, embed=leaderboard_embed) # Hello (Test) if message.content.startswith('$hello'): await client.send_message(message.channel, 'Hello {}'.format(author.mention)) if message.content.startswith('$help'): await client.send_message( author, "**Developed By:** Tyr4el#9451\n\n" "**$points:** Shows the user's current points\n" "**$leaderboard:** Displays the top 10 user's and their points\n" "**$subnet-network:** Starts a game for anyone in the channel to guess the network " "address of a given IP address and mask in the format xxx.xxx.xxx.xxx/yy\n" "**$subnet-broadcast:** Starts a game for anyone in the channel to guess the " "broadcast address of a given IP address and mask\n" "**$subnet-subnet:** Starts a game for anyone in the channel to guess the subnets " "of a given IP address and mask with answers delimited by a comma in the format " "xxx.xxx.xxx.xxx/yy (**WIP - NOT WORKING CURRENTLY**)\n" "**$power:** Starts a game for anyone in the channel to guess the answer of a " "random power with base 2 (i.e. 2^10)\n" "**$help:** DMs this help message to the user")
def points_post(text, user): if text.split()[0] == "points": points_dict = points.get_points() post_message(users_id[user].title() + ": " + str(points_dict[users_id[user]]))
logging.info("START") manager_data = json.loads("{{manager_data}}") logging.info( f"Hyperthreading = {not bool(manager_data['hyperthread_cost'] - 1)}") ec2 = boto3.resource("ec2") s3 = boto3.resource("s3") for file in ["userdata_template", "points", "combine_data_template"]: response = s3.meta.client.download_file(manager_data['s3_bucket'], f"script/{file}.py", f"{file}.py") from points import get_points points = get_points() instance_id = requests.get( "http://169.254.169.254/latest/meta-data/instance-id").text rcache = redis.Redis(host=manager_data['redis_endpoint'], port=manager_data['redis_port'], db=0) rcache.set(f"{instance_id}_all", json.dumps(points)) rcache.set(f"{instance_id}_remaining", json.dumps(points)) rcache.set(f"{instance_id}_completed", json.dumps([])) rcache.set(f"{instance_id}_in_progress", json.dumps({})) worker_data = dict(s3_bucket=manager_data['s3_bucket'], entry_point=manager_data['entry_point'], manager_instance_id=instance_id,