陌陌聊天数据分析 (一)

news2024/9/21 16:34:54

陌陌聊天数据分析(一)

目标

  • 基于Hadoop和Hive实现聊天数据统计分析,构建聊天数据分析报表

需求

  • 统计今日总消息量
  • 统计今日每小时消息量,发送和接收用户数量
  • 统计今日各地区发送消息数据量
  • 统计今日发送消息和接收消息用户数
  • 统计今日发送消息最多的用户前几名
  • 统计今日接收消息最多的用户前几名
  • 统计发送人手机型号分布情况
  • 统计发送人设备系统分布情况

数据来源

  • 聊天业务系统导出2021/11/01一天24小时用户聊天数据,以TSV文本形式存储在文件中
    • 数据大小:两个文件共14万条数据
    • 列分隔符:\t

数据集及所需文件

  • 链接:https://pan.baidu.com/s/1ToTanDrFRhAVsFTb2uclFg
    提取码:rkun

🥇基于Hive数仓实现需求开发

⚽建库建表 加载数据

  • 建库建表
--创建数据库
create database db_msg;
--切换数据库
use db_msg;

--建表
create table db_msg.tb_msg_source(
  msg_time             string  comment "消息发送时间"
  , sender_name        string  comment "发送人昵称"
  , sender_account     string  comment "发送人账号"
  , sender_sex         string  comment "发送人性别"
  , sender_ip          string  comment "发送人IP"
  , sender_os          string  comment "发送人操作系统"
  , sender_phonetype   string  comment "发送人手机型号"
  , sender_network     string  comment "发送人网络类型"
  , sender_gps         string  comment "发送人GPS定位"
  , receiver_name      string  comment "接收人昵称"
  , receiver_ip        string  comment "接收人IP"
  , receiver_account   string  comment "接收人账号"
  , receiver_os        string  comment "接收人操作系统"
  , receiver_phonetype string  comment "接收人手机型号"
  , receiver_network   string  comment "接收人网络类型"
  , receiver_gps       string  comment "接收人GPS定位"
  , receiver_sex       string  comment "接收人性别"
  , msg_type           string  comment "消息类型"
  , distance           string  comment "双方距离"
  , message            string  comment "消息内容"
)
--指定分隔符为制表符
row format delimited fields terminated by '\t';

  • 加载数据
#上传数据到node1服务器本地文件系统(HS2服务所在机器)
[root@node1 hivedata]# pwd
/root/hivedata
[root@node1 hivedata]# ll
total 54104
-rw-r--r-- 1 root root 28237023 Jun 13 20:24 data1.tsv
-rw-r--r-- 1 root root 27161148 Jun 13 20:24 data2.tsv

--加载数据入表
load data local inpath '/root/hivedata/data1.tsv' into table db_msg.tb_msg_source;
load data local inpath '/root/hivedata/data2.tsv' into table db_msg.tb_msg_source;
  • 查询表,查看数据是否导入成功
--查询表
select * from tb_msg_source limit 5;

在这里插入图片描述

⚾ETL数据清洗

数据问题

  • 当前数据,一些数据字段为空,不是合法数据。
  • 需求需要统计每天每个小时消息量,但数据中没有天和小时字段,只有整体时间字段,不好处理。
  • 需求中,GPS对经纬度在同一字段,不好处理。

ETL需求

  • 对字段为空的不合法数据进行过滤
    • where过滤
  • 通过时间字段构建天和小时字段
    • substr函数
  • 从GPS经纬度提取经纬度
    • split函数
  • 将ETL以后的结果保存到一张新的Hive表中
    • create table …as select…
create table db_msg.tb_msg_etl as
select *,
       substr(msg_time, 0, 10)   as dayinfo,    --获取天
       substr(msg_time, 12, 2)   as hourinfo,   --获取小时
       split(sender_gps, ",")[0] as sender_lng, --经度
       split(sender_gps, ",")[1] as sender_lat  --纬度
from db_msg.tb_msg_source
--过滤字段为空数据
where length(sender_gps) > 0;
select
    msg_time,dayinfo,hourinfo,sender_gps,sender_lng,sender_lat
from db_msg.tb_msg_etl
limit 5;
--查询数据

在这里插入图片描述

