protected function configure()
    {
        $this->setName('run')->setDescription('Run aggregation')->addArgument('uuid', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'UUID(s)', array(null))->addOption('level', 'l', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Level (hour|day|month|year)', array('day'))->addOption('mode', 'm', InputOption::VALUE_REQUIRED, 'Mode (full|delta)', 'delta')->addOption('period', 'p', InputOption::VALUE_REQUIRED, 'Previous time periods (full|delta)');
    }
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (!in_array($mode = $input->getOption('mode'), array('full', 'delta'))) {
            throw new \Exception('Unsupported aggregation mode ' . $mode);
        }
        // loop through all uuids
        foreach ($input->getArgument('uuid') as $uuid) {
            // loop through all aggregation levels
            foreach ($input->getOption('level') as $level) {
                if (!Util\Aggregation::isValidAggregationLevel($level)) {
                    throw new \Exception('Unsupported aggregation level ' . $level);
                }
                $msg = "Performing '" . $mode . "' aggregation";
                if ($uuid) {
                    $msg .= " for UUID " . $uuid;
                }
                echo $msg . " on '" . $level . "' level.\n";
                $rows = $this->aggregator->aggregate($uuid, $level, $mode, $input->getOption('period'));
                echo "Updated {$rows} rows.\n";
            }
        }
    }
}
$app = new Util\ConsoleApplication('Data aggregation tool');
$app->addCommands(array(new CreateCommand(), new OptimizeCommand(), new ClearCommand(), new RunCommand()));
$app->run();