<?php
include_once dirname(__FILE__) . '/../main.php';

//每天活跃人数在N天后的流失

$params = query_paras();

//$date = $params['date']['ts'];
//$uid = $params['date']['uid'];
$zoneid = $params['date']['zoneid'];

$loginKey = "loginUserNum-"+$zoneid;
 
$dic = gMem()->hgetall($loginKey);

$resultDic = new stdClass();
foreach ($dic as $day => $personNum) {
    $itemDic = new stdClass();
    $itemDic->personNum = $personNum;
    $itemDic->curDay = $day;
    for ($i = 1; $i <= 7; $i++) {
        $ts = $day + $i;               
        $loseKey = "LoseUserKeyCount-".$i."lose-zone".$zoneid."-".$ts;              
        if(gMem()->exists($loseKey)){
            continue;
        }    
        $loseDic = gMem()->hgetall($loseKey);            
        $n = 0;
        foreach ($loseDic as $key => $num) {
            if(strpos($key, "level") === true){
                $n += $num;
            }
        }           
        $itemDic->$i = $n;                
    }
    $resultDic->$day = $itemDic;
}

$result = new stdClass();
$result->data = $resultDic;
echo json_encode($result);