🏀需求指标SQL

  • 解读需求
  • 确定待查询数据表 from
  • 分析维度 group by
  • 找出计算指标 聚合
  • 细节 过滤 排序
  1. 统计今日消息总量

    --需求:统计今日总消息量
    create table if not exists tb_rs_total_msg_cnt
    comment "今日消息总量"
    as
    select
      dayinfo,
      count(*) as total_msg_cnt
    from db_msg.tb_msg_etl
    group by dayinfo;
    
    --查询
    select * from tb_rs_total_msg_cnt ;
    
    +------------------------------+------------------------------------+
    | tb_rs_total_msg_cnt.dayinfo  | tb_rs_total_msg_cnt.total_msg_cnt  |
    +------------------------------+------------------------------------+
    | 2021-11-01                   | 139062                             |
    +------------------------------+------------------------------------+
    
    
  2. 统计今日每小时消息量,发送/接收用户数

    create table tb_rs_hour_msg_cnt
    comment "每小时消息量趋势"
    as
    select
        dayinfo,
        hourinfo,
        count(*) as total_msg_cnt,
        count(distinct sender_account) as sender_usr_cnt,
        count(distinct receiver_account)as receiver_usr_cnt
    from db_msg.tb_msg_etl
    group by dayinfo,hourinfo;
    
    select * from tb_rs_hour_msg_cnt limit 5;
    
    +-----------------------------+------------------------------+-----------------------------------+------------------------------------+--------------------------------------+
    | tb_rs_hour_msg_cnt.dayinfo  | tb_rs_hour_msg_cnt.hourinfo  | tb_rs_hour_msg_cnt.total_msg_cnt  | tb_rs_hour_msg_cnt.sender_usr_cnt  | tb_rs_hour_msg_cnt.receiver_usr_cnt  |
    +-----------------------------+------------------------------+-----------------------------------+------------------------------------+--------------------------------------+
    | 2021-11-01                  | 00                           | 4349                              | 3520                               | 3558                                 |
    | 2021-11-01                  | 01                           | 2892                              | 2524                               | 2537                                 |
    | 2021-11-01                  | 02                           | 882                               | 842                                | 838                                  |
    | 2021-11-01                  | 03                           | 471                               | 463                                | 460                                  |
    | 2021-11-01                  | 04                           | 206                               | 202                                | 205                                  |
    +-----------------------------+------------------------------+-----------------------------------+------------------------------------+--------------------------------------+
    
    
  3. 统计今日各地区发送消息数据量

    create table tb_rs_loc_cnt
    comment "今日各地区发送总消息量"
    as select
      dayinfo,
      sender_gps,
      cast(sender_lng as double) as longitude,
      cast(sender_lat as double) as latitude,
      count(*) as total_msg_cnt
    from tb_msg_etl
    group by dayinfo, sender_gps, sender_lng,sender_lat;
    
    
    select * from tb_rs_loc_cnt limit 5;
    
    
    +------------------------+---------------------------+--------------------------+-------------------------+------------------------------+
    | tb_rs_loc_cnt.dayinfo  | tb_rs_loc_cnt.sender_gps  | tb_rs_loc_cnt.longitude  | tb_rs_loc_cnt.latitude  | tb_rs_loc_cnt.total_msg_cnt  |
    +------------------------+---------------------------+--------------------------+-------------------------+------------------------------+
    | 2021-11-01             | 100.297355,24.206808      | 100.297355               | 24.206808               | 1397                         |
    | 2021-11-01             | 100.591712,24.004148      | 100.591712               | 24.004148               | 1406                         |
    | 2021-11-01             | 101.62196,36.782187       | 101.62196                | 36.782187               | 1439                         |
    | 2021-11-01             | 102.357852,23.801165      | 102.357852               | 23.801165               | 1399                         |
    | 2021-11-01             | 102.357852,25.682909      | 102.357852               | 25.682909               | 1431                         |
    +------------------------+---------------------------+--------------------------+-------------------------+------------------------------+
    
    
  4. 统计今日发送消息和接受消息用户数

    create table tb_rs_usr_cnt
    comment "今日发送消息人数、接受消息人数"
    as
    select
      dayinfo,
      count(distinct sender_account) as sender_usr_cnt,
      count(distinct receiver_account) as receiver_usr_cnt
    from db_msg.tb_msg_etl
    group by dayinfo;
    
    select * from tb_rs_usr_cnt ;
    
    +------------------------+-------------------------------+---------------------------------+
    | tb_rs_usr_cnt.dayinfo  | tb_rs_usr_cnt.sender_usr_cnt  | tb_rs_usr_cnt.receiver_usr_cnt  |
    +------------------------+-------------------------------+---------------------------------+
    | 2021-11-01             | 10008                         | 10005                           |
    +------------------------+-------------------------------+---------------------------------+
    
    
  5. 统计今日发送消息最多的Top10用户

    create table tb_rs_susr_top10
    comment "发送消息条数最多的Top10用户"
    as
    select
      dayinfo,
      sender_name as username,
      count(*) as sender_msg_cnt
    from db_msg.tb_msg_etl
    group by dayinfo,sender_name
    order by sender_msg_cnt desc
    limit 10;
    
    select * from tb_rs_susr_top10;
    
    +---------------------------+----------------------------+----------------------------------+
    | tb_rs_susr_top10.dayinfo  | tb_rs_susr_top10.username  | tb_rs_susr_top10.sender_msg_cnt  |
    +---------------------------+----------------------------+----------------------------------+
    | 2021-11-01                | 茹鸿晖                        | 1466                             |
    | 2021-11-01                | 卢高达                        | 1464                             |
    | 2021-11-01                | 犁彭祖                        | 1460                             |
    | 2021-11-01                | 沐范                         | 1459                             |
    | 2021-11-01                | 夫潍                         | 1452                             |
    | 2021-11-01                | 烟心思                        | 1449                             |
    | 2021-11-01                | 称子瑜                        | 1447                             |
    | 2021-11-01                | 麻宏放                        | 1442                             |
    | 2021-11-01                | 邴时                         | 1439                             |
    | 2021-11-01                | 养昆颉                        | 1431                             |
    +---------------------------+----------------------------+----------------------------------+
    
    
  6. 统计今日接受消息最多的Top10用户

    create table tb_rs_rusr_top10
    comment "接受消息条数最多的Top10用户"
    as
    select
      dayinfo,
      receiver_name as username,
      count(*) as receiver_msg_cnt
    from db_msg.tb_msg_etl
    group by dayinfo,receiver_name
    order by receiver_msg_cnt desc
    limit 10;
    
    select * from tb_rs_rusr_top10 limit 3;
    
    +---------------------------+----------------------------+------------------------------------+
    | tb_rs_rusr_top10.dayinfo  | tb_rs_rusr_top10.username  | tb_rs_rusr_top10.receiver_msg_cnt  |
    +---------------------------+----------------------------+------------------------------------+
    | 2021-11-01                | 畅雅柏                        | 1539                               |
    | 2021-11-01                | 春纯                         | 1491                               |
    | 2021-11-01                | 邝琨瑶                        | 1469                               |
    +---------------------------+----------------------------+------------------------------------+
    
    
  7. 统计发送人手机型号分布情况

    create table if not exists tb_rs_sender_phone
    comment "发送人的手机型号分布"
    as
    select
      dayinfo,
      sender_phonetype,
      count(distinct sender_account) as cnt
    from tb_msg_etl
    group by dayinfo,sender_phonetype;
    
    select * from tb_rs_sender_phone limit 3;
    
    +-----------------------------+--------------------------------------+-------------------------+
    | tb_rs_sender_phone.dayinfo  | tb_rs_sender_phone.sender_phonetype  | tb_rs_sender_phone.cnt  |
    +-----------------------------+--------------------------------------+-------------------------+
    | 2021-11-01                  | Apple iPhone 10                      | 6749                    |
    | 2021-11-01                  | Apple iPhone 11                      | 3441                    |
    | 2021-11-01                  | Apple iPhone 7                       | 2424                    |
    +-----------------------------+--------------------------------------+-------------------------+
    
    
  8. 统计发送人设备操作系统分布情况

    create table tb_rs_sender_os
    comment "发送人的OS分布"
    as
    select
      dayinfo,
      sender_os,
      count(distinct sender_account) as cnt
    from tb_msg_etl
    group by dayinfo,sender_os;
    
    select * from tb_rs_sender_os;
    
    +--------------------------+----------------------------+----------------------+
    | tb_rs_sender_os.dayinfo  | tb_rs_sender_os.sender_os  | tb_rs_sender_os.cnt  |
    +--------------------------+----------------------------+----------------------+
    | 2021-11-01               | Android 5.1                | 5750                 |
    | 2021-11-01               | Android 6                  | 8514                 |
    | 2021-11-01               | Android 6.0                | 9398                 |
    | 2021-11-01               | Android 7.0                | 9181                 |
    | 2021-11-01               | Android 8.0                | 8594                 |
    | 2021-11-01               | IOS 10.0                   | 1289                 |
    | 2021-11-01               | IOS 12.0                   | 8102                 |
    | 2021-11-01               | IOS 9.0                    | 8760                 |
    +--------------------------+----------------------------+----------------------+
    
    

