💖💖作者:计算机毕业设计江挽 💙💙个人简介:曾长期从事计算机专业培训教学,本人也热爱上课教学,语言擅长Java、微信小程序、Python、Golang、安卓Android等,开发项目包括大数据、深度学习、网站、小程序、安卓、算法。平常会做一些项目定制化开发、代码讲解、答辩教学、文档编写、也懂一些降重方面的技巧。平常喜欢分享一些自己开发中遇到的问题的解决办法,也喜欢交流技术,大家有技术代码这一块的问题可以问我! 💛💛想说的话:感谢大家的关注与支持! 💜💜 网站实战项目 安卓/小程序实战项目 大数据实战项目 深度学习实战项目
基于大数据的哺乳动物睡眠数据可视化分析系统介绍
基于大数据的哺乳动物睡眠数据可视化分析系统是一个集数据采集、存储、处理、分析与可视化展示于一体的综合性数据分析平台。该系统采用Hadoop+Spark大数据技术架构作为核心数据处理引擎,通过HDFS分布式文件系统存储海量哺乳动物睡眠相关数据,利用Spark SQL进行高效的数据查询与统计分析,结合Pandas、NumPy等Python科学计算库实现复杂的数据预处理和特征提取。系统后端基于Django框架构建RESTful API接口,前端采用Vue.js+ElementUI组件库开发用户交互界面,通过Echarts图表库实现多维度数据可视化展示,支持柱状图、折线图、散点图、热力图等多种图表类型。系统具备完善的用户权限管理、数据导入导出、实时数据监控等功能模块,能够对不同种类哺乳动物的睡眠时长、睡眠周期、睡眠深度等关键指标进行深入挖掘分析,为生物学研究、动物行为学分析提供数据支撑和决策依据。
基于大数据的哺乳动物睡眠数据可视化分析系统演示视频
基于大数据的哺乳动物睡眠数据可视化分析系统演示图片
基于大数据的哺乳动物睡眠数据可视化分析系统代码展示
from pyspark.sql import SparkSession
from pyspark.sql.functions import col, avg, count, max, min, stddev, when, isnan, isnull
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
import pandas as pd
import numpy as np
import json
from .models import SleepData, AnalysisResult
spark = SparkSession.builder.appName("MammalSleepAnalysis").config("spark.sql.adaptive.enabled", "true").config("spark.sql.adaptive.coalescePartitions.enabled", "true").getOrCreate()
def sleep_pattern_analysis(request):
try:
sleep_df = spark.read.option("header", "true").option("inferSchema", "true").csv("hdfs://localhost:9000/mammal_sleep_data/*.csv")
sleep_df = sleep_df.filter(col("sleep_hours").isNotNull() & col("animal_type").isNotNull())
sleep_df = sleep_df.withColumn("sleep_category", when(col("sleep_hours") >= 15, "Long Sleeper").when(col("sleep_hours") >= 8, "Normal Sleeper").otherwise("Short Sleeper"))
analysis_result = sleep_df.groupBy("animal_type", "sleep_category").agg(count("*").alias("count"), avg("sleep_hours").alias("avg_sleep"), max("sleep_hours").alias("max_sleep"), min("sleep_hours").alias("min_sleep"), stddev("sleep_hours").alias("sleep_std"))
pandas_result = analysis_result.toPandas()
pandas_result = pandas_result.fillna(0)
result_data = []
for _, row in pandas_result.iterrows():
analysis_record = AnalysisResult.objects.create(animal_type=row['animal_type'], sleep_category=row['sleep_category'], count=int(row['count']), avg_sleep=float(row['avg_sleep']), max_sleep=float(row['max_sleep']), min_sleep=float(row['min_sleep']), sleep_std=float(row['sleep_std']) if not pd.isna(row['sleep_std']) else 0)
result_data.append({'id': analysis_record.id, 'animal_type': row['animal_type'], 'sleep_category': row['sleep_category'], 'count': int(row['count']), 'avg_sleep': round(float(row['avg_sleep']), 2), 'max_sleep': float(row['max_sleep']), 'min_sleep': float(row['min_sleep']), 'sleep_std': round(float(row['sleep_std']) if not pd.isna(row['sleep_std']) else 0, 2)})
return JsonResponse({'status': 'success', 'data': result_data, 'total_records': len(result_data)})
except Exception as e:
return JsonResponse({'status': 'error', 'message': str(e)})
def sleep_correlation_analysis(request):
try:
correlation_df = spark.read.option("header", "true").option("inferSchema", "true").csv("hdfs://localhost:9000/mammal_sleep_data/*.csv")
correlation_df = correlation_df.select("animal_type", "sleep_hours", "body_weight", "brain_weight", "life_span").filter(col("sleep_hours").isNotNull() & col("body_weight").isNotNull() & col("brain_weight").isNotNull() & col("life_span").isNotNull())
correlation_df = correlation_df.withColumn("weight_ratio", col("brain_weight") / col("body_weight"))
correlation_df = correlation_df.withColumn("sleep_efficiency", col("sleep_hours") / 24 * 100)
stats_result = correlation_df.groupBy("animal_type").agg(avg("sleep_hours").alias("avg_sleep"), avg("body_weight").alias("avg_body_weight"), avg("brain_weight").alias("avg_brain_weight"), avg("life_span").alias("avg_life_span"), avg("weight_ratio").alias("avg_weight_ratio"), avg("sleep_efficiency").alias("avg_sleep_efficiency"), count("*").alias("sample_count"))
pandas_stats = stats_result.toPandas()
correlation_matrix = pandas_stats[['avg_sleep', 'avg_body_weight', 'avg_brain_weight', 'avg_life_span', 'avg_weight_ratio', 'avg_sleep_efficiency']].corr()
correlation_data = []
for i, row_name in enumerate(correlation_matrix.index):
for j, col_name in enumerate(correlation_matrix.columns):
correlation_data.append({'x_factor': row_name, 'y_factor': col_name, 'correlation_value': round(correlation_matrix.iloc[i, j], 3)})
animal_stats = []
for _, row in pandas_stats.iterrows():
animal_stats.append({'animal_type': row['animal_type'], 'avg_sleep': round(row['avg_sleep'], 2), 'avg_body_weight': round(row['avg_body_weight'], 2), 'avg_brain_weight': round(row['avg_brain_weight'], 2), 'avg_life_span': round(row['avg_life_span'], 2), 'avg_weight_ratio': round(row['avg_weight_ratio'], 6), 'avg_sleep_efficiency': round(row['avg_sleep_efficiency'], 2), 'sample_count': int(row['sample_count'])})
return JsonResponse({'status': 'success', 'correlation_matrix': correlation_data, 'animal_statistics': animal_stats, 'total_animals': len(animal_stats)})
except Exception as e:
return JsonResponse({'status': 'error', 'message': str(e)})
@csrf_exempt
def sleep_data_preprocessing(request):
try:
raw_df = spark.read.option("header", "true").option("inferSchema", "true").csv("hdfs://localhost:9000/raw_mammal_data/*.csv")
cleaned_df = raw_df.filter(col("animal_name").isNotNull() & col("sleep_total").isNotNull())
cleaned_df = cleaned_df.withColumn("sleep_hours", when(col("sleep_total") > 24, 24).when(col("sleep_total") < 0, 0).otherwise(col("sleep_total")))
cleaned_df = cleaned_df.withColumn("body_weight_kg", when(col("body_weight") < 0.001, 0.001).when(col("body_weight") > 10000, 10000).otherwise(col("body_weight")))
cleaned_df = cleaned_df.withColumn("brain_weight_g", when(col("brain_weight") < 0.001, 0.001).when(col("brain_weight") > 5000, 5000).otherwise(col("brain_weight")))
cleaned_df = cleaned_df.withColumn("sleep_rem_hours", when(col("sleep_rem").isNull() | (col("sleep_rem") < 0), 0).when(col("sleep_rem") > col("sleep_hours"), col("sleep_hours")).otherwise(col("sleep_rem")))
cleaned_df = cleaned_df.withColumn("sleep_nonrem_hours", col("sleep_hours") - col("sleep_rem_hours"))
cleaned_df = cleaned_df.withColumn("data_quality", when((col("sleep_hours").isNull() | col("body_weight_kg").isNull() | col("brain_weight_g").isNull()), "Low").when((col("sleep_rem_hours").isNull() | (col("sleep_rem_hours") == 0)), "Medium").otherwise("High"))
final_df = cleaned_df.select("animal_name", "animal_type", "sleep_hours", "sleep_rem_hours", "sleep_nonrem_hours", "body_weight_kg", "brain_weight_g", "life_span", "data_quality")
processed_count = final_df.count()
final_df.write.mode("overwrite").option("header", "true").csv("hdfs://localhost:9000/processed_mammal_data/")
sample_data = final_df.limit(100).toPandas()
quality_stats = final_df.groupBy("data_quality").count().toPandas()
quality_distribution = [{'quality': row['data_quality'], 'count': int(row['count'])} for _, row in quality_stats.iterrows()]
sample_records = sample_data.fillna(0).to_dict('records')
for record in sample_records:
for key, value in record.items():
if pd.isna(value):
record[key] = 0
elif isinstance(value, (np.integer, np.floating)):
record[key] = float(value)
return JsonResponse({'status': 'success', 'processed_count': processed_count, 'quality_distribution': quality_distribution, 'sample_data': sample_records[:20], 'message': 'Data preprocessing completed successfully'})
except Exception as e:
return JsonResponse({'status': 'error', 'message': str(e)})
基于大数据的哺乳动物睡眠数据可视化分析系统文档展示
💖💖作者:计算机毕业设计江挽 💙💙个人简介:曾长期从事计算机专业培训教学,本人也热爱上课教学,语言擅长Java、微信小程序、Python、Golang、安卓Android等,开发项目包括大数据、深度学习、网站、小程序、安卓、算法。平常会做一些项目定制化开发、代码讲解、答辩教学、文档编写、也懂一些降重方面的技巧。平常喜欢分享一些自己开发中遇到的问题的解决办法,也喜欢交流技术,大家有技术代码这一块的问题可以问我! 💛💛想说的话:感谢大家的关注与支持! 💜💜 网站实战项目 安卓/小程序实战项目 大数据实战项目 深度学习实战项目