菜单

Administrator
发布于 2025-03-11 / 158 阅读
0
0

基于Hive的大数据天气分析系统

1. 背景

由于临近毕业季,实现了一个基于HIVE的大数据分析系统。

先介绍一下整体实现思路,要实现大数据分析系统首先明确需求,

1. 获取数据源,这里选择的是2345的天气数据,发现数据源之后要获取内容----可以通过爬虫实现

2. 明确要达到的目标----1)有一个用户管理的系统,2)有一些图表

3. 技术选型 由于采集较为简单 选用最简单的request即可 加上数据并不多且访问过快会影响网站业务,没有增加并发处理

4. 图表展示可选finebi or echars 为了与系统兼容性更好 选择了echars,finebi是商业软件

5. 由于XX需求要求必须使用HIVE和大数据技术栈,所以选取HIVE进行数据中间存储,spark做计算引擎,yarn实现调度和监控,最终保存在MYSQL作为业务数据表

6. 通过上述内容已经实现数据发现----数据采集----数据处理----数据存储

7. 需要一个管理系统,为了快速实现需求 选取了pear-admin-flask框架,该框架前端应用layui,后端采用flask实现

8.将实现好的管理系统与MYSQL进行对接,即可实现该系统

9. 数仓设计

由于数据采集的数据存储在MySQL里,第一步要先将数据抽取到HIVE,该步骤通过sqoop实现

按照数仓规范

第一层是ODS(源数据层)----该层不进行任何处理,只保留sqoop抽取过来的数据。

第二层是DWD(数据清洗层)----该层主要进行数据清洗,以及部分数据拆分----通过简单查询数据,发现有缺失值,进行填充。

第三次是DWM(中间层)----该层主要进行数据聚合,将DWD层清洗之后的数据进行一些指标计算。

第四层是DWS(统计层)----该层的主要目的是针对数据聚合之后的数据进行汇总。

第五层是ADS(应用层)----该层的主要目的是为导出做准备,数据是已经经过完全处理的数据。

10. 预测

该系统采用时间序列分析的方式进行预测气温,对未来气温将进行预测

2.研究背景和意义

自己想个理由:例如目前较少有针对XX地区的天气进行针对性分析,通过这些针对性分析,可以对出行规划,农事农忙,天气预测等进行分析

3. 技术背景和工具介绍

技术:

后端:Flask+flask-sqlalchemy+mysql

验证码:PILLOW(如果问的话)

前端:layui+echars

数据处理:sqoop+spark+hive+MySQL

数据进度监控:yarn

数据采集:requests+sqlite(去重)

预测:Prophet(时间序列)

语言:Python3.9

挑几个去百度一下搜索一下咋回事就行

4. 流程设计

MySQL表

CREATE TABLE `url_list` (
  `url` varchar(255) DEFAULT NULL,
  `title` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


CREATE TABLE `weather_data` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `record_date` date NOT NULL,
  `day_of_week` varchar(255) NOT NULL,
  `max_temperature` varchar(255) NOT NULL,
  `min_temperature` varchar(255) NOT NULL,
  `weather_condition` varchar(255) NOT NULL,
  `wind_speed_direction` varchar(255) NOT NULL,
  `air_quality_index` varchar(255) DEFAULT NULL,
  `air_quality` varchar(255) DEFAULT NULL,
  `month` int(11) NOT NULL,
  `year` int(11) NOT NULL,
  `title` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=705197 DEFAULT CHARSET=utf8mb4;


CREATE TABLE `ads_monthly_weather` (
  `title` text,
  `year` int(11) DEFAULT NULL,
  `month` int(11) DEFAULT NULL,
  `monthly_max_temp` double DEFAULT NULL,
  `monthly_min_temp` double DEFAULT NULL,
  `monthly_avg_max_temp` double DEFAULT NULL,
  `monthly_avg_min_temp` double DEFAULT NULL,
  `monthly_avg_aqi` double DEFAULT NULL,
  `monthly_avg_wind_speed` double DEFAULT NULL,
  `days_count` bigint(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE `ads_temp_range` (
  `title` text,
  `temp_range` text,
  `days_count` bigint(20) DEFAULT NULL,
  `avg_aqi` double DEFAULT NULL,
  `avg_wind_speed` double DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE `ads_weather_analysis` (
  `year` int(11) DEFAULT NULL,
  `month` int(11) DEFAULT NULL,
  `title` text,
  `yearly_avg_max_temp` double DEFAULT NULL,
  `YoY_temp_change` double DEFAULT NULL,
  `MoM_temp_change` double DEFAULT NULL,
  `yearly_avg_aqi` double DEFAULT NULL,
  `YoY_AQI_change` double DEFAULT NULL,
  `MoM_AQI_change` double DEFAULT NULL,
  `yearly_avg_wind_speed` double DEFAULT NULL,
  `YoY_wind_speed_change` double DEFAULT NULL,
  `MoM_wind_speed_change` double DEFAULT NULL,
  `air_quality_rank` int(11) DEFAULT NULL,
  `hottest_city` text,
  `coldest_city` text,
  `windiest_city` text
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE `ads_yearly_weather` (
  `title` text,
  `year` int(11) DEFAULT NULL,
  `yearly_max_temp` double DEFAULT NULL,
  `yearly_min_temp` double DEFAULT NULL,
  `yearly_avg_max_temp` double DEFAULT NULL,
  `yearly_avg_min_temp` double DEFAULT NULL,
  `yearly_avg_aqi` double DEFAULT NULL,
  `yearly_avg_wind_speed` double DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

HIVE表

create temporary table ods_weather_data
(
    id                   int,
    record_date          string,
    day_of_week          string,
    max_temperature      string,
    min_temperature      string,
    weather_condition    string,
    wind_speed_direction string,
    air_quality_index    string,
    air_quality          string,
    month                int,
    year                 int,
    title                string
);

create temporary table dwd_weather_data
(
    id                   int,
    record_date          string,
    day_of_week          string,
    max_temperature      double,
    min_temperature      double,
    weather_condition    string,
    wind_speed_direction string,
    air_quality_index    string,
    air_quality          string,
    month                int,
    year                 int,
    title                string,
    wind_speed           double,
    `date`               date,
    process_time         timestamp
);

create temporary table dwm_monthly_weather
(
    title                  string,
    year                   int,
    month                  int,
    monthly_max_temp       double,
    monthly_min_temp       double,
    monthly_avg_max_temp   double,
    monthly_avg_min_temp   double,
    monthly_avg_aqi        double,
    monthly_avg_wind_speed double,
    days_count             bigint
);



create temporary table dwm_temp_range
(
    title          string,
    temp_range     string,
    days_count     bigint,
    avg_aqi        double,
    avg_wind_speed double
);


create temporary table dwm_yearly_weather
(
    title                 string,
    year                  int,
    yearly_max_temp       double,
    yearly_min_temp       double,
    yearly_avg_max_temp   double,
    yearly_avg_min_temp   double,
    yearly_avg_aqi        double,
    yearly_avg_wind_speed double
);

create table dws_weather_data
(
    year                  int,
    month                 int,
    title                 string,
    yearly_avg_max_temp   double,
    yoy_temp_change       double,
    mom_temp_change       double,
    yearly_avg_aqi        double,
    yoy_aqi_change        double,
    mom_aqi_change        double,
    yearly_avg_wind_speed double,
    yoy_wind_speed_change double,
    mom_wind_speed_change double,
    air_quality_rank      int,
    hottest_city          string,
    coldest_city          string,
    windiest_city         string
)


评论