How to use test_age method in green

Best Python code snippet using green

datas.py

Source:datas.py Github

copy

Full Screen

1import csv2import pandas as pd3import operator4import numpy as np5import json6def get_category():7 df1 = pd.read_csv("국민연령별추천운동정보.csv", encoding='utf-8')8 category1 = df1['BMI_IDEX_GRAD'] == '정상'9 value1 = df1[category1]10 category2 = value1['SPORTS_STEP_NM'] == '본운동'11 value2 = value1[category2]12 category3 = value2['SE_ACCTO_RECOMEND_SPORTS_RANK'] == 113 value3 = value2[category3]14 15 print(value3['RECOMEND_SPORTS_NM'].unique())16def get_each_average(data):17 ave12 = int(data['ITEM_F012'].mean())18 ave19 = int(data['ITEM_F019'].mean())19 ave20 = int(data['ITEM_F020'].mean())20 ave21 = int(data['ITEM_F021'].mean())21 ave22 = int(data['ITEM_F022'].mean())22 result = {"data" : [ave12, ave19, ave20, ave21, ave22]}23 return result24def get_all_average(*args):25 i = 026 section = ['M19to24', 'M25to29', 'M30to34', 'M35to39', 'M40to44', 'M45to49', 'M50to54', 'M55to59', 'M60to64', 'F19to24', 'F25to29', 'F30to34', 'F35to39', 'F40to44', 'F45to49', 'F50to54', 'F55to59', 'F60to64']27 average = []28 for arg in args:29 average.append(get_each_average(arg))30 31 for j in section:32 average[i][j] = average[i]['data']33 del average[i]['data']34 i += 135 return average36def get_average():37 df = pd.read_csv("체력측정_항목별_측정_데이터.csv", encoding='utf-8')38 newdf=df[['AGE_GBN', 'TEST_AGE', 'CERT_GBN', 'TEST_SEX', 'ITEM_F001', 'ITEM_F002', 'ITEM_F012', 'ITEM_F019', 'ITEM_F020', 'ITEM_F021', 'ITEM_F022']]39 newdf=newdf.fillna(newdf.mean())40 is_adult=newdf['AGE_GBN']=='성인'41 is_adult=newdf[is_adult]42 is_teen=newdf['AGE_GBN']=='유소년'43 is_teen=newdf[is_teen]44 adult_Male=is_adult['TEST_SEX']=='M'45 adult_Male=is_adult[adult_Male]46 adult_Female=is_adult['TEST_SEX']=='F'47 adult_Female=is_adult[adult_Female]48 teen_Male=is_teen['TEST_SEX']=='M'49 teen_Male=is_teen[teen_Male]50 teen_Female=is_teen['TEST_SEX']=='F'51 teen_Female=is_teen[teen_Female]52 # Male53 M19to24=((adult_Male['TEST_AGE']>=19) & (adult_Male['TEST_AGE']<=24))54 M19to24=adult_Male[M19to24]55 M25to29=((adult_Male['TEST_AGE']>=25) & (adult_Male['TEST_AGE']<=29))56 M25to29=adult_Male[M25to29]57 M30to34=((adult_Male['TEST_AGE']>=30) & (adult_Male['TEST_AGE']<=34))58 M30to34=adult_Male[M30to34]59 M35to39=((adult_Male['TEST_AGE']>=35) & (adult_Male['TEST_AGE']<=39))60 M35to39=adult_Male[M35to39]61 M40to44=((adult_Male['TEST_AGE']>=40) & (adult_Male['TEST_AGE']<=44))62 M40to44=adult_Male[M40to44]63 M45to49=((adult_Male['TEST_AGE']>=45) & (adult_Male['TEST_AGE']<=49))64 M45to49=adult_Male[M45to49]65 M50to54=((adult_Male['TEST_AGE']>=50) & (adult_Male['TEST_AGE']<=54))66 M50to54=adult_Male[M50to54]67 M55to59=((adult_Male['TEST_AGE']>=55) & (adult_Male['TEST_AGE']<=59))68 M55to59=adult_Male[M55to59]69 M60to64=((adult_Male['TEST_AGE']>=60) & (adult_Male['TEST_AGE']<=64))70 M60to64=adult_Male[M60to64]71 M65to69=((adult_Male['TEST_AGE']>=65) & (adult_Male['TEST_AGE']<=69))72 M65to69=adult_Male[M65to69]73 M70to74=((adult_Male['TEST_AGE']>=70) & (adult_Male['TEST_AGE']<=74))74 M70to74=adult_Male[M70to74]75 M75to79=((adult_Male['TEST_AGE']>=75) & (adult_Male['TEST_AGE']<=79))76 M75to79=adult_Male[M75to79]77 M80to84=((adult_Male['TEST_AGE']>=80) & (adult_Male['TEST_AGE']<=84))78 M80to84=adult_Male[M80to84]79 M85=adult_Male['TEST_AGE']>=8580 M85=adult_Male[M85]81 # Female82 F19to24=((adult_Female['TEST_AGE']>=19) & (adult_Female['TEST_AGE']<=24))83 F19to24=adult_Female[F19to24]84 F25to29=((adult_Female['TEST_AGE']>=25) & (adult_Female['TEST_AGE']<=29))85 F25to29=adult_Female[F25to29]86 F30to34=((adult_Female['TEST_AGE']>=30) & (adult_Female['TEST_AGE']<=34))87 F30to34=adult_Female[F30to34]88 F35to39=((adult_Female['TEST_AGE']>=35) & (adult_Female['TEST_AGE']<=39))89 F35to39=adult_Female[F35to39]90 F40to44=((adult_Female['TEST_AGE']>=40) & (adult_Female['TEST_AGE']<=44))91 F40to44=adult_Female[F40to44]92 F45to49=((adult_Female['TEST_AGE']>=45) & (adult_Female['TEST_AGE']<=49))93 F45to49=adult_Female[F45to49]94 F50to54=((adult_Female['TEST_AGE']>=50) & (adult_Female['TEST_AGE']<=54))95 F50to54=adult_Female[F50to54]96 F55to59=((adult_Female['TEST_AGE']>=55) & (adult_Female['TEST_AGE']<=59))97 F55to59=adult_Female[F55to59]98 F60to64=((adult_Female['TEST_AGE']>=60) & (adult_Female['TEST_AGE']<=64))99 F60to64=adult_Female[F60to64]100 F65to69=((adult_Female['TEST_AGE']>=65) & (adult_Female['TEST_AGE']<=69))101 F65to69=adult_Female[F65to69]102 F70to74=((adult_Female['TEST_AGE']>=70) & (adult_Female['TEST_AGE']<=74))103 F70to74=adult_Female[F70to74]104 F75to79=((adult_Female['TEST_AGE']>=75) & (adult_Female['TEST_AGE']<=79))105 F75to79=adult_Female[F75to79]106 F80to84=((adult_Female['TEST_AGE']>=80) & (adult_Female['TEST_AGE']<=84))107 F80to84=adult_Female[F80to84]108 F85=adult_Female['TEST_AGE']>=85109 F85=adult_Female[F85]110 result = get_all_average(M19to24, M25to29, M30to34, M35to39, M40to44, M45to49, M50to54, M55to59, M60to64, F19to24, F25to29, F30to34, F35to39, F40to44, F45to49, F50to54, F55to59, F60to64)111 return result112def get_each_item(item, data):113 gold=int(data.shape[0]*0.3)114 gold_boundary = int(data.shape[0]*0.34)115 silver=int(data.shape[0]*0.5)116 silver_boundary = int(data.shape[0]*0.55)117 bronze=int(data.shape[0]*0.7)118 bronze_boundary = int(data.shape[0]*0.335)119 attend_boundary = int(data.shape[0]*0.72)120 121 item_all = []122 #gold123 item_all.append(int(data[item].sort_values(ascending=False)[0:gold].max()))124 item_all.append(int(data[item].sort_values(ascending=False)[0:gold].mean()))125 item_all.append(int(data[item].sort_values(ascending=False)[0:gold].min()))126 #silver127 item_all.append(int(data[item].sort_values(ascending=False)[gold_boundary:silver].max()))128 item_all.append(int(data[item].sort_values(ascending=False)[gold_boundary:silver].mean()))129 item_all.append(int(data[item].sort_values(ascending=False)[gold_boundary:silver].min()))130 #bronze131 item_all.append(int(data[item].sort_values(ascending=False)[silver_boundary:bronze].max()))132 item_all.append(int(data[item].sort_values(ascending=False)[silver_boundary:bronze].mean()))133 item_all.append(int(data[item].sort_values(ascending=False)[silver_boundary:bronze].min()))134 #attend135 item_all.append(int(data[item].sort_values(ascending=False)[attend_boundary:].max()))136 item_all.append(int(data[item].sort_values(ascending=False)[attend_boundary:].mean()))137 item_all.append(int(data[item].sort_values(ascending=False)[attend_boundary:].min())) 138 if item_all[3] == item_all[2]:139 item_all[3] -= 1140 if item_all[6] == item_all[5]:141 item_all[6] -= 1142 if item_all[9] == item_all[8]:143 item_all[9] -= 1144 return item_all145# M19TO24, 0, 19, 24146def get_each_rank(data, gender, a1, a2):147 result = {"one_gold_top" : -1, "one_gold_avg" : -1, "one_gold_low" : -1, "one_silver_top" : -1, "one_silver_avg" : -1, "one_silver_low" : -1, "one_bronze_top" : -1, "one_bronze_avg" : -1, "one_bronze_low" : -1, "one_attend_top" : -1, "one_attend_avg" : -1, "one_attend_low" : -1,148 "two_gold_top" : -1, "two_gold_avg" : -1, "two_gold_low" : -1, "two_silver_top" : -1, "two_silver_avg" : -1, "two_silver_low" : -1, "two_bronze_top" : -1, "two_bronze_avg" : -1, "two_bronze_low" : -1, "two_attend_top" : -1, "two_attend_avg" : -1, "two_attend_low" : -1,149 "three_gold_top" : -1, "three_gold_avg" : -1, "three_gold_low" : -1, "three_silver_top" : -1, "three_silver_avg" : -1, "three_silver_low" : -1, "three_bronze_top" : -1, "three_bronze_avg" : -1, "three_bronze_low" : -1, "three_attend_top" : -1, "three_attend_avg" : -1, "three_attend_low" : -1,150 "four_gold_top" : -1, "four_gold_avg" : -1, "four_gold_low" : -1, "four_silver_top" : -1, "four_silver_avg" : -1, "four_silver_low" : -1, "four_bronze_top" : -1, "four_bronze_avg" : -1, "four_bronze_low" : -1, "four_attend_top" : -1, "four_attend_avg" : -1, "four_attend_low" : -1,151 "five_gold_top" : -1, "five_gold_avg" : -1, "five_gold_low" : -1, "five_silver_top" : -1, "five_silver_avg" : -1, "five_silver_low" : -1, "five_bronze_top" : -1, "five_bronze_avg" : -1, "five_bronze_low" : -1, "five_attend_top" : -1, "five_attend_avg" : -1, "five_attend_low" : -1,}152 each_rank = []153 each_rank.append(get_each_item("ITEM_F012", data))154 each_rank.append(get_each_item("ITEM_F019", data))155 each_rank.append(get_each_item("ITEM_F020", data))156 each_rank.append(get_each_item("ITEM_F021", data))157 each_rank.append(get_each_item("ITEM_F022", data))158 i = 0159 j = 0160 for key, value in result.items():161 result[key] = each_rank[i][j]162 j += 1163 if j == 12:164 i += 1165 if i == 5:166 break167 j = 0168 for key, value in result.items():169 if value < 0:170 result[key] = 0171 result['gender'] = gender172 result['a1'] = a1173 result['a2'] = a2174 return result175 176def get_rank():177 df = pd.read_csv("체력측정_항목별_측정_데이터.csv", encoding='utf-8')178 newdf=df[['AGE_GBN', 'TEST_AGE', 'CERT_GBN', 'TEST_SEX', 'ITEM_F001', 'ITEM_F002', 'ITEM_F012', 'ITEM_F019', 'ITEM_F020', 'ITEM_F021', 'ITEM_F022']]179 newdf=newdf.fillna(newdf.mean())180 is_adult=newdf['AGE_GBN']=='성인'181 is_adult=newdf[is_adult]182 is_teen=newdf['AGE_GBN']=='유소년'183 is_teen=newdf[is_teen]184 adult_Male=is_adult['TEST_SEX']=='M'185 adult_Male=is_adult[adult_Male]186 adult_Female=is_adult['TEST_SEX']=='F'187 adult_Female=is_adult[adult_Female]188 teen_Male=is_teen['TEST_SEX']=='M'189 teen_Male=is_teen[teen_Male]190 teen_Female=is_teen['TEST_SEX']=='F'191 teen_Female=is_teen[teen_Female]192 # Male193 M19to24=((adult_Male['TEST_AGE']>=19) & (adult_Male['TEST_AGE']<=24))194 M19to24=adult_Male[M19to24]195 M25to29=((adult_Male['TEST_AGE']>=25) & (adult_Male['TEST_AGE']<=29))196 M25to29=adult_Male[M25to29]197 M30to34=((adult_Male['TEST_AGE']>=30) & (adult_Male['TEST_AGE']<=34))198 M30to34=adult_Male[M30to34]199 M35to39=((adult_Male['TEST_AGE']>=35) & (adult_Male['TEST_AGE']<=39))200 M35to39=adult_Male[M35to39]201 M40to44=((adult_Male['TEST_AGE']>=40) & (adult_Male['TEST_AGE']<=44))202 M40to44=adult_Male[M40to44]203 M45to49=((adult_Male['TEST_AGE']>=45) & (adult_Male['TEST_AGE']<=49))204 M45to49=adult_Male[M45to49]205 M50to54=((adult_Male['TEST_AGE']>=50) & (adult_Male['TEST_AGE']<=54))206 M50to54=adult_Male[M50to54]207 M55to59=((adult_Male['TEST_AGE']>=55) & (adult_Male['TEST_AGE']<=59))208 M55to59=adult_Male[M55to59]209 M60to64=((adult_Male['TEST_AGE']>=60) & (adult_Male['TEST_AGE']<=64))210 M60to64=adult_Male[M60to64]211 M65to69=((adult_Male['TEST_AGE']>=65) & (adult_Male['TEST_AGE']<=69))212 M65to69=adult_Male[M65to69]213 M70to74=((adult_Male['TEST_AGE']>=70) & (adult_Male['TEST_AGE']<=74))214 M70to74=adult_Male[M70to74]215 M75to79=((adult_Male['TEST_AGE']>=75) & (adult_Male['TEST_AGE']<=79))216 M75to79=adult_Male[M75to79]217 M80to84=((adult_Male['TEST_AGE']>=80) & (adult_Male['TEST_AGE']<=84))218 M80to84=adult_Male[M80to84]219 M85=adult_Male['TEST_AGE']>=85220 M85=adult_Male[M85]221 # Female222 F19to24=((adult_Female['TEST_AGE']>=19) & (adult_Female['TEST_AGE']<=24))223 F19to24=adult_Female[F19to24]224 F25to29=((adult_Female['TEST_AGE']>=25) & (adult_Female['TEST_AGE']<=29))225 F25to29=adult_Female[F25to29]226 F30to34=((adult_Female['TEST_AGE']>=30) & (adult_Female['TEST_AGE']<=34))227 F30to34=adult_Female[F30to34]228 F35to39=((adult_Female['TEST_AGE']>=35) & (adult_Female['TEST_AGE']<=39))229 F35to39=adult_Female[F35to39]230 F40to44=((adult_Female['TEST_AGE']>=40) & (adult_Female['TEST_AGE']<=44))231 F40to44=adult_Female[F40to44]232 F45to49=((adult_Female['TEST_AGE']>=45) & (adult_Female['TEST_AGE']<=49))233 F45to49=adult_Female[F45to49]234 F50to54=((adult_Female['TEST_AGE']>=50) & (adult_Female['TEST_AGE']<=54))235 F50to54=adult_Female[F50to54]236 F55to59=((adult_Female['TEST_AGE']>=55) & (adult_Female['TEST_AGE']<=59))237 F55to59=adult_Female[F55to59]238 F60to64=((adult_Female['TEST_AGE']>=60) & (adult_Female['TEST_AGE']<=64))239 F60to64=adult_Female[F60to64]240 F65to69=((adult_Female['TEST_AGE']>=65) & (adult_Female['TEST_AGE']<=69))241 F65to69=adult_Female[F65to69]242 F70to74=((adult_Female['TEST_AGE']>=70) & (adult_Female['TEST_AGE']<=74))243 F70to74=adult_Female[F70to74]244 F75to79=((adult_Female['TEST_AGE']>=75) & (adult_Female['TEST_AGE']<=79))245 F75to79=adult_Female[F75to79]246 F80to84=((adult_Female['TEST_AGE']>=80) & (adult_Female['TEST_AGE']<=84))247 F80to84=adult_Female[F80to84]248 F85=adult_Female['TEST_AGE']>=85249 F85=adult_Female[F85]250 result = []251 # Male252 result.append(get_each_rank(M19to24, 0, 19, 24))253 result.append(get_each_rank(M25to29, 0, 25, 29))254 result.append(get_each_rank(M30to34, 0, 30, 34))255 result.append(get_each_rank(M35to39, 0, 35, 39))256 result.append(get_each_rank(M40to44, 0, 40, 44))257 result.append(get_each_rank(M45to49, 0, 45, 49))258 result.append(get_each_rank(M50to54, 0, 50, 54))259 result.append(get_each_rank(M55to59, 0, 55, 59))260 result.append(get_each_rank(M60to64, 0, 60, 64))261 # Female262 result.append(get_each_rank(F19to24, 1, 19, 24))263 result.append(get_each_rank(F25to29, 1, 25, 29))264 result.append(get_each_rank(F30to34, 1, 30, 34))265 result.append(get_each_rank(F35to39, 1, 35, 39))266 result.append(get_each_rank(F40to44, 1, 40, 44))267 result.append(get_each_rank(F45to49, 1, 45, 49))268 result.append(get_each_rank(F50to54, 1, 50, 54))269 result.append(get_each_rank(F55to59, 1, 55, 59))270 result.append(get_each_rank(F60to64, 1, 60, 64))...

