Пример #1
0
    def post(self, table, user):
        data = flask.request.get_json(force=False, silent=True)
        dataAux = flask.request.get_json(force=False, silent=True)

        count = 0

        for key, value in dataAux.items():
            if value:
                count = count + 1
        try:

            children = Children.query.filter_by(userId=user).first()
            survey = Survey.query.filter_by(childrenId=children.id).first()
            sectionA = SectionA.query.filter_by(surveyId=survey.id).first()

            sw = Switcher()
            return_table, errors = sw.switch_table(table, data, sectionA.id)
            if errors:
                logging.error(errors)
                raise Exception(errors)

            return_table.sectionAId = sectionA.id

            return_table.total = count
            db.session.add(return_table)
            db.session.commit()
            msg = 'Table was created successfully'
            logging.info(msg)
            return resource_helper.response(msg, 201)
        except Exception as ex:
            msg_error = 'Error trying to create table, msjError: {}'.format(ex)
            logging.error(msg_error)
            return resource_helper.response(msg_error, 400)
Пример #2
0
    def post(self, user):
        data = flask.request.get_json(force=False, silent=True)

        logging.info('Payload: {}'.format(data))
        try:

            data = flask.request.get_json(force=False, silent=True)
            survey, errors = survey_schema.load(data)
            if errors:
                logging.error(errors)
                raise Exception(errors=errors)

            children = Children.query.filter_by(userId=user).first()

            survey.childrenId = children.id
            survey.creationDate = datetime.datetime.now()
            survey.finished = False
            db.session.add(survey)

            sectionA = SectionA()
            survey = Survey.query.filter_by(childrenId=children.id).first()
            sectionA.surveyId = survey.id
            db.session.add(sectionA)
            db.session.commit()
            msg = 'Survey: {} was created successfully'.format(survey.id)
            logging.info(msg)
            return resource_helper.response(msg, 201)
        except Exception as ex:
            msg_error = 'Error trying to create survey, msjError: {}'.format(
                ex)
            logging.error(msg_error)
            return resource_helper.response(msg_error, 400)
Пример #3
0
 def get(self, user):
     try:
         logging.info('getting survey from children {}'.format(user))
         children = Children.query.filter_by(userId=user).first()
         survey = Survey.query.filter_by(childrenId=children.id).first()
         if survey is not None:
             survey_dict = resource_helper.make_dict_survey(survey)
             return resource_helper.response(survey_dict, 200)
     except Exception as ex:
         msg_error = 'Error getting survey. MsjError: {}'.format(ex)
         logging.error(msg_error)
         return resource_helper.response(msg_error, 400)
Пример #4
0
 def get(self, username):
     logging.info('Trying to log user: {}'.format(username))
     try:
         user = User.query.filter_by(username=username).first()
         if user is not None:
             logging.info('Login succeed for user: {}'.format(resource_helper.make_dic_user(user)))
             return resource_helper.response(resource_helper.make_dic_user(user), 200)
         msj = 'User: {} not found or password incorrect'.format(username)
         logging.error(msj)
     except Exception as ex:
         logging.error('Error trying to loging: userName {}, msjError: {}'.format(username, ex))
         msj = 'Failed to loging user, error: {}'.format(ex)
     return resource_helper.response(msj, 400)
Пример #5
0
 def get(self, user_id):
     logging.info('Trying to get children from user: {}'.format(user_id))
     try:
         children = Children.query.filter_by(userId=user_id).first()
         if children is not None:
             logging.info('Login succeed for user: {}'.format(children))
             return resource_helper.response(
                 resource_helper.make_dic_children(children), 200)
         msj = 'Children for user: {} not found '.format(user_id)
         logging.error(msj)
     except Exception as ex:
         logging.error('Error getting child {}, msjError: {}'.format(
             user_id, ex))
         msj = 'Failed to create user, error: {}'.format(ex)
     return resource_helper.response(msj, 400)
Пример #6
0
 def post(self):
     json_data = flask.request.get_json(force=False, silent=True)
     logging.info('Payload: {}'.format(json_data))
     try:
         user, errors = user_schema.load(json_data)
         if errors:
             logging.error(errors)
             raise Exception(errors=errors)
         db.session.add(user)
         db.session.commit()
         msg = 'user: {} was created successfully'.format(user.username)
         logging.info(msg)
         return resource_helper.response(msg, 201)
     except Exception as ex:
         msg_error = 'Error trying to create user, msjError: {}'.format(ex)
         logging.error(msg_error)
         return resource_helper.response(msg_error, 400)
