Page 175 - FULL REPORT 30012024
P. 175

cursor.execute(query)
                                result = cursor.fetchall()
                                return jsonify(result)
                            finally:
                                cursor.close()
                                mydb.close()

                        @app.route('/data/smoking-status')
                        def smoking_status_data():
                            mydb = get_db_connection()
                            try:
                                cursor = mydb.cursor(dictionary=True)
                                query = "SELECT smoking_status, COUNT(*) as count FROM userdata
                        GROUP BY smoking_status"
                                cursor.execute(query)
                                result = cursor.fetchall()
                                return jsonify(result)
                            finally:
                                cursor.close()
                                mydb.close()

                        @app.route('/data/average-bmi')
                        def average_bmi_data():
                            mydb = get_db_connection()
                            try:
                                cursor = mydb.cursor(dictionary=True)
                                query = "SELECT age, AVG(bmi) as avg_bmi FROM userdata GROUP BY
                        age"
                                cursor.execute(query)
                                result = cursor.fetchall()
                                return jsonify(result)
                            finally:
                                cursor.close()
                                mydb.close()

                        @app.route('/data/work-type-distribution')
                        def work_type_distribution_data():
                            mydb = get_db_connection()
                            try:
                                cursor = mydb.cursor(dictionary=True)
                                query = "SELECT work_type, COUNT(*) as count FROM userdata GROUP
                        BY work_type"
                                cursor.execute(query)
                                result = cursor.fetchall()
                                return jsonify(result)
                            finally:
                                cursor.close()
                                mydb.close()

                        @app.route('/data/stroke-risk-by-gender')
                        def stroke_risk_by_gender_data():
                            mydb = get_db_connection()
                            try:
                                cursor = mydb.cursor(dictionary=True)
                                query = "SELECT gender, AVG(stroke_risk) as avg_stroke_risk FROM
                        userdata GROUP BY gender"
                                cursor.execute(query)
                                                               158
   170   171   172   173   174   175   176   177   178   179   180