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 getInsightForCounts($this_period_count, $last_period_count, $instance, $matching_posts) { $insight = null; if ($this_period_count > 0) { $insight = new Insight(); $insight->slug = $this->getSlug(); $insight->instance_id = $instance->id; $insight->date = $this->insight_date; $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_MED; $insight->headline = $this->getVariableCopy(array('30 days of !!!', 'OMG %username is serious!')); $showchart = count($this->point_chart) > 2; $insight->text = $this->getVariableCopy(array("%username used exclamation points in %total %post" . ($this_period_count == 1 ? '' : 's') . " this past month! " . ($showchart ? "" : "That's %percent% of %username's %posts!")), array('total' => $this_period_count, 'percent' => floor($this_period_count / $this->total_posts * 100))); if ($showchart) { $insight->text .= " Some things are just one-exclamation-point exciting! " . "Others are really exciting!!!! Here's " . $this->username . "'s breakdown."; asort($this->point_chart); $rows = array(); foreach ($this->point_chart as $label => $number) { $rows[] = array('c' => array(array('v' => str_repeat('!', $label)), array('v' => $number))); } $insight->setBarChart(array('cols' => array(array('label' => 'Exclamation Points', 'type' => 'string'), array('label' => 'Occurences', 'type' => 'number')), 'rows' => $rows)); } } return $insight; }
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__); $post_dao = DAOFactory::getDAO('PostDAO'); $last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $instance->network_user_id, $network = $instance->network); $words = $this->getWordsFromPosts($last_year_of_posts); $total_top_words = count($words); if ($total_top_words == 0) { $this->logger->logInfo("Done Generating Insight (no words)", __METHOD__ . ',' . __LINE__); return; } // Get qualified year $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 . ")"; } } foreach ($words as $key => $word) { $words[$key][0] = '“' . $word[0]; } $first = $words[0][0] . "”"; $top_words = array_slice($words, 1, 4); $num_words = count($top_words); $rest = false; if ($num_words == 1) { $rest = $top_words[0][0] . ".”"; } else { if ($num_words == 2) { $top_words[$num_words - 1][0] = '” and ' . $top_words[$num_words - 1][0]; $tmp_words = array_map(create_function('$a', 'return $a[0];'), $top_words); $rest = join($num_words > 2 ? ",” " : "", $tmp_words) . ".”"; } else { if ($num_words > 2) { $top_words[$num_words - 1][0] = 'and ' . $top_words[$num_words - 1][0]; $tmp_words = array_map(create_function('$a', 'return $a[0];'), $top_words); $rest = join($num_words > 2 ? ",” " : "", $tmp_words) . ".”"; } } } if ($instance->network == 'facebook') { $text = "How to describe {$year}? " . $this->username . " used <strong>{$first} " . number_format($words[0][1]) . " times</strong> on Facebook this year{$qualified_year}. That's more than any other word"; if (!$rest) { $text .= '.'; } else { $text .= " — followed by {$rest} Sound about right?"; } $headline = $this->username . "'s most-used word" . ($total_top_words == 1 ? '' : 's') . " on Facebook, {$year}"; } else { $network = ucfirst($instance->network); $text = "Would you say it's been a {$first} year? " . $this->username . " might. " . $this->username . " mentioned <strong>{$first} " . number_format($words[0][1]) . " times</strong> on {$network} in {$year}{$qualified_year}. That's more than any other word this year"; if (!$rest) { $text .= '.'; } else { $text .= " — followed by {$rest}"; } $headline = $this->username . "'s most-used word" . ($total_top_words == 1 ? '' : 's') . " on {$network}, {$year}"; } $insight = new Insight(); $insight->instance_id = $instance->id; $insight->slug = $this->slug; $insight->date = "{$year}-{$this->run_date}"; $insight->headline = $headline; $insight->text = $text; $insight->header_image = $user->avatar; $insight->filename = basename(__FILE__, ".php"); $insight->emphasis = Insight::EMPHASIS_HIGH; $rows = array(); foreach ($words as $word) { $rows[] = array('c' => array(array('v' => str_replace('“', '', $word[0])), array('v' => $word[1]))); } $insight->setBarChart(array('cols' => array(array('label' => 'Word', 'type' => 'string'), array('label' => 'Occurences', 'type' => 'number')), 'rows' => $rows)); $this->insight_dao->insertInsight($insight); } $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__); }