036 关于网站的UV分析
一:准备
1.统计的维度
guid
tracktime
provice
2.key与value的设定
key:date+provice_guid
value:NullWritable
3.案例分析
表示某天某个省份的某个人无论访问网站多少次,仅仅记做一次访问统计
UV:统计页面访问的总人数---》userID对于用户进行去重
二:程序
1.map程序

2.reduce程序

3.结果

4.理解点
1)怎么去重
数据key的形式:date+provice_guid。
当guid是相同的时候,在shuffle的group分组时,key被分组,一起的放在一起,而value则是nullwritable,没有使用value。
所以到达reduce的时候,数据已经被去重了。
2)NullWritable.get()
使用反射,获得NullWritable的对象。
5.完整程序
package com.senior.network; import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set; import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Mapper.Context;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner; public class WebUvCount extends Configured implements Tool{
//Mapper
public static class WebUvCountMapper extends Mapper<LongWritable,Text,Text,NullWritable>{
private Text mapoutputkey=new Text();
@Override
protected void cleanup(Context context) throws IOException,InterruptedException { }
@Override
protected void setup(Context context) throws IOException,InterruptedException { } @Override
protected void map(LongWritable key, Text value, Context context)throws IOException, InterruptedException {
String lineValue=value.toString();
String[] strs=lineValue.split("\t");
if(30>strs.length){
context.getCounter("webPvMapper_counter", "length_LT_30").increment(1L);
return;
}
String guidValue=strs[5]; //
if(StringUtils.isEmpty(guidValue)){
return;
}
String trackTimeValue=strs[17];
if(StringUtils.isEmpty(trackTimeValue)){
return;
}
String dateVAlue=trackTimeValue.substring(0,13);//
String priviceIdValue=strs[23]; Integer priviceId=Integer.MAX_VALUE;
try{
priviceId = Integer.valueOf(priviceIdValue); //
}catch(Exception e){
return;
} mapoutputkey.set(dateVAlue+"\t"+priviceIdValue+"_"+guidValue);
context.write(mapoutputkey,NullWritable.get());
} } //Reducer
public static class WebUvCountReducer extends Reducer<Text,NullWritable,Text,IntWritable>{
private Text outputkey=new Text();
private Map<String,Integer> dateMap;
private IntWritable outputvalue=new IntWritable(); @Override
protected void setup(Context context)throws IOException, InterruptedException {
dateMap=new HashMap<String,Integer>();
} @Override
protected void reduce(Text key, Iterable<NullWritable> values,Context context)throws IOException, InterruptedException {
String date=key.toString().split("_")[0];
if(dateMap.containsKey(date)){
Integer previousUV=dateMap.get(date);
Integer uv=previousUV+1;
dateMap.put(date, uv);
}else{
dateMap.put(date, 1);
}
} @Override
protected void cleanup(Context context)throws IOException, InterruptedException {
Set<String> dateSet=dateMap.keySet();
for(String date:dateSet){
Integer uv=dateMap.get(date);
outputkey.set(date);
outputvalue.set(uv);
context.write(outputkey, outputvalue);
}
} } //Driver
public int run(String[] args)throws Exception{
Configuration conf=this.getConf();
Job job=Job.getInstance(conf,this.getClass().getSimpleName());
job.setJarByClass(WebUvCount.class);
//input
Path inpath=new Path(args[0]);
FileInputFormat.addInputPath(job, inpath); //output
Path outpath=new Path(args[1]);
FileOutputFormat.setOutputPath(job, outpath); //map
job.setMapperClass(WebUvCountMapper.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(NullWritable.class); //shuffle //reduce
job.setReducerClass(WebUvCountReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class); //submit
boolean isSucess=job.waitForCompletion(true);
return isSucess?0:1;
} //main
public static void main(String[] args)throws Exception{
Configuration conf=new Configuration();
//compress
conf.set("mapreduce.map.output.compress", "true");
conf.set("mapreduce.map.output.compress.codec", "org.apache.hadoop.io.compress.SnappyCodec");
args=new String[]{
"hdfs://linux-hadoop01.ibeifeng.com:8020/user/beifeng/mapreduce/wordcount/inputWebData",
"hdfs://linux-hadoop01.ibeifeng.com:8020/user/beifeng/mapreduce/wordcount/outputWebData6"
};
int status=ToolRunner.run(new WebUvCount(), args);
System.exit(status);
} }
036 关于网站的UV分析的更多相关文章
- 关于网站的UV分析
一:准备 1.统计的维度 guid tracktime provice 2.key与value的设定 key:date+provice_guid value:NullWritable 3.案例分析 表 ...
- 对石家庄铁道大学网站UI的分析
作为我们团队的PM,老师对我们提出了一些额外的要求,所以我发表这篇博客来谈一下对石家庄铁道大学网站UI的分析. 首先,PM 对项目所有功能的把握, 特别是UI.最差的UI, 体现了 ...
- 基于React的PC网站前端架构分析
代码地址如下:http://www.demodashi.com/demo/12252.html 本文适合对象 有过一定开发经验的初级前端工程师: 有过完整项目的开发经验,不论大小: 对node有所了解 ...
- 【转】LAMP网站架构方案分析【精辟】
[转]LAMP网站架构方案分析[精辟] http://www.cnblogs.com/mo-beifeng/archive/2011/09/13/2175197.html Xubuntu下LAMP环境 ...
- WEB网站前端性能分析相关
现在的网站分析工具,数据源主要有两种,分别是服务器日志(WebServer Log)和采集日志 买 优化要根据具体的业务和场景来分析 埋点:监控用户点击的每一步
- Web 网站 故障常用分析命令
系统连接状态篇: 1.查看TCP连接状态 netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn netstat -n | awk '/^tcp/ { ...
- 对TSNU网站的初步分析
这是一个教育网的网站,其中网站的教务子系统,html页面是用表单嵌套来格式化显示样式的,另外还有<div>.<iframe>等等 .在这个上有个form表单,提交的参数有如下几 ...
- hadoop实例-网站用户行为分析
一.数据集 网站用户购物行为数据集2030万条,包括raw_user.csv(2000万条)和small_user.csv(30万条,适合新手) 字段说明: user_id 用户编号,item_id ...
- 网站jcms流程分析
本实例大致流程:基于jsp页面,通过servlet传递数据调用方法,利用service更改数据库.本文重点分析的是其中的两个小方法add()和delete(),来反映出反射机制的一个具体作用:减少Se ...
随机推荐
- Redis 模糊查询删除操作
创建一条测试 数据 查询 创建:set name xiaoming 查询: get name 1.模糊搜索查询 Redis 模糊搜索 keys * 2.删除指定key : # 删除所有以user开头的 ...
- 第17月第28天 python yield
1. class Fab(object): def __init__(self, max): self.max = max self.n, self.a, self.b = 0, 0, 1 def _ ...
- ubuntu16.10安装docker17.03.0-ce并配置国内源和加速器
说明:这个针对docker-ce安装,ce和ee的区别是前者是社区版,后者是企业版 1. 配置Ubuntu的源,不然慢的去哭吧.参考http://cn.archive.ubuntu.com/help ...
- Android五种数据存储方式
android 五种数据存储 :SharePreferences.SQLite.Contert Provider.File.网络存储 Android系统提供了四种存储数据方式.分别为:SharePre ...
- 实验一 Java开发环境的熟悉--20165221
实验报告封面 课程:Java程序设计 班级:1652班 姓名:谭笑 学号:20165221 成绩: 指导教师:娄嘉鹏 试验日期:2018.4.2 实验组次:21 预习程度:已预习 实验时间:15:35 ...
- mysql基本命令[转]
1.连接Mysql 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MYSQL.首先打开DOS窗口,然后进入目录mysql\bin,再键入命令mysql -u root ...
- Linux内存管理1---内存寻址
1.前言 本文所述关于内存管理的系列文章主要是对陈莉君老师所讲述的内存管理知识讲座的整理. 本讲座主要分三个主题展开对内存管理进行讲解:内存管理的硬件基础.虚拟地址空间的管理.物理地址空间的管理. 本 ...
- ARMV8 datasheet学习笔记4:AArch64系统级体系结构之VMSA
1. 前言 2. VMSA概述 2.1 ARMv8 VMSA naming VMSAv8 整个转换机中,地址转换有一个或两个stage VMSAv8-32 由运行AArch32的异常级别来管理 VMS ...
- CC254x/CC2540/CC2541库函数速查(转)
hci.h 转自:http://blog.csdn.net/xiaoleiacmer/article/details/44036607#t1 //分配内存,应用程序不应该调用这个函数. void *H ...
- Linux中涉及到计算优先级及其他问题
比如计算矩形周长: a= b= echo `expr \* $((a+b))` 1.expr外要使用反引号,且expr只支持整数计算,如果涉及到浮点数计算要采用下面方法 2.优先计算a+b时,要使用双 ...