Weather

需求:

每个月气温最高的2天

 

数据集:

1949-10-01 14:21:02	34c
1949-10-01 19:21:02	38c
1949-10-02 14:01:02	36c
1950-01-01 11:21:02	32c
1950-10-01 12:21:02	37c
1951-12-01 12:21:02	23c
1950-10-02 12:21:02	41c
1950-10-03 12:21:02	27c
1951-07-01 12:21:02	45c
1951-07-02 12:21:02	46c
1951-07-03 12:21:03	47c

客户端:

package com.ny.mapreduce.weather;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class MyTQ {
	
	public static void main(String[] args) throws Exception {
		//创建conf对象 读取配置文件
		Configuration conf = new Configuration(true);
		
		//创建job对象
		Job job = Job.getInstance(conf);
	
		//Jar包
		job.setJarByClass(MyTQ.class);
		
		//----conf---------配置环节---
		//输入格式化类的创建
//		job.setInputFormatClass(null); 
		/**-- MAP阶段-->*/
		//map类处理输入来的数据
		job.setMapperClass(TMapper.class);
		//Map类处理后产生得K,V    TQ天气的类型定义在TQ类中
		/*Map输出的类型*/
		job.setMapOutputKeyClass(TQ.class);
		job.setMapOutputValueClass(IntWritable.class);
		
		/*  (k,v,p)  分 区*/
		job.setPartitionerClass(TPartitioner.class);
		
		/*缓冲区去  排序*/
		job.setSortComparatorClass(TSortComparator.class);
		/* Combine*/
//		job.setCombinerClass(TCombiner.class);
		/**Map阶段结束*/
		
		
		/**Reduce环节*/
		//分组比较器
		job.setGroupingComparatorClass(TGroupComparator.class);
		//Reduce类处理
		job.setReducerClass(Treduce.class);
		/**Reduce阶段结束*/
		
		/** 输入输出路径*/
		Path input = new Path("/data/weather/input");
		FileInputFormat.addInputPath(job, input);
		
		Path output = new Path("/data/weather/output");
		FileOutputFormat.setOutputPath(job, output );
		
		/**设置reducetask的数量*/
		job.setNumReduceTasks(2);	
		
		job.waitForCompletion(true);
		
	}
	
}

 Map类:

package com.ny.mapreduce.weather;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.util.StringUtils;
//默认输入的格式化类为TextInputFormat.class     <KEYIN, VALUEIN, KEYOUT, VALUEOUT>
public class TMapper extends Mapper<LongWritable, Text, TQ, IntWritable>{

	TQ mkey = new TQ();
	IntWritable mval = new IntWritable();
	
	//重写map()
	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, TQ, IntWritable>.Context context)
			throws IOException, InterruptedException {
		
		try {
			//从value中拿去   1951-07-01 12:21:02	45c
			String[] strs = StringUtils.split(value.toString(), '\t');
			//转换为指定格式时间
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date date = sdf.parse(strs[0]);
			Calendar cal = Calendar.getInstance();
			cal.setTime(date);
			//对key赋值
			mkey.setYear(cal.get(Calendar.YEAR));
			mkey.setMonth(cal.get(Calendar.MONDAY) +1);
			mkey.setDay(cal.get(Calendar.DAY_OF_MONTH));
			
			//获取温度数值
			int wd = Integer.parseInt(strs[1].substring(0, strs[1].length()-1));
			
			mkey.setWd(wd);
			
			//对value赋值
			mval.set(wd);
			
			//map输出
			context.write(mkey, mval);
		} catch (Exception e) {
			e.printStackTrace();
		}
}
	
}

 设置Map输入key的类型

package com.ny.mapreduce.weather;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.io.WritableComparable;

//key实现接口
public class TQ implements WritableComparable<TQ>{
	private int year;
	private int month;
	private int day;
	private int wd;
	public int getYear() {
		return year;
	}

	public void setYear(int year) {
		this.year = year;
	}

	public int getMonth() {
		return month;
	}

	public void setMonth(int month) {
		this.month = month;
	}

	public int getDay() {
		return day;
	}

	public void setDay(int day) {
		this.day = day;
	}

	public int getWd() {
		return wd;
	}

	public void setWd(int wd) {
		this.wd = wd;
	}
	
