def show_result(): data = f.request.json fs = pidf.FilterSystem() to_apply = [] if data['gender'] != 'ALL': to_apply.append("Gender " + data['gender']) if data['age'] != 'ALL': to_apply.append("Age " + data['age']) if data['mindrugs'] != 'ALL': to_apply.append("MinDrugUse " + data['mindrugs']) if data['maxdrugs'] != 'ALL': to_apply.append("MaxDrugUse " + data['maxdrugs']) for fltr in fs.get_inactive_filters(): if fltr.get_kind_and_cat() in to_apply: fs.add_filter(fltr) result = len(fs.get_result_pids()) print(result) fltr_dict = {"filters": to_apply, "results": result} return f.jsonify(fltr_dict)
def main(): """Returns the initial html page""" fs = pidf.FilterSystem() try: f.session['fs'] = pickle.dumps(fs) except Exception as e: print(e) return f.render_template('faceted_search.html')
def get_new_guid_for_fs(app): """return a guid which maps to a FilterSystem""" fs = pidf.FilterSystem() guid = str(uuid.uuid1()) mc = base.Client(('localhost', 11211)) fs_str = pickle.dumps(fs) mc.set(guid, fs_str) print ("SESSION_MAP: Guid made: " + guid) return guid
def main(): """Returns the initial html page""" if (PICKLE_FS): fs = pidf.FilterSystem() else: guid = sm.get_new_guid_for_fs(app) fs = sm.get_FilterSystem(guid,app) try: if (PICKLE_FS): tmp = pickle.dumps(fs) print(" pickled fs") print(tmp) f.session['fs'] = tmp else: f.session['fs'] = guid except Exception as e: print(e) return f.render_template('faceted_search.html')
import flask as f from faceted_search import faceted_search_filter_instances as pidf app = f.Flask(__name__) app.secret_key = 'why would I tell you my secret key?' fs = pidf.FilterSystem() @app.route("/") def main(): return f.render_template('index_v2.html', result='this is main', fltrs=[]) @app.route("/show_results", methods=["POST", "GET"]) def show_result(): data = f.request.json to_apply = [] to_remove = [] print("incoming data:") print(data) if data['Gender'] == 'ALL': to_remove.append("Gender") elif data['Gender'] != "ASIS": to_apply.append("Gender " + data['Gender']) if data['Age'] == 'ALL': to_remove.append("Age") elif data['Age'] != 'ASIS': to_apply.append("Age " + data['Age'])
def make_memoize_table(): """Input: None. Output: Creates and populates the memoize table in the database.""" clear_memoize_table() fs = pidf.FilterSystem() get_filter_subsets(fs.get_inactive_filters(), [[]], fs)
def main(): """Returns the initial html page""" if 'fs' not in f.session: fs = pidf.FilterSystem() f.session['fs'] = fs return f.render_template('faceted_search.html')
choice = input(prompt) if choice == 'q': break filter_system.add_or_remove_filter(options[int(choice)]) # add or remove the selected filter print("New active filters:") for fltr in filter_system.get_active_filters(): # print all currently active filters print(fltr.get_kind() + ": " + fltr.get_cat()) # print the number of PIDs currently selected print("\nNumber of results: " + str(len(filter_system.get_result_pids()))) print("--------------------------------------------------------------------------") def memoize_all_and_time(): """Input: None. Output: Runs memoizing/caching and prints how long it took.""" start_time = t.time() m.make_memoize_table() print("--- %s seconds ---" % (t.time() - start_time)) print("--- %s minutes ---" % ((t.time() - start_time)/60)) #memoize_all_and_time() print_and_prompt(pidf.FilterSystem())