一种打点逻辑的实现方案

栏目: ASP.NET · 发布时间: 7年前

项目中经常需要做打点。下面是一种打点逻辑的实现方案,例子如下所示:
    public static void main(String[] args) {
        // 1. 新建一个统计项
        StatisticPipeLine pipeLine = StatisticPipeLine.create("game_statistic");
 
        // 标记一些动作
        // 默认提供了开始-结束计时动作(TimerAction)、计数器动作(CounterAction)、枚举动作(EnumAction)
        pipeLine.put(EnumAction.fromValue(5), "entrance")
                .put(CounterAction.zero(), "counter")
                .put(TimerAction.Start.fromCurrentTimestamp(), "start_click");
 
        // 模拟耗时操作
        sleep(2000);
 
        // 结束计时
        pipeLine.put(TimerAction.End.fromStart("start_click"), "show_ui");
 
        // 计数器+1
        pipeLine.put(CounterAction.increase("counter")); // should print counter=1
 
        // 模拟耗时操作
        sleep(1000);
 
        // 结束计时
        pipeLine.put(TimerAction.End.fromStart("start_click"), "show_video");
 
        // 获得统计结果
        Map<String, Object> assemble = pipeLine.assemble();
 
        // 结果为 {show_video=3005, counter=1, entrance=5, show_ui=2002}
        System.out.println(assemble);
    }
代码在: https://github.com/legendmohe/StatisticPipeLine

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Learning jQuery

Learning jQuery

Jonathan Chaffer、Karl Swedberg / Packt Publishing / 2007-7-7 / GBP 24.99

jQuery is a powerful JavaScript library that can enhance your websites regardless of your background. In this book, creators of the popular jQuery learning resource, learningquery.com, share the......一起来看看 《Learning jQuery》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

MD5 加密
MD5 加密

MD5 加密工具

SHA 加密
SHA 加密

SHA 加密工具