Full Screen

Full Screen

app.py

Source:app.py Github

copy

Full Screen

1from flask import Flask, render_template, session, redirect, url_for, session2from flask_wtf import FlaskForm3from wtforms import TextField,SubmitField4from wtforms.validators import NumberRange5import numpy as np 6import pandas as pd7from tensorflow.keras.models import load_model8import joblib9app = Flask(__name__)10# Configure a secret SECRET_KEY 11# We will later learn much better ways to do this!!12app.config['SECRET_KEY'] = 'someRandomKey'13# Loading the model and scaler14youth_model = load_model("model/youth_model.h5")15adult_model = load_model("model/adult_model.h5")16elder_model = load_model("model/elder_model.h5")17youth_scaler = joblib.load("model/youth_scaler.pkl")18adult_scaler = joblib.load("model/adult_scaler.pkl")19elder_scaler = joblib.load("model/elder_scaler.pkl")20youth_group =pd.read_pickle("model/youth_group.pkl")21adult_group =pd.read_pickle("model/adult_group.pkl")22elder_group =pd.read_pickle("model/elder_group.pkl")23# Now create a WTForm Class24class input_youth(FlaskForm):25 test_age = TextField('연령')26 test_sex = TextField('성별')27 height = TextField('신장')28 weight = TextField('몸무게')29 core_cm = TextField('허리둘레')30 run20 = TextField('20m왕복오래달리기')31 situp = TextField('윗몸말아올리기')32 flex = TextField('앉아윗몸앞으로굽히기')33 submit = SubmitField('분석하기')34class input_adult(FlaskForm):35 test_age = TextField('연령')36 test_sex = TextField('성별')37 height = TextField('신장')38 weight = TextField('몸무게')39 core_cm = TextField('허리둘레')40 run20 = TextField('20m왕복오래달리기')41 situp = TextField('교차윗몸일으키기')42 flex = TextField('앉아윗몸앞으로굽히기')43 submit = SubmitField('분석하기')44class input_elder(FlaskForm):45 test_age = TextField('연령')46 test_sex = TextField('성별')47 height = TextField('신장')48 weight = TextField('몸무게')49 core_cm = TextField('허리둘레')50 walk2m = TextField('2분제자리걷기')51 chairup = TextField('의자앉았다일어서기')52 flex = TextField('앉아윗몸앞으로굽히기')53 submit = SubmitField('분석하기')54class typeForm(FlaskForm):55 model_type = TextField('model_type')56 submit = SubmitField('분석하기')57# 메인 페이지58@app.route('/', methods=['GET', 'POST'])59def mainp():60 # Create instance of the form.61 form = typeForm()62 63 # If the form is valid on submission64 if form.validate_on_submit():65 # Grab the data from the input on the form.66 session['model_type'] = form.model_type.data67 return redirect(url_for("index"))68 return render_template('home.html', form=form)69# 예측 페이지70@app.route('/index', methods=['GET', 'POST'])71def index():72 # Create instance of the form.73 model_type = str(session['model_type'])74 if model_type == 'youth':75 form = input_youth()76 # If the form is valid on submission77 if form.validate_on_submit():78 session['test_age'] = form.test_age.data79 age = float(form.test_age.data)80 if age < 15:81 session['group'] = 'A'82 elif age < 17:83 session['group'] = 'B'84 else : session['group'] = 'C'85 86 session['test_sex'] = form.test_sex.data87 session['height'] = form.height.data88 session['weight'] = form.weight.data89 session['core_cm'] = form.core_cm.data90 session['run20'] = form.run20.data91 session['situp'] = form.situp.data92 session['flex'] = form.flex.data93 session['model_type'] = 'youth'94 return redirect(url_for("prediction"))95 return render_template('youth_main.html', form=form)96 97 elif model_type == 'elder':98 form = input_elder()99 if form.validate_on_submit():100 session['test_age'] = form.test_age.data101 age = float(form.test_age.data)102 if age < 70:103 session['group'] = 'A'104 elif age < 80:105 session['group'] = 'B'106 else : session['group'] = 'C'107 session['test_sex'] = form.test_sex.data108 session['height'] = form.height.data109 session['weight'] = form.weight.data110 session['core_cm'] = form.core_cm.data111 session['walk2m'] = form.walk2m.data112 session['chairup'] = form.chairup.data113 session['flex'] = form.flex.data114 session['model_type'] = 'elder'115 return redirect(url_for("prediction"))116 return render_template('elder_main.html', form=form)117 else :118 form = input_adult()119 if form.validate_on_submit():120 session['test_age'] = form.test_age.data121 age = float(form.test_age.data)122 if age < 30:123 session['group'] = 'A'124 elif age < 40:125 session['group'] = 'B'126 elif age < 50:127 session['group'] = 'C'128 else : session['group'] = 'D'129 session['test_sex'] = form.test_sex.data130 session['height'] = form.height.data131 session['weight'] = form.weight.data132 session['core_cm'] = form.core_cm.data133 session['run20'] = form.run20.data134 session['situp'] = form.situp.data135 session['flex'] = form.flex.data136 session['model_type'] = 'adult'137 return redirect(url_for("prediction"))138 return render_template('main.html', form=form)139@app.route('/prediction')140def prediction():141 model_type = session['model_type']142 if model_type == 'youth' :143 144 content = {}145 content['test_age'] = float(session['test_age'])146 content['test_sex'] = float(session['test_sex'])147 content['height'] = float(session['height'])148 content['weight'] = float(session['weight'])149 content['core_cm'] = float(session['core_cm'])150 content['run20'] = float(session['run20'])151 content['situp'] = float(session['situp'])152 content['flex'] = float(session['flex'])153 results = return_prediction(mode = 'youth', model=youth_model,scaler=youth_scaler,sample_json=content)154 155 # pivot data select156 group_label = str(session['group'])157 pivot_select = pd.DataFrame(youth_group.loc[group_label]).T158 if float(session['test_sex']) > 0.5:159 pivot_col = [pivot_select.columns[1][0],pivot_select.columns[3][0],pivot_select.columns[5][0]]160 pivot_data = [pivot_select.iloc[0,1],pivot_select.iloc[0,3],pivot_select.iloc[0,5]]161 else :162 pivot_col = [pivot_select.columns[0][0],pivot_select.columns[2][0],pivot_select.columns[4][0]]163 pivot_data = [pivot_select.iloc[0,0],pivot_select.iloc[0,2],pivot_select.iloc[0,4]]164 return render_template('youth_prediction.html',results=results, pivot_col = pivot_col, pivot_data = pivot_data)165 elif model_type == 'elder':166 content = {}167 content['test_age'] = float(session['test_age'])168 content['test_sex'] = float(session['test_sex'])169 content['height'] = float(session['height'])170 content['weight'] = float(session['weight'])171 content['core_cm'] = float(session['core_cm'])172 content['walk2m'] = float(session['walk2m'])173 content['chairup'] = float(session['chairup'])174 content['flex'] = float(session['flex'])175 results = return_prediction(mode = 'elder', model=elder_model,scaler=elder_scaler,sample_json=content)176 177 # pivot data select178 group_label = str(session['group'])179 pivot_select = pd.DataFrame(elder_group.loc[group_label]).T180 if float(session['test_sex']) > 0.5 :181 pivot_col = [pivot_select.columns[1][0],pivot_select.columns[3][0],pivot_select.columns[5][0]]182 pivot_data = [pivot_select.iloc[0,1],pivot_select.iloc[0,3],pivot_select.iloc[0,5]]183 else :184 pivot_col = [pivot_select.columns[0][0],pivot_select.columns[2][0],pivot_select.columns[4][0]]185 pivot_data = [pivot_select.iloc[0,0],pivot_select.iloc[0,2],pivot_select.iloc[0,4]]186 return render_template('elder_prediction.html',results=results, pivot_col = pivot_col, pivot_data = pivot_data)187 else:188 content = {}189 content['test_age'] = float(session['test_age'])190 content['test_sex'] = float(session['test_sex'])191 content['height'] = float(session['height'])192 content['weight'] = float(session['weight'])193 content['core_cm'] = float(session['core_cm'])194 content['run20'] = float(session['run20'])195 content['situp'] = float(session['situp'])196 content['flex'] = float(session['flex'])197 results = return_prediction(mode = 'adult', model=adult_model,scaler=adult_scaler,sample_json=content)198 199 # pivot data select200 group_label = str(session['group'])201 pivot_select = pd.DataFrame(adult_group.loc[group_label]).T202 if float(session['test_sex']) >0.5 :203 pivot_col = [pivot_select.columns[1][0],pivot_select.columns[3][0],pivot_select.columns[5][0]]204 pivot_data = [pivot_select.iloc[0,1],pivot_select.iloc[0,3],pivot_select.iloc[0,5]]205 else :206 pivot_col = [pivot_select.columns[0][0],pivot_select.columns[2][0],pivot_select.columns[4][0]]207 pivot_data = [pivot_select.iloc[0,0],pivot_select.iloc[0,2],pivot_select.iloc[0,4]]208 return render_template('prediction.html',results=results, pivot_col = pivot_col, pivot_data = pivot_data)209 210def return_prediction(mode, model,scaler,sample_json):211 if mode == 'youth':212 213 test_age = sample_json['test_age']214 test_sex = sample_json['test_sex']215 height = sample_json['height']216 weight = sample_json['weight']217 core_cm = sample_json['core_cm']218 run20 = sample_json['run20']219 situp = sample_json['situp']220 flex = sample_json['flex']221 test_data = [[test_age,test_sex,height,weight,core_cm,run20,situp,flex]]222 elif mode == 'elder':223 224 test_age = sample_json['test_age']225 test_sex = sample_json['test_sex']226 height = sample_json['height']227 weight = sample_json['weight']228 core_cm = sample_json['core_cm']229 walk2m = sample_json['walk2m']230 chairup = sample_json['chairup']231 flex = sample_json['flex']232 test_data = [[test_age,test_sex,height,weight,core_cm,walk2m,chairup,flex]]233 else:234 235 test_age = sample_json['test_age']236 test_sex = sample_json['test_sex']237 height = sample_json['height']238 weight = sample_json['weight']239 core_cm = sample_json['core_cm']240 run20 = sample_json['run20']241 situp = sample_json['situp']242 flex = sample_json['flex']243 test_data = [[test_age,test_sex,height,weight,core_cm,run20,situp,flex]]244 test_data_scaled = scaler.transform(test_data)245 predict = model.predict(test_data_scaled)246 return str(round(predict[0][0],3))247if __name__ == '__main__':...

