Ejemplo n.º 1
0
 protected function execute($arguments = array(), $options = array())
 {
     if (!$this->safeToRun()) {
         print "Process already running!\n";
         die;
     }
     $timer = sfTimerManager::getTimer('execute');
     $databaseManager = new sfDatabaseManager($this->configuration);
     $databaseManager->initialize($this->configuration);
     //set up index
     $index = EntityTable::getLuceneIndex();
     //delete deleted entities
     $q = LsDoctrineQuery::create()->from('Entity e')->where('e.is_deleted = ?', true)->setHydrationMode(Doctrine::HYDRATE_ARRAY);
     foreach ($q->execute() as $entity) {
         if ($hits = $index->find('key:' . $entity['id'])) {
             if ($options['debug_mode']) {
                 printf("Deleting index for Entity %s\n", $entity['id']);
             }
             foreach ($hits as $hit) {
                 $index->delete($hit->id);
             }
         }
     }
     printf("Memory used: %s\n", LsNumber::makeBytesReadable(memory_get_usage()));
     printf("Index size: %s\n", $index->count());
     $timer->addTime();
     printf("Run time: %s\n", $timer->getElapsedTime());
     sfTimerManager::clearTimers();
 }
Ejemplo n.º 2
0
 public function getDetails()
 {
     $details = array();
     if ($this->percent_stake) {
         $details[] = $this->percent_stake . '% stake';
     }
     if ($this->shares) {
         $details[] = LsNumber::makeReadable($this->shares) . ' shares';
     }
     return implode(', ', $details);
 }
Ejemplo n.º 3
0
 public function execute()
 {
     try {
         $this->urls = $this->getUrls();
         if (!$this->urls) {
             $this->printDebug("Could not retrieve list of URLS");
         }
     } catch (Exception $e) {
         throw $e;
     }
     $this->setListOptions();
     if ($this->list_name == null || $this->list_description == null || $this->list_fields == null) {
         throw new Exception('setListOptions must define: list_name, list_description, list_fields');
     }
     $this->setList($this->list_name, $this->list_description, $this->list_fields);
     if (count($this->urls)) {
         foreach ($this->urls as $count => $url) {
             //get DB connection for transactions
             try {
                 //begin transaction
                 $this->db->beginTransaction();
                 $this->printDebug("\n***** Searching  *****");
                 $this->printDebug("Memory used: " . LsNumber::makeBytesReadable(memory_get_usage()));
                 $this->printDebug("Now: " . date('l jS \\of F Y h:i:s A'));
                 $urlkey = md5($url);
                 /*if ($this->hasMeta($urlkey, 'refesh_time') && time() < (int)$this->getMeta($urlkey, 'refesh_time') )
                 		{
                          $this->printDebug("Refresh time: " . date('l jS \of F Y h:i:s A', (int)$this->getMeta($urlkey, 'refesh_time') ) );
                 			$this->printDebug("Already scraped; skipping");
                 			$this->db->rollback();
                 			continue;
                 		}*/
                 $this->import($url);
                 if ($this->limit === $count) {
                     break;
                 }
                 if ($this->testMode) {
                     continue;
                 }
                 //commit transaction
                 $this->db->commit();
                 $refresh_days = time() + $this->refreshDays * 24 * 60 * 60;
                 $this->saveMeta($urlkey, 'refesh_time', $refresh_days);
                 $this->printDebug("OK");
             } catch (Exception $e) {
                 //something bad happened, rollback
                 $this->db->rollback();
                 throw $e;
             }
         }
     } else {
         $this->printDebug('No URLs found');
     }
 }