🎖️FineBI实现可视化报表

官网

https://www.finebi.com/

🏐配置数据源及数据准备

官方文档

https://help.fanruan.com/finebi/doc-view-301.html

  • 使用FineBI连接Hive,读取Hive数据表,需要在FineBI中添加Hive驱动jar包

  • 将Hive驱动jar包放入FineBI的lib目录下

  • 找到提供文件的HiveConnectDrive

在这里插入图片描述

  • 放入安装路径下的 webapps\webroot\WEB-INF\lib

在这里插入图片描述

插件安装

  • 我们自己Hive驱动包会与FineBI自带驱动包冲突,导致FineBI无法识别我们自己的驱动
  • 安装FineBI官方提供驱动包隔离插件

隔离插件:fr-plugin-hive-driver-loader-3.0.zip

  • 安装插件

    在这里插入图片描述

  • 重启FineBI

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/659710.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

vue移动端手把手教你封装一个可移动悬浮窗、可移动打开扇形悬浮按钮组件

目录 概要 功能设计 技术细节-API回顾 touchstart 事件 touchmove事件 完整的代码实现(悬浮窗) 运行效果 进阶封装——可移动扇形展开悬浮按钮 实现效果演示 需求分析 代码实现 概要 悬浮窗、悬浮按钮是项目中常见的一种交互设计,特别是在移…

