Example #1
0
def jourQuestionSante():
    dateToday = date.today().strftime("%d-%m-%Y")
    timestampToday = date2Timestamp(str(dateToday))

    dateDebutMouvinsa = datetime.datetime(2015, 03, 05).strftime("%d-%m-%Y")
    timestampDateDebutMouvinsa = date2Timestamp(str(dateDebutMouvinsa))

    # 02 avril
    dateMilieuMouvinsa = datetime.datetime(2015, 04, 02).strftime("%d-%m-%Y")
    timestampDateMilieuMouvinsa = date2Timestamp(str(dateMilieuMouvinsa))

    # 06 mai
    dateFinMouvinsa = datetime.datetime(2015, 05, 06).strftime("%d-%m-%Y")
    timestampdateFinMouvinsa = date2Timestamp(str(dateFinMouvinsa))

    person = getPersonFromSession()
    question = Questions.query.filter_by(person_id=person.id).first()

    if timestampToday >= timestampDateDebutMouvinsa and len(question.firstValue) == 0:
        return 1
    elif timestampToday >= timestampDateMilieuMouvinsa and len(question.secondValue) == 0:
        return 2
    elif timestampToday >= timestampdateFinMouvinsa and len(question.thirdValue) == 0:
        return 3
    else:
        return 0
Example #2
0
def group():
    person = getPersonFromSession()
    if person != "none" and "idEquipe" not in request.args:
        return render_template("group/main.html", group=person.group, person=person)
    else:
        if "idEquipe" in request.args:
            idEq = request.args.get("idEquipe", "")
            try:
                idEqInt = int(idEq)
                if idEqInt > 0 and idEqInt < 43:
                    group = Group.query.filter_by(id=idEq).first()
                    person = getPersonFromSession()
                    return render_template("group/main.html", group=group, person=person)
                else:
                    error = u"ERROR : le parametre idEquipe doit etre un entier compris entre 1 et 43"
                    return error
            except ValueError:
                error = u"ERROR : le parametre idEquipe doit etre un entier compris entre 1 et 43"
                return error
        else:
            error = u"ERROR : le parametre idEquipe est demandé"
            return error
Example #3
0
def questionSante():
    if request.method == "POST":
        numeroQuestion = request.form["input-numeroQuestion"]
        value = request.form["select-value"]
        person = getPersonFromSession()
        question = Questions.query.filter_by(person_id=person.id).first()
        if int(numeroQuestion) == 1:
            question.firstValue = value
            db.session.commit()
        elif int(numeroQuestion) == 2:
            question.secondValue = value
            db.session.commit()
        elif int(numeroQuestion) == 3:
            question.thirdValue = value
            db.session.commit()
        return jsonify(result="OK")
Example #4
0
def home():
    person = getPersonFromSession()
    index = "yes"
    groups = Group.query.order_by(desc(Group.stepSum))
    nbPasTotales = 0
    distanceTotale = 0
    for group in groups:
        nbPasTotales = nbPasTotales + group.stepSum
        distanceTotale = distanceTotale + group.distance

    distanceTotaleRound = round(distanceTotale / 1000, 2)
    toursTerre = round(distanceTotaleRound / 40075, 2)
    distanceTotale = int(distanceTotale / 1000)

    persMail = Person.query.filter_by(id=13).first()

    if toursTerre > 0.6:
        mailSent = persMail.token
        # Check if I already sent the email
        if mailSent != "mailSent":
            # sendMail
            persMail.token = "passoDaQui"
    else:
        persMail.token = "mailNotSent"

    db.session.commit()

    return render_template(
        "/accueil/index.html",
        person=person,
        index=index,
        groups=groups,
        nbPasTotales="{:,}".format(nbPasTotales),
        distanceTotale="{:,}".format(distanceTotale),
        toursTerre=toursTerre,
    )
Example #5
0
def reglages():
    person = getPersonFromSession()
    if request.method == "GET":
        return UserController.displaySettings(request, person)
    elif request.method == "POST":
        return UserController.validateSetting(request, person)
Example #6
0
def personnel():
    person = getPersonFromSession()

    if request.method == "GET":

        todayDate = date.today()
        today = todayDate.strftime("%d-%m")

        startDate = datetime.datetime(2015, 02, 26)
        days = 70

        list_date_steps = {}

        for day in range(0, days):
            dateTemp = startDate + timedelta(days=day)

            stepsDay = Steps.query.filter_by(person_id=person.id, date=dateTemp).first()

            if stepsDay:
                list_date_steps[dateTemp] = stepsDay.stepnumber
            else:
                list_date_steps[dateTemp] = 0

        stepNumberPerson = round(FitnessInfo.query.filter_by(person_id=person.id).first().stepSum * 0.00064, 2)

        sortedDateSteps = sorted(list_date_steps.items(), key=operator.itemgetter(0))
        chartDates = ["["]
        chartValues = ["["]
        chartObjectifs = ["["]

        dateToday = datetime.datetime.today()

        goal = person.fitnessInfo.goal or "0"

        for dateIt in sortedDateSteps:
            if dateIt[0] > dateToday:
                break
            chartObjectifs.append(str(goal))
            chartObjectifs.append(",")
            chartDates.append("'" + dateIt[0].strftime("%d-%m") + "'")
            chartDates.append(",")
            chartValues.append(str(dateIt[1]))
            chartValues.append(",")

        chartValues.pop()
        chartDates.pop()
        chartObjectifs.pop()

        chartValues = " ".join(chartValues) + "]"
        chartDates = " ".join(chartDates) + "]"
        chartObjectifs = " ".join(chartObjectifs) + "]"

        jQuesSante = jourQuestionSante()
        if jQuesSante != 0:
            display = "display:block;"
            title = u"Niveau d'activité physique"
        else:
            display = ""
            title = ""

        return render_template(
            "person/main.html",
            title=title,
            display=display,
            jQuesSante=jQuesSante,
            chartValues=chartValues,
            chartDates=chartDates,
            chartObjectifs=chartObjectifs,
            person=person,
            today=today,
            list_date_steps=sortedDateSteps,
            stepNumberPerson=stepNumberPerson,
        )
    elif request.method == "POST":
        return UserController.validateStepsData(request, person)
Example #7
0
def apropos():
    person = getPersonFromSession()
    return render_template("/a propos/main.html", person=person)