美文网首页Raku Programming Language
日期区间和 ... 操作符

日期区间和 ... 操作符

作者: 焉知非鱼 | 来源:发表于2016-12-01 23:45 被阅读11次
    use v6;
    
    my $insert = "insert into `ald_stay_logs` (`id`, `app_key`, `day`, `day_after`, `new_people_left`, `people_left`) values";
    
    my @app_key = <2323423dsfds 21e689e6bb76 f05883cf4dd8 7c8ccee05d025>;  # 要遍历的 app_key
    my @date = Date.new('2016-11-22') .. Date.new('2016-11-28'); # 上一周
    my @day_after = 0..30;                    # 多少天以后的数据, 最大查看30天的数据
    my @init_nums = <5500 5800 8000 9500>;    # 新增用户的起始值
    #my @init_peoples = <6000 7000 8000 9000>; # 活跃用户的起始值
    
    for @app_key.kv -> $idx, $app_key  {
        my $init  = @init_nums[$idx];
        #my $start = @init_peoples[$idx];
        my @step  = 15, 20, 40;
        my @new_people_left = lazy $init, $init-$init*0.15, $init-$init*0.20, $init-$init*0.40, {$^a - @step.pick} ... 0;
        #my @people_left = lazy $start, $start-$start*0.15, $start-$start*0.20, $start-$start*0.40, {$^a - @step.pick} ... 0;
        for @date -> $day {
            for @day_after.kv -> $idx, $day_after {
                say $insert, "(null,'$app_key', '$day', '$day_after', '@new_people_left[$idx]', '')";
            }
        }
    }
    

    2018 年哪些日子是周六:

    enum DoW < Sunday Monday Tuesday Wednesday Thursday Friday Saturday >;
    say (Date.new("2018-01-01")..Date.new("2018-12-31")).grep( *.day-of-week == Saturday );
    

    相关文章

      网友评论

        本文标题:日期区间和 ... 操作符

        本文链接:https://www.haomeiwen.com/subject/toefmttx.html