Skip to content

Commit

Permalink
Merge pull request #347 from brandonsavage/bug720871
Browse files Browse the repository at this point in the history
Fixes 720871 - Adds support for multiple products, no products, products without versions, and products with versions.
  • Loading branch information
brandonsavage committed Feb 15, 2012
2 parents ccc0c75 + 334ae39 commit bd253fa
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 42 deletions.
20 changes: 15 additions & 5 deletions socorro/external/postgresql/signature_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get(self, **kwargs):
("signature", None, "str"),
("start_date", None, "datetime"),
("end_date", None, "datetime"),
("product", None, "str"),
("product", None, ["list", "str"]),
("versions", None, ["list", "str"]),
]

Expand All @@ -58,6 +58,12 @@ def get(self, **kwargs):
else:
version_search = ''

if params['product'] and params['report_type'] is not 'products':
glue = ','
product_list = ' AND product_name IN %s'
else:
product_list = ''

query_params = report_type_sql.get(params['report_type'], {})
if params['report_type'] != 'products' and 'first_col' not in query_params:
raise Exception('Invalid report type')
Expand Down Expand Up @@ -107,8 +113,8 @@ def get(self, **kwargs):
WHERE signature = %s)
AND date_processed >= %s
AND date_processed < %s
AND product_name = %s
""")
query_string.append(product_list)
query_string.append(version_search)
query_string.append(""" GROUP BY """)
query_string.append(query_params['first_col'])
Expand All @@ -127,12 +133,16 @@ def get(self, **kwargs):
ORDER BY report_count DESC""")
query_string = " ".join(query_string)

query_parameters = (params['signature'],
query_parameters = [params['signature'],
params['start_date'],
params['end_date'],
params['product'],
)
]

if(product_list):
# This MUST be a tuple otherwise it gets cast to an array.
query_parameters.append(tuple(params['product']))

query_parameters = tuple(query_parameters)
sql_results = db.execute(cursor, query_string, query_parameters)
results = []
for row in sql_results:
Expand Down
12 changes: 6 additions & 6 deletions webapp-php/application/controllers/signature_summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function index()

public function json_data()
{
$d = array('signature' => '', 'range_value' => '7', 'range_unit' => 'days', 'product' => 'Firefox', 'version' => array(), 'date' => date('Y-m-d'));
$d = array('signature' => '', 'range_value' => '7', 'range_unit' => 'days', 'version' => array(), 'date' => date('Y-m-d'));
$params = $this->getRequestParameters($d);
$signature = $params['signature'];
$start = date('Y-m-d', strtotime($params['date'] .
Expand All @@ -42,12 +42,12 @@ public function json_data()
$versions = array();
}

$uptime = $this->summary_model->getSummary('uptime', $signature, $start, $end, $params['product'], $versions);
$uptime = $this->summary_model->getSummary('uptime', $signature, $start, $end, $versions);
$products = $this->summary_model->getSummary('products', $signature, $start, $end);
$oses = $this->summary_model->getSummary('os', $signature, $start, $end, $params['product'], $versions);
$processes = $this->summary_model->getSummary('process_type', $signature, $start, $end, $params['product'], $versions);
$flashes = $this->summary_model->getSummary('flash_version', $signature, $start, $end, $params['product'], $versions);
$architecture = $this->summary_model->getSummary('architecture', $signature, $start, $end, $params['product'], $versions);
$oses = $this->summary_model->getSummary('os', $signature, $start, $end, $versions);
$processes = $this->summary_model->getSummary('process_type', $signature, $start, $end, $versions);
$flashes = $this->summary_model->getSummary('flash_version', $signature, $start, $end, $versions);
$architecture = $this->summary_model->getSummary('architecture', $signature, $start, $end, $versions);
$results = array();

foreach($architecture as $arch) {
Expand Down
1 change: 1 addition & 0 deletions webapp-php/application/libraries/Web_Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public function __construct($config=array())
*/
public function get($url, $response_type='json', $cache_lifetime=null)
{

if (is_null($cache_lifetime)) {
$this->status_code = 200;
return $this->_get($url, $response_type);
Expand Down
50 changes: 36 additions & 14 deletions webapp-php/application/models/signature_summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ class Signature_Summary_Model extends Model {

protected $_sig_cache = array();

public function getSummary($report_type, $signature, $start, $end, $product = 'Firefox', $versions = array())
public function getSummary($report_type, $signature, $start, $end, $versions = array())
{

if(!empty($versions)) {
$versions = $this->_calculateVersionIds($product, $versions);
$versions = $this->_calculateVersionIds($versions);
}

$config = array();
Expand All @@ -19,34 +20,55 @@ public function getSummary($report_type, $signature, $start, $end, $product = 'F
$host = Kohana::config('webserviceclient.socorro_hostname');
$report_type = rawurlencode($report_type);
$signature = rawurlencode($signature);
$product = rawurlencode($product);
$url = "{$host}/signaturesummary/report_type/{$report_type}/signature/{$signature}/start_date/{$start}/end_date/{$end}/product/{$product}";
$url = "{$host}/signaturesummary/report_type/{$report_type}/signature/{$signature}/start_date/{$start}/end_date/{$end}";

if($versions) {
$url .= "/versions/{$versions}";
if(isset($versions['products']) && !empty($versions['products'])) {
$url .= "/product/{$versions['products']}";
}

if(isset($versions['versions']) && !empty($versions['versions'])) {
$url .= "/versions/{$versions['versions']}";
}

$resp = $service->get($url);

return $resp;
}

protected function _calculateVersionIds($product, array $versions)
protected function _calculateVersionIds(array $versions)
{
$versions_new = array();
$product = $this->db->escape($product);
$products_new = array();

foreach($versions as $version) {
$version = $this->db->escape($version);
if (isset($this->_sig_cache[$version])) {
$versions_new[] = $this->_sig_cache[$version];
$vs = explode(':', $version);
if(count($vs) != 2) {
$products_new[] = $version; // Just in case we get a single product.
continue;
}
$product = $vs[0];
$version = $this->db->escape($vs[1]);
if (isset($this->_sig_cache[$product . $version])) {
$versions_new[] = $this->_sig_cache[$product . $version];
$products_new[] = $product;
} else {
$sql = "SELECT product_version_id FROM product_versions WHERE product_name = {$product} AND version_string = {$version}";
$sql = "SELECT product_version_id FROM product_versions WHERE product_name = ";
$sql .= $this->db->escape($product);
$sql .= " AND version_string = {$version}";

$version_id = $this->db->query($sql)->as_array();
$version_id = $version_id[0]->product_version_id;
$this->_sig_cache[$version] = $version_id;
$this->_sig_cache[$product . $version] = $version_id;
$versions_new[] = $version_id;
if(!in_array($product, $products_new)) {
$products_new[] = $product;
}
}
}
return implode('+', $versions_new);
$results = array();
$results['products'] = implode('+', $products_new);
$results['versions'] = implode('+', $versions_new);
return $results;
}

public function search_signature_table($signature_string)
Expand Down
18 changes: 1 addition & 17 deletions webapp-php/application/views/report/do_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,8 @@
'css/signature_summary.css'
), 'screen')?>
<!--[if IE]><?php echo html::script('js/flot-0.7/excanvas.pack.js') ?><![endif]-->

<?php
$vl = array();
$vs = 'Firefox';
if(!empty($params['version'])) {
foreach($params['version'] as $v) {
$pv = explode(':', $v);
if(count($pv) != 2) {
continue;
}
$vl[] = $pv[1];
$vs = $pv[0];
}
}
$sigParams = array('range_value' => $params['range_value'], 'range_unit' => $params['range_unit'], 'signature' => $params['signature'], 'product' => $vs);
if(!empty($vl)) {
$sigParams['version'] = $vl;
}
$sigParams = array('range_value' => $params['range_value'], 'range_unit' => $params['range_unit'], 'signature' => $params['signature'], 'version' => $params['version']);
if(isset($params['date']) && !empty($params['date'])) {
$sigParams['date'] = $params['date'];
}
Expand Down

0 comments on commit bd253fa

Please sign in to comment.