基于大数据的烟酒成瘾个体数据分析与可视化系统演示效果

52 阅读9分钟

💖💖作者:计算机编程小央姐 💙💙个人简介:曾长期从事计算机专业培训教学,本人也热爱上课教学,语言擅长Java、微信小程序、Python、Golang、安卓Android等,开发项目包括大数据、深度学习、网站、小程序、安卓、算法。平常会做一些项目定制化开发、代码讲解、答辩教学、文档编写、也懂一些降重方面的技巧。平常喜欢分享一些自己开发中遇到的问题的解决办法,也喜欢交流技术,大家有技术代码这一块的问题可以问我! 💛💛想说的话:感谢大家的关注与支持! 💜💜

💕💕文末获取源码

@TOC

基于大数据的烟酒成瘾个体数据分析与可视化系统演示效果-系统功能介绍

基于大数据的烟酒成瘾个体数据分析与可视化系统是一套专门针对烟酒成瘾行为进行深度数据挖掘和智能分析的综合性平台。该系统采用Hadoop分布式文件系统作为底层存储架构,结合Spark大数据处理引擎实现对海量成瘾个体数据的高效计算和分析。系统通过收集和整理不同人群的吸烟饮酒习惯、人口统计学特征、健康状况、生活方式等多维度数据,运用Spark SQL进行复杂的关联分析和统计计算,深入挖掘年龄、性别、教育水平、收入状况等因素与成瘾行为之间的内在关联。前端采用Vue框架结合ElementUI组件库构建直观的用户交互界面,通过Echarts图表库将分析结果以柱状图、饼图、散点图、热力图等多种可视化形式呈现,帮助研究人员和相关机构直观了解不同群体的成瘾模式和风险特征。系统同时支持Python Django和Java Spring Boot两套后端技术方案,通过Pandas和NumPy进行数据预处理和统计分析,为制定针对性的干预策略和预防措施提供科学的数据支撑。

基于大数据的烟酒成瘾个体数据分析与可视化系统演示效果-系统技术介绍

大数据框架:Hadoop+Spark(本次没用Hive,支持定制) 开发语言:Python+Java(两个版本都支持) 后端框架:Django+Spring Boot(Spring+SpringMVC+Mybatis)(两个版本都支持) 前端:Vue+ElementUI+Echarts+HTML+CSS+JavaScript+jQuery 详细技术点:Hadoop、HDFS、Spark、Spark SQL、Pandas、NumPy 数据库:MySQL

基于大数据的烟酒成瘾个体数据分析与可视化系统演示效果-系统背景意义

现代社会中烟酒成瘾问题日益严重,不仅严重危害个人身心健康,也给家庭和社会带来沉重负担。传统的成瘾研究往往依赖小规模样本调查和定性分析,缺乏对大规模人群数据的深入挖掘和系统性分析。随着大数据技术的快速发展和普及,为深入研究成瘾行为模式提供了新的技术手段和分析思路。当前的成瘾研究数据散落在各个医疗机构、调研机构和社会组织中,缺乏统一的数据整合和分析平台,导致研究结果碎片化且难以形成系统性认知。同时,现有的数据分析工具大多停留在简单的统计层面,无法深入挖掘多维因素之间的复杂关联关系,也缺乏直观的可视化展示方式来支撑决策制定。面对这样的现状,迫切需要构建一个基于大数据技术的综合分析平台,能够整合多源异构的成瘾相关数据,通过先进的数据挖掘算法揭示隐藏的行为模式和风险因素。 本课题的研究意义主要体现在技术创新和实际应用两个层面。从技术角度来看,该系统将大数据处理技术应用于成瘾行为研究领域,探索了Hadoop和Spark等技术在健康数据分析中的具体应用方法,为类似的健康大数据分析项目提供了技术参考和实施方案。通过构建完整的数据处理流水线,验证了大数据技术在处理复杂多维健康数据方面的可行性和有效性。从实际应用角度来看,该系统能够为相关研究机构和公共卫生部门提供数据分析工具,帮助他们更好地理解不同人群的成瘾行为特征和影响因素。系统产生的分析结果可以为制定更精准的干预策略提供参考依据,比如针对特定年龄段或职业群体设计差异化的戒瘾方案。同时,系统的可视化功能使得研究成果能够以更直观的方式呈现给决策者和公众,提高了研究结果的传播效果和社会影响力。虽然作为毕业设计项目在规模和深度上存在一定局限性,但该系统仍然能够为相关领域的研究工作提供有价值的技术支撑和方法借鉴。

