def genus2_curve_search(**args): info = to_dict(args) query = {} # database callable bread = [('Genus 2 Curves', url_for(".index")), ('$\Q$', url_for(".index_Q")), ('Search Results', '.')] #if 'SearchAgain' in args: # return rational_genus2_curves() if 'jump' in args: return render_curve_webpage_by_label(info["jump"]) if info.get("disc"): field = "abs_disc" ran = info["disc"] ran = ran.replace('..', '-').replace(' ','') # Past input check dlist = parse_discs(ran) tmp = g2_list_to_query(dlist) if len(tmp) == 1: tmp = tmp[0] else: query[tmp[0][0]] = tmp[0][1] tmp = tmp[1] print tmp # work around syntax for $or # we have to foil out multiple or conditions if tmp[0] == '$or' and '$or' in query: newors = [] for y in tmp[1]: oldors = [dict.copy(x) for x in query['$or']] for x in oldors: x.update(y) newors.extend(oldors) tmp[1] = newors query[tmp[0]] = tmp[1] if info.get("is_gl2_type"): query['is_gl2_type']=bool(info['is_gl2_type']) for fld in ['aut_grp', 'geom_aut_grp','st_group','real_geom_end_alg']: if info.get(fld): query[fld] = info[fld] for fld in ['aut_grp', 'geom_aut_grp']: if info.get(fld): query[fld] = eval(info[fld]) if info.get("cond"): field = "cond" ran = str(info[field]) ran = ran.replace('..', '-').replace(' ','') # Past input check tmp = parse_range2(ran, field) print tmp # work around syntax for $or # we have to foil out multiple or conditions if tmp[0] == '$or' and '$or' in query: newors = [] for y in tmp[1]: oldors = [dict.copy(x) for x in query['$or']] for x in oldors: x.update(y) newors.extend(oldors) tmp[1] = newors query[tmp[0]] = tmp[1] if info.get("count"): try: count = int(info["count"]) except: count = 100 else: count = 100 info["query"] = dict(query) #res = db_g2c().curves.find(query).sort([("cond", pymongo.ASCENDING), #("label", pymongo.ASCENDING)]).limit(count) res = db_g2c().curves.find(query).sort([("cond", pymongo.ASCENDING), ("class", pymongo.ASCENDING), ("disc_key", pymongo.ASCENDING), ("label", pymongo.ASCENDING)]) nres = res.count() if nres == 1: info["report"] = "unique match" else: if nres > count: info["report"] = "displaying first %s of %s matches" % (count, nres) else: info["report"] = "displaying all %s matches" % nres res_clean = [] for v in res: v_clean = {} v_clean["label"] = v["label"] v_clean["isog_label"] = v["class"] isogeny_class = db_g2c().isogeny_classes.find_one({'label' : isog_label(v["label"])}) v_clean["is_gl2_type"] = isogeny_class["is_gl2_type"] v_clean["equation_formatted"] = list_to_min_eqn(v["min_eqn"]) res_clean.append(v_clean) info["curves"] = res_clean info["curve_url"] = lambda dbc: url_for_label(dbc['label']) info["isog_url"] = lambda dbc: isog_url_for_label(dbc['label']) credit = 'Genus 2 Team' title = 'Genus 2 Curves search results' return render_template("search_results_g2.html", info=info, credit=credit, bread=bread, title=title)
def genus2_curve_search(**args): info = to_dict(args) info["st_group_list"] = st_group_list info["st_group_dict"] = st_group_dict info["real_geom_end_alg_list"] = real_geom_end_alg_list info["real_geom_end_alg_dict"] = real_geom_end_alg_dict info["aut_grp_list"] = aut_grp_list info["aut_grp_dict"] = aut_grp_dict info["geom_aut_grp_list"] = geom_aut_grp_list info["geom_aut_grp_dict"] = geom_aut_grp_dict query = {} # database callable bread = [('Genus 2 Curves', url_for(".index")), ('$\Q$', url_for(".index_Q")), ('Search Results', '.')] #if 'SearchAgain' in args: # return rational_genus2_curves() if 'jump' in args: return render_curve_webpage_by_label(info["jump"]) if info.get("disc"): field = "abs_disc" ran = info["disc"] ran = ran.replace('..', '-').replace(' ','') # Past input check dlist = parse_discs(ran) tmp = g2_list_to_query(dlist) if len(tmp) == 1: tmp = tmp[0] else: query[tmp[0][0]] = tmp[0][1] tmp = tmp[1] # work around syntax for $or # we have to foil out multiple or conditions if tmp[0] == '$or' and '$or' in query: newors = [] for y in tmp[1]: oldors = [dict.copy(x) for x in query['$or']] for x in oldors: x.update(y) newors.extend(oldors) tmp[1] = newors query[tmp[0]] = tmp[1] if info.get("is_gl2_type"): if info['is_gl2_type'] == "True": query['is_gl2_type']= True elif info['is_gl2_type'] == "False": query['is_gl2_type']= False for fld in ['st_group', 'real_geom_end_alg']: if info.get(fld): query[fld] = info[fld] for fld in ['aut_grp', 'geom_aut_grp','igusa_clebsch']: if info.get(fld): query[fld] = map(int,info[fld].strip()[1:-1].split(",")) if info.get('torsion'): res = parse_torsion_structure(info['torsion'],4) if 'Error' in res: # no error handling of malformed input yet! info['torsion'] = '' #info['err'] = res #return search_input_error(info, bread) else: #update info for repeat searches info['torsion'] = str(res).replace(' ','') query['torsion'] = [int(r) for r in res] if info.get('ic0'): query['igusa_clebsch']=[info['ic0'], info['ic1'], info['ic2'], info['ic3'] ] for fld in ["cond", "num_rat_wpts", "torsion_order", "two_selmer_rank"]: if info.get(fld): field = fld ran = str(info[field]) ran = ran.replace('..', '-').replace(' ','') # Past input check tmp = parse_range2(ran, field) # work around syntax for $or # we have to foil out multiple or conditions if tmp[0] == '$or' and '$or' in query: newors = [] for y in tmp[1]: oldors = [dict.copy(x) for x in query['$or']] for x in oldors: x.update(y) newors.extend(oldors) tmp[1] = newors query[tmp[0]] = tmp[1] info["query"] = dict(query) count_default = 50 if info.get('count'): try: count = int(info['count']) except: count = count_default else: count = count_default info['count'] = count start_default = 0 if info.get('start'): try: start = int(info['start']) if(start < 0): start += (1 - (start + 1) / count) * count except: start = start_default else: start = start_default cursor = db_g2c().curves.find(query) nres = cursor.count() if(start >= nres): start -= (1 + (start - nres) / count) * count if(start < 0): start = 0 res = cursor.sort([("cond", pymongo.ASCENDING), ("class", pymongo.ASCENDING), ("disc_key", pymongo.ASCENDING), ("label", pymongo.ASCENDING)]).skip(start).limit(count) nres = res.count() if nres == 1: info["report"] = "unique match" else: if nres > count or start != 0: info['report'] = 'displaying matches %s-%s of %s' % (start + 1, min(nres, start + count), nres) else: info['report'] = 'displaying all %s matches' % nres res_clean = [] for v in res: v_clean = {} v_clean["label"] = v["label"] v_clean["isog_label"] = v["class"] isogeny_class = db_g2c().isogeny_classes.find_one({'label' : isog_label(v["label"])}) v_clean["is_gl2_type"] = isogeny_class["is_gl2_type"] if isogeny_class["is_gl2_type"] == True: v_clean["is_gl2_type_display"] = '✔' #checkmark else: v_clean["is_gl2_type_display"] = '' v_clean["equation_formatted"] = list_to_min_eqn(v["min_eqn"]) v_clean["st_group_name"] = st_group_name(isogeny_class['st_group']) res_clean.append(v_clean) info["curves"] = res_clean info["curve_url"] = lambda dbc: url_for_label(dbc['label']) info["isog_url"] = lambda dbc: isog_url_for_label(dbc['label']) info["start"] = start info["count"] = count info["more"] = int(start+count<nres) credit = credit_string title = 'Genus 2 Curves search results' return render_template("search_results_g2.html", info=info, credit=credit, bread=bread, title=title)
def genus2_curve_search(**args): info = to_dict(args) info["st_group_list"] = st_group_list info["st_group_dict"] = st_group_dict info["real_geom_end_alg_list"] = real_geom_end_alg_list info["real_geom_end_alg_dict"] = real_geom_end_alg_dict info["aut_grp_list"] = aut_grp_list info["aut_grp_dict"] = aut_grp_dict info["geom_aut_grp_list"] = geom_aut_grp_list info["geom_aut_grp_dict"] = geom_aut_grp_dict query = {} # database callable bread = [('Genus 2 Curves', url_for(".index")), ('$\Q$', url_for(".index_Q")), ('Search Results', '.')] #if 'SearchAgain' in args: # return rational_genus2_curves() if 'jump' in args: return render_curve_webpage_by_label(info["jump"]) if info.get("disc"): field = "abs_disc" ran = info["disc"] ran = ran.replace('..', '-').replace(' ','') # Past input check dlist = parse_discs(ran) tmp = g2_list_to_query(dlist) if len(tmp) == 1: tmp = tmp[0] else: query[tmp[0][0]] = tmp[0][1] tmp = tmp[1] # work around syntax for $or # we have to foil out multiple or conditions if tmp[0] == '$or' and '$or' in query: newors = [] for y in tmp[1]: oldors = [dict.copy(x) for x in query['$or']] for x in oldors: x.update(y) newors.extend(oldors) tmp[1] = newors query[tmp[0]] = tmp[1] if info.get("is_gl2_type"): if info['is_gl2_type'] == "True": query['is_gl2_type']= True elif info['is_gl2_type'] == "False": query['is_gl2_type']= False for fld in ['st_group', 'real_geom_end_alg']: if info.get(fld): query[fld] = info[fld] for fld in ['aut_grp', 'geom_aut_grp','torsion','igusa_clebsch']: if info.get(fld): query[fld] = map(int,info[fld].strip()[1:-1].split(",")) if info.get('ic0'): query['igusa_clebsch']=[info['ic0'], info['ic1'], info['ic2'], info['ic3'] ] for fld in ["cond", "num_rat_wpts", "torsion_order", "two_selmer_rank"]: if info.get(fld): field = fld ran = str(info[field]) ran = ran.replace('..', '-').replace(' ','') # Past input check tmp = parse_range2(ran, field) # work around syntax for $or # we have to foil out multiple or conditions if tmp[0] == '$or' and '$or' in query: newors = [] for y in tmp[1]: oldors = [dict.copy(x) for x in query['$or']] for x in oldors: x.update(y) newors.extend(oldors) tmp[1] = newors query[tmp[0]] = tmp[1] info["query"] = dict(query) count_default = 50 if info.get('count'): try: count = int(info['count']) except: count = count_default else: count = count_default info['count'] = count start_default = 0 if info.get('start'): try: start = int(info['start']) if(start < 0): start += (1 - (start + 1) / count) * count except: start = start_default else: start = start_default cursor = db_g2c().curves.find(query) nres = cursor.count() if(start >= nres): start -= (1 + (start - nres) / count) * count if(start < 0): start = 0 res = cursor.sort([("cond", pymongo.ASCENDING), ("class", pymongo.ASCENDING), ("disc_key", pymongo.ASCENDING), ("label", pymongo.ASCENDING)]).skip(start).limit(count) nres = res.count() if nres == 1: info["report"] = "unique match" else: if nres > count or start != 0: info['report'] = 'displaying matches %s-%s of %s' % (start + 1, min(nres, start + count), nres) else: info['report'] = 'displaying all %s matches' % nres res_clean = [] for v in res: v_clean = {} v_clean["label"] = v["label"] v_clean["isog_label"] = v["class"] isogeny_class = db_g2c().isogeny_classes.find_one({'label' : isog_label(v["label"])}) v_clean["is_gl2_type"] = isogeny_class["is_gl2_type"] if isogeny_class["is_gl2_type"] == True: v_clean["is_gl2_type_display"] = '✔' #checkmark else: v_clean["is_gl2_type_display"] = '' v_clean["equation_formatted"] = list_to_min_eqn(v["min_eqn"]) v_clean["st_group_name"] = st_group_name(isogeny_class['st_group']) res_clean.append(v_clean) info["curves"] = res_clean info["curve_url"] = lambda dbc: url_for_label(dbc['label']) info["isog_url"] = lambda dbc: isog_url_for_label(dbc['label']) info["start"] = start info["count"] = count info["more"] = int(start+count<nres) credit = credit_string title = 'Genus 2 Curves search results' return render_template("search_results_g2.html", info=info, credit=credit, bread=bread, title=title)
def genus2_curve_search(**args): info = to_dict(args) query = {} # database callable bread = [('Genus 2 Curves', url_for(".index")), ('$\Q$', url_for(".index_Q")), ('Search Results', '.')] #if 'SearchAgain' in args: # return rational_genus2_curves() if 'jump' in args: return render_curve_webpage_by_label(info["jump"]) if info.get("disc"): field = "abs_disc" ran = info["disc"] ran = ran.replace('..', '-').replace(' ', '') # Past input check dlist = parse_discs(ran) tmp = g2_list_to_query(dlist) if len(tmp) == 1: tmp = tmp[0] else: query[tmp[0][0]] = tmp[0][1] tmp = tmp[1] print tmp # work around syntax for $or # we have to foil out multiple or conditions if tmp[0] == '$or' and '$or' in query: newors = [] for y in tmp[1]: oldors = [dict.copy(x) for x in query['$or']] for x in oldors: x.update(y) newors.extend(oldors) tmp[1] = newors query[tmp[0]] = tmp[1] if info.get("is_gl2_type"): query['is_gl2_type'] = bool(info['is_gl2_type']) for fld in ['aut_grp', 'geom_aut_grp', 'st_group', 'real_geom_end_alg']: if info.get(fld): query[fld] = info[fld] for fld in ['aut_grp', 'geom_aut_grp']: if info.get(fld): query[fld] = eval(info[fld]) if info.get("cond"): field = "cond" ran = str(info[field]) ran = ran.replace('..', '-').replace(' ', '') # Past input check tmp = parse_range2(ran, field) print tmp # work around syntax for $or # we have to foil out multiple or conditions if tmp[0] == '$or' and '$or' in query: newors = [] for y in tmp[1]: oldors = [dict.copy(x) for x in query['$or']] for x in oldors: x.update(y) newors.extend(oldors) tmp[1] = newors query[tmp[0]] = tmp[1] if info.get("count"): try: count = int(info["count"]) except: count = 100 else: count = 100 info["query"] = dict(query) #res = db_g2c().curves.find(query).sort([("cond", pymongo.ASCENDING), #("label", pymongo.ASCENDING)]).limit(count) res = db_g2c().curves.find(query).sort([("cond", pymongo.ASCENDING), ("class", pymongo.ASCENDING), ("disc_key", pymongo.ASCENDING), ("label", pymongo.ASCENDING)]) nres = res.count() if nres == 1: info["report"] = "unique match" else: if nres > count: info["report"] = "displaying first %s of %s matches" % (count, nres) else: info["report"] = "displaying all %s matches" % nres res_clean = [] for v in res: v_clean = {} v_clean["label"] = v["label"] v_clean["isog_label"] = v["class"] isogeny_class = db_g2c().isogeny_classes.find_one( {'label': isog_label(v["label"])}) v_clean["is_gl2_type"] = isogeny_class["is_gl2_type"] v_clean["equation_formatted"] = list_to_min_eqn(v["min_eqn"]) res_clean.append(v_clean) info["curves"] = res_clean info["curve_url"] = lambda dbc: url_for_label(dbc['label']) info["isog_url"] = lambda dbc: isog_url_for_label(dbc['label']) credit = credit_string title = 'Genus 2 Curves search results' return render_template("search_results_g2.html", info=info, credit=credit, bread=bread, title=title)