def get(self): results = [] ids = request.args.get('ids') print(ids) if (ids == None): questions = QuestionModel.find_all() else: questions = QuestionModel.find_by_array(array=ids) if (len(questions) == 0): return {'data': []} else: #return jsonify(json_list = questions) for item in questions: results.append({ "id": item.id, "statement": item.statement, "q1": item.ld_option_1, "q2": item.ld_option_2, "q3": item.ld_option_3, "q4": item.ld_option_4, "futurible": item.futurible, "statement": item.statement, "strategy": item.strategy, "more_information": item.more_information }) return {'data': results}
def question(): if flask.request.method == 'GET': return flask.render_template('question.html') else: title = flask.request.form.get('title') content = flask.request.form.get('content') question_model = QuestionModel(title=title,content=content) question_model.author = flask.g.user db.session.add(question_model) db.session.commit() return flask.redirect(flask.url_for('index'))
def populate_questions(): for question, details in questions.items(): question_model = QuestionModel.get_by_question(question) if not question_model: # New Question - add it yes = details['yes'] no = details['no'] why = details['why'] question_model = QuestionModel(question=question, answer_yes=yes, answer_no=no, why=why) question_model.save()
async def submit_reply(event, ctx, user, *args, **kwargs): data = event.body replier_uid = str(user['_id']) rid = 'r' + str(uuid.uuid4())[:13] qid = data.qid q_m = QuestionModel.get_maybe(qid) if q_m == Nothing: raise LambdaError(404, 'question not found') body = data.body if not (0 < len(body) <= 4000): raise Exception("Your question is too large!") ts = datetime.datetime.now() parent_rid = data.get('parent_rid', None) child_rids = list() is_staff = await has_role('qanda_staff', user['_id']) r = Reply(rid=rid, qid=qid, uid=replier_uid, body=body, ts=ts, parent_rid=parent_rid, child_rids=child_rids, is_staff=is_staff, display_name=gen_display_name(user, data.display_choice)) r.save() update_actions = [ ReplyIdsByQid.rids.set( (ReplyIdsByQid.rids | []).prepend([GenericPointer(ts=ts, id=rid)])) ] ReplyIdsByQid(qid="global").update(actions=update_actions) ReplyIdsByQid(qid=qid).update(actions=update_actions) ReplyIdsByUid(uid=replier_uid).update(actions=update_actions) await email_notify_new_reply(replier_uid, r, q_m.getValue()) return {'reply': r.to_python(), 'submitted': True, 'rid': rid}
async def get_mine(event, ctx, user, *args, **kwargs): qs_log = UserQuestionsModel.get_or(str(user['_id']), default=AttrDict({'qs': []})).qs qs = sort_qs_by_ts([ q if type(q) is dict else q.to_python() for q_log in qs_log for q in [QuestionModel.get_or(q_log.qid, default={})] ]) return {"questions": qs}
def save_questions(questions_yes, request): user = None if request.user.is_authenticated(): user = request.user for question, details in questions.items(): question_model = QuestionModel.get_by_question(question) if not question_model: populate_questions() question_model = QuestionModel.get_by_question(question) q = Question(question=question_model, user=user, session_key=request.session.session_key) if question in questions_yes: q.answer = True else: q.answer = False q.save()
def get(self): tsvin1 = open( '/home/ericanoanira/projects/encercla_server/data_questions.csv', 'rt') tsvin2 = csv.reader(tsvin1, delimiter='\t') for row in tsvin2: new_question = QuestionModel(statement=row[1], strategy=row[0], ld_option_1=row[2], ld_option_2=row[3], ld_option_3=row[4], ld_option_4=row[5], futurible=row[7], more_information=row[6], advise=row[8], proposta_millora=row[9]) new_question.save_to_db()
def mutate(self, info, input): data = input_to_dictionary(input) data['created'] = datetime.utcnow() data['edited'] = datetime.utcnow() print(datetime.utcnow()) question = QuestionModel(**data) db_session.add(question) db_session.commit() #middleware 처리할 return CreateQuestion(question=question)
async def get_all(event, ctx): global_log = UserQuestionsModel.get_or("global", default=UserQuestionsModel( uid="global", qs=[])) # print('global_log', global_log) qs = sort_qs_by_ts([ q.strip_private() for q in QuestionModel.batch_get([q['qid'] for q in global_log.qs]) ]) # print('qs', qs) return {'questions': qs}
def get(self, id): results = [] question = QuestionModel.find_by_id(id=id) if (questions == None): return {'data': []} else: return { "id": question.id, "statement": question.statement, "q1": question.ld_option_1, "q2": question.ld_option_2, "q3": question.ld_option_3, "q4": question.ld_option_4, "futurible": question.futurible, "statement": question.statement, "strategy": question.strategy }
async def submit(event, ctx, user, *args, **kwargs): data = event.body uid = str(user['_id']) qid = 'q' + str(uuid.uuid4())[:13] prev_q = data.get('prev_q', None) display_choice = data['display_choice'] title = data['title'] if prev_q: full_prev_q = QuestionModel.get(prev_q) if full_prev_q.uid != uid: raise Exception("prev_q does not match!") question = data['question'] if not (20 < len(question) <= 4000): raise Exception("Your question is too large!") if not (10 < len(title) <= 200): raise Exception("Your title is too long!") ts = datetime.datetime.now() params = { 'qid': qid, 'uid': uid, 'display_name': gen_display_name(user, data.display_choice), 'is_anon': display_choice == "anon", 'question': question, 'title': title, 'ts': ts } params.update({'prev_q': prev_q} if prev_q else {}) q = QuestionModel(**params) q.save() update_actions = [ UserQuestionsModel.qs.set((UserQuestionsModel.qs | []).prepend( [UserQuestionLogEntry(ts=ts, qid=q.qid)])) ] UserQuestionsModel(uid="global").update(actions=update_actions) UserQuestionsModel(uid=uid).update(actions=update_actions) return {'submitted': True, 'qid': qid, 'question': q.to_python()}
async def get_question(event, ctx): return { 'question': QuestionModel.get(event.pathParameters.qid).strip_private() }
data[split] = sorted(map(parse_dataset, stuff)) # load model model_savedir = args.expdir.rstrip('/') try: os.mkdir(model_savedir) except: pass model_checkpoint_file = model_savedir + '/checkpoint.pt' best_binary_model_savefile = model_savedir + '/best_binary_model.pt' best_numerical_model_savefile = model_savedir + '/best_numerical_model.pt' if args.word_embeddings is None: if not args.statutes: model = QuestionModel(pretrained_model=args.bert_model, tokenizer=args.bert_tokenizer, use_context=args.context, tax_statistics=(mean_tax_amount, stddev_tax_amount), max_length=args.max_length) else: model = StatuteModel(pretrained_model=args.bert_model, tokenizer=args.bert_tokenizer, sample_size=args.sample_size, pooling_function=args.pooling_function, tax_statistics=(mean_tax_amount, stddev_tax_amount), max_length=args.max_length) model.freeze_bert(thaw_top_layer=args.thaw_top_layer) model_file = None if os.path.isfile(model_checkpoint_file): model_file = model_checkpoint_file elif os.path.isfile(best_binary_model_savefile):