Пример #1
0
def weight_add():
    form = AddWeightForm()
    if form.validate_on_submit():
        weight = Weight(weight=form.weight.data, weight_patient=current_user)
        db.session.add(weight)
        db.session.commit()
        flash('weight recorded')
        return redirect(url_for('main.index'))
    return render_template('weight/add_weight.html', form=form)
Пример #2
0
def add_weight():
    form = WeightForm()
    if form.validate_on_submit():
        weight = Weight(value=form.value.data, author=current_user)
        db.session.add(weight)
        db.session.commit()
        flash('Weight added.')
        return redirect(url_for('health'))
    return render_template('add_weight.html', form=form)
Пример #3
0
def update_weight():
    form = AddWeightForm()
    if request.args.get('update_week'):
        base_date = datetime.fromtimestamp(
            float(request.args.get('update_week')))
        form.orgin_date.data = request.args.get('update_week')
    elif request.method == 'Post':
        base_date = datetime.fromtimestamp(form.start_date.data)
    else:
        base_date = datetime.today()
    py_week = [day for week in calendar.Calendar(firstweekday=calendar.SUNDAY)\
               .monthdatescalendar(base_date.year, base_date.month) if base_date.date() in week for day in week]
    form.start_date.data = datetime(year=py_week[0].year,
                                    month=py_week[0].month,
                                    day=py_week[0].day).timestamp()

    week_values = {
        w.measurement_date.isoformat(): w
        for w in Weight.query.filter(
            Weight.measurement_date.between(py_week[0], py_week[-1])).all()
    }

    if request.method == 'GET':
        day_labels = []
        date_labels = []
        for day in py_week:
            if day.isoformat() in week_values:
                form.days_list.append_entry(
                    week_values[day.isoformat()].weight)
            else:
                form.days_list.append_entry('')
            day_labels.append(day.strftime('%A'))
            date_labels.append(day.strftime('%m-%d'))

    if form.validate_on_submit():
        start_date = date.fromtimestamp(form.start_date.data)
        for nth, updated in enumerate(form.days_list):
            cur_date = (start_date + timedelta(days=nth)).isoformat()
            if week_values.get(cur_date, -1) == -1 and updated.data != '':
                db.session.add(
                    Weight(measurement_date=py_week[nth],
                           weight=float(updated.data)))
            elif week_values.get(cur_date, -1) != -1 and updated.data == '':
                db.session.delete(week_values[cur_date])
            elif week_values.get(
                    cur_date,
                    -1) != -1 and week_values[cur_date].weight != updated.data:
                week_values[cur_date].weight = float(updated.data)
        db.session.commit()
        return redirect(url_for('view_weight', view_date=form.orgin_date.data))
    return render_template("insert_weight.html",
                           form=form,
                           labels=day_labels,
                           dates=date_labels)
Пример #4
0
 def test_add_weight(self) -> None:
     """ Test A new weight can be added """
     u = User(username="******", email="*****@*****.**")
     db.session.add(u)
     db.session.commit()
     random_weight = randint(100, 999)
     w = Weight(weight=random_weight, weight_patient=u)
     db.session.add(w)
     db.session.commit()
     test_user = User.query.first_or_404()
     for weight in test_user.weights:
         self.assertEqual(str(weight), f"<Weight {random_weight}>")
Пример #5
0
for k, v in lists.items():
    q = Question(text=k, for_first_round=True, duration=15)
    db.session.add(q)
db.session.commit()
for k, v in lists.items():
    q = Question.query.filter(Question.text == k).first()
    for i in range(4):
        o = Option(question=q, text=v[i])
        db.session.add(o)
db.session.commit()
#########################################################
options = Option.query.join(Question).filter(Question.for_first_round == True)
c = 0
for option in options:
    if c % 4 == 0:
        w = Weight(option=option, f1=60, f2=20, f3=10, f4=0, f5=0)
    elif c % 4 == 1:
        w = Weight(option=option, f1=0, f2=70, f3=0, f4=50, f5=20)
    elif c % 4 == 2:
        w = Weight(option=option, f1=20, f2=10, f3=70, f4=20, f5=40)
    elif c % 4 == 3:
        w = Weight(option=option, f1=20, f2=0, f3=20, f4=30, f5=60)
    db.session.add(w)
    c += 1
db.session.commit()
###############################
for faction in Faction.query.all():
    question = Question.query.filter(Question.faction_id == faction.id).all()
    for ques in question:
        options = Option.query.filter(Option.question == ques).all()
        for option in options:
expense_type_food = ExpenseType(
    name  = "Food Expenses",
    event = event
)
expense_type_food.save()

expense_type_hotel = ExpenseType(
    name  = "Hotel Expenses",
    event = event
)
expense_type_hotel.save()

weight_a_food = Weight(
    expense_type = expense_type_food,
    participant  = participant_a,
    weight       = 0.7
)
weight_a_food.save()

weight_b_food = Weight(
    expense_type = expense_type_food,
    participant  = participant_b,
    weight       = 1.0
)
weight_b_food.save()