Ejemplo n.º 4
0
 public function getDetails()
 {
     $stuff = array();
     if ($amount = LsNumber::makeReadable($this->Relationship->amount, '$')) {
         $stuff[] = $amount;
     }
     if ($this->Relationship->goods) {
         $stuff[] = $this->Relationship->goods;
     }
     return implode(', ', $stuff);
 }
 protected function execute($arguments = array(), $options = array())
 {
     if (!$this->safeToRun()) {
         print "Process already running!\n";
         die;
     }
     $timer = sfTimerManager::getTimer('execute');
     //get index and optimize
     $index = EntityTable::getLuceneIndex();
     $index->optimize();
     printf("Memory used: %s\n", LsNumber::makeBytesReadable(memory_get_usage()));
     printf("Index size: %s\n", $index->count());
     $timer->addTime();
     printf("Run time: %s\n", $timer->getElapsedTime());
     sfTimerManager::clearTimers();
 }
Ejemplo n.º 6
0
 public function execute()
 {
     //loop through entities
     $entities = $this->getEntitiesByExtension('Org')->execute();
     if ($entities->count()) {
         foreach ($entities as $count => $entity) {
             //get DB connection for transactions
             try {
                 //begin transaction
                 $this->db->beginTransaction();
                 $this->printDebug("\n***** Searching entity: " . $entity->getName() . " *****");
                 $this->printDebug("Memory used: " . LsNumber::makeBytesReadable(memory_get_usage()));
                 $this->printDebug("Now: " . date('l jS \\of F Y h:i:s A'));
                 /*
                 					if ($this->hasMeta($entity->id, 'refesh_time') && time() < (int)$this->getMeta($entity->id, 'refesh_time') && !$this->forceScaper) 
                 					{
                   $this->printDebug("Refresh time: " . date('l jS \of F Y h:i:s A', (int)$this->getMeta($entity->id, 'refesh_time') ) );
                 						$this->printDebug($entity->name . " already scraped; skipping");
                 						$this->db->rollback();
                 						continue;
                 					}
                 */
                 $this->import($entity);
                 if ($this->limit === $count) {
                     break;
                 }
                 //if ($this->testMode) { continue; }
                 //commit transaction
                 //$this->db->commit();
                 //die();
                 /*
                 $refresh_days = time() + ($this->refreshDays * 24 * 60 * 60);
                 $last_scraped = time();
                 $this->saveMeta($entity->id, 'refesh_time', $refresh_days);					
                 $this->saveMeta($entity->id, 'last_scraped', $last_scraped);					
                 					$this->printDebug( $entity->name . ": OK");
                 */
             } catch (Exception $e) {
                 //something bad happened, rollback
                 $this->db->rollback();
                 throw $e;
             }
         }
     } else {
         $this->printDebug('No entities found on database');
     }
 }
 public function execute()
 {
     if (!$this->safeToRun('fec')) {
         $this->printDebug('script already running');
         die;
     }
     $this->beginTimer();
     $this->stopTimer();
     $this->_time = $this->timer->getElapsedTime();
     $this->beginTimer();
     //loop through persons
     $persons = $this->getPersonsQuery($this->entity_id)->execute();
     if ($persons->count()) {
         foreach ($persons as $count => $person) {
             //get DB connection for transactions
             try {
                 $this->temp_postal = array();
                 $this->printDebug("\n***** Searching person: " . $person->getName() . " *****");
                 $this->printDebug("Memory used: " . LsNumber::makeBytesReadable(memory_get_usage()));
                 $this->printDebug("Now: " . date('l jS \\of F Y h:i:s A'));
                 if ($this->hasMeta($person->id, 'scraped') && $this->getMeta($person->id, 'scraped') && $this->forceScraper != true) {
                     $this->printDebug($person->name . " already scraped; skipping");
                     continue;
                 }
                 $this->getDonations($person);
                 if ($this->limit === $count) {
                     break;
                 }
                 if ($this->testMode) {
                     continue;
                 }
                 //commit transaction
                 $this->saveMeta($person->id, 'scraped', 1);
                 if (!$this->entity_id) {
                     $this->saveMeta('first_round', 'last_processed', $person->id);
                 }
                 $this->printDebug($person->name . ": OK");
             } catch (Exception $e) {
                 //something bad happened, rollback
                 throw $e;
             }
         }
     } else {
         $this->printDebug('No persons found on database');
     }
 }
 protected function execute($arguments = array(), $options = array())
 {
     if (!$this->safeToRun()) {
         print "Process already running!\n";
         die;
     }
     $timer = sfTimerManager::getTimer('execute');
     $databaseManager = new sfDatabaseManager($this->configuration);
     $databaseManager->initialize($this->configuration);
     //get id of last-indexed entity
     $index = EntityTable::getLuceneIndex($options['index_file']);
     $index->setMergeFactor(200);
     $index->setMaxBufferedDocs(20);
     if ($count = $index->count()) {
         if (!($lastDoc = $index->getDocument($count - 1))) {
             throw new Exception("Can't find last document in index");
         }
         $maxEntityId = $lastDoc->key;
     } else {
         $maxEntityId = 0;
     }
     //find non-deleted entities with greater IDs
     $q = LsDoctrineQuery::create()->from('Entity e')->leftJoin('e.Alias a')->where('e.id > ? AND e.is_deleted = ?', array($maxEntityId, false))->andWhere('a.context IS NULL')->offset($options['offset'])->limit($options['limit'])->orderBy('e.id ASC');
     //index entities
     $optimize = 0;
     foreach ($q->fetchArray() as $entity) {
         if (EntityTable::updateLuceneIndex($entity, $index, $batchMode = true)) {
             if ($options['debug_mode']) {
                 printf("Indexed entity with ID %s\n", $entity['id']);
             }
         } else {
             if ($options['debug_mode']) {
                 printf("Skipped entity with ID %s\n", $entity['id']);
             }
         }
     }
     printf("Memory used: %s\n", LsNumber::makeBytesReadable(memory_get_usage()));
     printf("Index size: %s\n", $index->count());
     $timer->addTime();
     printf("Run time: %s\n", $timer->getElapsedTime());
     sfTimerManager::clearTimers();
 }
