Skip to content

Commit

Permalink
Adding middleware required for bug 838251.
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonsavage committed Jun 3, 2013
1 parent 867d458 commit ffd23c8
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions socorro/external/postgresql/signature_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def get(self, **kwargs):
params['versions'] = versions
params['product'] = products

if params['versions'] and params['report_type'] is not 'products':
if (params['versions'] and
params['report_type'] not in ('products', 'distinct_install')):
glue = ','
version_search = ' AND reports_clean.product_version_id IN (%s)'
version_search = version_search % glue.join(params['versions'])
Expand All @@ -88,16 +89,18 @@ def get(self, **kwargs):
product_list = ''

query_params = report_type_sql.get(params['report_type'], {})
if (params['report_type'] != 'products' and
'first_col' not in query_params):
if (params['report_type'] not in ('products', 'distinct_install')
and 'first_col' not in query_params):
raise Exception('Invalid report type')

self.connection = self.database.connection()
cursor = self.connection.cursor()

if params['report_type'] == 'products':
result_cols = ['product_name', 'version_string',
'report_count', 'percentage']
result_cols = ['product_name',
'version_string',
'report_count',
'percentage']
query_string = """WITH counts AS (
SELECT product_version_id, product_name, version_string,
count(*) AS report_count
Expand Down Expand Up @@ -125,6 +128,27 @@ def get(self, **kwargs):
query_parameters = (params['signature'],
params['start_date'],
params['end_date'])
elif params['report_type'] == 'distinct_install':
result_cols = ['product_name',
'version_string',
'crashes',
'installations']
query_string = """
SELECT product_name, version_string,
count(*) AS crashes,
COUNT(DISTINCT client_crash_date - install_age) as
installations
FROM reports_clean
JOIN product_versions USING (product_version_id)
WHERE
signature_id = (SELECT signature_id FROM signatures
WHERE signature = %s)
AND date_processed >= %s
AND date_processed < %s
GROUP BY product_name, version_string"""
query_parameters = (params['signature'],
params['start_date'],
params['end_date'])
else:
result_cols = ['category', 'report_count', 'percentage']
query_string = ["""WITH counts AS ( SELECT """]
Expand Down

0 comments on commit ffd23c8

Please sign in to comment.