基于大数据的烟酒成瘾个体数据分析与可视化系统演示效果-系统演示视频

演示视频

基于大数据的烟酒成瘾个体数据分析与可视化系统演示效果-系统演示图片

在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述

基于大数据的烟酒成瘾个体数据分析与可视化系统演示效果-系统部分代码

from pyspark.sql import SparkSession

from pyspark.sql.functions import *

from pyspark.sql.types import *

import pandas as pd

import numpy as np

from django.http import JsonResponse

from django.views.decorators.csrf import csrf_exempt

import json

spark = SparkSession.builder.appName("SmokingDrinkingAnalysis").config("spark.sql.adaptive.enabled", "true").config("spark.sql.adaptive.coalescePartitions.enabled", "true").getOrCreate()

@csrf_exempt

def analyze_age_addiction_patterns(request):

    if request.method == 'POST':

        data = json.loads(request.body)

        df = spark.createDataFrame(pd.read_csv(data.get('file_path')))

        df = df.filter(col("age").isNotNull() & col("smokes_per_day").isNotNull() & col("drinks_per_week").isNotNull())

        age_groups = df.withColumn("age_group", 

            when(col("age") < 25, "18-24")

            .when(col("age") < 35, "25-34")

            .when(col("age") < 45, "35-44")

            .when(col("age") < 55, "45-54")

            .otherwise("55+"))

        smoking_stats = age_groups.groupBy("age_group").agg(

            avg("smokes_per_day").alias("avg_smokes"),

            stddev("smokes_per_day").alias("std_smokes"),

            max("smokes_per_day").alias("max_smokes"),

            min("smokes_per_day").alias("min_smokes"),

            count("*").alias("count")

        ).orderBy("age_group")

        drinking_stats = age_groups.groupBy("age_group").agg(

            avg("drinks_per_week").alias("avg_drinks"),

            stddev("drinks_per_week").alias("std_drinks"),

            max("drinks_per_week").alias("max_drinks"),

            min("drinks_per_week").alias("min_drinks")

        ).orderBy("age_group")

        correlation_analysis = age_groups.groupBy("age_group").agg(

            corr("smokes_per_day", "drinks_per_week").alias("smoke_drink_correlation")

        ).orderBy("age_group")

        heavy_addiction_threshold = age_groups.filter((col("smokes_per_day") > 20) | (col("drinks_per_week") > 14))

        heavy_addiction_by_age = heavy_addiction_threshold.groupBy("age_group").agg(

            count("*").alias("heavy_addiction_count")

        ).orderBy("age_group")

        total_by_age = age_groups.groupBy("age_group").count().orderBy("age_group")

        addiction_rate = heavy_addiction_by_age.join(total_by_age, "age_group").withColumn(

            "heavy_addiction_rate", 

            round((col("heavy_addiction_count") / col("count")) * 100, 2)

        ).select("age_group", "heavy_addiction_rate")

        smoking_result = smoking_stats.collect()

        drinking_result = drinking_stats.collect()

        correlation_result = correlation_analysis.collect()

        addiction_rate_result = addiction_rate.collect()

        analysis_results = {

            'smoking_patterns': [row.asDict() for row in smoking_result],

            'drinking_patterns': [row.asDict() for row in drinking_result],

            'correlations': [row.asDict() for row in correlation_result],

            'heavy_addiction_rates': [row.asDict() for row in addiction_rate_result],

            'total_records': df.count(),

            'analysis_timestamp': pd.Timestamp.now().strftime('%Y-%m-%d %H:%M:%S')

        }

        return JsonResponse(analysis_results)

    return JsonResponse({'error': 'Invalid request method'})

@csrf_exempt

def analyze_dual_addiction_patterns(request):

    if request.method == 'POST':

        data = json.loads(request.body)

        df = spark.createDataFrame(pd.read_csv(data.get('file_path')))

        df = df.filter(col("smokes_per_day").isNotNull() & col("drinks_per_week").isNotNull())

        df = df.withColumn("smoking_level",

            when(col("smokes_per_day") == 0, "non_smoker")

            .when(col("smokes_per_day") <= 10, "light_smoker")

            .when(col("smokes_per_day") <= 20, "moderate_smoker")

            .otherwise("heavy_smoker"))

        df = df.withColumn("drinking_level",

            when(col("drinks_per_week") == 0, "non_drinker")

            .when(col("drinks_per_week") <= 7, "light_drinker")

            .when(col("drinks_per_week") <= 14, "moderate_drinker")

            .otherwise("heavy_drinker"))

        dual_addiction_matrix = df.groupBy("smoking_level", "drinking_level").agg(

            count("*").alias("count"),

            avg("smokes_per_day").alias("avg_smokes"),

            avg("drinks_per_week").alias("avg_drinks")

        ).orderBy("smoking_level", "drinking_level")

        high_risk_combinations = df.filter(

            ((col("smokes_per_day") > 15) & (col("drinks_per_week") > 10)) |

            ((col("smokes_per_day") > 20) & (col("drinks_per_week") > 7)) |

            ((col("smokes_per_day") > 10) & (col("drinks_per_week") > 14))

        )

        risk_demographics = high_risk_combinations.groupBy("gender", "age_group").agg(

            count("*").alias("high_risk_count"),

            avg("smokes_per_day").alias("avg_smokes_high_risk"),

            avg("drinks_per_week").alias("avg_drinks_high_risk")

        ) if 'gender' in df.columns and 'age_group' in df.columns else None

        correlation_coefficient = df.select(corr("smokes_per_day", "drinks_per_week").alias("correlation")).collect()[0]["correlation"]

        synergy_analysis = df.withColumn("addiction_score",

            col("smokes_per_day") * 0.6 + col("drinks_per_week") * 0.4

        ).withColumn("risk_category",

            when(col("addiction_score") < 5, "low_risk")

            .when(col("addiction_score") < 15, "medium_risk")

            .otherwise("high_risk"))

        risk_distribution = synergy_analysis.groupBy("risk_category").agg(

            count("*").alias("count"),

            avg("addiction_score").alias("avg_score"),

            min("addiction_score").alias("min_score"),

            max("addiction_score").alias("max_score")

        ).orderBy("risk_category")

        cessation_difficulty = df.withColumn("cessation_challenge",

            when((col("smokes_per_day") > 0) & (col("drinks_per_week") > 0), "dual_cessation_needed")

            .when(col("smokes_per_day") > 0, "smoking_cessation_only")

            .when(col("drinks_per_week") > 0, "drinking_cessation_only")

            .otherwise("no_cessation_needed"))

        cessation_stats = cessation_difficulty.groupBy("cessation_challenge").count().orderBy("cessation_challenge")

        matrix_result = dual_addiction_matrix.collect()

        risk_result = risk_distribution.collect()

        cessation_result = cessation_stats.collect()

        demographics_result = risk_demographics.collect() if risk_demographics else []

        analysis_results = {

            'dual_addiction_matrix': [row.asDict() for row in matrix_result],

            'risk_distribution': [row.asDict() for row in risk_result],

            'cessation_needs': [row.asDict() for row in cessation_result],

            'high_risk_demographics': [row.asDict() for row in demographics_result],

            'correlation_coefficient': float(correlation_coefficient) if correlation_coefficient else 0.0,

            'high_risk_count': high_risk_combinations.count(),

            'total_population': df.count(),

            'analysis_timestamp': pd.Timestamp.now().strftime('%Y-%m-%d %H:%M:%S')

        }

        return JsonResponse(analysis_results)

    return JsonResponse({'error': 'Invalid request method'})

@csrf_exempt