Ejemplo n.º 9
0
 public function execute()
 {
     $schools = $this->getSchoolList();
     $position = 0;
     if ($this->hasMeta('current_postion', 'position') && ($position = $this->getMeta('current_postion', 'position'))) {
         $this->printDebug("Resuming scraping. Starting at position: " . $position);
     }
     //print_r($schools);
     $count = 0;
     while ($position <= count($schools)) {
         $school = $schools[$position];
         //get DB connection for transactions
         try {
             //begin transaction
             $this->db->beginTransaction();
             $this->printDebug("\n***** Searching  *****");
             $this->printDebug("Memory used: " . LsNumber::makeBytesReadable(memory_get_usage()));
             $this->printDebug("Now: " . date('l jS \\of F Y h:i:s A'));
             $this->import($school);
             if ($this->limit === $count) {
                 break;
             }
             if ($this->testMode) {
                 continue;
             }
             //commit transaction
             $this->db->commit();
             $position++;
             $count++;
             $this->saveMeta('current_postion', 'position', $position);
             $this->printDebug("OK");
         } catch (Exception $e) {
             //something bad happened, rollback
             $this->db->rollback();
             throw $e;
         }
     }
 }
Ejemplo n.º 10
0
 public function execute()
 {
     if (!$this->safeToRun('fedspending')) {
         $this->printDebug('script already running');
         die;
     }
     $orgs = $this->getBusinessQuery()->execute();
     if ($orgs->count()) {
         //loop through orgs
         foreach ($orgs as $count => $org) {
             $this->printDebug("\n***** Searching Organization: " . $org->getName() . " *****");
             $this->printDebug("Memory used: " . LsNumber::makeBytesReadable(memory_get_usage()));
             $this->printDebug("Now: " . date('l jS \\of F Y h:i:s A'));
             /*if ($this->hasMeta($org->id, 'refresh_time') && time() < (int)$this->getMeta($org->id, 'refresh_time') )
               {
                 $this->printDebug("Refresh time: " . date('l jS \of F Y h:i:s A', (int)$this->getMeta($org->id, 'refresh_time') ) );
                 $this->printDebug($org->name . " already scraped; skipping");
                 //$this->db->rollback();
                 //continue;
               }*/
             $this->getFedSpendingData($org);
             if ($this->testMode) {
                 continue;
             }
             if ($this->_count >= $this->_filing_limit) {
                 $this->printDebug('filing limit reached');
                 die;
             }
             $refresh_days = time() + $this->refreshDays * 24 * 60 * 60;
             $this->saveMeta($this->_round, 'last_processed', $org->id);
             $this->printDebug($org->name . ": OK");
         }
     } else {
         $this->printDebug("No businesses found on database");
     }
 }
