-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1441 from selenamarie/bug853452-devices-sigsum
Fixes bug 853452 Adds signature summary for Android Devices
- Loading branch information
Showing
9 changed files
with
228 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
"""bug 853452 android devices | ||
Revision ID: 49bf379b5a8 | ||
Revises: 35604f61bc24 | ||
Create Date: 2013-08-26 13:51:45.423498 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '49bf379b5a8' | ||
down_revision = '35604f61bc24' | ||
|
||
import os | ||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
from sqlalchemy import types | ||
from sqlalchemy.sql import table, column | ||
|
||
|
||
class CITEXT(types.UserDefinedType): | ||
name = 'citext' | ||
|
||
def get_col_spec(self): | ||
return 'CITEXT' | ||
|
||
def bind_processor(self, dialect): | ||
return lambda value: value | ||
|
||
def result_processor(self, dialect, coltype): | ||
return lambda value: value | ||
|
||
def __repr__(self): | ||
return "citext" | ||
|
||
class JSON(types.UserDefinedType): | ||
name = 'json' | ||
|
||
def get_col_spec(self): | ||
return 'JSON' | ||
|
||
def bind_processor(self, dialect): | ||
return lambda value: value | ||
|
||
def result_processor(self, dialect, coltype): | ||
return lambda value: value | ||
|
||
def __repr__(self): | ||
return "json" | ||
|
||
def upgrade(): | ||
### commands auto generated by Alembic - please adjust! ### | ||
op.create_table(u'signature_summary_device', | ||
sa.Column(u'report_date', sa.DATE(), nullable=False), | ||
sa.Column(u'signature_id', sa.INTEGER(), nullable=False), | ||
sa.Column(u'android_device_id', sa.INTEGER(), nullable=False), | ||
sa.Column(u'report_count', sa.INTEGER(), nullable=False), | ||
sa.PrimaryKeyConstraint(u'report_date', u'signature_id', u'android_device_id') | ||
) | ||
op.create_table(u'android_devices', | ||
sa.Column(u'android_device_id', sa.INTEGER(), nullable=False), | ||
sa.Column(u'android_cpu_abi', sa.TEXT(), nullable=True), | ||
sa.Column(u'android_manufacturer', sa.TEXT(), nullable=True), | ||
sa.Column(u'android_model', sa.TEXT(), nullable=True), | ||
sa.Column(u'android_version', sa.TEXT(), nullable=True), | ||
sa.PrimaryKeyConstraint(u'android_device_id') | ||
) | ||
app_path=os.getcwd() | ||
procs = [ | ||
'update_signature_summary.sql' | ||
, 'backfill_android_devices.sql' | ||
, 'update_android_devices.sql' | ||
] | ||
for myfile in [app_path + '/socorro/external/postgresql/raw_sql/procs/' + line for line in procs]: | ||
with open(myfile, 'r') as file: | ||
op.execute(file.read()) | ||
|
||
|
||
def downgrade(): | ||
### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table(u'android_devices') | ||
op.drop_table(u'signature_summary_device') | ||
### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
socorro/external/postgresql/raw_sql/procs/backfill_android_devices.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE OR REPLACE FUNCTION backfill_android_devices(updateday date) RETURNS boolean | ||
LANGUAGE plpgsql | ||
AS $$ | ||
BEGIN | ||
-- stored procudure to re-run android_devices | ||
-- intended to be called by backfill_matviews | ||
|
||
PERFORM update_android_devices(updateday, false); | ||
|
||
RETURN TRUE; | ||
END; $$; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
socorro/external/postgresql/raw_sql/procs/update_android_devices.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
CREATE OR REPLACE FUNCTION update_android_devices(updateday date, checkdata boolean DEFAULT true) RETURNS boolean | ||
LANGUAGE plpgsql | ||
SET "TimeZone" TO 'UTC' | ||
AS $$ | ||
BEGIN | ||
|
||
CREATE TEMPORARY TABLE new_android_devices | ||
AS | ||
SELECT DISTINCT | ||
json_object_field_text(raw_crash, 'Android_CPU_ABI') as android_cpu_abi | ||
, json_object_field_text(raw_crash, 'Android_Manufacturer') as android_manufacturer | ||
, json_object_field_text(raw_crash, 'Android_Model') as android_model | ||
, json_object_field_text(raw_crash, 'Android_Version') as android_version | ||
FROM raw_crashes | ||
WHERE | ||
date_processed >= updateday | ||
AND date_processed <= (updateday + 1) | ||
GROUP BY | ||
android_cpu_abi | ||
, android_manufacturer | ||
, android_model | ||
, android_version | ||
; | ||
|
||
PERFORM 1 FROM new_android_devices; | ||
IF NOT FOUND THEN | ||
IF checkdata THEN | ||
RAISE NOTICE 'no new android devices found in raw_crashes for date %',updateday; | ||
RETURN FALSE; | ||
END IF; | ||
END IF; | ||
|
||
ANALYZE new_android_devices; | ||
|
||
-- update android_devices | ||
|
||
INSERT INTO android_devices ( | ||
android_cpu_abi | ||
, android_manufacturer | ||
, android_model | ||
, android_version | ||
) | ||
SELECT | ||
new_android_devices.android_cpu_abi | ||
, new_android_devices.android_manufacturer | ||
, new_android_devices.android_model | ||
, new_android_devices.android_version | ||
FROM new_android_devices | ||
LEFT OUTER JOIN android_devices | ||
ON new_android_devices.android_cpu_abi = android_devices.android_cpu_abi | ||
AND new_android_devices.android_manufacturer = android_devices.android_manufacturer | ||
AND new_android_devices.android_model = android_devices.android_model | ||
AND new_android_devices.android_version = android_devices.android_version | ||
GROUP BY | ||
new_android_devices.android_cpu_abi | ||
, new_android_devices.android_manufacturer | ||
, new_android_devices.android_model | ||
, new_android_devices.android_version | ||
; | ||
|
||
DROP TABLE new_android_devices; | ||
|
||
RETURN True; | ||
|
||
END; | ||
$$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters