Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusting unmapped request to incorporate it into stats #1738

Merged
merged 3 commits into from
May 16, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public function __invoke($entities)
'type' => 'FeatureCollection',
'features' => []
];
$unmapped = 0;

foreach ($entities as $entity)
{
Expand All @@ -48,7 +47,7 @@ public function __invoke($entities)
{
$color = ltrim($entity->color, '#');
$color = $color ? '#' . $color : null;

$output['features'][] = [
'type' => 'Feature',
'geometry' => [
Expand All @@ -68,12 +67,7 @@ public function __invoke($entities)
]
];
}
if(empty($geometries))
{
$unmapped++;
}
}
$output['unmapped'] = $unmapped;

if ($this->search->bbox)
{
Expand Down
4 changes: 4 additions & 0 deletions application/classes/Ushahidi/Formatter/Post/Stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function __invoke($records)
} else {
$data['totals'] = $this->formatTotals($records);
}

if ($records['unmapped']) {
$data['unmapped'] = $records['unmapped'];
}
}

return $data;
Expand Down
34 changes: 25 additions & 9 deletions application/classes/Ushahidi/Repository/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,15 @@ protected function setSearchConditions(SearchData $search)
;
}

$raw_union = '(select post_geometry.post_id from post_geometry union select post_point.post_id from post_point)';
if($search->has_location === 'mapped') {

$query
->where("$table.id", 'IN', DB::select('post_id')
->from('post_point'));
$query->where("$table.id", 'IN',
DB::query(Database::SELECT, $raw_union)
);
} else if($search->has_location === 'unmapped') {
$query
->where("$table.id", 'NOT IN', DB::select('post_id')
->from('post_point'));
$query->where("$table.id", 'NOT IN',
DB::query(Database::SELECT, $raw_union)
);
}

// Filter by tag
Expand Down Expand Up @@ -520,6 +520,18 @@ public function getSearchTotal()
return (int) $result->get('total', 0);
}

public function getUnmappedTotal($total_posts)
{
$mapped = 0;
$raw_sql = "select count(distinct post_id) as 'total' from (select post_geometry.post_id from post_geometry union select post_point.post_id from post_point) as sub;";
if ($total_posts > 0) {

$mapped = DB::query(Database::SELECT, $raw_sql)->execute();
}

return $total_posts - (int) $mapped->get('total', 0);
}

// PostRepository
public function getPublishedTotal()
{
Expand Down Expand Up @@ -689,9 +701,13 @@ public function getGroupedTotals(SearchData $search)

// Fetch the results and...
$results = $this->search_query->execute($this->db);
$results = $results->as_array();

// Append unmapped totals to
$results['unmapped'] = $this->getUnmappedTotal($this->getSearchTotal());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of weird adding this to all the stats responses (ie. regardless of what we're grouping by... but I don't have a better solution particularly.

Does this mess with the activity view at all? (hopefully our code was robust and it doesn't)


// ... return them as an array
return $results->as_array();
return $results;
}

// PostRepository
Expand Down Expand Up @@ -1044,4 +1060,4 @@ public function doesPostRequireApproval($formId)

return true;
}
}
}