def post(self, class_name): """Calculate scores for a given class feature sort""" unit_json = request.json # The request body contains our unit json. Not sure atm how to include this as a swagger param # Attach scores and send back to the client unit_json["stats"]["ip"] = request.remote_addr # unit_json["scores"] = scores # unit_json["stats"]["accuracy_before"] = scores["accuracy_before"] # unit_json["stats"]["accuracy_after"] = scores["accuracy_after"] # unit_json["stats"]["f1_before"] = scores["f1_before"] # unit_json["stats"]["f1_after"] = scores["f1_after"] unit_json["stats"]["requestedOn"] = unit_json["requestedOn"] unit_json["stats"]["dtEnd"] = datetime.now().isoformat() get_equas_db().db.oneshot_answer_v3.insert(unit_json["stats"]) unit_json["stats"]["_id"] = str( unit_json["stats"] ['_id']) # Stringify the Mongo ID. Fixes: 'ObjectId' is not JSON unit_json["_id"] = unit_json["stats"]["_id"] get_equas_db().db.oneshot_answer_v3_full.insert(unit_json) unit_json["_id"] = str( unit_json['_id'] ) # Stringify the Mongo ID. Fixes: 'ObjectId' is not JSON serializable return unit_json
def post(self): aspect_json = request.json # Creating a Cursor instance using find() function get_equas_db().db.oneshot_demo_save.insert(aspect_json) # cursor = get_equas_db().db.oneshot_demo_aspects.find() # # Converting cursor to the list of dictionaries # list_cur = list(cursor) # # Converting to the JSON # data = [] # for doc in list_cur: # doc['_id'] = str(doc['_id']) # Convert id to string # data.append(doc) return json.dumps({'success': True}), 200, { 'ContentType': 'application/json' }
def get(self): # Creating a Cursor instance using find() function cursor = get_equas_db().db.oneshot_answer_v3_full.find() # Converting cursor to the list of dictionaries list_cur = list(cursor) # Converting to the JSON return list_cur
def get(self, save_id): # Creating a Cursor instance using find() function cursor = get_equas_db().db.oneshot_demo_save.find( {'_id': ObjectId(save_id)}) list_cur = list(cursor) for doc in list_cur: doc['_id'] = str(doc['_id']) # Convert id to string return doc
def post(self, class_name): """Calculate scores for a given class feature sort""" # class_name = {image_class} activities = [ 'badminton', 'bocce', 'croquet', 'polo', 'RockClimbing', 'rowing', 'sailing', 'snowboarding' ] preextracted_data_path = settings.data_path + 'sun397_features.npz' classifier = settings.data_path + class_name + '_units_applied.npz' if (class_name in activities): preextracted_data_path = settings.data_path + 'places_features.npz' classifier = settings.data_path + class_name + '_w_new.npz' unit_json = request.json # The request body contains our unit json. Not sure atm how to include this as a swagger param # print(json.dumps(unit_json)) #unit_json["initalSort"] #This is the random sorting the Turker recieved and should serve as the baseline for the scoring. scores = get_scores(class_name, unit_json, classifier, preextracted_data_path) print(json.dumps(scores)) # Attach scores and send back to the client unit_json["stats"]["ip"] = request.remote_addr unit_json["scores"] = scores unit_json["stats"]["accuracy_before"] = scores["accuracy_before"] unit_json["stats"]["accuracy_after"] = scores["accuracy_after"] unit_json["stats"]["f1_before"] = scores["f1_before"] unit_json["stats"]["f1_after"] = scores["f1_after"] unit_json["stats"]["requestedOn"] = unit_json["requestedOn"] unit_json["stats"]["dtEnd"] = datetime.now().isoformat() get_equas_db().db.oneshot_answer_v2.insert(unit_json["stats"]) unit_json["stats"]["_id"] = str( unit_json["stats"] ['_id']) # Stringify the Mongo ID. Fixes: 'ObjectId' is not JSON # unit_json["stats"]["id"] = unit_json["stats"]["_id"] # unit_json["id"] = unit_json["stats"]["_id"] # unit_json["_id"] = unit_json["id"] unit_json["_id"] = unit_json["stats"]["_id"] get_equas_db().db.oneshot_answer_v2_full.insert(unit_json) unit_json["_id"] = str( unit_json['_id'] ) # Stringify the Mongo ID. Fixes: 'ObjectId' is not JSON serializable return unit_json
def get(self): # Creating a Cursor instance using find() function cursor = get_equas_db().db.oneshot_answer_v3.find() # Converting cursor to the list of dictionaries list_cur = list(cursor) # Converting to the JSON data = [] for doc in list_cur: doc['_id'] = str(doc['_id']) # Convert id to string data.append(doc) return data
def get(self, session_id): # Creating a Cursor instance using find() function # cursor = get_equas_db().db.oneshot_demo_save.find({'sessionId': session_id}, {'aspects': 0}) cursor = get_equas_db().db.oneshot_demo_save.find( {"$or": [{ 'sessionId': session_id }, { 'sessionId': 'example' }]}, {'aspects': 0}) list_cur = list(cursor) # Converting to the JSON data = [] for doc in list_cur: doc['_id'] = str(doc['_id']) # Convert id to string data.append(doc) return data