Пример #7
0
    def get(self, user):
        logging.info('Getting results for: {}'.format(user))

        try:
            children = Children.query.filter_by(userId=user).first()
            survey = Survey.query.filter_by(childrenId=children.id).first()
            count = db.session.query(Results.result).filter(
                Results.age == survey.age
                and Results.result <= survey.results).count()
            count_total = db.session.query(
                Results.result).filter(Results.age == survey.age).count()
            percentile = (count - 0.5) / count_total * 100
            if percentile < 10:

                min = 0
                max = 10
            else:
                if percentile < 25:
                    min = 10
                    max = 25
                else:
                    if percentile < 50:
                        min = 25
                        max = 50
                    else:
                        if percentile < 75:
                            min = 50
                            max = 75
                        else:
                            if percentile < 90:
                                min = 75
                                max = 90
                            else:
                                min = 90
                                max = 100

            message = "Su hija/o se encuentra entre el {}% y {}% de la poblacion de su edad".format(
                min, max)
            return resource_helper.response(message, 200)
        except Exception as ex:
            msg_error = 'Error trying to getting results,  msjError: {}'.format(
                ex)
            logging.error(msg_error)
            return resource_helper.response(msg_error, 400)
Пример #8
0
    def put(self, table, user):
        data = flask.request.get_json(force=False, silent=True)
        dataAux = flask.request.get_json(force=False, silent=True)

        count = 0

        for key, value in dataAux.items():
            if value:
                count = count + 1
        try:
            children = Children.query.filter_by(userId=user).first()
            survey = Survey.query.filter_by(childrenId=children.id).first()
            sectionA = SectionA.query.filter_by(surveyId=survey.id).first()

            sw = Switcher()
            return_table, errors = sw.switch_table(table, data, sectionA.id)
            if errors:
                logging.error(errors)
                raise Exception(errors)

            return_table.total = count
            return_table.sectionAId = sectionA.id
            db.session.add(return_table)
            db.session.commit()

            survey.finished = True

            totalSurvey = self.getTotal(survey.id)
            survey.total = totalSurvey
            db.update(Survey).where(id == survey.id)
            results = self.results(survey.id, survey.gender, survey.total,
                                   survey.age)
            db.session.add(results)
            db.session.commit()
            msg = 'Finished survey {}'.format(survey.id)
            logging.info(msg)
            return resource_helper.response(msg, 201)

        except Exception as ex:
            msg_error = 'Error trying to create table, not finished survey. MsjError: {}'.format(
                ex)
            logging.error(msg_error)
            return resource_helper.response(msg_error, 400)
Пример #9
0
 def post(self, user):
     json_data = flask.request.get_json(force=False, silent=True)
     logging.info('Payload: {}'.format(json_data))
     try:
         #   address = address_schema.load(json_data.address)
         children, errors = children_schema.load(json_data)
         if errors:
             logging.error(errors)
             raise Exception(errors=errors)
         children.userId = user
         db.session.add(children)
         db.session.commit()
         msg = 'Children: {} was created successfully'.format(children.id)
         logging.info(msg)
         return resource_helper.response(msg, 201)
     except Exception as ex:
         msg_error = 'Error trying to create children, msjError: {}'.format(
             ex)
         logging.error(msg_error)
         return resource_helper.response(msg_error, 400)
Пример #10
0
 def get(self, gender):
     logging.info('Getting results for: {}'.format(gender))
     result_dict = []
     try:
         for i in ages:
             result_list = self.get_result_list(gender, i)
             dict_aux = {
                 "age": i,
                 "10": np.percentile(result_list, 10),
                 "25": np.percentile(result_list, 25),
                 "50": np.percentile(result_list, 50),
                 "75": np.percentile(result_list, 75),
                 "90": np.percentile(result_list, 90)
             }
             result_dict.append(dict_aux)
             logging.info('Percentile {} : {}'.format(i, dict_aux))
         return resource_helper.response(result_dict, 200)
     except Exception as ex:
         msg_error = 'Getting results for: {}, error {}'.format(gender, ex)
         logging.error(msg_error)
     return resource_helper.response(msg_error, 400)
Пример #11
0
 def put(self):
     json_data = request.get_json(force=False, silent=True)
     logging.info('Payload: {}'.format(json_data))
     username = json_data.get("username")
     if username is not None:
         try:
             user = User.query.filter_by(username=username).first()
             if user:
                 if user.username == username and user.secretWord == json_data.get("actualPassword"):
                     user.secretWord = json_data.get("newPassword")
                     db.session.add(user)
                     db.session.commit()
                     return resource_helper.response(jsonify(message='The password was reset for user: {}'.format(username)),
                                          200)
                 error_msj = 'Error checking actualPassword for user: {}'.format(username)
             else:
                 error_msj = 'User nor found, username: {}'.format(username)
         except Exception as ex:
             error_msj = 'Failed trying to update password, userName: {}, msjError: {}'.format(username, ex)
         logging.error(error_msj)
         return resource_helper.response(error_msj, 400)