Ejemplo n.º 11
0
<tr class="text_small hover<?php 
echo $shaded ? ' shaded' : '';
?>
">
  <td><?php 
echo $object->getStartDateForDisplay();
?>
</td>
  <td><?php 
echo LsNumber::makeReadable($object->amount, '$');
?>
</td>
  <td><?php 
echo $object->fec_filing_id;
?>
</td>
  <td>
    <?php 
if ($url = $object->getSourceUrl()) {
    ?>
      <?php 
    echo link_to('Source', $url);
    ?>
    <?php 
}
?>
  </td>
</tr>
Ejemplo n.º 12
0
 static function merge(LsDatespan $s1, LsDatespan $s2, $disambiguate = true, $mergeAdjacent = false)
 {
     //check for overlap
     if (self::overlap($s1, $s2, $disambiguate)) {
         $merged = new LsDatespan();
         $start1 = $s1->getStart();
         $start2 = $s2->getStart();
         $end1 = $s1->getEnd();
         $end2 = $s2->getEnd();
         //generate start date
         $comp = LsNumber::compare($start1->howSpecific(), $start2->howSpecific());
         switch ($comp) {
             //start1 is more specific, use it unless start2's year is earlier
             case 1:
                 $merged->setStart($start1->getYear() <= $start2->getYear() ? $start1 : $start2);
                 break;
                 //same specificity, use the earlier date
             //same specificity, use the earlier date
             case 0:
                 $merged->setStart($start1->format() <= $start2->format() ? $start1 : $start2);
                 break;
                 //start2 is more specific, use it unless start1's year is earlier
             //start2 is more specific, use it unless start1's year is earlier
             case -1:
                 $merged->setStart($start1->getYear() >= $start2->getYear() ? $start2 : $start1);
                 break;
         }
         //generate end date
         if ($end1->isBlank() || $end2->isBlank()) {
             $merged->setEnd(new LsDate());
         } else {
             $comp = LsNumber::compare($end1->howSpecific(), $end2->howSpecific());
             switch ($comp) {
                 //end1 is more specific, use it unless end2's year is later
                 case 1:
                     $merged->setEnd($end1->getYear() >= $end2->getYear() ? $end1 : $end2);
                     break;
                     //same specificity, use the later date
                 //same specificity, use the later date
                 case 0:
                     $merged->setEnd($end1->format() >= $end2->format() ? $end1 : $end2);
                     break;
                     //end2 is more specific, use it unless end1's year is later
                 //end2 is more specific, use it unless end1's year is later
                 case -1:
                     $merged->setEnd($end1->getYear() <= $end2->getYear() ? $end2 : $end1);
                     break;
             }
         }
         return $merged;
     } else {
         return false;
     }
 }
Ejemplo n.º 13
0
<tr>
  <td style='padding-bottom:.6em'>
    <?php 
echo entity_link($object, null);
?>
  </td>
  <td style='padding-bottom:.6em'>
    <?php 
$recipients = LsDoctrineQuery::create()->from('Entity e')->andWhereIn('e.id', explode(',', $object['degree1_ids']))->fetchArray();
?>
    <?php 
echo LsNumber::makeReadable($object['total'], '$');
?>
  </td>
  <td style='padding-bottom:.6em'>
    <?php 
$recipientLinks = array();
?>
    <?php 
foreach ($recipients as $recipient) {
    ?>
      <?php 
    $recipientLinks[] = entity_link($recipient, null, false);
    ?>
    <?php 
}
?>
    <?php 