	//序列化
	@Override
	public void write(DataOutput out) throws IOException {
		out.writeInt(year);
		out.writeInt(month);
		out.writeInt(day);
		out.writeInt(wd);
		
	}
	//反序列化
	@Override
	public void readFields(DataInput in) throws IOException {
		this.year = in.readInt();
		this.month = in.readInt();
		this.day = in.readInt();
		this.wd = in.readInt();
		
	}
	//按日期时间做正序
	@Override
	public int compareTo(TQ that) {
		int c1 = Integer.compare(this.year, that.getYear());
		//年相同按月比
		if(c1 ==0) {
			int c2 = Integer.compare(this.month, that.getMonth());
			//月相同按日比
			if(c2 ==0) {
				return Integer.compare(this.day, that.getDay());
			}
		}
		return 0;
	}
		
}

分区类: 

package com.ny.mapreduce.weather;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Partitioner;

public class TPartitioner extends Partitioner<TQ, IntWritable>{
	//对key进行分组  (分区)
	@Override
	public int getPartition(TQ key, IntWritable value, int numPartitions) {
		
		
		return key.getYear() % numPartitions;
	}

}

排序类:

package com.ny.mapreduce.weather;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

//排序类
public class TSortComparator extends WritableComparator{
	
	public TSortComparator() {
		super(TQ.class,true);
	}
	
	@Override
	public int compare(WritableComparable a, WritableComparable b) {
		TQ t1 = (TQ) a;
		TQ t2 = (TQ) b;
		int c1 = Integer.compare(t1.getYear(), t2.getYear());
		if(c1 ==0) {//年相等比较月
			int c2 = Integer.compare(t1.getMonth(), t2.getMonth());
			if(c2 == 0) {//月相等比较温度
				return -Integer.compare(t1.getWd(), t2.getWd());		
			}
			return c2;
		}
		return c1;	
	}
}

分组类:

package com.ny.mapreduce.weather;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

public class TGroupComparator extends WritableComparator{
	public TGroupComparator() {
		super(TQ.class,true);
	}
	
	@Override
	public int compare(WritableComparable a, WritableComparable b) {
		TQ t1 = (TQ) a;
		TQ t2 = (TQ) b;
		int c1 = Integer.compare(t1.getYear(), t2.getYear());
		if(c1 ==0) {//年相等比较月        年相同月相同表示为一组   reduce   年相同月不同不是一组
			return Integer.compare(t1.getMonth(), t2.getMonth());
		}
		return c1;	
	}
	
}

reduce类 :

package com.ny.mapreduce.weather;
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
//<KEYIN, VALUEIN, KEYOUT, VALUEOUT>
public class Treduce extends Reducer<TQ, IntWritable, Text, IntWritable>{
	Text rkey = new Text();
	IntWritable rval = new IntWritable();
	@Override
	protected void reduce(TQ key, Iterable<IntWritable> valuese, Context context)
			throws IOException, InterruptedException {
		//相同的key为一组1949-10-01   value 23
//		1949 10 01 23
//		1949 10 01 25
		
		int flag=0;
		int day=0;
		for (IntWritable v : valuese) {
			if(flag ==0) {
			rkey.set(key.getYear()+"-"+key.getMonth()+"-"+key.getDay()+":"+key.getWd());
			rval.set(key.getWd());
			flag++;
			day=key.getDay();
			context.write(rkey, rval);
			}
			if(flag!=0 && day!=key.getDay()) {
				rkey.set(key.getYear()+"-"+key.getMonth()+"-"+key.getDay()+":"+key.getWd());
				rval.set(key.getWd());
				context.write(rkey, rval);
				break;
			}
			
		}
}

}

 

出现了数据倾斜 

 

 

