当前位置: 首页 > news >正文

气象大数据案例项目(求各气象站的平均气温)

气象大数据案例项目(求各气象站的平均气温)

  • 一、项目需求
  • 二、数据格式
  • 三、项目开发
    • 3.1 在windows 进行开发
    • 3.2 运行结果
    • 3.3 对项目打包

一、项目需求

现在有一份来自美国国家海洋和大气管理局的数据集,里面包含近30年每个气象站、每小时的天气预报数据,每个报告的文件大小大约15M。一共有10个气象站,每个报告文件的名字包含气象站ID,每条记录包含气温、风向、天气状况等多个字段信息。现在要求统计美国各气象站30年平均气温。

二、数据格式

在这里插入图片描述
一共10份气象站的数据
在这里插入图片描述
文档里面的数据格式,注意 -9999 说明数据缺失
在这里插入图片描述

三、项目开发

3.1 在windows 进行开发

  • 引入 Hadoop 依赖
<dependency><groupId>org.apache.hadoop</groupId><artifactId>hadoop-client</artifactId><version>2.10.2</version>
</dependency>
  • 开发脚本
package com.feifei.mapreduce;import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileSplit;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;import java.io.IOException;public class WeatherAnalysis {public static class MyMapper extends Mapper<Object, Text, Text, IntWritable> {@Overrideprotected void map(Object key, Text value, Mapper<Object, Text, Text, IntWritable>.Context context) throws IOException, InterruptedException {String line = value.toString();int temperature = Integer.parseInt(line.substring(14, 19).trim());if(temperature != -9999){FileSplit fileSplit = (FileSplit) context.getInputSplit();String id = fileSplit.getPath().getName().substring(5, 10);context.write(new Text(id), new IntWritable(temperature));}}}public static class MyReducer extends Reducer<Text, IntWritable, Text, IntWritable> {private IntWritable mean = new IntWritable();@Overrideprotected void reduce(Text key, Iterable<IntWritable> values, Reducer<Text, IntWritable, Text, IntWritable>.Context context) throws IOException, InterruptedException {int sum = 0;int count = 0;for (IntWritable val : values) {sum += val.get();}mean.set(sum / count);context.write(key, mean);}}public static void main(String[] args) throws Exception {Configuration conf = new Configuration();Job job = Job.getInstance(conf);job.setJarByClass(WeatherAnalysis.class);job.setJobName("WeatherAnalysis");job.setInputFormatClass(TextInputFormat.class);job.setOutputFormatClass(TextOutputFormat.class);FileInputFormat.addInputPath(job, new Path(args[0]));FileOutputFormat.setOutputPath(job, new Path(args[1]));job.setMapperClass(WeatherAnalysis.MyMapper.class);job.setReducerClass(WeatherAnalysis.MyReducer.class);job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(IntWritable.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(IntWritable.class);job.waitForCompletion(true);}
}

在这里插入图片描述

  • 设置入参和保存路径

在这里插入图片描述

3.2 运行结果

在这里插入图片描述

3.3 对项目打包

 mvn clean package

在这里插入图片描述

http://www.lryc.cn/news/420952.html

相关文章:

  • 博客摘录「 一个ModBus RTU程序(支持01、02、03、05、06、15、16功能码)」2024年4月19日
  • Vue3学习笔记第一天
  • C++之类与对象(完结撒花篇)
  • 代码质量的守护者:Python静态代码分析工具的集成之道
  • JVM -- 类加载器
  • OLAP引擎之StarRocks
  • 基于微信小程序的小区业主服务系统(源码+论文+部署讲解等)
  • C++ | Leetcode C++题解之第327题区间和的个数
  • C# Winform 多窗体切换方式一
  • 笔记本CPU天梯图(2024年8月),含AMD/骁龙等新CPU
  • GitLab-CI/CD指南
  • io目录操作学习
  • Ant-Design-Vue
  • 2024互联网暑期实习面经和流程记录分享
  • 风云崛起之拉氏变换和拉式逆变换
  • 1、.Net UI框架:WinUI - .Net宣传系列文章
  • 计算机的错误计算(五十九)
  • 【数学分析笔记】第1章第1节:集合(1)
  • 计算机毕业设计 校园失物招领网站 Java+SpringBoot+Vue 前后端分离 文档报告 代码讲解 安装调试
  • GIT指令大全详解
  • ECCV2024,清华百度提出ReSyncer:可实现音频同步嘴唇动作视频生成。
  • 论文笔记:YOLOv8-QSD 自动驾驶场景小目标检测算法
  • Vue.js状态管理:Vuex与Pinia的比较
  • OJ题目【栈和队列】
  • [shell][git]git将当前分支的HEAD指针重置到最后一次提交的状态
  • 高翔【自动驾驶与机器人中的SLAM技术】学习笔记(六)卡尔曼滤波器二:图解卡尔曼滤波器;卡尔曼滤波器公式理解;面试答法;
  • 高性能日志系统 日志输出模块逻辑
  • haproxy基础
  • C++ 面试题常用总结 详解(满足c++ 岗位必备,不定时更新)
  • LVS实验——部署DR模式集群