Linux国产操作系统,UCA-系统工程师学习必备技能,文件管理和查找、内容查找、归档的再学习

复习和巩固Linux的基础操作,对文件管理和查找、内容查找、归档以及管道和输入输出重定向进行再学习。 目录 1.文件管理 1. 1.head命令 1.2. tail命令 1.3. more/less命令 1.4. wc 统计命令 1.5. sort 排序命令 1.6. uniq 去重命令 1.7. paste合并命令 2.文…

基于matlab对现代相控阵系统中常用的子阵列进行建模分析(附源码)

一、前言 本示例说明如何使用相控阵系统工具箱对现代相控阵系统中常用的子阵列进行建模并进行分析。 相控阵天线与传统碟形天线相比具有许多优势。相控阵天线的元件更容易制造;整个系统受组件故障的影响较小;最重要的是,可以向不同方向进行电子扫描。 但是&#xff…

耗时半个月,终于把十几个大厂的python面试题整理成了PDF合集(基础+高级+web+数据库+爬虫)

大家好,最近有不少小伙伴在后台留言,近期的面试越来越难了,要背的越来越多了,考察得越来越细,明摆着就是想让我们徒手造航母嘛!实在是太为难我们这些程序员了。 这不,为了帮大家节约时间&#…

JVM垃圾回收与双亲委派模型

观前提示:本篇博客演示使用的 IDEA 版本为2021.3.3版本,使用的是Java8(又名jdk1.8) 前端使用VSCode(Visual Studio Code1.78.2) 电脑使用的操作系统版本为 Windows 10 目录 1. 什么是 JVM 2. jvm 发展史 2.1 Sun Classic VM 2.2 Exact VM 2.3 HotSpot VM 2.4 JRockit …

Docker部署——将jar包打成docker镜像并启动容器

在代码编写完成即将部署的时候,如果采用docker容器的方法,需要将jar包打成docker镜像并通过镜像将容器启动起来。具体的步骤如下。 一、首先下载java镜像 先使用docker search java命令进行搜索。 然而在拉取镜像的时候要注意不能直接去选择pull java ,…

在线DDL操作踩坑记录

官方地址:GitHub - github/gh-ost: GitHubs Online Schema-migration Tool for MySQL 使用ghost方式在线对mysql表进行ddl ghost原理: 要对表A进行DDL,在主库建立一个ghost表 A1在表A1上进行alter操作伪装成一个mysql的从库,监…

Java集合框架:队列、Queue和Deque详解

目录 一、普通队列 1. 概念 2. Queue(Java集合框架的接口) 3. Queue中的方法 4. 方法使用演示 5. 队列的模拟实现 6. 顺序普通队列的缺点: 二、循环队列 1. 循环队列也是一种数据结构。基于上述队列的缺点,此时就有了循环…