Enviro - The complete dynamic AAA sky and weather solution! Very easy setup: The new manager component makes it easy as possible to setup enviro in your scenes. Includes Enviro Lite! This version includes Enviro Lite version aswell. Ideal for multi-platform projects: Use lite version for low end platform like mobiles and standard for pc and consoles. With one click you can switch between enviro versions. The centralized API for your own scripts will work for both versions of course. Profile System: Enviro's new profile system makes tweaking your sky as easy as possible. Tweak settings in runtime and save to profile. Load profiles in design and runtime. Create different profiles for different scenes or share your configurations with other user. Day-Night cycle: Enviro supports a realistic day-night cycle. With correct sun and moon positions with full location support with latitude and longitude. You have options to use your system time or let enviro update time based on realtime minutes. Skybox: Enviro includes an advanced fast atmospheric skybox shader to get great looking skies! You got a lot of options to tweak the sky and even can setup funky alien skies! Lighting: Enviro will realisticly light your scene based on sun altitude. You have complete control over light intensity and color by modifying curves and gradients right in editor! You also can choose between different ambient light modes of course. Seasons: Enviro will change seasons and got a components to swap out gameobject, materials and textures of unity terrain. You are not limited to realistic settings! You can set the start and end days of each season. Enviro also supports temperature simulation, based on season, time of day and current weather. Clouds: Enviro new raymarching cloud system is based on latest cloud rendering papers. These will bring you sky to life and offer plenty options to customize. Clouds performance is optimized by using techs like temporal reprojection and LOD system. In addition there are also fast flat and particle clouds options to mix or use for maximum performance. Fog: Need stunnishing looking fog? Enviro includes an advanced light scattering fog image effect with distance, height and sky fog support. Need fog on your transparent material? No problem, with only a few lines of code you could modify your own transparent shaders to be fogged correctly. And a few particle and transparent shaders already included to get you started! Weather: Enviro includes a very powerfull weather system. You can create your own weather types and drive light, sky, fog and clouds. Enviro supports all kind of unity shuriken particle effects to give you the freedom to create any weather effect you can think of. It includes 11 premade weather types including: Clear Sky, cloudy, raining, stormy, snowy and foggy weather. You can enable lightning storms and choose different ambient and weather sounds for each weather with smooth transitions. Volumetric Lighting: Need some volume light effects you see in AAA games? No problem, enviro support volumetric lighting for directional, point and spot lights out of the box! Scene View Effects: Preview enviro effects like clouds, volume lighting and fog directly while you work on your scenes. You can enable or disable scene view preview for each effect individual of course. Networking: Enviro support UNet, Mirror and Photon out of the box. It will synchronize time and weather with all your players. Enviro also got an minimal mode for headless servers to only calculate time and weather but nothing more. Virtual Reality: Enviro supports multi and singlepass stereoscopic rendering! Tested on Oculus Rift. That's not all! Enviro includes a lot more great features: * Event system for you game logic. * Weather Zones. Create as many zones with their own weather for your biomes. * Orbiting satellites. * Vegetation Growth. And you can use a lot of awesome 3rd-party assets right of the box. Activate and add 3rd-party support through the new interface. Again its easy and fast as possible! * Gaia Compatible! * CTS Compatible! * AQUAS Integration! * LUX Water Integration! * FogVolume 3 Integration! * Vegetation Studio Pro Integration! * Playmaker Actions! * Relief Terrain Shader Integration! * UBER Shader Integration! * MicroSplat Integration! * MegaSplat Shader Integration! * Lux Shader Integration! * Photon Network Integration! * Mirror Network Integration! * Pegasus Integration! Requirements: * Support gamma and linear color space. * Support forward and deferred rendering. * Working on DX9, DX11, DX12, OpenGlCore, Metal and Vulkan. * Volumetric Lighting requires at least shader-model 3.5+ and will be deactivated on DX9 Current limitation: * Volumetric clouds are currently not suitable for fly-throughs! Will be worked on in later updates!
插件名称:Enviro - Sky and Weather 2.0 Enviro - The complete dynamic AAA sky and weather solution! Very easy setup: Just drag-and drop into your scene and assign your main camera or use the runtime assignment features. Profile System: Enviro's new profile system makes tweaking your sky as easy as possible. Tweak settings in runtime and save to profile. Load profiles in design and runtime. Create different profiles for different scenes or share your configurations with other user. Day-Night cycle: Enviro supports a realistic day-night cycle. With correct sun and moon positions with full location support with latitude and longitude. You have options to use your system time or let enviro update time based on realtime minutes. Skybox: Enviro includes an advanced fast atmospheric skybox shader to get great looking skies! You got a lot of options to tweak the sky and even can setup funky alien skies! Lighting: Enviro will realisticly light your scene based on sun altitude. You have complete control over light intensity and color by modifying curves and gradients right in editor! You also can choose between different ambient light modes of course. Seasons: Enviro will change seasons and got a components to swap out gameobject, materials and textures of unity terrain. You are not limited to realistic settings! You can set the amount of days each season last. Clouds: Enviro new volumetric cloud system is based on latest cloud rendering papers. These will bring you sky to life and offer plenty options to customize. In addition there are also fast flat clouds options to mix or use for maximum performance. Fog: Need stunnishing looking fog? Enviro includes an advanced light scattering fog image effect with distance, height and sky fog support. Need fog on your transparent material? No problem, with only a few lines of code you could modify your own transparent shaders to be fogged correctly. And a few particle and transparent shaders already included to get you started! Volumetric Lighting: Need some volume light effects you see in AAA games? No problem, enviro support volumetric lihting for directional, point and spot lights out of the box! Weather: Enviro includes a very powerfull weather system. You can create your own weather types and drive light, sky, fog and clouds. Enviro supports all kind of unity shuriken particle effects to give you the freedom to create any weather effect you can think of. It includes 11 premade weather types including: Clear Sky, cloudy, raining, stormy, snowy and foggy weather. You can enable lightning storms and choose different ambient and weather sounds for each weather with smooth transitions. Networking: Enviro support UNet and Photon out of the box. It will synchronize time and weather with all your players. Enviro also got an minimal mode for headless servers to only calculate time and weather but nothing more. Virtual Reality: Enviro supports multi and singlepass stereoscopic rendering! Tested on Oculus Rift. (Attention: Singlepass currently only supported on Unity 2017+ !) That's not all! Enviro includes a lot more great features: * Event system for you game logic. * Weather Zones. Create as many zones with their own weather for your biomes. * Orbiting satellites. * Vegetation Growth. And you can use a lot of awesome 3rd-party assets right of the box with the included enviro components: * Gaia Compatible! * CTS Compatible! * AQUAS Integration! * FogVolume 3 Integration! * Playmaker Actions! * Relief Terrain Shader Integration! * UBER Shader Integration! * MegaSplat Shader Integration! * Lux Shader Integration! * Photon Network Integration! * Pegasus Integration! Requirements: * Support gamma and linear color space. * Support forward and deferred rendering. * Working on DX9, DX11, DX12, OpenGlCore, Metal and Vulkan. * Volumetric Lighting requires at least shader-model 3.5+ and will be deactivated on DX9 Current limitation: * Volumetric clouds are currently not suitable for fly-throughs! Will be worked on in later updates! WebGL Demo Forum Thread
Enviro - 完整的动态AAA天空和天气解决方案! 非常简单的设置: 只需拖放到您的场景中,分配您的主摄像头或使用运行时分配功能。 配置文件系统: Enviro的新配置文件系统可以尽可能简单地调整你的天空。在运行时调整设置并保存到配置文件。在设计和运行时加载配置文件。为不同的场景创建不同的配置文件或与其他用户共享您的配置。 日夜循环: Enviro支持逼真的夜间循环。具有正确的太阳和月亮位置以及全方位的经纬度支持。你可以选择使用你的系统时间,或根据实时分钟让enviro更新时间。 空中包厢: Enviro包括一个先进的快速大气天空箱着色器,以获得美丽的天空!你有很多选择来调整天空,甚至可以设置时髦的外星人的天空! 照明: Enviro会根据太阳高度真实地照亮您的场景。通过在编辑器中修改曲线和渐变,您可以完全控制光线强度和颜色!您当然也可以选择不同的环境光模式。 季节: Enviro将改变季节,并有一个组件来换取游戏对象,材料和团结地形的纹理。你不仅限于现实的设置!您可以设置每个赛季的最后天数。 云: Enviro新的容积云系统基于最新的云渲染论文。这些将带给你生命的天空,并提供丰富的选项来定制。此外,还有快速平坦的云层选项可以混合或使用,以实现最佳性能。 雾: 需要惊人的看起来雾?Enviro具有高级光散射雾影像效果,支持距离,高度和天空雾。您的透明材质需要雾?没问题,只需要几行代码就可以修改自己的透明着色器,使其正确模糊。并且已经包含一些粒子和透明着色器以帮助您开始! 体积照明: 需要在AAA游戏中看到一些音量灯光效果?没问题,enviro支持定向,点和射灯箱体积立体化! 天气: Enviro包括一个非常强大的天气系统。您可以创建自己的天气类型,并驱动光线,天空,雾和云。Enviro支持所有类型的统一shuriken粒子效果,使您可以自由创建任何您能想到的天气效果。它包括11种预制天气类型,包括:晴朗天空,多云,下雨,暴风雨,下雪和有雾的天气。您可以启用闪电风暴,并为每个天气选择不同的环境和天气声音,并进行平滑过渡。 网络: Enviro支持UNet和Photon开箱即用。它将与所有玩家同步时间和天气。Enviro还为无头服务器提供了最低限度的模式,只计算时间和天气,但仅此而已。 虚拟现实: Enviro支持多通道和单通道立体渲染!经过Oculus Rift测试。(注意:Singlepass目前仅支持Unity 2017+!) 这还不是全部!Enviro包含许多更好的功能: *游戏逻辑的事件系统。 *天气区。为您的生物群组创建与自己的天气一样多的区域。 *轨道卫星。 *植被生长。 资源名称: Sky and Weather v2.3.1(2020/10/4更新) 资源版本:v2.3.1 资源类型: .unitypackage 资源大小: 192 MB 支持版本:5.6.0及以上版本
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值