Ejemplo n.º 1
0
 public function performAction()
 {
     $userCols = WakaUser::columns();
     $statCols = Stat7Days::columns();
     $detCols = Stat7Details::columns();
     $typeCols = StatType::columns();
     $exprDaily = Stat7Days::statement()->select('GROUP_CONCAT(?)', $statCols->dailyAverage)->where('? = ?', $statCols->userId, $userCols->id)->groupBy($statCols->userId);
     $exprTotal = Stat7Days::statement()->select('GROUP_CONCAT(?)', $statCols->totalSeconds)->where('? = ?', $statCols->userId, $userCols->id)->groupBy($statCols->userId);
     $exprLang = Stat7Details::statement()->select('GROUP_CONCAT(? || ":" || cast(? as int))', $typeCols->type, $detCols->percent)->innerJoin('? ON ? = ?', StatType::table(), $typeCols->id, $detCols->typeId)->where('? = ?', $detCols->stat7id, $userCols->latestStatId)->where('? > 10 AND ? = ?', $detCols->percent, $typeCols->section, 'languages');
     $res = WakaUser::statement()->select('? AS User,round(?/3600.0, 2) AS "Dly, h", ? AS Daily,round(?/3600.0, 2) AS "Tot, h", ? AS H, ? AS Specialty', $userCols->userName, $statCols->dailyAverage, $exprDaily, $statCols->totalSeconds, $statCols->holidays, $exprLang)->leftJoin('? ON ? = ?', Stat7Days::table(), $statCols->id, $userCols->latestStatId)->order('? DESC', Stat7Days::columns()->totalSeconds)->bindResultClass()->query()->fetchAll();
     $minDaily = $maxDaily = null;
     foreach ($res as &$item) {
         $item['Daily'] = explode(',', $item['Daily']);
         if (null === $minDaily) {
             $minDaily = min($item['Daily']);
             $maxDaily = max($item['Daily']);
         } else {
             $minDaily = min($minDaily, min($item['Daily']));
             $maxDaily = max($maxDaily, max($item['Daily']));
         }
     }
     $processor = new Processor($res);
     $processor->map(function ($row) use($minDaily, $maxDaily) {
         $dailySpark = new Text(Spark::getString($row['Daily'], $minDaily, $maxDaily));
         $dailySpark->forceLength = strlen($dailySpark->value) / 3;
         $row['Daily'] = $dailySpark;
         //$row['Total'] = Spark::getString(explode(',', $row['Total']));
         return $row;
     });
     //print_r($res->fetchAll());
     $this->response->addContent(new Rows($processor));
 }
Ejemplo n.º 2
0
 /**
  * @param Columns|static $columns
  */
 static function setUpColumns($columns)
 {
     $columns->id = Column::AUTO_ID;
     $columns->typeId = StatType::columns()->id;
     $columns->stat7id = Stat7Days::columns()->id;
     $columns->seconds = Column::INTEGER;
     $columns->percent = Column::FLOAT;
 }
Ejemplo n.º 3
0
 public function performAction()
 {
     /** @var Migration[] $migrations */
     $migrations = array(WakaUser::migration(), StatType::migration(), Stat7Details::migration(), Stat7Days::migration());
     $log = new Log('colored-stdout');
     if ($this->wipe) {
         foreach ($migrations as $migration) {
             $migration->setLog($log)->setDryRun($this->dryRun)->rollback();
         }
     }
     foreach ($migrations as $migration) {
         $migration->setLog($log)->setDryRun($this->dryRun)->apply();
     }
 }
Ejemplo n.º 4
0
 public function fetchStats()
 {
     $wakaPub = new WakaPub();
     $stats = $wakaPub->getStats($this->wakaId);
     $stats->userId = $this->id;
     if ($exists = $stats->findSaved()) {
         //$this->latestStatId = $exists->id;
         //$this->save();
         throw new Exception('Stats already exists', Exception::ALREADY_EXISTS);
     }
     $stats->save();
     $this->latestStatId = $stats->id;
     $this->save();
     foreach ($stats->details as $detail) {
         $detail->stat7id = $stats->id;
         $detail->typeId = StatType::getByText($detail->sectionText, $detail->typeText);
         $detail->save();
     }
 }