为什么我不建议你入行网络安全,因为99.9%的人都绕不过这三个坎

前言 我一个朋友老赵,老赵在一家大型互联网公司做高级网络安全工程师,从实习生到工程师整整呆了六年。去年他们公司为了缩减成本,做了裁员,他也在其中,取而代之的是一个只有三年工作经验的 “新人” … 老赵想着&…

Windows10下安装Oracle19c提示“无法将 **\** 安装用户添加到 ** 组“解决办法

问题描述 操作系统:window10 数据库版本:Oracle19c 本机在安装Oracle19c提示无法将 ZHOUQUAN\zhouquan 安装用户添加到 %2% 组。 问题原因 根据安装的对话框中的日志,找到并打开 日志报错信息: 信息: WindowsSecurityExcep…

时序预测 | Matlab实现INFO-ELM向量加权算法优化极限学习机时间序列预测

时序预测 | Matlab实现INFO-ELM向量加权算法优化极限学习机时间序列预测 目录 时序预测 | Matlab实现INFO-ELM向量加权算法优化极限学习机时间序列预测效果一览基本介绍程序设计学习总结参考资料 效果一览 基本介绍 Matlab实现INFO-ELM向量加权算法优化极限学习机时间序列预测 …

skywalking 源码

源码核心是SkyWalkingAgent 找到一堆插件,来对符合条件的类来代理 通过AbstractClassEnhancePluginDefine.define方法来。 如果有很多版本的插件,spring有2.0版本,3.0版本,4.0版。 具体使用哪个版本,看被增加的类使用的是哪个版本的spring …

vue基础--计算商品的总价格

计算商品的总价格: 1、在 父组件中 通过计算属性 动态把总价格计算出来, 2、通过 父向子传值,通过自定义属性,把值传给 子组件 父组件: 1、使用计算属性computed 计算总价格: 1.1、先用filter 过滤出 数…

Unity UGUI5——图集

一、Drawcall ​ 字面理解 DrawCall,就是绘制呼叫的意思,表示 CPU(中央处理器)通知 GPU(图形处理器-显卡) (一)DrawCall 概念 就是 CPU (处理器)准备好渲染…

基于Web的停车场管理系统(Java)

目录 一、系统介绍 1.开发的环境 2.本系统实现的功能 3.数据库用到的表 4.工程截图 二、系统展示 1、登录页面 2、首页 3、系统信息管理模块 4、车位信息管理模块 5、IC卡信息管理模块 ​编辑6、固定车主停车管理模块 7、临时车主停车管理模块 8、系统功能操作模块 …

unity3d:小地图UV,UGUIshader毒圈挖孔,缩圈

运行效果 场景中缩圈 小地图中挖孔 大地图中挖孔 小地图 方案1使用Mask 给了一个方形的mask组件,然后根据玩家位置计算出地图左下角的位置进行移动。这种实现方式虽然简单,但是会有两个问题: 1.Overdraw特别大,几乎很多时候会有…

【LLMs 入门实战 】Vicuna 模型学习与实战

UC伯克利学者联手CMU、斯坦福等,再次推出一个全新模型70亿/130亿参数的Vicuna,俗称「小羊驼」,小羊驼号称能达到GPT-4的90%性能。 欢迎使用小羊驼🦙环境搭建权重下载下载 Vicuna Weight下载 LLAMA Weight构建真正的 working weigh…

Lattice Planner从入门到放弃

Lattice Planner相关背景和更正式的公式推导可以直接参考其原始论文《Optimal Trajectory Generation for Dynamic Street Scenarios in a Frent Frame》(ICRA 2010),本文侧重于Lattic planner理论和代码的结合。 1. Lattice Planner基本流程…

2023年6月GESP能力等级认证C++一级真题

2023-06 GESP一级真题 题数:27 分数:100 测试时长:60min 一、选择题(每题 2 分,共 30 分) 1.以下不属于计算机输入设备的有 (B ) 。(2分) A、键盘 B、音箱 C、鼠标 D、传感器 答案解析&#xff1…

如果你正在做AI测试,那么这十点你必须注意

AI是一个已经进入人类日常生活的新技术时代,例如Siri,Alexa语音接口等。通过大数据和数据科学实现数据存储的进步,使用户能够进行快速分析和数据检索。机器学习是一个新领域,机 AI是一个已经进入人类日常生活的新技术时代&#x…