コード例 #1
0
 protected function execute($arguments = array(), $options = array())
 {
     $stop_watch = new StopWatch();
     $stop_watch->start();
     logline('Started processing.');
     $databaseManager = new sfDatabaseManager($this->configuration);
     $queries = QueryPeer::doSelect(new Criteria());
     logline(sprintf("There are %s queries to process.", sizeof($queries)));
     foreach ($queries as $query) {
         $connection = Propel::getConnection();
         $sql = "SELECT STD(%s) as standard_deviation FROM %s where %s=%s";
         $sql = sprintf($sql, QueryResultPeer::RESULT_SIZE, QueryResultPeer::TABLE_NAME, QueryResultPeer::QUERY_ID, $query->getId());
         $statement = $connection->prepareStatement($sql);
         $resultset = $statement->executeQuery();
         $resultset->next();
         $std = $resultset->getString('standard_deviation');
         $sql = "SELECT AVG(%s) as mean_of_all FROM %s where %s=%s";
         $sql = sprintf($sql, QueryResultPeer::RESULT_SIZE, QueryResultPeer::TABLE_NAME, QueryResultPeer::QUERY_ID, $query->getId());
         $statement = $connection->prepareStatement($sql);
         $resultset = $statement->executeQuery();
         $resultset->next();
         $mean = $resultset->getString('mean_of_all');
         $query->setStandardDeviation($std / $mean);
         logline(sprintf('Average stdev for query %s is %s.', $query->getQuery(), $query->getStandardDeviation()));
         $query->save();
         //logLine(sprintf("Standart deviation for %s is %s.", $query->getQuery(), $deviation));
     }
     logline(sprintf("Finished processing."));
     $stop_watch->end();
     logline(sprintf('Execution time: %s seconds.', $stop_watch->getTime()));
     logline(sprintf('!!!!!CAN RUN %s TIMES A DAY!!!!!', 24 * 60 * 60 / ($stop_watch->getTime() == 0 ? 1 : $stop_watch->getTime())));
 }
コード例 #2
0
 protected function execute($arguments = array(), $options = array())
 {
     $stop_watch = new StopWatch();
     $stop_watch->start();
     logline('Started processing.');
     $searchEngine = new GoogleHitFetcher();
     $databaseManager = new sfDatabaseManager($this->configuration);
     $queries = QueryPeer::doSelect(new Criteria());
     logline(sprintf("There are %s queries to process.", sizeof($queries)));
     foreach ($queries as $query) {
         $qr = new QueryResultBulk();
         $qr->setQuery($query);
         $result_size = $searchEngine->fetch($query->getQuery());
         $qr->setResultSize($result_size);
         logline(sprintf("Found %s results for %s.", $result_size, $query->getQuery()));
         $qr->save();
     }
     logline(sprintf("Finished processing."));
     $stop_watch->end();
     logline(sprintf('Execution time: %s seconds.', $stop_watch->getTime()));
     logline(sprintf('!!!!!CAN RUN %s TIMES A DAY!!!!!', 24 * 60 * 60 / $stop_watch->getTime()));
 }
コード例 #3
0
 protected function execute($arguments = array(), $options = array())
 {
     $frequencies = array('D' => 'Daily', 'W' => 'Weekly', 'M' => 'Monthly');
     $frequency = $arguments['frequency'];
     if (!array_key_exists($frequency, $frequencies)) {
         logline(sprintf('Invalid frequency %s use [D|W|M]', $frequency));
         exit;
     }
     sfLoader::loadHelpers('Partial', 'My');
     $context = sfContext::createInstance($this->configuration);
     $stop_watch = new StopWatch();
     $stop_watch->start();
     logline(sprintf('Started processing %s mails.', $frequencies[$frequency]));
     $databaseManager = new sfDatabaseManager($this->configuration);
     $c1 = new Criteria();
     $c1->addJoin(sfGuardUserPeer::ID, ReportPeer::USER_ID);
     $c1->add(ReportPeer::MAIL_FREQUENCY, $frequency);
     $c1->setDistinct();
     $users = sfGuardUserPeer::doSelect($c1);
     foreach ($users as $user) {
         $c = new Criteria();
         $c->add(ReportPeer::USER_ID, $user->getId());
         $c->add(ReportPeer::MAIL_FREQUENCY, $frequency);
         $reports = ReportPeer::doSelect($c);
         logline(sprintf("There are %s reports to process.", sizeof($reports)));
         $sfGuardUserProfile = $user->getsfGuardUserProfiles();
         $sfGuardUserProfile = $sfGuardUserProfile[0];
         $connection = new Swift_Connection_SMTP('mail.sis-nav.com', 25);
         $connection->setUsername('*****@*****.**');
         $connection->setPassword('gahve123');
         $mailer = new Swift($connection);
         $message = new Swift_Message(sprintf("Goole Volume - %s notifications.", $frequencies[$frequency]));
         $images = array();
         foreach ($reports as $report) {
             //                $rtn = ReportPeer::_getReportChart(
             //                $report, date('Y-m-d', strtotime(date('Ymd') . ' -1 months')),
             //                date('Y-m-d', strtotime(date('Y-m-d') . ' +1 days')),
             //                QueryResultPeer::FREQUENCY_DAY, new MailChartDecorator());
             $rtn = ReportPeer::_getReportChartt($report, new MailChartDecorator());
             $data = $rtn['values'];
             $line_chart = $rtn['chart'];
             $image_path = $local_url = sfConfig::get('app_web_images') . '/' . $line_chart->__toString();
             $images[$report->getTitle()] = new Swift_Message_Image(new Swift_File($image_path));
             $imageReferences = array();
             foreach ($images as $name => $image) {
                 $imageReferences[$name] = $message->attach($image);
             }
             $mailContext = array('data' => $data, 'full_name' => $sfGuardUserProfile->getFullName(), 'report' => $report, 'images' => $imageReferences);
         }
         try {
             $message->attach(new Swift_Message_Part(get_partial('mail/mailReportHtmlBody', $mailContext), 'text/html'));
             $message->attach(new Swift_Message_Part(get_partial('mail/mailReportTextBody', $mailContext), 'text/plain'));
             $mailer->send($message, $sfGuardUserProfile->getEmail(), '*****@*****.**');
             $mailer->disconnect();
         } catch (Exception $e) {
             logline(sprintf('Exception while sending email to %s about %s. %s', $sfGuardUserProfile->getEmail(), $report->getTitle(), $e));
             $mailer->disconnect();
         }
         logline(sprintf('Sent mail to %s.', $sfGuardUserProfile->getEmail()));
     }
     logline(sprintf("Finished processing."));
     $stop_watch->end();
     logline(sprintf('Execution time: %s seconds.', $stop_watch->getTime()));
     logline(sprintf('!!!!!CAN RUN %s TIMES A DAY!!!!!', 24 * 60 * 60 / ($stop_watch->getTime() == 0 ? 1 : $stop_watch->getTime())));
 }