26

reminder提醒记

 5 years ago
source link: https://studygolang.com/articles/19734?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Repo地址: https://github.com/guoruibiao/reminder

nEJnM3q.jpg!web

基于艾宾浩斯遗忘曲线的reminder

先前就写了几篇关于艾宾浩斯遗忘曲线相关的博客,比如 浅读艾宾浩斯遗忘曲线

期间用了段Mac自带的日历工具,行程安排这块不太好同步,需要向系统申请权限,我本人对macOS开发不熟悉,就没有在上面花心思。也曾用过influxdb作为存储介质,但是有一点小材大用的感觉,不够灵活。

昨天TB去了密云附近,爬了司马台长城,逛了古北水镇。全天走了20公里,真的是腿酸脚麻。一路上大家说说笑笑,聊天的时候发现平时积累的一些小知识点忘得是一干二净,更是提醒了我给自己做一个小工具,来时不时地提醒我该复习哪些知识了。

晚上构思了下大致的雏形,早上起来就开始编码了,因为是基于艾宾浩斯遗忘曲线的,所以某些场景的提醒就不太合适了,这里就硬性规定了几个时间点。

/**
  短时记忆  5分钟,20分钟, 1小时
  长时记忆  12小时,1天,3天,7天,14天,30天
 */
func generateEvents(event Event) []Event {
    slots := []int64{
        // 短时记忆槽
        5 * 60,
        20 * 60,
        60 * 60,
        // 长时记忆槽
        12 * 60 * 60,
        86400,
        86400*3,
        86400*7,
        86400*14,
        86400*30,
        86400*90,
    }
    var events []Event
    for _, addseconds := range slots {
        tmp := event
        tmp.Tiptime = tmp.Addtime + addseconds
        events = append(events, tmp)
    }
    return events
}

存储方面借助的还是Redis,数据结构选择了Sorted_set,核心依旧是一个Timeline模式,时间轴与现实平行前进,对未来的某一个时间点进行规划,提醒方面不够强,用的浏览器的Notification。

function makeNotification(event) {
  var popNotice = function(event) {
    if (Notification.permission == "granted") {
        var notification = new Notification(event.Title, {
            body: event.Description,
            icon: 'https://avatar.csdn.net/0/8/F/3_marksinoberg.jpg'
        });
        
        notification.onclick = function() {
            // TODO just一个展示思路
            // alert(event.Description)
            notification.close();    
        };
    }    
};

  if(Notification.permission == "granted") {
    popNotice(event);   
  }else if(Notification.permission != "denied") {
    Notification.requestPermission(function(permission){
        popNotice(event);
    });
  }
}

测试期间发现golang的gin框架是真滴厉害,速度杠杠的。

[GIN] 2019/04/14 - 16:19:55 | 200 |     771.716µs |       127.0.0.1 | GET      /getevent?starttime=1554970795&endtime=1555575595&_=1555229995723
[GIN] 2019/04/14 - 16:20:09 | 200 |      27.777µs |       127.0.0.1 | GET      /ping
[GIN] 2019/04/14 - 16:20:10 | 200 |      10.779µs |       127.0.0.1 | GET      /ping
[GIN] 2019/04/14 - 16:20:10 | 200 |       9.726µs |       127.0.0.1 | GET      /ping

唯一遗憾的是,不会客户端开发,大学期间学的安卓开发,当时是4.X,再看现在,早过了不知道多少代了,就不浪费时间瞎折腾了。

展望下,如果有客户端,就可以通过暴露出的接口进行APP端的强提醒,做好缓存以及数据更新、数据同步策略,应该可以做成一个不错的小工具。

Repo地址: https://github.com/guoruibiao/reminder


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK