当前位置:   article > 正文

手机app日志分析系统(六)_app后台日志数据统计分析系统

app后台日志数据统计分析系统
  1. 一、目前出现的BUG解决
  2. -------------------------------------------------------------
  3. 1.hive命令启动时出现假死机
  4. 有可能是两个namenode都处于standby状态。
  5. 2.hive的UDF函数找不到问题
  6. a.注册函数,使用using jar方式在hdfs上引用udf库。
  7. $hive> create function formattime as 'com.test.applogs.udf.FormatTimeUDF' using jar 'hdfs://s100/data/jars/app-logs-hive-1.0-SNAPSHOT.jar';
  8. $hive> create function getdaybegin as 'com.test.applogs.udf.DayBeginUDF' using jar 'hdfs://s100/data/jars/app-logs-hive-1.0-SNAPSHOT.jar';
  9. $hive> create function getweekbegin as 'com.test.applogs.udf.WeekBeginUDF' using jar 'hdfs://s100/data/jars/app-logs-hive-1.0-SNAPSHOT.jar';
  10. $hive> create function getmonthbegin as 'com.test.applogs.udf.MonthBeginUDF' using jar 'hdfs://s100/data/jars/app-logs-hive-1.0-SNAPSHOT.jar';
  11. b.注销函数,只需要删除mysql的hive数据记录即可。
  12. delete from func_ru ;
  13. delete from funcs ;
  14. 二、框架中增加新的查询方法 -- 统计查询一周内每天新增加的用户数量
  15. ----------------------------------------------------------------
  16. 1.首先做服务提供端的工作provider
  17. a.准备查询串
  18. select formattime(t.mintime, 'yyyy/MM/dd') , count(*) from
  19. (
  20. select deviceid, min(createdatms) as mintime
  21. from ext_startup_logs group by deviceid having mintime >= getweekbegin() and mintime < getweekbegin(1)
  22. ) as t
  23. group by formattime(t.mintime, 'yyyy/MM/dd');
  24. b.将查询串添加到mybatis映射文件[StatBeanMapper.xml]中
  25. <!-- 统计查询一周内每天新增加的用户数量 -->
  26. <select id="selectDayNewusersInThisWeek" resultMap="rm_StatBean">
  27. select formattime(t.mintime, 'yyyy/MM/dd') stdate , count(*) stcount
  28. from
  29. (
  30. select deviceid , min(createdatms) as mintime
  31. from ext_startup_logs
  32. where appid = #{appid}
  33. group by deviceid
  34. having mintime &gt;= getweekbegin() and mintime &lt; getweekbegin(1)
  35. ) as t
  36. group by formattime(t.mintime, 'yyyy/MM/dd')
  37. </select>
  38. <resultMap id="rm_StatBean" type="_StatBean">
  39. <result column="stdate" property="date" />
  40. <result column="stcount" property="count" />
  41. </resultMap>
  42. c.dao接口中添加对应的查询方法声明
  43. [BaseDao<T>]
  44. //统计查询一周内每天新增加的用户数量
  45. public List<T> findDayNewUsersInWeek(String appid);
  46. d.daoImpl实现类中添加对用的实现方法[用来与服务器进行交互的增删改查等工作]
  47. [StatDaoImpl]
  48. //统计查询一周内每天新增加的用户数量
  49. public List<StatBean> findDayNewUsersInWeek(String appid) {
  50. return getSqlSession().selectList("stats.selectDayNewusersInThisWeek",appid);
  51. }
  52. e.dao添加完毕之后,开始在服务接口中添加方法
  53. [StatService]
  54. /**
  55. * 统计查询一周内每天新增加的用户数量
  56. */
  57. public List<StatBean> findDayNewUsersInWeek();
  58. f.在服务接口的实现类中添加方法[服务接口是用来与dao交互,然后将dao注册到框架体系,使用其方法]。
  59. [StatServiceImpl]
  60. /**
  61. * 统计查询一周内每天新增加的用户数量
  62. */
  63. public List<StatBean> findDayNewUsersInWeek(String appid)
  64. {
  65. return getDao().findDayNewUsersInWeek(appid);
  66. }
  67. 2.其次是web展示端工作 --- 消费者端的工作
  68. a.服务接口中添加方法
  69. [StatService]
  70. //统计查询一周内每天新增加的用户数量
  71. public List<StatBean> findDayNewUsersInWeek(String appid);
  72. b.在Controller控制器中添加方法的控制器
  73. [StatController]
  74. /**
  75. * 统计查询一周内每天新增加的用户数量
  76. */
  77. @RequestMapping("/newUsersInWeek")
  78. public String findDayNewUsersInWeek()
  79. {
  80. List<StatBean> bean = ss.findDayNewUsersInWeek("sdk34734");
  81. for(StatBean s : bean)
  82. {
  83. System.out.println(s.getDate() + ":" + s.getCount());
  84. }
  85. return "index";
  86. }
  87. 三、项目升级
  88. ----------------------------------------------------------------
  89. 1.抽取provider和web模块中公共的类到公共模块中。这样如果修改类的话,就统一修改一处就行
  90. a.抽取Service接口包 -- com.test.applogs.visualize.service,复制到common模块中
  91. b.抽取domain包 -- com.test.applogs.visualize.domian,复制到common模块中
  92. c.web模块中删除包com.test.applogs.visualize.service和com.test.applogs.visualize.domian
  93. d.在web模块的项目结构Project Structure中,添加common模块到web项目中
  94. e.同样方式才操作provider模块
  95. 删除包com.test.applogs.visualize.service和com.test.applogs.visualize.domian
  96. 注意别把service.serviceimpl删除了
  97. 在项目结构中引入common模块的依赖
  98. f.记得将新增的common模块和common中的jar包,构建到web项目中
  99. 四、集成echart进行可视化展示
  100. ---------------------------------------------------------------
  101. 1.使用ajax,实现局部刷新,使用jquery,实现异步请求
  102. 异步请求 + 局部刷新。
  103. <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  104. <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  105. <html lang="en">
  106. <head>
  107. <meta charset="utf-8">
  108. <title>大数据分析系统</title>
  109. <link rel="stylesheet"
  110. href="//apps.bdimg.com/libs/jqueryui/1.10.4/css/jquery-ui.min.css">
  111. <script src="//apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
  112. <script src="//apps.bdimg.com/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
  113. <script src="../js/echarts.js"></script>
  114. <script>
  115. $(function () {
  116. //手风琴特效
  117. $("#accordion").accordion();
  118. //菜单鼠标悬停
  119. $("#accordion a").mouseenter(function () {
  120. //重置所有连接的颜色
  121. $("#accordion a").css("background-color", "white");
  122. $(this).css("background-color", "#EAEAEA");
  123. });
  124. //鼠标移除
  125. $("#accordion a").click(function () {
  126. //重置所有连接的颜色
  127. $("#accordion a").css("color", "#6a6a6a");
  128. $(this).css("background-color", "#EAEAEA");
  129. $(this).css("color", "#3DA1A7");
  130. });
  131. $("#a_newusers").click(function(){
  132. $.getJSON("/js/log.json",function(d){
  133. option.xAxis.data = d.data;
  134. myChart.setOption(option);
  135. });
  136. // option.xAxis.data = ["aa", "bb", "cc", "dd", "ee", "ff"];
  137. // myChart.setOption(option);
  138. //阻止事件的传递
  139. return false;
  140. });
  141. });
  142. </script>
  143. <style type="text/css">
  144. .test {
  145. background-color: #3DA1A7;
  146. }
  147. body {
  148. padding: 0px;
  149. margin: 0px;
  150. }
  151. #div-top {
  152. height: 30px;
  153. width: 100%;
  154. background-color: #3b485b;
  155. border: 0px solid #3b485b;
  156. }
  157. #div-top ul {
  158. margin: 0px;
  159. }
  160. #div-top ul li {
  161. list-style: none;
  162. display: block;
  163. float: left;
  164. color: white;
  165. border: 0px solid white;
  166. line-height: 30px;
  167. width: 70px;
  168. vertical-align: middle;
  169. text-align: center;
  170. }
  171. #div-top ul li:first-child {
  172. list-style: none;
  173. display: block;
  174. float: left;
  175. color: white;
  176. border: 0px solid white;
  177. line-height: 30px;
  178. width: 130px;
  179. vertical-align: middle;
  180. text-align: center;
  181. }
  182. #div-top ul li a {
  183. text-decoration: none;
  184. font-size: smaller;
  185. color: #9da4ad;
  186. }
  187. #div-top ul li:first-child a {
  188. color: white;
  189. text-decoration: none;
  190. font-size: 15px;
  191. }
  192. #div-banner {
  193. background: url("../images1/backg.png") repeat-x 0 -61px;
  194. height: 60px;
  195. width: 100%;
  196. border: 0px solid blue;
  197. text-align: left;
  198. }
  199. #div-banner form {
  200. border: 0px solid blue;
  201. width: 200px;
  202. height: 57px;
  203. vertical-align: middle;
  204. line-height: 57px;
  205. text-align: center;
  206. }
  207. #div-banner select {
  208. border-radius: 20px;
  209. font-size: 15px;
  210. display: inline;
  211. padding: 3px 10px;
  212. }
  213. #div-banner ul {
  214. border: 0px solid blue;
  215. list-style: none;
  216. display: block;
  217. position: absolute;
  218. left: 200px;
  219. top: 14px;
  220. height: 57px;
  221. width: 600px;
  222. vertical-align: middle;
  223. line-height: 57px;
  224. margin-left: 380px;
  225. }
  226. #div-banner ul li {
  227. display: inline;
  228. padding: 0px 20px;
  229. }
  230. #div-banner ul li a {
  231. text-decoration: none;
  232. font-size: 16px;
  233. color: #333333;
  234. }
  235. #accordion {
  236. margin: 10px 20px;
  237. width: 200px;
  238. }
  239. #accordion a {
  240. display: block;
  241. height: 45px;
  242. width: 200px;
  243. text-decoration: none;
  244. text-align: center;
  245. line-height: 45px;
  246. font-size: 14px;
  247. border-radius: 2px;
  248. margin: 1px 0px 0px -40px;
  249. border: 1px solid #AAAAAA;
  250. border-width: 0px 0px 1px 0px;
  251. }
  252. /*第一个a子元素*/
  253. #accordion a:first-child {
  254. margin-top: -20px;
  255. }
  256. #div-stat-header {
  257. border: 1px solid #B4B4B4;
  258. position: absolute;
  259. left: 250px;
  260. top: 100px;
  261. width: 1050px;
  262. height: 50px;
  263. border-top-left-radius: 5px;
  264. border-top-right-radius: 5px;
  265. background-color: rgb(230, 230, 230);
  266. vertical-align: middle;
  267. line-height: 50px;
  268. padding-left: 20px;
  269. }
  270. #div-chart {
  271. border: 1px solid #B4B4B4;
  272. position: absolute;
  273. left: 250px;
  274. top: 151px;
  275. width: 1050px;
  276. height: 440px;
  277. vertical-align: middle;
  278. line-height: 50px;
  279. padding-left: 20px;
  280. }
  281. </style>
  282. </head>
  283. <body>
  284. <div id="div-top">
  285. <ul>
  286. <li><a href="#">出品+</a></li>
  287. <li><a href="#">首页</a></li>
  288. <li><a href="#">产品</a></li>
  289. <li><a href="#">报告</a></li>
  290. <li><a href="#">开发者中心</a></li>
  291. <li><a href="#">论坛</a></li>
  292. <li><a href="#">活动</a></li>
  293. </ul>
  294. </div>
  295. <div id="div-banner">
  296. <form action="" method="post">
  297. <select name="appid">
  298. <option>全部</option>
  299. <option>微信</option>
  300. <option>QQ</option>
  301. <option>UC</option>
  302. <option>植物大战僵尸</option>
  303. </select>
  304. </form>
  305. <ul>
  306. <li><a href="#">统计分析</a></li>
  307. <li><a href="#">组件</a></li>
  308. <li><a href="#">管理</a></li>
  309. </ul>
  310. </div>
  311. <div id="accordion">
  312. <h3>概况</h3>
  313. <div>
  314. <a href="#">实时统计</a>
  315. <a href="#">整体分析</a>
  316. </div>
  317. <h3>用户分析</h3>
  318. <div>
  319. <a id="a_newusers" href='<c:url value="/stat/newusers" />'>新增用户</a>
  320. <a href="#">活跃用户</a>
  321. <a href="#">沉默用户</a>
  322. <a href="#">启动次数</a>
  323. <a href="#">版本分布</a>
  324. <a href="#">行业数据</a>
  325. </div>
  326. <h3>用户构成</h3>
  327. <div>
  328. <a href="#">周用户构成</a>
  329. <a href="#">用户成分转化</a>
  330. <a href="#">变化系数分析</a>
  331. </div>
  332. <h3>留存分析</h3>
  333. <div>
  334. <a href="#">留存用户</a>
  335. <a href="#">用户新鲜度</a>
  336. <a href="#">用户活跃度</a>
  337. </div>
  338. </div>
  339. <div id="div-stat-header">
  340. 新增用户趋势
  341. </div>
  342. <div id="div-chart">
  343. </div>
  344. <script type="application/javascript">
  345. // 基于准备好的dom,初始化echarts实例
  346. var myChart = echarts.init(document.getElementById('div-chart'));
  347. // 指定图表的配置项和数据
  348. var option = {
  349. title: {
  350. text: '日活跃用户统计'
  351. },
  352. tooltip: {},
  353. legend: {
  354. data: ['v1.1', 'v1.2', 'v1.3']
  355. },
  356. xAxis: {
  357. axisLabel: {
  358. rotate: 20,
  359. interval: 0,//横轴信息全部显示
  360. },
  361. data: ["6月10日/周一(父亲节)", "6月11日/周二", "6月12日/周三", "6月13日/周四", "6月14日/周五", "6月15日/周六"]
  362. },
  363. yAxis: {},
  364. series: [{
  365. name: 'v1.1',
  366. type: 'bar',
  367. data: [5, 20, 36, 10, 10, 20]
  368. }, {
  369. name: 'v1.2',
  370. type: 'bar',
  371. data: [6, 23, 38, 13, 15, 26]
  372. }, {
  373. name: 'v1.3',
  374. type: 'bar',
  375. data: [10, 35, 29, 21, 9, 33]
  376. }]
  377. };
  378. // 使用刚指定的配置项和数据显示图表。
  379. myChart.setOption(option);
  380. </script>
  381. </body>
  382. </html>
  383. 2.通过hive查询统计数据返回到web端,生成图表
  384. a.修改web模块的pom.xml
  385. <?xml version="1.0" encoding="UTF-8"?>
  386. <project xmlns="http://maven.apache.org/POM/4.0.0"
  387. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  388. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  389. <modelVersion>4.0.0</modelVersion>
  390. <groupId>com.test</groupId>
  391. <artifactId>app-logs-visualize-web</artifactId>
  392. <version>1.0-SNAPSHOT</version>
  393. <dependencies>
  394. <dependency>
  395. <groupId>junit</groupId>
  396. <artifactId>junit</artifactId>
  397. <version>4.11</version>
  398. </dependency>
  399. <dependency>
  400. <groupId>org.springframework</groupId>
  401. <artifactId>spring-webmvc</artifactId>
  402. <version>4.3.3.RELEASE</version>
  403. </dependency>
  404. <dependency>
  405. <groupId>javax.servlet</groupId>
  406. <artifactId>servlet-api</artifactId>
  407. <version>2.5</version>
  408. </dependency>
  409. <dependency>
  410. <groupId>jstl</groupId>
  411. <artifactId>jstl</artifactId>
  412. <version>1.2</version>
  413. </dependency>
  414. <dependency>
  415. <groupId>com.alibaba</groupId>
  416. <artifactId>dubbo</artifactId>
  417. <version>2.5.3</version>
  418. <exclusions>
  419. <exclusion>
  420. <groupId>org.springframework</groupId>
  421. <artifactId>*</artifactId>
  422. </exclusion>
  423. </exclusions>
  424. </dependency>
  425. <dependency>
  426. <groupId>com.101tec</groupId>
  427. <artifactId>zkclient</artifactId>
  428. <version>0.9</version>
  429. </dependency>
  430. <!-- 新增部分 -->
  431. <dependency>
  432. <groupId>com.fasterxml.jackson.core</groupId>
  433. <artifactId>jackson-core</artifactId>
  434. <version>2.8.8</version>
  435. </dependency>
  436. <dependency>
  437. <groupId>com.fasterxml.jackson.core</groupId>
  438. <artifactId>jackson-databind</artifactId>
  439. <version>2.8.3</version>
  440. </dependency>
  441. <!-- 公共模块 -->
  442. <dependency>
  443. <groupId>com.test</groupId>
  444. <artifactId>app-analyze-common</artifactId>
  445. <version>1.0-SNAPSHOT</version>
  446. </dependency>
  447. </dependencies>
  448. </project>
  449. b.配置dispatcher-servet.xml配置文件,增加jsonMapping,类似于app-logs-collect-web模块。使javabean在进程间是以json形式传递的
  450. <?xml version="1.0" encoding="UTF-8"?>
  451. <beans xmlns="http://www.springframework.org/schema/beans"
  452. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  453. xmlns:mvc="http://www.springframework.org/schema/mvc"
  454. xmlns:context="http://www.springframework.org/schema/context"
  455. xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
  456. xsi:schemaLocation="http://www.springframework.org/schema/beans
  457. http://www.springframework.org/schema/beans/spring-beans.xsd
  458. http://www.springframework.org/schema/mvc
  459. http://www.springframework.org/schema/mvc/spring-mvc.xsd
  460. http://www.springframework.org/schema/context
  461. http://www.springframework.org/schema/context/spring-context.xsd
  462. http://code.alibabatech.com/schema/dubbo
  463. http://code.alibabatech.com/schema/dubbo/dubbo.xsd
  464. ">
  465. <mvc:annotation-driven/>
  466. <!-- 静态资源 -->
  467. <mvc:resources mapping="/html/**" location="/html/"/>
  468. <mvc:resources mapping="/css/**" location="/css/"/>
  469. <mvc:resources mapping="/js/**" location="/js/"/>
  470. <mvc:resources mapping="/images/**" location="/images/"/>
  471. <!-- 扫描控制器 -->
  472. <context:component-scan
  473. base-package="com.test.applogs.visualize.web.controller"/>
  474. <!-- 配置视图解析器 -->
  475. <bean id="viewResolver"
  476. class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  477. <property name="prefix" value="/jsps/"/>
  478. <property name="suffix" value=".jsp"/>
  479. </bean>
  480. <dubbo:application name="consumer_app"/>
  481. <dubbo:registry address="zookeeper://s200:2181"/>
  482. <dubbo:consumer timeout="500000"/>
  483. <dubbo:reference id="statService"
  484. interface="com.test.applogs.visualize.service.StatService"/>
  485. <!-- 此处乃进行json数据传输的关键,当配置 -->
  486. <bean id="jsonMapping"
  487. class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
  488. <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
  489. <property name="messageConverters">
  490. <list>
  491. <ref bean="jsonMapping"/>
  492. </list>
  493. </property>
  494. </bean>
  495. </beans>
  496. c.Controller中增加方法,返回javabean,javabean对象会进行转换成json格式数据回传给client
  497. /**
  498. * 测试单个bean
  499. */
  500. @RequestMapping("/stat1")
  501. @ResponseBody
  502. public StatBean stat1(){
  503. StatBean b1 = new StatBean();
  504. b1.setDate("2018/06/30");
  505. b1.setCount(1000);
  506. return b1 ;
  507. }
  508. /**
  509. * 测试Listbean
  510. */
  511. @RequestMapping("/stat2")
  512. @ResponseBody
  513. public List<StatBean> stat2(){
  514. List<StatBean> list = new ArrayList<StatBean>();
  515. for(int i = 0 ; i < 10 ; i ++){
  516. StatBean b1 = new StatBean();
  517. b1.setDate("2017/06/" + (10 + i));
  518. b1.setCount(100 + i);
  519. list.add(b1) ;
  520. }
  521. return list ;
  522. }
  523. 3.回传StatBean列表,处理数据后,回传map,操纵json数据
  524. a.查询本周指定app的每天新增的用户数
  525. 1) controller中添加新方法
  526. /**
  527. * 查询本周指定app的每天新增的用户数
  528. */
  529. @RequestMapping("/week1")
  530. @ResponseBody
  531. public List<StatBean> stat3(){
  532. return ss.findThisWeekNewUsers("sdk34734");
  533. }
  534. 2)StatService中添加接口
  535. //查询指定app本周每天新增的用户
  536. public List<StatBean> findThisWeekNewUsers(String appid);
  537. 3)StatServiceImpl中添加接口的实现方法
  538. public List<StatBean> findThisWeekNewUsers(String appid) {
  539. return getDao().findThisWeekNewUsers(appid);
  540. }
  541. 4)StatDao接口中添加方法描述
  542. public List<T> findThisWeekNewUsers(String appid);
  543. 5)StatDaoImpl实现类中实现方法
  544. public List findThisWeekNewUsers(String appid) {
  545. return getSqlSession().selectList("stats.selectThisWeekNewusers",appid);
  546. }
  547. 6)在mybatis映射文件StatBeanMapper.xml中添加查询串语句
  548. <!-- 统计查询一周内每天新增加的用户数量 -->
  549. <select id="selectThisWeekNewusers" resultMap="rm_StatBean">
  550. select formattime(t.mintime, 'yyyy/MM/dd') stdate , count(*) stcount
  551. from
  552. (
  553. select deviceid , min(createdatms) as mintime
  554. from ext_startup_logs
  555. where appid = #{appid}
  556. group by deviceid
  557. having mintime &gt;= getweekbegin() and mintime &lt; getweekbegin(1)
  558. ) as t
  559. group by formattime(t.mintime, 'yyyy/MM/dd')
  560. </select>
  561. <resultMap id="rm_StatBean" type="_StatBean">
  562. <result column="stdate" property="date" />
  563. <result column="stcount" property="count" />
  564. </resultMap>
  565. b.将查询出来的list以json的格式回传,并在浏览器端显示相应的图表
  566. 1)改造StatController中的查询方法stat3
  567. /**
  568. * 查询本周指定app的每天新增的用户数
  569. */
  570. @RequestMapping("/week1")
  571. @ResponseBody
  572. public Map<String, Object> stat3(){
  573. List<StatBean> list = ss.findThisWeekNewUsers("sdk34734");
  574. Map<String,Object> map = new HashMap<String,Object>();
  575. for( StatBean s : list)
  576. {
  577. System.out.println(s.getDate() + ":" + s.getCount());
  578. }
  579. String[] xlabels = new String[list.size()] ;
  580. long[] newUsers = new long[list.size()];
  581. for(int i = 0 ; i < list.size() ; i ++){
  582. xlabels[i] = list.get(i).getDate();
  583. newUsers[i] = list.get(i).getCount();
  584. }
  585. map.put("labels",xlabels);
  586. map.put("data", newUsers);
  587. return map ;
  588. }
  589. 2)修改index.jsp.显示回传数据图表
  590. $("#a_newusers").click(function(){
  591. $.getJSON("/stat/week1",function(d){
  592. option.xAxis.data = d.labels;
  593. option.series[0].data = d.data
  594. myChart.setOption(option);
  595. });
  596. //阻止事件的传递
  597. return false;
  598. });
  599. 五、其他聚合查询
  600. -----------------------------------------------------------------------
  601. [用户分析]
  602. 1.过去的五周(包含本周)某个app每周的周活跃用户数
  603. Hive优化--> 注意,如果能够界定分区区间的话,务必要进行分区限定查询。
  604. ym/day/hm
  605. //20181118 47
  606. select formattime(createdatms,'yyyyMMdd',0) stdate, count(distinct deviceid) stcount from ext_startup_logs where concat(ym,day) >= formattime(getweekbegin(-4),'yyyyMMdd') and appid ='sdk34734' group by formattime(createdatms,'yyyyMMdd',0) ;
  607. 2.最近的六个月(包含本月)每月的月活跃数。
  608. select formattime(createdatms,'yyyyMM') stdate, count(distinct deviceid) stcount from ext_startup_logs where ym >= formattime(getmonthbegin(-5),'yyyyMM') and appid ='sdk34734' group by formattime(createdatms,'yyyyMM') ;
  609. 3.沉默用户数
  610. 3.1)查询今天沉默用户数
  611. select count(*) from (select deviceid , count(createdatms) dcount,min(createdatms) dmin from ext_startup_logs where appid = 'sdk34734' group by deviceid having dcount = 1 and dmin < getdaybegin(-1)) t
  612. 4.启动次数
  613. 4.1)今天app的启动次数
  614. 启动次数类似于活跃用户数,活跃用户数去重,启动次数不需要去重。
  615. select
  616. count(*)
  617. from ext_startup_logs
  618. where appid = 'sdk34734' ym = formattime(getdaybegin(),'yyyyMM') and day = formattime(getdaybegin(),'dd')
  619. 5.版本分布
  620. 5.1)今天appid为34734的不同版本的活跃用户数。
  621. select
  622. appversion,count(distinct deviceid)
  623. from ext_startup_logs
  624. where appid = 'sdk34734' ym = formattime(getdaybegin(),'yyyyMM') and day = formattime(getdaybegin(),'dd')
  625. group by appversion ;
  626. 5.2)本周内每天各版本日活
  627. select formattime(createdatms,'yyyyMMdd'),appversion , count(distinct deviceid) from ext_startup_logs where appid = 'sdk34734' and concat(ym,day) >= formattime(getweekbegin(),'yyyyMMdd') group by formattime(createdatms,'yyyyMMdd') , appversion
  628. [用户构成分析]
  629. 1.本周回流用户
  630. select
  631. distinct deviceid
  632. from ext_startup_logs
  633. where appid = 'sdk34734' and concat(ym,day) >= formattime(getweekbegin(),'yyyyMMdd') and deviceid not in (
  634. select
  635. distinct t.deviceid
  636. from ext_startup_logs t
  637. where t.appid = 'sdk34734' and concat(t.ym,t.day) >= formattime(getweekbegin(-1),'yyyyMMdd') and concat(t.ym,t.day) < formattime(getweekbegin(),'yyyyMMdd')
  638. )
  639. 2.连续活跃n周
  640. select deviceid , count(distinct(formattime(createdatms,'yyyyMMdd',0))) c from ext_startup_logs where appid = 'sdk34734' and concat(ym,day) >= formattime(getweekbegin(-2),'yyyyMMdd') group by deviceid having c = 3
  641. 3.忠诚用户
  642. select deviceid , count(distinct(formattime(createdatms,'yyyyMMdd',0))) c from ext_startup_logs where appid = 'sdk34734' and concat(ym,day) >= formattime(getweekbegin(-4),'yyyyMMdd') group by deviceid having c = 5
  643. 4.连续活跃用户
  644. select deviceid , count(distinct(formattime(createdatms,'yyyyMMdd',0))) c from ext_startup_logs where appid = 'sdk34734' and concat(ym,day) >= formattime(getweekbegin(-1),'yyyyMMdd') group by deviceid having c = 2
  645. 5.近期流失用户
  646. 最近2、3、4都没有启动过app.
  647. 查询所有用户访问的时间的max,max不能落在
  648. //四周内流失
  649. select
  650. distinct(deviceid)
  651. from ext_startup_logs
  652. where appid='#'
  653. and concat(ym,day) >= formattime(getweekbegin(-4),'yyyyMMdd')
  654. and concat(ym,day) < formattime(getweekbegin(-3),'yyyyMMdd')
  655. and deviceid not in (
  656. select
  657. distinct(t.deviceid)
  658. from ext_startup_logs t
  659. where t.appid=''
  660. and concat(t.ym,t.day) >= formattime(getweekbegin(-3),'yyyyMMdd')
  661. )
  662. union
  663. //三周内流失
  664. select
  665. distinct(deviceid)
  666. from ext_startup_logs
  667. where appid='#'
  668. and concat(ym,day) >= formattime(getweekbegin(-3),'yyyyMMdd')
  669. and concat(ym,day) < formattime(getweekbegin(-2),'yyyyMMdd')
  670. and deviceid not in (
  671. select
  672. distinct(t.deviceid)
  673. from ext_startup_logs t
  674. where t.appid=''
  675. and concat(t.ym,t.day) >= formattime(getweekbegin(-2),'yyyyMMdd')
  676. )
  677. union
  678. //两周内流失
  679. select
  680. distinct(deviceid)
  681. from ext_startup_logs
  682. where appid='#'
  683. and concat(ym,day) >= formattime(getweekbegin(-2),'yyyyMMdd')
  684. and concat(ym,day) < formattime(getweekbegin(-1),'yyyyMMdd')
  685. and deviceid not in (
  686. select
  687. distinct(t.deviceid)
  688. from ext_startup_logs t
  689. where t.appid=''
  690. and concat(t.ym,t.day) >= formattime(getweekbegin(-1),'yyyyMMdd')
  691. )
  692. [留存分析]
  693. 1.留存用户
  694. 周留存用户。
  695. select
  696. distinct(deviceid)
  697. from ext_startup_logs
  698. where appid = 'sdk34734'
  699. and concat(ym,day) >= formattime(getweekbegin(-1),'yyyyMMdd')
  700. and concat(ym,day) < formattime(getweekbegin(),'yyyyMMdd')
  701. and deviceid in (
  702. select distinct(t.deviceid)
  703. from (
  704. select tt.deviceid , min(tt.createdatms) mintime
  705. from ext_startup_logs tt
  706. where tt.appid = 'sdk34734'
  707. group by tt.deviceid having mintime >= getweekbegin(-2) and mintime < getweekbegin(-1)
  708. ) t
  709. )
  710. 2.用户的新鲜度
  711. 新鲜度 = 某段时间的新增用户数/某段时间的活跃的老用户数 .
  712. //今天活跃用户
  713. m = select count(distinct(t.deviceid))
  714. from ext_startup_logs where concat(ym,day) = formattime(getdaybegin(),'yyyyMMdd') and appid = ... ;
  715. //今天新增用户
  716. n = select count(distinct(t.deviceid))
  717. from (
  718. select tt.deviceid , min(tt.createdatms) mintime
  719. from ext_startup_logs tt
  720. where tt.appid = 'sdk34734'
  721. group by tt.deviceid having mintime >= getdaybegin(0)
  722. ) t
  723. 新鲜度 = n / (m - n )
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/301008?site
推荐阅读
相关标签
  

闽ICP备14008679号