weight_c_food = Weight(
    expense_type = expense_type_food,
    participant  = participant_c,
    weight       = 1.0
Пример #7
0
def profile():
    weight_form = WeightEntryForm()
    sleep_form = SleepEntryForm()
    grade_form = GradeEntryForm()
    if request.method == 'POST' and weight_form.validate():
        weight = Weight(weight=weight_form.weight.data,
                        date=weight_form.date.data,
                        userId=current_user.userId)
        try:
            print("passed")
            db.session.add(weight)
            db.session.commit()
            flash('You have submitted your weight!')
            return redirect(url_for('prof.profile'))
        except IntegrityError:
            db.session.rollback()
            flash(
                'ERROR! Unable to submit weight of {}. Please check your details are correct and resubmit'
                .format(weight_form.weight.data), 'error')
    if request.method == 'POST' and sleep_form.validate():
        sleep = Sleep(sleep=sleep_form.sleep.data,
                      date=sleep_form.date.data,
                      userId=current_user.userId)
        try:
            print("passed")
            db.session.add(sleep)
            db.session.commit()
            flash('You have submitted your sleep!')
            return redirect(url_for('prof.profile'))
        except IntegrityError:
            db.session.rollback()
            flash(
                'ERROR! Unable to submit weight of {}. Please check your details are correct and resubmit'
                .format(weight_form.weight.data), 'error')
    if request.method == 'POST' and grade_form.validate():
        grade = Grade(grade=grade_form.grade.data,
                      gradeSubject=grade_form.gradeSubject.data,
                      date=grade_form.date.data,
                      userId=current_user.userId)
        try:
            print("passed")
            db.session.add(grade)
            db.session.commit()
            flash('You have submitted your grade!')
            return redirect(url_for('prof.profile'))
        except IntegrityError:
            db.session.rollback()
            flash(
                'ERROR! Unable to submit the grade of {}. Please check your details are correct and resubmit'
                .format(grade_form.grade.data), 'error')

    weightlabels = Weight.query.with_entities(
        Weight.date).filter_by(userId=current_user.userId).all()
    weightlabels = [str(item).replace("(", "") for item in weightlabels]
    weightlabels = [str(item).replace(")", "") for item in weightlabels]
    weightlabels = [str(item).replace(",", "") for item in weightlabels]
    weightlabels = [str(item).replace("'", "") for item in weightlabels]
    #print(weightlabels)
    weightvalues = Weight.query.with_entities(
        Weight.weight).filter_by(userId=current_user.userId).all()
    weightvalues = [str(item).replace("(", "") for item in weightvalues]
    weightvalues = [str(item).replace(")", "") for item in weightvalues]
    weightvalues = [str(item).replace(",", "") for item in weightvalues]
    #print(weightvalues)

    sleeplabels = Sleep.query.with_entities(
        Sleep.date).filter_by(userId=current_user.userId).all()
    sleeplabels = [str(item).replace("(", "") for item in sleeplabels]
    sleeplabels = [str(item).replace(")", "") for item in sleeplabels]
    sleeplabels = [str(item).replace(",", "") for item in sleeplabels]
    sleeplabels = [str(item).replace("'", "") for item in sleeplabels]
    # print(sleeplabels)
    sleepvalues = Weight.query.with_entities(
        Sleep.sleep).filter_by(userId=current_user.userId).all()
    sleepvalues = [str(item).replace("(", "") for item in sleepvalues]
    sleepvalues = [str(item).replace(")", "") for item in sleepvalues]
    sleepvalues = [str(item).replace(",", "") for item in sleepvalues]
    # print(sleepvalues)

    gradelabels = Grade.query.with_entities(
        Grade.date).filter_by(userId=current_user.userId).all()
    gradelabels = [str(item).replace("(", "") for item in gradelabels]
    gradelabels = [str(item).replace(")", "") for item in gradelabels]
    gradelabels = [str(item).replace(",", "") for item in gradelabels]
    gradelabels = [str(item).replace("'", "") for item in gradelabels]
    # print(gradelabels)
    gradevalues = Weight.query.with_entities(
        Grade.grade).filter_by(userId=current_user.userId).all()
    gradevalues = [str(item).replace("(", "") for item in gradevalues]
    gradevalues = [str(item).replace(")", "") for item in gradevalues]
    gradevalues = [str(item).replace(",", "") for item in gradevalues]
    # print(gradevalues)
    gradesubject = Weight.query.with_entities(
        Grade.gradeSubject).filter_by(userId=current_user.userId).all()
    gradesubject = [str(item).replace("(", "") for item in gradesubject]
    gradesubject = [str(item).replace(")", "") for item in gradesubject]
    gradesubject = [str(item).replace(",", "") for item in gradesubject]
    gradesubject = [str(item).replace("'", "") for item in gradesubject]
    print(gradesubject)

    return render_template('profile.html',
                           weight_form=weight_form,
                           sleep_form=sleep_form,
                           grade_form=grade_form,
                           weightlabels=weightlabels,
                           weightvalues=weightvalues,
                           sleeplabels=sleeplabels,
                           sleepvalues=sleepvalues,
                           gradelabels=gradelabels,
                           gradevalues=gradevalues,
                           gradesubject=gradesubject)