Best Python code snippet using sure_python
data_analysis.py
Source:data_analysis.py  
1#!/home/shah/yes/bin/python2print("Content-Type: text/html")3print()4def htmlTop():5    print("""6<!DOCTYPE html>7<html>8<head>9<meta name="viewport" content="width=device-width, initial-scale=1">10  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">11  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>12  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>13<script>14function myFunction() {15  window.print();16}17</script>18<style>19.pg {20  width: 100%;21  background-color: #ddd;22}23.mybr1 {24text-align: center;25 width: 1%;26  height: 30px;27  background-color: yellow;28}29.mybr2 {30text-align: center;31 32  width: 1%;33  height: 30px;34  background-color: green;35}36.mybr3 {37text-align: center;38 39  width: 1%;40  height: 30px;41  background-color: red;42}43@media print {44    #printbtn {45        display :  none;46    }47}48td,th{49font-weight: bold;50    vertical-align: inherit;51	text-align:center;52border: 1px solid black;53margin: 3px;54}55div.sticky {56  top: 0;57  padding: 5px;58  background-color: #cae8ca;59  border: 2px solid #4CAF50;60}61p.indent{ padding-left: 1.8em }62</style>63</head>64<body>65<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>66    67""")68import cgi69import mysql.connector70form = cgi.FieldStorage()71session = form.getvalue("session")72branch = form.getvalue("branch")73sem = form.getvalue("sem")74subject = form.getvalue("subject")75def htmlBottom():76    print("""77<br> 78<br> 79<br> 80<br>81""")82    print("""       83	</body></html>84  """)85def connectDB():86    con = mysql.connector.connect(user='root', password='', host='localhost', database='result_demo')87    cur = con.cursor()88    return con, cur89def select(con, cur):90    sec_A = """91    select DISTINCT COUNT(*) from MASTER_TABLE where 92    (93    SESSION= {}  AND BRANCH_CODE = {} and SEMESTER= {} AND SUBJECT_CODE = '{}' AND SECTION ='A') """.format(session,branch,sem,subject)94    cur.execute(sec_A)95    myresult = cur.fetchall()96    sec_A_total_students=myresult[0][0]97    #print(sec_A_total_students)98    sec_B = """99     select DISTINCT COUNT(*) from MASTER_TABLE where 100        (101        SESSION= {}  AND BRANCH_CODE = {} and SEMESTER= {} AND SUBJECT_CODE = '{}' AND SECTION ='B') """.format(session,branch,sem,subject)102    cur.execute(sec_B)103    myresult = cur.fetchall()104    sec_B_total_students = myresult[0][0]105    #print(sec_B_total_students)106    sec_C = """107        select DISTINCT COUNT(*) from MASTER_TABLE where 108        (109        SESSION= {}  AND BRANCH_CODE = {} and SEMESTER= {} AND SUBJECT_CODE = '{}' AND SECTION ='C') """.format(session,110                                                                                                                branch,111                                                                                                                sem,112                                                                                                                subject)113    cur.execute(sec_C)114    myresult = cur.fetchall()115    sec_C_total_students = myresult[0][0]116    #print(sec_C_total_students)117    sec_D = """118           select DISTINCT COUNT(*) from MASTER_TABLE where 119           (120           SESSION= {}  AND BRANCH_CODE = {} and SEMESTER= {} AND SUBJECT_CODE = '{}' AND SECTION ='D') """.format(121        session,122        branch,123        sem,124        subject)125    cur.execute(sec_D)126    myresult = cur.fetchall()127    sec_D_total_students = myresult[0][0]128    #print(sec_D_total_students)129    fail_1 =  """130           select COUNT(*) from MASTER_TABLE where 131           (132           SESSION= {}  AND BRANCH_CODE = {} and SEMESTER= {} AND SUBJECT_CODE = '{}' AND SECTION ='A' AND GRADE ='F') """.format(133        session,134        branch,135        sem,136        subject)137    cur.execute(fail_1)138    fail_1=cur.fetchall()139    sec_A_fail=fail_1[0][0]140    fail_1 = """141             select COUNT(*) from MASTER_TABLE where 142             (143             SESSION= {}  AND BRANCH_CODE = {} and SEMESTER= {} AND SUBJECT_CODE = '{}' AND SECTION ='B' AND GRADE ='F') """.format(144        session,145        branch,146        sem,147        subject)148    cur.execute(fail_1)149    fail_1 = cur.fetchall()150    sec_B_fail = fail_1[0][0]151    fail_1 = """152             select COUNT(*) from MASTER_TABLE where 153             (154             SESSION= {}  AND BRANCH_CODE = {} and SEMESTER= {} AND SUBJECT_CODE = '{}' AND SECTION ='C' AND GRADE ='F') """.format(155        session,156        branch,157        sem,158        subject)159    cur.execute(fail_1)160    fail_1 = cur.fetchall()161    sec_C_fail = fail_1[0][0]162    fail_1 = """163             select COUNT(*) from MASTER_TABLE where 164             (165             SESSION= {}  AND BRANCH_CODE = {} and SEMESTER= {} AND SUBJECT_CODE = '{}' AND SECTION ='D' AND GRADE ='F') """.format(166        session,167        branch,168        sem,169        subject)170    cur.execute(fail_1)171    fail_1 = cur.fetchall()172    sec_D_fail = fail_1[0][0]173    return sec_A_total_students,sec_B_total_students,sec_C_total_students,sec_D_total_students,sec_A_fail,sec_B_fail,sec_C_fail,sec_D_fail174def print_data(s1_total,s2_total,s3_total,s4_total,fail1,fail2,fail3,fail4):175    print("""176    <div style="border: 15px SOLID grey" >177    <br><table width="80%" id="tableID" align="center">178    179    <center>180    <tr style="background-color: lightgrey" >181    <th width="100">SR. NO.</th> <th width="250">TEACHER NAME</th><th width="100">SECTION</th><th width="250">TOTAL STUDENTS</th> <th width="100">PASS</th> <th width="100">FAIL</th> <th width="100">PASS %</th></tr>182   183    """)184    try:185        x = round(((s1_total-fail1)/s1_total)*100,2)186    except:187        x= 0188    print("<tr>")189    print("<th align =\"center\" style=\"background-color: lightblue\">1</th>")190    print("<th align =\"center\">SHYAMU</th>")191    print("<th align =\"center\">A</th>")192    print("<th align =\"center\" style=\"background-color: yellow\" >{}</th>".format(s1_total))193    print("<th align =\"center\" style=\"background-color: lightgreen\">{}</th>".format(s1_total-fail1))194    print("<th align =\"center\" style=\"background-color: red\">{}</th>".format(fail1))195    print("<th align =\"center\" style=\"background-color: pink\">{}</th>".format(x))196    print("</tr>")197    try:198        x = round(((s2_total - fail2) / s2_total) * 100, 2)199    except:200        x = 0201    print("<tr>")202    print("<th align =\"center\" style=\"background-color: lightblue\">2</th>")203    print("<th align =\"center\">JAY</th>")204    print("<th align =\"center\">B</th>")205    print("<th align =\"center\" style=\"background-color: yellow\">{}</th>".format(s2_total))206    print("<th align =\"center\" style=\"background-color: lightgreen\">{}</th>".format(s2_total-fail2))207    print("<th align =\"center\" style=\"background-color: red\">{}</th>".format(fail2))208    print("<th align =\"center\" style=\"background-color: pink\">{}</th>".format(x))209    print("</tr>")210    try:211        x = round(((s3_total - fail3) / s3_total) * 100, 2)212    except:213        x = 0214    print("<tr>")215    print("<th align =\"center\" style=\"background-color: lightblue\">3</th>")216    print("<th align =\"center\">VEERU</th>")217    print("<th align =\"center\">C</th>")218    print("<th align =\"center\" style=\"background-color: yellow\">{}</th>".format(s3_total))219    print("<th align =\"center\" style=\"background-color: lightgreen\">{}</th>".format(s3_total-fail3))220    print("<th align =\"center\" style=\"background-color: red\">{}</th>".format(fail3))221    print("<th align =\"center\" style=\"background-color: pink\">{}</th>".format(x))222    print("</tr>")223    try:224        x = round(((s4_total - fail4) / s4_total) * 100, 2)225    except:226        x = 0227    print("<tr>")228    print("<th align =\"center\" style=\"background-color: lightblue\">4</th>")229    print("<th align =\"center\">MINTU</th>")230    print("<th align =\"center\">D</th>")231    print("<th align =\"center\" style=\"background-color: yellow\">{}</th>".format(s4_total))232    print("<th align =\"center\" style=\"background-color: lightgreen\">{}</th>".format(s4_total-fail4))233    print("<th align =\"center\" style=\"background-color: red\">{}</th>".format(fail4))234    print("<th align =\"center\" style=\"background-color: pink\">{}</th>".format(x))235    print("</tr>")236    print("</center></tbody></table>")237# con.commit()238# cur.close()239# con.close()240print("<br>")241def columns_chart(p1,p2,p3,p4,f1,f2,f3,f4):242    print("<br><center>")243    print("""<button onclick="abcd({},{},{},{},{},{},{},{})">click here for column chart</button></center>244        <button><a href='data_analysis.php'>Another Result</a></button>245<br><br>""".format(p1,p2,p3,p4,f1,f2,f3,f4))246    print("""247    <!DOCTYPE HTML>248<html>249<head>  250<meta charset="UTF-8">251<script>252function abcd(p1,p2,p3,p4,f1,f2,f3,f4){253var chart = new CanvasJS.Chart("chartContainer", {254	animationEnabled: true,255	title:{256		text: "Section Wise Result"257	},	258	axisY: {259		title: "Percentage",260		titleFontColor: "#4F81BC",261		lineColor: "#4F81BC",262		labelFontColor: "#4F81BC",263		tickColor: "#4F81BC"264	},265	toolTip: {266		shared: true267	},268	legend: {269		cursor:"pointer",270		itemclick: toggleDataSeries271	},272	data: [{273		type: "column",274		name: "Pass %",275		legendText: "Pass %",276		showInLegend: true, 277		dataPoints:[278			{ label: "SECTION A", y: p1 },279			{ label: "SECTION B", y: p2 },280			{ label: "SECTION C", y: p3 },281			{ label: "SECTION D", y: p4 },282			283		]284	},285	{286		type: "column",	287		name: "Fail %",288		legendText: "Fail %",289		showInLegend: true,290		dataPoints:[291			{ label: "SECTION A", y: f1 },292			{ label: "SECTION B", y: f2 },293			{ label: "SECTION C", y: f3 },294			{ label: "SECTION D", y: f4 },295			296		]297	}]298});299chart.render();300function toggleDataSeries(e) {301	if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {302		e.dataSeries.visible = false;303	}304	else {305		e.dataSeries.visible = true;306	}307	chart.render();308}309}310</script>311</head>312<body>313<div id="chartContainer" style="height: 380px; max-width: 920px; margin: 0px auto;"></div>314<script src="../../canvasjs.min.js"></script>315""")316# print("the connection is closed")317if __name__ == "__main__":318    htmlTop()319    db, cursor = connectDB()320    s1_total,s2_total,s3_total,s4_total,fail1,fail2,fail3,fail4 = select(db, cursor)321    try:322        sec1_pass_per = round(((s1_total - fail1) / s1_total) * 100, 2)323        fail1_per = 100 - sec1_pass_per324    except:325        sec1_pass_per = 0326    try:327        sec2_pass_per = round(((s2_total - fail2) / s2_total) * 100, 2)328        fail2_per = 100 - sec2_pass_per329    except:330        sec2_pass_per = 0331    try:332        sec3_pass_per = round(((s3_total - fail3) / s3_total) * 100, 2)333        fail3_per = 100 - sec3_pass_per334    except:335        sec3_pass_per = 0336    try:337        sec4_pass_per = round(((s4_total - fail4) / s4_total) * 100, 2)338        fail4_per = 100 - sec4_pass_per339    except:340        sec4_pass_per = 0341    print("<h3><center>Data Analysis for <b><mark>{}<mark></b></center></h3>".format(subject))342    print_data(s1_total,s2_total,s3_total,s4_total,fail1,fail2,fail3,fail4)343    columns_chart(sec1_pass_per,sec2_pass_per,sec3_pass_per,sec4_pass_per,fail1_per,fail2_per,fail3_per,fail4_per)344    #pie_chart()...app2.py
Source:app2.py  
1import flask2from flask import request3import pickle4import datetime5from chart import logg_import as logg_import,logg_import26# import matplotlib.pyplot as plt7import pandas as pd8# Initialize the app9app = flask.Flask(__name__)10# @app.route("/")11# def hello():12#     return """welcome"""13# Let's turn this into an API where you can post input data and get14# back output data after some calculations.15# If a user makes a POST request to http://127.0.0.1:5000/predict, and16# sends an X vector (to predict a class y_pred) with it as its data,17# we will use our trained LogisticRegression model to make a18# prediction and send back another JSON with the answer. You can use19# this to make interactive visualizations.20@app.route("/", methods=["POST", "GET"])21def predict():22    video_num = 26370848323    fail_1 = 024    if (request.args):25        video_num = int(request.args.get('video_num')) or 26370848326        # fail_1 = int(request.args.get('myRange')) or 027    # if (request.args):28    #     video_num = int(request.args.get('video_num')) or 029    #     fail_1 = int(request.args.get('myRange')) or 030    # else:31    #     video_num = 032    #     fail_1 = 033    #34    time_play=(datetime.timedelta(seconds=fail_1))35    fail_2= fail_1 * 3036    hour_play=fail_2//360037    minute_play=(fail_2%3600) // 6038    second_play=(fail_2%3600)%6039    # group_seconds=logg_import(fail_1,video_num)40    df4,comments,df3=logg_import2(fail_1,video_num)41    df5= df4[pd.notnull(df4['outcome'])]42    return flask.render_template('predictor.html',43    data = df3.to_json(),44    data2=df4.to_json(),45    data3=df5.to_json(),46    word_data = comments,47    video_num =video_num  ,  min_time = 0, max_time =len(df3),max_time2 =len(df4)*30,48    fail_2=fail_2,49    )50# Start the server, continuously listen to requests.51# We'll have a running web app!52# For local development:53app.run(debug=True)54app.run(host='0.0.0.0',port='8001')55# For public web serving:...수포자문제.py
Source:수포자문제.py  
1def solution(answers):2    fail_1 = [1,2,3,4,5]3    fail_2 = [2,1,2,3,2,4,2,5]4    fail_3 = [3,3,1,1,2,2,4,4,5,5]5    fail_1_c = 06    fail_2_c = 07    fail_3_c = 08    if len(answers)>len(fail_1):9        for i in range(len(answers)-len(fail_1)):10            fail_1.append(fail_1[i])11    if len(answers)>len(fail_2):12        for i in range(len(answers) - len(fail_2)):13            fail_2.append(fail_2[i])14    if len(answers)>len(fail_3):15        for i in range(len(answers) - len(fail_3)):16            fail_3.append(fail_3[i])17    for i in range(len(answers)):18        if fail_1[i]==answers[i]:19            fail_1_c += 120        if fail_2[i] == answers[i]:21            fail_2_c += 122        if fail_3[i] == answers[i]:23            fail_3_c += 124        else:25            pass26    ww = {1 : fail_1_c, 2:fail_2_c, 3:fail_3_c}27    print(ww)28    answer = []29    for key, value in ww.items():30        if value == max(ww.values()):31            answer.append(key)...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