echo implode(', ', $recipientLinks);
?>
  </td>
Ejemplo n.º 14
0
function readable_number($num, $prefix = null)
{
    return LsNumber::makeReadable($num, $prefix);
}
Ejemplo n.º 15
0
 function import(Entity $person, $possible_persons)
 {
     //loop through the people we found. usually just one.
     foreach ($possible_persons as $possible_person) {
         $this->printDebug('Query returned ' . count($possible_person) . ' person named ' . $possible_person->name);
         //this person does not provide education. we skip
         if (count($possible_person->education)) {
             $this->printDebug('Education found');
         } else {
             $this->printDebug('No education history found');
             continue;
         }
         //get employement info for this possible match
         $possible_person_bio = $possible_person->summary;
         if (count($possible_person->employment_history)) {
             foreach ($possible_person->employment_history as $employment) {
                 $possible_person_bio .= ' ' . $employment->company . " ";
             }
             $this->printDebug('Employment found');
         } else {
             $this->printDebug('No employment history found');
             continue;
         }
         //get employment info for the person in our database
         $relationship_orgs = $person->getRelatedEntitiesQuery('Org', RelationshipTable::POSITION_CATEGORY, null, null, null, false, 1)->execute();
         $person_bio = $person->summary;
         foreach ($relationship_orgs as $org) {
             $person_bio .= ' ' . $org->name;
         }
         //lets see how many matches we get
         $matches = LsLanguage::getCommonPronouns($person_bio, trim($possible_person_bio), LsLanguage::$business);
         if (count($matches)) {
             foreach ($possible_person->education as $school) {
                 $school->institution = mb_convert_encoding($school->institution, 'UTF-8');
                 $school->institution = preg_replace('/–/isu', ' ', $school->institution);
                 $this->printDebug('Looking for the school: ' . $school->institution);
                 $current_school = EntityTable::findByAlias($school->institution, $context = 'bw_school');
                 //find school
                 if ($current_school) {
                     $this->printDebug('Found school');
                 } else {
                     $current_school = EntityTable::getByExtensionQuery(array('Org', 'School'))->addWhere('LOWER(org.name) LIKE ?', '%' . strtolower($school->institution) . "%")->fetchOne();
                     if (!$current_school) {
                         $new_school = new Entity();
                         $new_school->addExtension('Org');
                         $new_school->addExtension('School');
                         $new_school->name = $school->institution;
                         $wikipedia = new LsWikipedia();
                         $wikipedia->request($school->institution);
                         if ($wikipedia->execute() && !$wikipedia->isDisambiguation()) {
                             $info_box = $wikipedia->getInfoBox();
                             if (isset($info_box['students']) && preg_match('/([\\d\\,]{2,})/isu', $info_box['students']['clean'], $match)) {
                                 $new_school->students = LsNumber::clean($match[1]);
                             } else {
                                 $student_types = array('undergrad', 'postgrad', 'grad', 'doctoral');
                                 $num_students = 0;
                                 foreach ($student_types as $st) {
                                     if (isset($info_box[$st]) && preg_match('/([\\d\\,]{2,})/isu', $info_box[$st]['clean'], $match)) {
                                         $num_students += LsNumber::clean($match[1]);
                                     }
                                 }
                                 if ($num_students > 0) {
                                     $new_school->students = $num_students;
                                 }
                             }
                             if (isset($info_box['faculty']) && preg_match('/([\\d\\,]{2,})/isu', $info_box['faculty']['clean'], $match)) {
                                 $new_school->faculty = LsNumber::clean($match[1]);
                             }
                             if (isset($info_box['type'])) {
                                 if (stristr($info_box['type']['clean'], 'public')) {
                                     $new_school->is_private = 0;
                                 } else {
                                     if (stristr($info_box['type']['clean'], 'private')) {
                                         $new_school->is_private = 1;
                                     }
                                 }
                             }
                             if (isset($info_box['endowment'])) {
                                 if (preg_match('/(\\$[\\d\\,\\.\\s]+)(million|billion)/isu', $info_box['endowment']['clean'], $match)) {
                                     if (strtolower($match[2]) == 'billion') {
                                         $factor = 1000000000;
                                     } else {
                                         $factor = 1000000;
                                     }
                                     $new_school->endowment = LsNumber::formatDollarAmountAsNumber($match[1], $factor);
                                 }
                             }
                             if (isset($info_box['established'])) {
                                 $year = null;
                                 if ($date = LsDate::convertDate($info_box['established']['clean'])) {
                                     $new_school->start_date = $date;
                                 } else {
                                     if (preg_match('/\\b(\\d\\d\\d\\d)\\b/isu', $info_box['established']['clean'], $match)) {
                                         $new_school->start_date = $match[1];
                                     }
                                 }
                             }
                             $summary = trim($wikipedia->getIntroduction());
                             $summary = preg_replace('/\\n\\s*\\n/isu', '', $summary);
                             if (strlen($summary) > 10) {
                                 $new_school->summary = $summary;
                             }
                             $new_school->save();
                             $new_school->addReference($source = $wikipedia->getUrl(), $excerpt = null, $fields = array('summary'), $name = 'Wikipedia');
                         } else {
                             $new_school->save();
                         }
                         $current_school = $new_school;
                         $this->printDebug('Adding new school');
                     }
                     $alias = new Alias();
                     $alias->name = $school->institution;
                     $alias->context = 'bw_school';
                     $alias->Entity = $current_school;
                     $alias->save();
                 }
                 //find degree
                 $degree = null;
                 if (!($degree = DegreeTable::getByText($school->degree))) {
                     $degree = DegreeTable::addDegree($school->degree);
                     $this->printDebug('Adding new degree');
                 }
                 //find relationship
                 $relationship = null;
                 $relationships = $person->getRelationshipsWithQuery($current_school, RelationshipTable::EDUCATION_CATEGORY)->execute();
                 foreach ($relationships as $existing_relationship) {
                     if ($existing_relationship->degree_id == $degree->id) {
                         $relationship = $existing_relationship;
                         break;
                     }
                 }
                 if ($relationship) {
                     $this->printDebug('Relationship between person and school exists');
                 } else {
                     $relationship = new Relationship();
                     $relationship->Entity1 = $person;
                     $relationship->Entity2 = $current_school;
                     $relationship->description1 = 'student';
                     $relationship->is_current = 0;
                     if ($school->year) {
                         $relationship->end_date = $school->year;
                     }
                     $relationship->setCategory('Education');
                     $this->printDebug('Creating new relationship between person and school');
                 }
                 //save
                 $relationship->save();
                 //add degree and reference
                 if ($relationship->degree_id == null) {
                     $reference_name = strstr($school->source, 'wikipedia') ? "Wikipedia" : "BusinessWeek";
                     $relationship->Degree = $degree;
                     $relationship->save();
                     $relationship->addReference($source = $school->source, $excerpt = null, $fields = array('degree_id'), $name = $reference_name, $detail = null, $date = null);
                     $this->printDebug('Adding degree and reference');
                 }
             }
         } else {
             $this->printDebug('No organization matches');
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 16
0
 private function importCompany($name, $ticker, $website, $address_raw, $telephone, $revenue, $url, $industry)
 {
     $corp = new Entity();
     $corp->addExtension('Org');
     $corp->addExtension('Business');
     if ($ticker) {
         $corp->addExtension('PublicCompany');
         $corp->ticker = $ticker;
     } else {
         $corp->addExtension('PrivateCompany');
     }
     $corp->name = $name;
     $corp->revenue = LsNumber::formatDollarAmountAsNumber($revenue, 1000000);
     $corp->website = $website;
     $modified = $corp->getAllModifiedFields();
     if ($address = $corp->addAddress($address_raw)) {
         $addressModified = $address->getAllModifiedFields();
     }
     if ($telephone) {
         $phone = $corp->addPhone($telephone);
         $phoneModified = $phone->getAllModifiedFields();
     }
     $corp->save();
     $corp->addReference($url, null, $modified, 'Fortune Magazine Online');
     if ($address) {
         $address->addReference($url, null, $addressModified, 'Fortune Magazine Online');
     }
     if ($phone) {
         $phone->addReference($url, null, $phoneModified, 'Fortune Magazine Online');
     }
     if ($industry) {
     }
     return $corp;
 }
Ejemplo n.º 17
0
 static function getDonationSummary($id, $options = array())
 {
     $blank = array('person_recipients' => array(), 'org_recipients' => array(), 'donors' => array(), 'rep_amts' => array(), 'dem_amts' => array(), 'other_amts' => array(), 'total' => 0, 'rep_total' => 0, 'dem_total' => 0, 'other_total' => 0, 'cycles' => array());
     if (!($start_cycle = @$options['start_cycle'])) {
         $start_cycle = '1990';
     }
     if (!($end_cycle = @$options['end_cycle'])) {
         $end_cycle = '2012';
     }
     if (!($ext = @$options['type'])) {
         $db = Doctrine_Manager::connection();
         $sql = "SELECT primary_ext FROM entity WHERE id = ?";
         $stmt = $db->execute($sql, array($id));
         $ext = $stmt->fetch(PDO::FETCH_COLUMN);
     }
     if ($ext == 'Person') {
         $donations = self::getPersonDonationData($id, $start_cycle, $end_cycle);
     } else {
         if ($ext == 'Org') {
             $donations = self::getOrgDonationData($id, $start_cycle, $end_cycle);
         } else {
             if ($ext = 'Couple') {
                 $donations = self::getCoupleDonationData($id, $start_cycle, $end_cycle);
             } else {
                 return $blank;
             }
         }
     }
     if (count($donations) == 0) {
         return $blank;
     }
     $cycles = array_map('strval', range(1990, 2020, 2));
     $filter = function ($ary) use($start_cycle, $end_cycle) {
         return $ary >= $start_cycle && $ary <= $end_cycle;
     };
     $cycles = array_filter($cycles, $filter);
     $cycleAmts = $repAmts = $demAmts = $otherAmts = array_fill_keys($cycles, 0);
     $recipients = array('personData' => array(), 'orgData' => array());
     $donors = array();
     $total = 0;
     $repTotal = 0;
     $demTotal = 0;
     $otherTotal = 0;
     $numDonations = 0;
     $parties = array(12886 => 'D', 12901 => 'R');
     $party = null;
     $entity_fec_map = array();
     $fec_party_map = array();
     $org_donations = array_filter($donations, function ($d) {
         return $d['recipient_ext'] == 'Org';
     });
     $org_ids = array_map(function ($d) {
         return $d['recipient_id'];
     }, $org_donations);
     $org_party_map = self::getOrgPartyMap($org_ids);
     foreach ($donations as $d) {
         if ($d['recipient_ext'] == 'Person') {
             $party = @$parties[$d['party_id']];
         } else {
             $party = @$org_party_map[$d['recipient_id']];
         }
         $amt = intval($d['amt']);
         if ($amt > 0) {
             $numDonations++;
         }
         $recipientType = strtolower($d['recipient_ext']) . 'Data';
         if (!isset($recipients[$recipientType][$d['recipient_id']])) {
             $url = EntityTable::getUri(array('id' => $d['recipient_id'], 'name' => $d['recipient_name'], 'primary_ext' => $d['recipient_ext']));
             $recipients[$recipientType][$d['recipient_id']] = array('name' => $d['recipient_name'], 'url' => $url, 'amount' => $amt, 'donor_count' => 1, 'party' => $party, 'donor_ids' => array($d['donor_id']));
         } else {
             $recipients[$recipientType][$d['recipient_id']]['amount'] += $amt;
             if (!in_array($d['donor_id'], $recipients[$recipientType][$d['recipient_id']]['donor_ids'])) {
                 $recipients[$recipientType][$d['recipient_id']]['donor_ids'][] = $d['donor_id'];
                 $recipients[$recipientType][$d['recipient_id']]['donor_count']++;
             }
         }
         if (!isset($donors[$d['donor_id']])) {
             $url = EntityTable::getUri(array('id' => $d['donor_id'], 'name' => $d['donor_name'], 'primary_ext' => $d['donor_ext']));
             $donors[$d['donor_id']] = array('name' => $d['donor_name'], 'url' => $url, 'amount' => $amt, 'recipient_count' => 1, 'recipient_ids' => array($d['recipient_id']));
         } else {
             $donors[$d['donor_id']]['amount'] += $amt;
             if (!in_array($d['recipient_id'], $donors[$d['donor_id']]['recipient_ids'])) {
                 $donors[$d['donor_id']]['recipient_ids'][] = $d['recipient_id'];
                 $donors[$d['donor_id']]['recipient_count']++;
             }
         }
         $cycleAmts[$d['crp_cycle']] += $amt;
         $total += $amt;
         if ($party == 'D') {
             $demAmts[$d['crp_cycle']] += $amt;
             $demTotal += $amt;
         } else {
             if ($party == 'R') {
                 $repAmts[$d['crp_cycle']] += $amt;
                 $repTotal += $amt;
             } else {
                 $otherAmts[$d['crp_cycle']] += $amt;
                 $otherTotal += $amt;
             }
         }
     }
     $personRecipients = $recipients['personData'];
     $orgRecipients = $recipients['orgData'];
     $amountCompareDesc = function ($a, $b) {
         return $b['amount'] - $a['amount'];
     };
     uasort($personRecipients, $amountCompareDesc);
     uasort($orgRecipients, $amountCompareDesc);
     uasort($donors, $amountCompareDesc);
     if ($numDonations > 0) {
         $avgDonation = $total / $numDonations;
     }
     if ($repTotal > 0 || $demTotal > 0) {
         $demPct = LsNumber::makeReadable($demTotal / ($repTotal + $demTotal) * 100, null, 1, "%");
         $repPct = LsNumber::makeReadable($repTotal / ($repTotal + $demTotal) * 100, null, 1, "%");
     }
     return array('person_recipients' => $personRecipients, 'org_recipients' => $orgRecipients, 'donors' => $donors, 'rep_amts' => $repAmts, 'dem_amts' => $demAmts, 'other_amts' => $otherAmts, 'total' => $total, 'rep_total' => $repTotal, 'dem_total' => $demTotal, 'other_total' => $otherTotal, 'cycles' => $cycles);
 }
Ejemplo n.º 18
0
<tr class="text_small hover<?php 
echo $shaded ? ' shaded' : '';
?>
">
  <td><?php 
echo Dateable::convertForDisplay($object['start_date']);
?>
</td>
  <td><?php 
echo LsNumber::makeReadable($object['amount'], '$');
?>
</td>
  <td>
    <?php 
$agencies = array();
?>
    <?php 
foreach (LobbyFilingTable::getAgenciesQuery($object)->setHydrationMode(Doctrine::HYDRATE_ARRAY)->execute() as $agency) {
    ?>
      <?php 
    $agencies[] = entity_link($agency, null);
    ?>
    <?php 
}
?>
    <?php 
echo implode('<br /> ', $agencies);
?>
  </td>

  <td>
Ejemplo n.º 19
0
<tr>
  <td>
    <?php 
echo entity_link($object, null);
?>
  </td>
  <td>
    <?php 
echo LsNumber::makeReadable($object['degree1_total'], '$');
?>
  </td>
  <td>
    <?php 
$people = EntityTable::getMultipleById(explode(',', $object['degree1_ids']));
?>
    <?php 
$people_links = array();
?>
    <?php 
foreach ($people as $person) {
    ?>
      <?php 
    $people_links[] = entity_link($person, null, false);
    ?>
    <?php 
}
?>
  
    <?php 
echo implode(', ', $people_links);
?>