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 ...
随机推荐
- solr学习
入门文档 http://www.cnblogs.com/edwinchen/p/3972904.html 中文分词 https://github.com/EugenePig/ik-analyzer-s ...
- mysql 案例 ~ 分析执行完的大事务
一 简介:今天咱们来聊聊如何定位以及执行完的大事务 二 目的:通过分析binlog脚本来定位执行的大事务 三 分析脚本 mysqlbinlog --base64-output=decode-rows ...
- nginx反向代理实现前后端分离&跨域问题
1.代理和跨域 1.1 正向代理 1)用户希望代理服务器帮助其和要访问服务器之间实现通信,需要: a.用户IP报文的目的IP=代理服务器IP: b.用户报文端口号=代理服务器监听端口号: c.HTTP ...
- Dubbo监控中心
(1).dubbo-admin(管理控制台) 1).从https://github.com/apache/incubator-dubbo-ops下载解压 2).修改dubbo-admin配置文件中zo ...
- 关于报错stale element reference: element is not attached to the page document处理
1.现象 在执行脚本时,有时候引用一些元素对象会抛出如下异常 org.openqa.selenium.StaleElementReferenceException: stale element ref ...
- PYTHON-绑定方法 反射 内置函数
'''绑定方法类中定义函数分为了两大类: 1. 绑定方法 特殊之处: 绑定给谁就应该由谁来调用,谁来调用就会将谁当做第一个参数自动传入 如何用: 绑定给对象的方法: 在类中定义函数没有被任何装饰器修饰 ...
- php获取POST数据的三种方法
方法一,$_POST $_POST或$_REQUEST存放的是PHP以key=>value的形式格式化以后的数据. $_POST方式是通过 HTTP POST 方法传递的变量组成的数组,是自动全 ...
- main.js 里的/* eslint-disable no-new */
注意项目中的这个,它的作用是: 在js里面,new 一个对象,需要赋值给某个值(变量),用Vue实例化的时候,不需要赋值给值(变量),所以要单独给配一条规则,给new Vue这行代码上面加这个注释,把 ...
- 从零开始自己搭建复杂网络2(以Tensorflow为例)
从零开始自己搭建复杂网络(以DenseNet为例) DenseNet 是一种具有密集连接的卷积神经网络.在该网络中,任何两层之间都有直接的连接,也就是说,网络每一层的输入都是前面所有层输出的并集, 而 ...
- ubuntu 语言设置
1.ubuntu ibus 输入法无法切换拼音 原因未安装中文输入法 sudo apt install ibus-pinyin //安装pinyinwin + space(空格) 切换中文输入法 再用 ...