Beispiel #1
0
def get_tracking(baby_id, types, show_date_way, data_type):
    """
    获得随访记录_身长,体重,头围
    """
    tracking_count = db.query(Tracking).\
            filter(Tracking.baby_id == baby_id).\
            order_by(Tracking.measure_date).\
            group_by(Tracking.common).count()
    # session.query(Address.user_id, func.count('*').\
    # sums = session.query(func.sum(Irterm.n).label('a1')).group_by(Irterm.item_id)
    # average = session.query(func.avg(sums.subquery().columns.a1)).scalar()
    # label('address_count')).\    group_by(Address.user_id).subquery()
    # subresult = engine.execute("""SELECT count(*) FROM (SELECT * FROM tracking where baby_id = 29 ORDER BY measure_date DESC) as t GROUP BY t.common ORDER BY t.measure_date""")
    # sub = db.query(Tracking.label('al'))
    tracking_result = db.execute("select * from (select * from tracking where baby_id = "+str(baby_id)+" order by measure_date desc) as a group by a.common")
    grow_line = []
    baby = Baby.query.filter(Baby.id == baby_id).first()
    week = 0
    size = True
    if baby:
        if baby.due_date and baby.born_birthday:
            due_date = baby.due_date
            birthday = baby.born_birthday
            is_compare = ''
            s = int((birthday - due_date).total_seconds())
            week = s / 3600 / 24 / 7
            if birthday > due_date:
                if week > 10:
                    is_compare = 50
                else:
                    is_compare = 45
            elif birthday < due_date:
                is_compare = 40
                size = False
            else:
                is_compare = 45
            add_is_compare(is_compare, due_date, baby)
    result = []
    if tracking_count > 1:
        # tracking_result = Tracking.query.filter(Tracking.baby_id == baby_id).order_by(Tracking.measure_date).all()
        tracking_result = db.query(Tracking).\
            filter(Tracking.baby_id == baby_id).\
            order_by(Tracking.measure_date).\
            group_by(Tracking.common).all()
        median = 18
        if data_type:
            if size:
                grow_line = dynamic_create(week, tracking_count)
            else:
                grow_line = dynamic_create_list(week, tracking_count)
        for tracking in tracking_result:
            result.append(tracking)
        for tracking in result:
            if types == 'weight':
                if data_type:
                    if median > 28:
                        pass
                    elif size:
                        grow_line[(median + int(math.fabs(week)))] = tracking.weight
                    else:
                        grow_line[(median - int(math.fabs(week)))] = tracking.weight
                    median = median + 1
                else:
                    grow_line.append(tracking.weight)
            if types == 'height':
                if data_type:
                    if median > 28:
                        pass
                    elif size:
                        grow_line[(median + int(math.fabs(week)))] = tracking.height
                    else:
                        grow_line[(median - int(math.fabs(week)))] = tracking.height
                    median = median + 1
                else:
                    grow_line.append(tracking.height)
            if types == 'head':
                if data_type:
                    if median > 28:
                        pass
                    elif size:
                        grow_line[(median + int(math.fabs(week)))] = tracking.head_wai
                    else:
                        grow_line[(median - int(math.fabs(week)))] = tracking.head_wai
                    median = median + 1
                else:
                    grow_line.append(tracking.head_wai)
        return grow_line
    elif tracking_count == 1:
        tracking = Tracking.query.filter(Tracking.baby_id == baby_id).first()
        if data_type:
            if size:
                grow_line = dynamic_create(week, tracking_count)
            else:
                grow_line = dynamic_create_list(week, tracking_count)
        for tracking in tracking_result:
            result.append(tracking)
        if tracking:
            if types == 'weight':
                grow_line.append(result[0].weight)
            if types == 'height':
                grow_line.append(result[0].height)
            if types == 'head':
                grow_line.append(result[0].head_wai)
        return grow_line
    else:
        return grow_line
Beispiel #2
0
def get_tracking_week(baby_id, types, show_date_way, data_type):
    tracking_count = db.query(Tracking).\
        filter(Tracking.baby_id == baby_id).\
        order_by(Tracking.measure_date).\
        group_by(Tracking.week).count()
    tracking_result = db.execute("select * from (select * from tracking where baby_id = "+str(baby_id)+" order by measure_date desc) as a group by a.week")
    tracking_count = tracking_result.rowcount
    grow_line = []
    baby = Baby.query.filter(Baby.id == baby_id).first()
    week = 0
    size = True
    if baby:
        if baby.due_date and baby.born_birthday:
            due_date = baby.due_date
            birthday = baby.born_birthday
            is_compare = ''
            s = int((birthday - due_date).total_seconds())
            week = s / 3600 / 24 / 7
            if birthday > due_date:
                if week > 10:
                    is_compare = 50
                else:
                    is_compare = 45
            elif birthday < due_date:
                is_compare = 40
                size = False
            else:
                is_compare = 45
            add_is_compare(is_compare, due_date, baby)
    result = []
    if tracking_count > 1:
        # tracking_result = Tracking.query.filter(Tracking.baby_id == baby_id).order_by(Tracking.measure_date).all()
        #tracking_result = db.query(Tracking).\
        #        filter(Tracking.baby_id == baby_id).\
        #        order_by(Tracking.measure_date).\
        #        group_by(Tracking.week).all()
        median = 18
        if data_type:
            if size:
                grow_line = dynamic_create(week, tracking_count)
            else:
                grow_line = dynamic_create_list(week, tracking_count)
        for tracking in tracking_result:
            result.append(tracking)
        for tracking in result:
            if types == 'weight':
                if data_type:
                    if median > 28:
                        pass
                    elif size:
                        grow_line[(median + int(math.fabs(week)))] = tracking.weight
                    else:
                        grow_line[(median - int(math.fabs(week)))] = tracking.weight
                    median = median + 1
                else:
                    grow_line.append(tracking.weight)
            if types == 'height':
                if data_type:
                    if median > 28:
                        pass
                    elif size:
                        grow_line[(median + int(math.fabs(week)))] = tracking.height
                    else:
                        grow_line[(median - int(math.fabs(week)))] = tracking.height
                    median = median + 1
                else:
                    grow_line.append(tracking.height)
            if types == 'head':
                if data_type:
                    if median > 28:
                        pass
                    elif size:
                        grow_line[(median + int(math.fabs(week)))] = tracking.head_wai
                    else:
                        grow_line[(median - int(math.fabs(week)))] = tracking.head_wai
                    median = median + 1
                else:
                    grow_line.append(tracking.head_wai)
        return grow_line
    elif tracking_count == 1:
        tracking = Tracking.query.filter(Tracking.baby_id == baby_id).first()
        for tracking in tracking_result:
            result.append(tracking)
        if data_type:
            if size:
                grow_line = dynamic_create(week, tracking_count)
            else:
                grow_line = dynamic_create_list(week, tracking_count)
        if tracking:
            if types == 'weight':
                grow_line.append(result[0].weight)
            if types == 'height':
                grow_line.append(result[0].height)
            if types == 'head':
                grow_line.append(result[0].head_wai)
        return grow_line
    else:
        return grow_line