def analyze_health_lifestyle_correlations(request):

    if request.method == 'POST':

        data = json.loads(request.body)

        df = spark.createDataFrame(pd.read_csv(data.get('file_path')))

        required_columns = ["smokes_per_day", "drinks_per_week", "has_health_issues", "bmi", "exercise_frequency", "sleep_hours"]

        df = df.select(*[col(c) for c in required_columns if c in df.columns])

        df = df.filter(col("smokes_per_day").isNotNull() & col("drinks_per_week").isNotNull())

        health_impact_analysis = df.withColumn("addiction_severity",

            when((col("smokes_per_day") > 20) | (col("drinks_per_week") > 14), "high")

            .when((col("smokes_per_day") > 10) | (col("drinks_per_week") > 7), "moderate")

            .when((col("smokes_per_day") > 0) | (col("drinks_per_week") > 0), "low")

            .otherwise("none"))

        health_stats = health_impact_analysis.groupBy("addiction_severity", "has_health_issues").agg(

            count("*").alias("count"),

            avg("bmi").alias("avg_bmi"),

            avg("smokes_per_day").alias("avg_smokes"),

            avg("drinks_per_week").alias("avg_drinks")

        ).orderBy("addiction_severity", "has_health_issues") if "has_health_issues" in df.columns and "bmi" in df.columns else None

        lifestyle_correlations = df.select(

            corr("smokes_per_day", "exercise_frequency").alias("smoking_exercise_corr"),

            corr("drinks_per_week", "exercise_frequency").alias("drinking_exercise_corr"),

            corr("smokes_per_day", "sleep_hours").alias("smoking_sleep_corr"),

            corr("drinks_per_week", "sleep_hours").alias("drinking_sleep_corr")

        ).collect()[0] if "exercise_frequency" in df.columns and "sleep_hours" in df.columns else None

        bmi_addiction_analysis = df.withColumn("bmi_category",

            when(col("bmi") < 18.5, "underweight")

            .when(col("bmi") < 25, "normal")

            .when(col("bmi") < 30, "overweight")

            .otherwise("obese"))

        bmi_addiction_stats = bmi_addiction_analysis.groupBy("bmi_category").agg(

            count("*").alias("count"),

            avg("smokes_per_day").alias("avg_smokes"),

            avg("drinks_per_week").alias("avg_drinks"),

            avg("bmi").alias("avg_bmi_in_category")

        ).orderBy("bmi_category") if "bmi" in df.columns else None

        exercise_impact = df.withColumn("exercise_level",

            when(col("exercise_frequency") >= 5, "high")

            .when(col("exercise_frequency") >= 3, "moderate")

            .when(col("exercise_frequency") >= 1, "low")

            .otherwise("sedentary"))

        exercise_addiction_stats = exercise_impact.groupBy("exercise_level").agg(

            count("*").alias("count"),

            avg("smokes_per_day").alias("avg_smokes"),

            avg("drinks_per_week").alias("avg_drinks"),

            stddev("smokes_per_day").alias("std_smokes"),

            stddev("drinks_per_week").alias("std_drinks")

        ).orderBy("exercise_level") if "exercise_frequency" in df.columns else None

        sleep_addiction_analysis = df.withColumn("sleep_quality",

            when(col("sleep_hours") >= 8, "adequate")

            .when(col("sleep_hours") >= 6, "moderate")

            .otherwise("insufficient"))

        sleep_stats = sleep_addiction_analysis.groupBy("sleep_quality").agg(

            count("*").alias("count"),

            avg("smokes_per_day").alias("avg_smokes"),

            avg("drinks_per_week").alias("avg_drinks"),

            avg("sleep_hours").alias("avg_sleep_in_category")

        ).orderBy("sleep_quality") if "sleep_hours" in df.columns else None

        comprehensive_risk_score = df.withColumn("comprehensive_risk",

            col("smokes_per_day") * 0.4 + 

            col("drinks_per_week") * 0.3 +

            (when(col("exercise_frequency") < 2, 5).otherwise(0)) +

            (when(col("sleep_hours") < 6, 3).otherwise(0)) +

            (when(col("bmi") > 30, 4).when(col("bmi") < 18.5, 2).otherwise(0))

        ) if all(c in df.columns for c in ["exercise_frequency", "sleep_hours", "bmi"]) else None

        risk_categories = comprehensive_risk_score.withColumn("risk_level",

            when(col("comprehensive_risk") < 10, "low")

            .when(col("comprehensive_risk") < 20, "moderate")

            .otherwise("high")

        ).groupBy("risk_level").count().orderBy("risk_level") if comprehensive_risk_score else None

        health_result = health_stats.collect() if health_stats else []

        bmi_result = bmi_addiction_stats.collect() if bmi_addiction_stats else []

        exercise_result = exercise_addiction_stats.collect() if exercise_addiction_stats else []

        sleep_result = sleep_stats.collect() if sleep_stats else []

        risk_result = risk_categories.collect() if risk_categories else []

        correlation_dict = lifestyle_correlations.asDict() if lifestyle_correlations else {}

        analysis_results = {

            'health_impact_stats': [row.asDict() for row in health_result],

            'bmi_addiction_patterns': [row.asDict() for row in bmi_result],

            'exercise_addiction_patterns': [row.asDict() for row in exercise_result],

            'sleep_addiction_patterns': [row.asDict() for row in sleep_result],

            'comprehensive_risk_distribution': [row.asDict() for row in risk_result],

            'lifestyle_correlations': correlation_dict,

            'total_analyzed_records': df.count(),

            'analysis_timestamp': pd.Timestamp.now().strftime('%Y-%m-%d %H:%M:%S')

        }

        return JsonResponse(analysis_results)

    return JsonResponse({'error': 'Invalid request method'})

基于大数据的烟酒成瘾个体数据分析与可视化系统演示效果-结语

💟💟如果大家有任何疑虑,欢迎在下方位置详细交流。