public function testInsightRelatedDataSetters() { $i = new Insight(); $i->setPhotos("this is my list of photos"); $this->assertEqual($i->related_data["photos"], "this is my list of photos"); $i->setPosts("my posts"); $this->assertEqual($i->related_data["posts"], "my posts"); $i->setLineChart("line chart data goes here"); $this->assertEqual($i->related_data["line_chart"], "line chart data goes here"); $i->setBarChart("bar chart data goes here"); $this->assertEqual($i->related_data["bar_chart"], "bar chart data goes here"); $i->setPeople("list 'o users"); $this->assertEqual($i->related_data["people"], "list 'o users"); $i->setLinks("listoflinks"); $this->assertEqual($i->related_data["links"], "listoflinks"); $i->setMilestoneNumber("milestone_number"); $this->assertEqual($i->related_data["milestone_number"], "milestone_number"); }
public function testInsightRelatedDataSetters() { $i = new Insight(); // @TODO Assign and assert that the data is in the array structure it should be $i->setPhotos("this is my list of photos"); $this->assertEqual($i->related_data["photos"], "this is my list of photos"); $i->setPosts("my posts"); $this->assertEqual($i->related_data["posts"], "my posts"); $i->setLineChart("line chart data goes here"); $this->assertEqual($i->related_data["line_chart"], "line chart data goes here"); $i->setBarChart("bar chart data goes here"); $this->assertEqual($i->related_data["bar_chart"], "bar chart data goes here"); $i->setPeople("list 'o users"); $this->assertEqual($i->related_data["people"], "list 'o users"); $i->setLinks("listoflinks"); $this->assertEqual($i->related_data["links"], "listoflinks"); $i->setMilestones("milestones"); $this->assertEqual($i->related_data["milestones"], "milestones"); $i->setButton("button"); $this->assertEqual($i->related_data["button"], "button"); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $year = date('Y'); $regenerate = false; //testing //$regenerate = true; $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date); if ($should_generate_insight) { $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__); $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = "{$year}-{$this->run_date}"; $count = 0; $post_dao = DAOFactory::getDAO('PostDAO'); /** * Track occurences of exclamations per month */ $point_chart = array(); $last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $instance->network_user_id, $network = $instance->network); $total_posts = 0; $months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); foreach ($months as $month) { $point_chart[$month] = 0; } foreach ($last_year_of_posts as $post) { if ($this->hasFBomb($post, $instance)) { $date = new DateTime($post->pub_date); $month = $date->format('M'); $point_chart[$month]++; $count++; } $total_posts++; } $percent = round($count / $total_posts * 100); $max_month = $this->getMaxMonth($point_chart); $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance); $qualified_year = ""; if (date('Y', strtotime($earliest_pub_date)) == date('Y')) { if (date('n', strtotime($earliest_pub_date)) > 1) { //not January //Earliest post was this year; figure out what month we have data since this year $since = date('F', strtotime($earliest_pub_date)); $qualified_year = " (at least since " . $since . ")"; $since_int = date('n', strtotime($earliest_pub_date)); $since_int--; $point_chart = array_slice($point_chart, $since_int); } } $copy = array('twitter' => array('normal' => array('headline' => "%username gave %total f***s on Twitter in %year", 'body' => "Whiskey Tango Foxtrot: %username said “f**k” " . "<strong>%adverbed_total</strong> on Twitter this year, with %month eliciting the most " . "f***s%qualified_year."), 'one' => array('headline' => "%username really gave a f**k on Twitter in %year", 'body' => "F**k yeah: %username said “f**k” <strong>once</strong> " . "on Twitter this year%qualified_year, in %month.")), 'facebook' => array('normal' => array('headline' => "%username put the “F” in “Facebook” this year", 'body' => "%username dropped <strong>%total F-bombs</strong> on Facebook in %year, " . "with %month on the receiving end of the most f***s%qualified_year. WTF?!"), 'one' => array('headline' => "%username put the “F” in “Facebook” this year", 'body' => "%username dropped <strong>1 F-bomb</strong> on Facebook in %year, in %month."))); if ($count > 1) { $type = 'normal'; $rows = array(); $do_include_chart = false; foreach ($point_chart as $label => $number) { $rows[] = array('c' => array(array('v' => $label), array('v' => $number))); if ($number >= 4) { //Y-axis always renders 4 points $do_include_chart = true; } } if ($do_include_chart && sizeof($rows) > 2) { $insight->setLineChart(array('cols' => array(array('label' => 'Month', 'type' => 'string'), array('label' => 'Occurences', 'type' => 'number')), 'rows' => $rows)); } } elseif ($count == 1) { $type = "one"; } else { return; } $terms = new InsightTerms($instance->network); $adverbed_total = $terms->getOccurrencesAdverb($count); $headline = $this->getVariableCopy(array($copy[$instance->network][$type]['headline']), array('total' => $count, 'year' => $year)); $insight_text = $this->getVariableCopy(array($copy[$instance->network][$type]['body']), array('year' => $year, 'total' => $count, 'month' => $max_month, 'qualified_year' => $qualified_year, 'adverbed_total' => $adverbed_total)); $insight->headline = $headline; $insight->text = $insight_text; $insight->header_image = $user->avatar; $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; $this->insight_dao->insertInsight($insight); } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $year = date('Y'); $regenerate = false; //testing //$regenerate = true; $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date); if ($should_generate_insight) { $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__); $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = "{$year}-{$this->run_date}"; $count = 0; $post_dao = DAOFactory::getDAO('PostDAO'); $network = $instance->network; /** * Track occurences of exclamations per month */ $point_chart = array(); $last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $instance->network_user_id, $network = $network); $total_posts = 0; $months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); foreach ($months as $month) { $point_chart[$month] = 0; } foreach ($last_year_of_posts as $post) { if ($this->hasExclamationPoint($post->post_text)) { $date = new DateTime($post->pub_date); $month = $date->format('M'); $point_chart[$month]++; $count++; } $total_posts++; } $percent = round($count / $total_posts * 100); $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance); $qualified_year = ""; if (date('Y', strtotime($earliest_pub_date)) == date('Y')) { if (date('n', strtotime($earliest_pub_date)) > 1) { //not January //Earliest post was this year; figure out what month we have data since this year $since = date('F', strtotime($earliest_pub_date)); $qualified_year = " (at least since " . $since . ")"; $since_int = date('n', strtotime($earliest_pub_date)); $since_int--; $point_chart = array_slice($point_chart, $since_int); } } $copy = array('twitter' => array('normal' => array('headline' => "%username's !!!'s of Twitter, %year", 'body' => "OMG! In %year, %username used exclamation points " . "in <strong>%total tweets</strong>. That's %percent% " . "of %username's tweets this year%qualified_year!"), 'none' => array('headline' => "%username was not impressed with %year", 'body' => "In %year, %username didn't use one exclamation " . "point on Twitter%qualified_year. Must be holding out for something " . "really exciting!")), 'facebook' => array('normal' => array('headline' => "%username's emphatic %year on Facebook!", 'body' => "Enthusiasm is contagious, and in %year, %username " . "spread the excitement in a total of <strong>%total %posts" . "</strong> containing exclamation points. " . "That's %percent% of %username's Facebook posts " . "this year%qualified_year!"), 'none' => array('headline' => "%username was not impressed with %year", 'body' => "In %year, %username didn't use one exclamation " . "point on Facebook%qualified_year. Must be holding out for something " . "really exciting!"))); if ($count > 0) { $type = 'normal'; $rows = array(); $do_include_chart = false; foreach ($point_chart as $label => $number) { $rows[] = array('c' => array(array('v' => $label), array('v' => $number))); if ($number >= 4) { //Y-axis always renders 4 points $do_include_chart = true; } } if ($do_include_chart && sizeof($rows) > 2) { $insight->setLineChart(array('cols' => array(array('label' => 'Month', 'type' => 'string'), array('label' => 'Total', 'type' => 'number')), 'rows' => $rows)); } } else { $type = 'none'; } $headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('year' => $year)); $insight_text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('year' => $year, 'total' => number_format($count), 'percent' => $percent, 'qualified_year' => $qualified_year)); $insight->headline = $headline; $insight->text = $insight_text; $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; $insight->header_image = $user->avatar; $this->insight_dao->insertInsight($insight); } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }
public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days) { parent::generateInsight($instance, $user, $last_week_of_posts, $number_days); $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__); $regenerate = false; //testing //$regenerate = true; $year = date('Y'); $should_generate_insight = self::shouldGenerateEndOfYearAnnualInsight($this->slug, $instance, $insight_date = "{$year}-{$this->run_date}", $regenerate, $day_of_year = $this->run_date, $count_related_posts = null, array('instagram')); if ($should_generate_insight) { $this->logger->logInfo("Should generate", __METHOD__ . ',' . __LINE__); $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = "{$year}-{$this->run_date}"; $count = 0; $post_dao = DAOFactory::getDAO('PostDAO'); $network = $instance->network; // Track occurences of words per month $point_chart = array(); $post_dao = DAOFactory::getDAO('PostDAO'); $last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $instance->network_user_id, $network = $network); $months = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); foreach ($months as $month) { $point_chart[$month] = 0; } $word_count = 0; foreach ($last_year_of_posts as $post) { if ($post->in_retweet_of_post_id == null) { //don't count retweets $post_word_count = $this->countWords($post->post_text); $word_count += $post_word_count; $date = new DateTime($post->pub_date); $month = $date->format('M'); $point_chart[$month] += $post_word_count; $count++; } } $earliest_pub_date = $post_dao->getEarliestCapturedPostPubDate($instance); $qualified_year = ""; if (date('Y', strtotime($earliest_pub_date)) == date('Y')) { if (date('n', strtotime($earliest_pub_date)) > 1) { //not January //Earliest post was this year; figure out what month we have data since this year $since = date('F', strtotime($earliest_pub_date)); $qualified_year = " (at least since " . $since . ")"; $since_int = date('n', strtotime($earliest_pub_date)); $since_int--; $point_chart = array_slice($point_chart, $since_int); } } $max_month = $this->getMaxMonth($point_chart); $month_words = number_format($point_chart[substr($max_month, 0, 3)]); $number_pages = round($word_count / 275); $word_count = number_format($word_count); if ($number_pages > 5) { $page_copy = "If %username were writing a book, that would be about " . $number_pages . " pages. "; } else { $page_copy = ""; } $copy = array('twitter' => array('normal' => array('headline' => "%username tweeted %total words in 2015", 'body' => "In %year, %username entered a grand total of <strong>%total words</strong> " . "into the Twitter data entry box%qualified_year, reaching peak wordage " . "in %month, with %words_in_month words. %page_copyHere's the month-by-month breakdown.")), 'facebook' => array('normal' => array('headline' => "%username had a word or two (or %total) for Facebook in 2015", 'body' => "In %year, %username typed and tapped <strong>%total words</strong> " . "into Facebook's status update or comment box%qualified_year, topping " . "out with %words_in_month words in %month. %page_copyHere's a breakdown by month."))); $type = 'normal'; foreach ($point_chart as $label => $number) { $rows[] = array('c' => array(array('v' => $label), array('v' => $number))); } $insight->setLineChart(array('cols' => array(array('label' => 'Month', 'type' => 'string'), array('label' => 'Words', 'type' => 'number')), 'rows' => $rows)); $headline = $this->getVariableCopy(array($copy[$network][$type]['headline']), array('total' => $word_count)); $insight_text = $this->getVariableCopy(array($copy[$network][$type]['body']), array('year' => $year, 'total' => $word_count, 'month' => $max_month, 'words_in_month' => $month_words, 'qualified_year' => $qualified_year, 'page_copy' => $page_copy)); $insight->headline = $headline; $insight->text = $insight_text; $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; $insight->header_image = $user->avatar; $this->insight_dao->insertInsight($insight); } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }