def help_embed(self, prefix): desc = "Erhalte eine ausführliche Erklärung zu\neinzelnen " \ "Commands mit `{0}help <commandname>`".format(prefix) emb_help = discord.Embed(description=desc, color=discord.Color.blue()) emb_help.set_footer(text="Supportserver: https://discord.gg/s7YDfFW") groups = {name: [] for name in self.categories} for name, cog in self.bot.cogs.items(): cog_type = getattr(cog, 'type', None) if cog_type is None: continue category = self.categories[cog_type] for cmd in cog.get_commands(): if cmd.hidden is True: continue for alias in cmd.aliases: if len(alias) < 3: cmd_name = f"{alias} [{cmd}]" break else: cmd_name = str(cmd) groups[category].append(cmd_name) for name, cmd_list in groups.items(): cache = [] datapack = [] sorted_list = utils.sort_list(cmd_list) for cmd in sorted_list: if len("".join(cache) + cmd) > 30 and len(cache) > 1: self.packing(datapack, cache) cache.append(cmd) num = 4 if len(cmd) > 4 else 5 if len(cache) >= num or len(cache) > 1 and "[" in cache[-2]: self.packing(datapack, cache) if cmd == sorted_list[-1] and cache: self.packing(datapack, cache) elif "[" in cmd and len(cache) == 2: self.packing(datapack, cache) emb_help.add_field(name=f"{name}:", value="\n".join(datapack), inline=False) return emb_help
def fetch_profile(self, route_id, start_time, end_time): fig = None route_store = RouteStore() route = { #'route_id': 'umairs_place|broadcom', #'route_id': 'home|yelp', #'route_id': 'yelp|home', 'route_id': route_id, #'route_id': 'omer|broadcom', } routes = route_store.get_routes() for cur_route in routes: if cur_route['route_id'] == route['route_id']: route = cur_route recs = route_store.get_time_profile( #{'route_id': 'broadcom|umairs_place'}, route, start_time=start_time, end_time=end_time, ) x = [] y = [] for r in recs: x.append(float(r['epoch'])) d = datetime.fromtimestamp(r['epoch']) day_hour = '{0}/{1}/{2} {3}'.format(d.month, d.day, d.year, d.hour) try: y.append({ 'traffic_time': float(r['info']['best_guess']), 'epoch': r['epoch'], 'date': day_hour, }) except KeyError: continue y = utils.sort_list(y, 'epoch') #fig, graph = plotter.plot_stock_qty(y_p, 'traffic_time', fig=fig, line_type='-', show_xticks=False) fig, graph = plotter.plot_stock_qty(y, 'traffic_time', fig=fig, line_type='-', show_xticks=True) #fig, graph = plotter.plot_stock_qty(y_o, 'traffic_time', fig=fig, line_type='-', show_xticks=True) start_time = min([r['epoch'] for r in y]) max_traffic_time = max([r['traffic_time'] for r in y]) addr_str = 'From:{0} ==> To:{1}'.format(route['from'], route['to']) graph.text(start_time, max_traffic_time * 1.10, addr_str, fontsize=15) pl.ylabel('Time in traffic (mins)') pl.ylim([0, max_traffic_time * 1.05]) pl.legend(traffic_models, loc='lower left') pl.savefig('image.png', dpi=400)
def fetch_profile(self, route_id, start_time, end_time, fig=None, show_text=True): route_store = RouteStore() route = { #'route_id': 'umairs_place|broadcom', #'route_id': 'home|yelp', #'route_id': 'yelp|home', 'route_id': route_id, #'route_id': 'omer|broadcom', } routes = route_store.get_routes() for cur_route in routes: if cur_route['route_id'] == route['route_id']: route = cur_route recs=route_store.get_time_profile( #{'route_id': 'broadcom|umairs_place'}, route, start_time=start_time, end_time=end_time, ) x=[] y=[] for r in recs: x.append(float(r['epoch'])) d = datetime.fromtimestamp(r['epoch']) day_hour = '{0}/{1}/{2} {3}'.format(d.month, d.day, d.year, d.hour) try: y.append({ 'traffic_time': float(r['info']['best_guess']), 'epoch': r['epoch'], 'date': day_hour, }) except KeyError: continue y = utils.sort_list(y, 'epoch') fig, graph = plotter.plot_stock_qty(y, 'traffic_time', fig=fig, line_type='-', show_xticks=True) #fig, graph = plotter.plot_relative_to_start(y, 'traffic_time', fig=fig, line_type='-', show_xticks=True, lw=1) start_time = min([r['epoch'] for r in y]) max_traffic_time = max([r['traffic_time'] for r in y]) min_traffic_time = min([r['traffic_time'] for r in y]) addr_str = 'From:{0} ==> To:{1}'.format(route['from'], route['to']) if show_text: graph.text(start_time, max_traffic_time * 1.10, addr_str, fontsize=15) pl.ylabel('Time in traffic (mins)') ymin, ymax = graph.get_ylim() if ymax < max_traffic_time * 1.05: pl.ylim([min_traffic_time * 0.9, max_traffic_time * 1.05]) return fig
def log(id): '''log progress on a goal''' g = Goals() goal = g.find_one(id) if goal: if request.method == 'POST': error = [] # fetch the log log = goal['log'] if goal['variant'] == 'value': # validate if 'value' not in request.form or not request.form['value']: error.append('New value is missing') if not error: if not log: # difference from the beginning points = (float(request.form['value']) - goal['values']['begin']) / goal['points']['conversion'] else: # difference from last log points = (float(request.form['value']) - log[-1]['value']) / goal['points']['conversion'] entry = { 'value': round(float(request.form['value']), 1), 'points': round(points, 1), 'description': request.form['description'], 'date': utils.timestamp_new( year = request.form['date[year]'], month = request.form['date[month]'], day = request.form['date[day]']) } else: entry = { 'points': goal['points']['currency'][int(request.form['points'])]['points'], 'name': goal['points']['currency'][int(request.form['points'])]['name'], 'description': request.form['description'], 'date': utils.timestamp_new( year = request.form['date[year]'], month = request.form['date[month]'], day = request.form['date[day]']) } if not error: # append to the log log.append(entry) # sort (yeah, not smart when already sorted) log = utils.sort_list(log) # update current value on the last entry (by date, not actual entry) if goal['variant'] == 'value': g.update(id, 'values.current', log[-1]['value']) # update the entry g.update(id, 'log', log) # increment running total of logged points g.increment(id, 'points.logged', entry['points']) return redirect(url_for('goals.goal', id=id)) date = utils.date_list(utils.timestamp_new()) return render_template(goal['variant']+'-log.html', **locals()) else: return redirect(url_for('goals.all'))
def log(id): '''log progress on a goal''' g = Goals() goal = g.find_one(id) if goal: if request.method == 'POST': error = [] # fetch the log log = goal['log'] if goal['variant'] == 'value': # validate if 'value' not in request.form or not request.form['value']: error.append('New value is missing') if not error: if not log: # difference from the beginning points = (float(request.form['value']) - goal['values']['begin'] ) / goal['points']['conversion'] else: # difference from last log points = ( float(request.form['value']) - log[-1]['value']) / goal['points']['conversion'] entry = { 'value': round(float(request.form['value']), 1), 'points': round(points, 1), 'description': request.form['description'], 'date': utils.timestamp_new(year=request.form['date[year]'], month=request.form['date[month]'], day=request.form['date[day]']) } else: entry = { 'points': goal['points']['currency'][int( request.form['points'])]['points'], 'name': goal['points']['currency'][int( request.form['points'])]['name'], 'description': request.form['description'], 'date': utils.timestamp_new(year=request.form['date[year]'], month=request.form['date[month]'], day=request.form['date[day]']) } if not error: # append to the log log.append(entry) # sort (yeah, not smart when already sorted) log = utils.sort_list(log) # update current value on the last entry (by date, not actual entry) if goal['variant'] == 'value': g.update(id, 'values.current', log[-1]['value']) # update the entry g.update(id, 'log', log) # increment running total of logged points g.increment(id, 'points.logged', entry['points']) return redirect(url_for('goals.goal', id=id)) date = utils.date_list(utils.timestamp_new()) return render_template(goal['variant'] + '-log.html', **locals()) else: return redirect(url_for('goals.all'))
def sort_log(self, log=None): if log is None: if self.logs is not None: return utils.sort_list(self.logs) else: return utils.sort_list(log)