Full Screen

Full Screen

loops.py

Source:loops.py Github

copy

Full Screen

1# Let's start with some variables to work with.2age = 123test_age = 14# Much like with an if statement, a while statement checks whether a value is true.5# Then, if it is, it does everything under it, in the indented block,6# then returns to the top and checks the condition again.7while test_age < age:8 print("Age is at least:")9 print(test_age)10 test_age = test_age + 111# The last line above is very important in a while loop. If you don't change the condition12# that's being checked, somewhere in the loop, it will evaluate the same way every time.13# This means that your loop will run forever!14# There are a couple ways to clean up the code above. First, we can replace the unwieldy15# increment line (adding one) with the shortcut +=. Next, we can shrink down the code16# to a single print statement by adding a formatted string. To do this, we do three things:17# First, insert the letter 'f' prior to the string itself.18# Next, add curly braces, {}, wherever you want a variable's value to be pasted.19# Finally, add the name of the variable to paste inside the curly braces.20while test_age <= age:21 print(f"Found the age! {test_age}")22 test_age += 123print("test with while loop completed")24# Next we can look at for loops. These loops behave very similarly to while loops,25# But they do some of the bookkeeping for us. Instead of having to manually change the 26# condition being tested each time, a for loop will do it for us.27# The easiest way to do this is with range(). This function will tell the for loop to28# iterate through a loop five times, each time changing the value of the variable in the 29# for _____ statement. In the case below, that's test_age.30for test_age in range(20):31 if test_age == age:32 print(f"Found the age! {test_age}")33 print(test_age)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run green automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful