def api_query(request): ret = {} jsonstr = request.GET.get('json', None) if not jsonstr: # print("query: no json string. giving up") return ret args = json.loads(jsonstr) username = request.user.get_username() repo_base = args.get('username') repo = args.get('db') table = args.get('table') args['table'] = "%s.%s" % (repo, table) o, params = create_sql_obj(None, args) o.limit = 10000 query = str(o) # print(query) # print(params) if not repo or not table or not query: # print("query: no db/table/query. giving up") return ret manager = DataHubManager(user=username, repo_base=repo_base) res = manager.execute_sql(query, params) rows = res['tuples'] cols = pick(res['fields'], 'name') data = [dict(zip(cols, vals)) for vals in rows] ret['data'] = data ret['schema'] = get_schema(repo, table, username, repo_base) # print("%d points returned" % len(ret.get('data', []))) return ret
def get_parameters(msg): skill_name, parsed_correction = parse('{} {}', msg).fixed result = {} result['skill_name'] = skill_name for opt in ['+', '-', '*', '/']: if opt in parsed_correction: correction = pick(opt+'{:d}', parsed_correction) result['correction'] = (opt, correction) break else: continue return result
def simulate_ant(self): city = randint(0, self.n - 1) path = [city] visited = set([city]) for _ in range(self.n - 1): desir = [ # desirability based on distance (self.pow_dists[city][i] if i not in visited else 0) # desirability based on pheromones * (self.phero_trails[city][i]**self.params['phero_power']) # for each city for i in range(self.n) ] city = pick(normalizedArray(desir)) path.append(city) visited.add(city) return path
def get_parameters(msg): result = {} skill_name = pick('/{:w}', msg) result['skill_name'] = skill_name parsed_msg, = parse('/{}', msg).fixed result['correction'] = None for opt in ['+', '-', '*', '/']: if opt in parsed_msg: correction = pick(opt+'{:d}', parsed_msg) result['correction'] = (opt, correction) break else: continue result['bonus'] = pick('b{:d}', msg) if pick('b{:d}', msg) else 0 result['penalty'] = pick('p{:d}', msg) if pick('p{:d}', msg) else 0 return result
def get_parameters(msg): result = {} parsed_msg, = parse('/dice {}', msg).fixed plus_dice = re.findall('\A\d{1,2}d\d{1,3}|(?<=\+)\d{1,2}d\d{1,3}', parsed_msg) minus_dice = re.findall('(?<=\-)\d{1,2}d\d{1,3}', parsed_msg) plus_opt = re.findall('(?<=\+)\d{1,2}(?!d)', parsed_msg) minus_opt = re.findall('(?<=\-)\d{1,2}(?!d)', parsed_msg) result['plus_dice'] = tuple(plus_dice) result['minus_dice'] = tuple(minus_dice) if minus_dice else None result['plus_opt'] = tuple(plus_opt) if plus_opt else None result['minus_opt'] = tuple(minus_opt) if minus_opt else None result['bonus'] = pick('b{:d}', msg) if pick('b{:d}', msg) else 0 result['penalty'] = pick('p{:d}', msg) if pick('p{:d}', msg) else 0 result['target'] = pick('({:d})', msg) if pick('({:d})', msg) else None result['secret'] = True if 'secret' in msg else False return result
def get_columns(self): """ engine specific way to get table columns """ return pick(self.get_columns_and_types(), 0)