计算出10月1日这天每小时的载客量
CarMapper:
package com.hadoop.map; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper; import java.io.IOException; public class CarMapper extends Mapper<LongWritable, Text,Text,Text> {
@Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
if (value!=null&&value.toString().length()>0){
String[] split = value.toString().split(","); String time=split[3]; if (time.substring(4,6).equals("10")&&time.substring(6,8).equals("01")){
//key是车牌号+每小时 context.write(new Text(time.substring(8,10)),value); } } } }
讯享网
CarReduce:
讯享网package com.hadoop.reduce; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; public class CarReduce extends Reducer<Text,Text,Text,Text> {
@Override protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
/ * 载客量 */ int CarryingCapacity=0; HashMap<String, ArrayList<String>> map = new HashMap<>(); ArrayList<String> list = new ArrayList<>(); for (Text value : values) {
String[] split = value.toString().split(","); if (split[2].equals("1")){
CarryingCapacity++; } } context.write(key,new Text(CarryingCapacity+"")); } }
CarDriver:
package com.hadoop.driver; import com.hadoop.map.CarMapper; import com.hadoop.reduce.CarReduce; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; public class CarDriver extends Configured implements Tool {
@Override public int run(String[] args) throws Exception {
Configuration configuration = new Configuration(); Job JB = Job.getInstance(configuration, "CarDriver"); FileSystem fileSystem = FileSystem.get(configuration); JB.setInputFormatClass(TextInputFormat.class); TextInputFormat.addInputPath(JB,new Path("E:\\出租车数据\\")); JB.setMapperClass(CarMapper.class); JB.setMapOutputKeyClass(Text.class); JB.setMapOutputValueClass(Text.class); JB.setReducerClass(CarReduce.class); JB.setOutputKeyClass(Text.class); JB.setOutputValueClass(Text.class); boolean exists = fileSystem.exists(new Path("E:\\出租车数据\\Out")); if (exists){
fileSystem.delete(new Path("E:\\出租车数据\\Out"),true); } JB.setOutputFormatClass(TextOutputFormat.class); TextOutputFormat.setOutputPath(JB,new Path("E:\\出租车数据\\Out")); return JB.waitForCompletion(true)?0:1; } public static void main(String[] args) throws Exception {
ToolRunner.run(new CarDriver(),args); } }
计算出10月1日这天超速(超过120)的车辆,超速的次数,超速的详细时间
CarMapper:
讯享网package com.hadoop.Car1; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper; import java.io.IOException; public class CarMapper extends Mapper<LongWritable, Text,Text,Text> {
@Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
if (value!=null&&value.toString().length()>0){
String[] split = value.toString().split(","); if (Integer.parseInt(split[6])>120){
context.write(new Text(split[0]),value); } } } }
CarReduce:
package com.hadoop.Car1; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer; import java.io.IOException; public class CarReduce extends Reducer<Text,Text,Text,Text> {
@Override protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
StringBuffer sb =new StringBuffer(); int count=0; for (Text value : values) {
count++; String s = value.toString().split(",")[3]; sb.append(s).append("-"); } context.write(key,new Text("超速的次数:"+count+"超速的时间---->"+sb)); } }
CarDriver:
讯享网package com.hadoop.Car1; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; public class CarDriver extends Configured implements Tool {
@Override public int run(String[] args) throws Exception {
Configuration configuration = new Configuration(); Job JB = Job.getInstance(configuration, "CarDriver"); FileSystem fileSystem = FileSystem.get(configuration); JB.setInputFormatClass(TextInputFormat.class); TextInputFormat.addInputPath(JB,new Path("E:\\出租车数据\\")); JB.setMapperClass(CarMapper.class); JB.setMapOutputKeyClass(Text.class); JB.setMapOutputValueClass(Text.class); JB.setReducerClass(CarReduce.class); JB.setOutputKeyClass(Text.class); JB.setOutputValueClass(Text.class); boolean exists = fileSystem.exists(new Path("E:\\出租车数据\\Out")); if (exists){
fileSystem.delete(new Path("E:\\出租车数据\\Out"),true); } JB.setOutputFormatClass(TextOutputFormat.class); TextOutputFormat.setOutputPath(JB,new Path("E:\\出租车数据\\Out")); return JB.waitForCompletion(true)?0:1; } public static void main(String[] args) throws Exception {
ToolRunner.run(new CarDriver(),args); } }
计算出10月1日这天全天停运的车辆
CarMapper:
package com.hadoop.Car2; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper; import java.io.IOException; public class CarMapper extends Mapper<LongWritable, Text,Text,Text> {
@Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
if (value!=null&&value.toString().length()>0){
String[] split = value.toString().split(","); if (split[3].substring(4,6).equals("10")&&split[3].substring(6,8).equals("01")){
context.write(new Text(""),value); } } } }
CarReduce:
讯享网package com.hadoop.Car2; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer; import java.io.IOException; public class CarReduce extends Reducer<Text,Text,Text,Text> {
@Override protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
int count=0; for (Text value : values) {
String[] split = value.toString().split(","); if (split[2].equals("3")||split[2]=="3"){
count++; } } context.write(new Text(""),new Text("这天全天停运的车辆为:"+count+"辆")); } }
CarDriver:
package com.hadoop.Car2; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; public class CarDriver extends Configured implements Tool {
@Override public int run(String[] args) throws Exception {
Configuration configuration = new Configuration(); Job JB = Job.getInstance(configuration, "CarDriver"); FileSystem fileSystem = FileSystem.get(configuration); JB.setInputFormatClass(TextInputFormat.class); TextInputFormat.addInputPath(JB,new Path("E:\\出租车数据\\")); JB.setMapperClass(CarMapper.class); JB.setMapOutputKeyClass(Text.class); JB.setMapOutputValueClass(Text.class); JB.setReducerClass(CarReduce.class); JB.setOutputKeyClass(Text.class); JB.setOutputValueClass(Text.class); boolean exists = fileSystem.exists(new Path("E:\\出租车数据\\Out")); if (exists){
fileSystem.delete(new Path("E:\\出租车数据\\Out"),true); } JB.setOutputFormatClass(TextOutputFormat.class); TextOutputFormat.setOutputPath(JB,new Path("E:\\出租车数据\\Out")); return JB.waitForCompletion(true)?0:1; } public static void main(String[] args) throws Exception {
ToolRunner.run(new CarDriver(),args); } }
计算出10月1日这天载客次数超过10次的车辆,载客总次数,载客详细时间。
CarMapper:
讯享网package com.hadoop.Car3; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper; import java.io.IOException; public class CarMapper extends Mapper<LongWritable, Text,Text,Text> {
@Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
if (value!=null&&value.toString().length()>0){
String[] split = value.toString().split(","); if (split[3].substring(4,6).equals("10")&&split[3].substring(6,8).equals("01")){
context.write(new Text(split[0]),value); } } } }
CarReduce:
package com.hadoop.Car3; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer; import java.io.IOException; public class CarReduce extends Reducer<Text,Text,Text,Text> {
@Override protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
int count=0; StringBuffer sb = new StringBuffer(); for (Text value : values) {
String[] split = value.toString().split(","); if (split[2].equals("1")||split[2]=="1"){
count++; String s=split[3]; sb.append(s).append("_"); } } if (count>10){
context.write(new Text(key),new Text("载客总次数:"+count+"------>载客详细时间:"+sb)); } } }
CarDriver:
讯享网package com.hadoop.Car3; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; public class CarDriver extends Configured implements Tool {
@Override public int run(String[] args) throws Exception {
Configuration configuration = new Configuration(); Job JB = Job.getInstance(configuration, "CarDriver"); FileSystem fileSystem = FileSystem.get(configuration); JB.setInputFormatClass(TextInputFormat.class); TextInputFormat.addInputPath(JB,new Path("E:\\出租车数据\\")); JB.setMapperClass(CarMapper.class); JB.setMapOutputKeyClass(Text.class); JB.setMapOutputValueClass(Text.class); JB.setReducerClass(CarReduce.class); JB.setOutputKeyClass(Text.class); JB.setOutputValueClass(Text.class); boolean exists = fileSystem.exists(new Path("E:\\出租车数据\\Out")); if (exists){
fileSystem.delete(new Path("E:\\出租车数据\\Out"),true); } JB.setOutputFormatClass(TextOutputFormat.class); TextOutputFormat.setOutputPath(JB,new Path("E:\\出租车数据\\Out")); return JB.waitForCompletion(true)?0:1; } public static void main(String[] args) throws Exception {
ToolRunner.run(new CarDriver(),args); } }
计算出10月1日这天连续与运行12小时一以上的车辆
CarMapper:
package com.hadoop.Car4; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper; import java.io.IOException; public class CarMapper extends Mapper<LongWritable, Text,Text,Text> {
@Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
if (value!=null&&value.toString().length()>0){
String[] split = value.toString().split(","); if (split[3].substring(4,6).equals("10")&&split[3].substring(6,8).equals("01")){
context.write(new Text(split[0]),value); } } } }
CarReduce:
讯享网package com.hadoop.Car4; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer; import java.io.IOException; import java.util.HashSet; public class CarReduce extends Reducer<Text,Text,Text,Text> {
@Override protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
StringBuffer sb = new StringBuffer(); // ArrayList<Text> list = new ArrayList<>();// [01 01 02 01 03 05 06 ] HashSet<Integer> list12 = new HashSet<>(); for (Text value : values) {
String[] split = value.toString().split(","); // list.add(new Text(split[3].substring(8,10))); for (int i = 0; i < 24; i++) {
if (Integer.parseInt(split[3].substring(8,10))==i){
list12.add(Integer.parseInt(split[3].substring(8,10))); } } } for (int i = 0; i < 24; i++) {
if (list12.contains(i)){
sb.append("1"); }else{
sb.append("0"); } } if (sb.toString().contains("1")) {
context.write(key,new Text("----->此车运行了12以上")); } } }
CarDriver:
package com.hadoop.Car4; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; public class CarDriver extends Configured implements Tool {
@Override public int run(String[] args) throws Exception {
Configuration configuration = new Configuration(); Job JB = Job.getInstance(configuration, "CarDriver"); FileSystem fileSystem = FileSystem.get(configuration); JB.setInputFormatClass(TextInputFormat.class); TextInputFormat.addInputPath(JB,new Path("E:\\出租车数据\\")); JB.setMapperClass(CarMapper.class); JB.setMapOutputKeyClass(Text.class); JB.setMapOutputValueClass(Text.class); JB.setReducerClass(CarReduce.class); JB.setOutputKeyClass(Text.class); JB.setOutputValueClass(Text.class); boolean exists = fileSystem.exists(new Path("E:\\出租车数据\\Out")); if (exists){
fileSystem.delete(new Path("E:\\出租车数据\\Out"),true); } JB.setOutputFormatClass(TextOutputFormat.class); TextOutputFormat.setOutputPath(JB,new Path("E:\\出租车数据\\Out")); return JB.waitForCompletion(true)?0:1; } public static void main(String[] args) throws Exception {
ToolRunner.run(new CarDriver(),args); } }
计算出10月1日载客次数大于10月2日载客次数的车辆
CarMapper:
讯享网package com.hadoop.Car5; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.FileSplit; import java.io.IOException; public class CarMapper extends Mapper<LongWritable, Text,Text,Text> {
@Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
FileSplit sp = (FileSplit) context.getInputSplit(); String name = sp.getPath().getName(); if (name.contains("")){
if (value!=null&&value.toString().length()>0){
String[] split = value.toString().split(","); context.write(new Text(split[0]),value); } }else {
if (value!=null&&value.toString().length()>0){
String[] split = value.toString().split(","); context.write(new Text(split[0]),value); } } } }
CarReduce:
package com.hadoop.Car5; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer; import java.io.IOException; public class CarReduce extends Reducer<Text,Text,Text,Text> {
@Override protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
int One=0; int Two=0; for (Text value : values) {
if (value.toString().contains("")){
String[] split = value.toString().split(","); if (split[1].equals("4")&&split[2].equals("1")){
One++; } }else{
String[] split = value.toString().split(","); if (split[1].equals("4")&&split[2].equals("1")) {
Two++; } } } if (One>Two){
context.write(key,new Text("十月一日载客量:"+One+"----大于---"+"十月二日载客量:"+Two)); } } }
CarDriver:
讯享网package com.hadoop.Car5; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; public class CarDriver extends Configured implements Tool {
@Override public int run(String[] args) throws Exception {
Configuration configuration = new Configuration(); Job JB = Job.getInstance(configuration, "CarDriver"); FileSystem fileSystem = FileSystem.get(configuration); JB.setInputFormatClass(TextInputFormat.class); TextInputFormat.addInputPath(JB,new Path("E:\\出租车数据\\2")); JB.setMapperClass(CarMapper.class); JB.setMapOutputKeyClass(Text.class); JB.setMapOutputValueClass(Text.class); JB.setReducerClass(CarReduce.class); JB.setOutputKeyClass(Text.class); JB.setOutputValueClass(Text.class); boolean exists = fileSystem.exists(new Path("E:\\出租车数据\\Out")); if (exists){
fileSystem.delete(new Path("E:\\出租车数据\\Out"),true); } JB.setOutputFormatClass(TextOutputFormat.class); TextOutputFormat.setOutputPath(JB,new Path("E:\\出租车数据\\Out")); return JB.waitForCompletion(true)?0:1; } public static void main(String[] args) throws Exception {
ToolRunner.run(new CarDriver(),args); } }
计算出10月1日上班10月2日没有上班的车辆
CarMapper:
package com.hadoop.Car6; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.FileSplit; import java.io.IOException; public class CarMapper extends Mapper<LongWritable, Text,Text,Text> {
@Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
FileSplit sp = (FileSplit) context.getInputSplit(); String name = sp.getPath().getName(); if (name.contains("")){
if (value!=null&&value.toString().length()>0){
String[] split = value.toString().split(","); context.write(new Text(split[0]),value); } }else {
if (value!=null&&value.toString().length()>0){
String[] split = value.toString().split(","); context.write(new Text(split[0]),value); } } } }
CarReduce:
讯享网package com.hadoop.Car6; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer; import java.io.IOException; public class CarReduce extends Reducer<Text,Text,Text,Text> {
@Override protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
boolean falg1=true;//当falg1为false的时候就证明10月1日没有上班 boolean falg2=true;//当falg1为false的时候就证明10月2日没有上班 for (Text value : values) {
if (value.toString().contains("")){
String[] split = value.toString().split(","); if (split[2].equals("3")){
falg1=false; } }else{
String[] split = value.toString().split(","); if (split[2].equals("3")) {
falg2=false; } } } if (falg1==true&&falg2==false){
context.write(key,new Text("十月一日:"+falg1+"-----"+"十月二日:"+falg2)); } } }
CarDriver:
package com.hadoop.Car6; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; public class CarDriver extends Configured implements Tool {
@Override public int run(String[] args) throws Exception {
Configuration configuration = new Configuration(); Job JB = Job.getInstance(configuration, "CarDriver"); FileSystem fileSystem = FileSystem.get(configuration); JB.setInputFormatClass(TextInputFormat.class); TextInputFormat.addInputPath(JB,new Path("E:\\出租车数据\\2")); JB.setMapperClass(CarMapper.class); JB.setMapOutputKeyClass(Text.class); JB.setMapOutputValueClass(Text.class); JB.setReducerClass(CarReduce.class); JB.setOutputKeyClass(Text.class); JB.setOutputValueClass(Text.class); boolean exists = fileSystem.exists(new Path("E:\\出租车数据\\Out")); if (exists){
fileSystem.delete(new Path("E:\\出租车数据\\Out"),true); } JB.setOutputFormatClass(TextOutputFormat.class); TextOutputFormat.setOutputPath(JB,new Path("E:\\出租车数据\\Out")); return JB.waitForCompletion(true)?0:1; } public static void main(String[] args) throws Exception {
ToolRunner.run(new CarDriver(),args); } }
计算出连续48小时运营的车辆
CarMapper:
讯享网package com.hadoop.Taxi08; import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper; import org.apache.hadoop.mapreduce.lib.input.FileSplit; import java.io.IOException; public class TaxiMap08 extends Mapper<LongWritable,Text,Text,Text> {
@Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
FileSplit fileSplit = (FileSplit) context.getInputSplit(); String name = fileSplit.getPath().getName(); if (name.contains("")){
if (value.toString().length()>0){
String[] split = value.toString().split(","); context.write(new Text(split[0]), value); } }else{
if (value.toString().length()>0){
String[] split = value.toString().split(","); context.write(new Text(split[0]), value); } } } }
CarReduce:
package com.hadoop.Taxi08; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Reducer; import java.io.IOException; import java.util.HashSet; public class TaxiReduce08 extends Reducer<Text,Text,Text,Text> {
@Override protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
HashSet<Integer> One = new HashSet<>(); HashSet<Integer> Two = new HashSet<>(); StringBuffer sbOne = new StringBuffer(); StringBuffer sbTwo = new StringBuffer(); for (Text value : values) {
if (value.toString().contains("")){
String[] split = value.toString().split(","); One.add(Integer.parseInt(split[3].substring(8,10 ))); //key ----> value:01 02 03 04 05 06 }else{
String[] split = value.toString().split(","); Two.add(Integer.parseInt(split[3].substring(8,10 ))); //key ----> value:01 02 03 04 05 06 } } for (int i = 0; i < 24; i++) {
if (One.contains(i)){
sbOne.append("1"); }else{
sbOne.append("0"); } if (Two.contains(i)){
sbTwo.append("1"); }else{
sbTwo.append("0"); } } if (!sbOne.toString().contains("0")&&!sbTwo.toString().contains("0")){
context.write(key, new Text(sbOne+"---------"+sbTwo+"---------"+"此车连续运行48小时")); } } }
CarDriver:
讯享网package com.hadoop.Taxi08; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Job; import org.apache.hadoop.mapreduce.lib.input.TextInputFormat; import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat; import org.apache.hadoop.util.Tool; import org.apache.hadoop.util.ToolRunner; public class TaxiDriver08 extends Configured implements Tool {
@Override public int run(String[] args) throws Exception {
Configuration configuration = new Configuration(); Job job=Job.getInstance(configuration, "TaxiDriver08"); job.setJarByClass(TaxiDriver08.class); job.setInputFormatClass(TextInputFormat.class); TextInputFormat.addInputPath(job, new Path("D:\\出租车数据\\ALLtxt")); job.setMapperClass(TaxiMap08.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(Text.class); job.setReducerClass(TaxiReduce08.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); job.setOutputFormatClass(TextOutputFormat.class); TextOutputFormat.setOutputPath(job, new Path("data/08_output")); return job.waitForCompletion(true)?0:1; } public static void main(String[] args) throws Exception {
int run = ToolRunner.run(new TaxiDriver08(), args); System.out.println(run); } }
GPS数据格式说明
数据项及顺序:
车机标识,触发事件,运营状态,GPS时间,GPS经度,GPS纬度,GPS速度,GPS方向,GPS状态
车机标识:6个字符
触发事件:0=变空车,1=变载客,2=设防,3=撤防,4=其它
运营状态:0=空车,1=载客,2=驻车,3=停运,4=其它
GPS时间:格式yyyymmddhhnnss,北京时间
GPS经度:格式ddd.ddddddd,以度为单位。
GPS纬度:格式dd.ddddddd,以度为单位。
GPS速度:格式ddd,取值000-255内整数,以公里/小时为单位。
GPS方位:格式ddd,取值000-360内整数,以度为单位。
GPS状态:0=无效,1=有效
结束串:回车符+换行符
数据发送方式:
每次200条以上的数据压缩打包后UDP发送。采用ZLIB125压缩库最大压缩率压缩。
接收应答:每接收1包或多包回复1个4字节整数,这个整数可以是收到的包数累计或字节数累计,该回复仅用于判断链路是否正常,不用于重发判断。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/82753.html