public function testHasFirstPersonReferences() { $has = AllAboutYouInsight::hasFirstPersonReferences("I don't know, really? I thought so."); $this->assertTrue($has); $has = AllAboutYouInsight::hasFirstPersonReferences("Now that I'm back on Android, realizing just how under sung Google Now is. I want it everywhere."); $this->assertTrue($has); $has = AllAboutYouInsight::hasFirstPersonReferences("New YearÕs Eve! Feeling very gay today, but not very homosexual."); $this->assertFalse($has); $has = AllAboutYouInsight::hasFirstPersonReferences("Tis the season for adorable cards w/ photos of my " . "friends' kids & pets that remind me what I'd do for the holidays if I had my act together."); $this->assertTrue($has); $has = AllAboutYouInsight::hasFirstPersonReferences("Took 1 firearms safety class to realize my " . "fantasy of stopping an attacker was just that: http://bit.ly/mybH2j Slate: http://slate.me/T6vwde"); $this->assertTrue($has); $has = AllAboutYouInsight::hasFirstPersonReferences("When @anildash told me he was writing this I was " . "like 'yah whatever cool' then I read it and it knocked my socks off http://bit.ly/W9ASnj "); $this->assertTrue($has); $has = AllAboutYouInsight::hasFirstPersonReferences("I like http://about.me/"); $this->assertTrue($has); $has = AllAboutYouInsight::hasFirstPersonReferences("Me like http://about.me/"); $this->assertTrue($has); $has = AllAboutYouInsight::hasFirstPersonReferences("People like http://about.me/"); $this->assertFalse($has); $has = AllAboutYouInsight::hasFirstPersonReferences("The new site is cdmoyer.me"); $this->assertFalse($has); $has = AllAboutYouInsight::hasFirstPersonReferences("My new site is cdmoyer.me"); $this->assertTrue($has); }
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}"; $network = $instance->network; $count = 0; $post_dao = DAOFactory::getDAO('PostDAO'); $last_year_of_posts = $post_dao->getThisYearOfPostsIterator($author_id = $instance->network_user_id, $network = $network); $total_posts = 0; foreach ($last_year_of_posts as $post) { $count += AllAboutYouInsight::hasFirstPersonReferences($post->post_text) ? 1 : 0; $total_posts++; } $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 . ")"; } } if ($instance->network == 'twitter') { $headline = $this->getVariableCopy(array("A year's worth of %username")); } elseif ($instance->network == 'instagram') { $headline = $this->getVariableCopy(array("A year of %username photos")); } else { $headline = $this->getVariableCopy(array("A year about %username")); } $percent = round($count / $total_posts * 100); if ($count > 0) { if ($instance->network == 'twitter' || $instance->network == 'facebook') { $insight_text = $this->getVariableCopy(array("In %year, <strong>{$percent}%</strong> of %username's %posts " . "— a grand total of %total — contained " . "the words “I”, “me”, “my”, " . "“mine”, or “myself”%qualified_year. " . ($instance->network == 'facebook' ? "Go ahead: tell your story" : "Sometimes, you've just got to get personal") . "."), array('total' => number_format($count), 'year' => $year, 'qualified_year' => $qualified_year)); } else { $insight_text = $this->getVariableCopy(array("In %year, <strong>{$percent}%</strong> of %username's Instagram captions " . "— a grand total of %total — contained " . "the words “I”, “me”, “my”, " . "“mine”, or “myself”%qualified_year. " . "What a life in pictures!"), array('total' => number_format($count), 'year' => $year, 'qualified_year' => $qualified_year)); } } else { $insight_text = $this->getVariableCopy(array("In %year, none of %username's %posts contained " . "the words “I”, “me”, “my”, " . "“mine”, or “myself”%qualified_year. Sometimes, " . "you've just got to get personal — unless you're " . "%username, apparently!"), array('total' => number_format($count), 'year' => $year, '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__); }