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 ...
随机推荐
- Linq 中的 in 与 not in 的使用
接 触 LINQ 也有很长的一段时间了,有些在 SQL 语句中用的很顺手的东西在 Linq 中却不知道如何实现了,最近遇到了一个问题,在 LINQ 的 Where 条件式中要如何使用 IN 与 NOT ...
- Java EE之Hibernate的HibernateSessionFactory
昨天,一下午都被一个bug缠身,最后逐层排查,发现是MyEclipse 2014自动生成的HibernateSessionFactory有问题.后观察网友提供的自动生成的HibernateSessio ...
- luogu P3707 [SDOI2017]相关分析
传送门 对于题目要求的东西,考虑拆开懒得拆了 ,可以发现有\(\sum x\sum y\sum x^2\sum xy\)四个变量影响最终结果,考虑维护这些值 下面记\(l,r\)为区间两端点 首先是区 ...
- Android五种数据存储方式
android 五种数据存储 :SharePreferences.SQLite.Contert Provider.File.网络存储 Android系统提供了四种存储数据方式.分别为:SharePre ...
- Jquery中AJAX参数详细介绍
Jquery中AJAX参数详细列表: 参数名 类型 描述 url String (默认: 当前页地址) 发送请求的地址. type String (默认: "GET") 请求方式 ...
- ReLu、LeakyRelu、PReLu(转载)
转载链接:http://blog.csdn.net/cham_3/article/details/56049205
- 【转】Source Insight中文注释为乱码的解决办法
我网上查了一堆解决办法,但是都是2017年以前的,并且都是针对于source insight 3.5及以下版本的解决方案,软件版本都到4.0了,应该有新方法出现. 干货:Source Insight ...
- go语言标准库 时刻更新
Packages Standard library Other packages Sub-repositories Community Standard library ▾ Name Synops ...
- Java中日期格式化SimpleDateFormat类包含时区的处理方法
1.前言 需要把格式为“2017-02-23T08:04:02+01:00”转化成”23-02-2017-T15:04:02“格式(中国时区为+08:00所以是15点),通过网上查找答案,发现没有我需 ...
- 如何把JS对象转成数组
1. 前言 首先,当JS对象是键值对的情况时(Json对象),因为数组时以数字为索引的,所以只能把JS对象中的Key或者Value组成数组使用. 2. 样例如下: var obj={"one ...