Dirk Vogt | 62ff7f2 | 2017-05-04 16:07:21 +0200 | [diff] [blame^] | 1 | class FormatDict(dict): |
| 2 | def __missing__(self, key): |
| 3 | return "{" + key + "}" |
| 4 | |
| 5 | def fill_in_build_fingerprints(query, build_fingerprints): |
| 6 | all_fingerprints_query = 'select distinct build_fingerprint from crashreports_crashreport' |
| 7 | if len(build_fingerprints) > 0 : |
| 8 | return query.format( |
| 9 | FormatDict(fingerprint_placeholers= |
| 10 | ','.join(["%s"] * len(build_fingerprints)))) |
| 11 | else: |
| 12 | return query.format(FormatDict(fingerprint_placeholers = all_fingerprints_query)) |
| 13 | |
| 14 | def execute_device_update_history_query(cursor, params): |
| 15 | query = ''' |
| 16 | SELECT |
| 17 | min(crashreports_heartbeat.date) as update_date, |
| 18 | build_fingerprint |
| 19 | FROM |
| 20 | crashreports_device |
| 21 | JOIN |
| 22 | crashreports_heartbeat |
| 23 | ON |
| 24 | crashreports_device.id == crashreports_heartbeat.device_id |
| 25 | where |
| 26 | crashreports_device.uuid=%s |
| 27 | group by build_fingerprint; |
| 28 | ''' |
| 29 | uuid = params.get('uuid', '18f530d7-e9c3-4dcf-adba-3dddcd7d3155') |
| 30 | param_array = [uuid] |
| 31 | cursor.execute(query, param_array) |
| 32 | |
| 33 | |
| 34 | def execute_device_report_history(cursor, params): |
| 35 | query = ''' |
| 36 | SELECT |
| 37 | strftime("%%Y-%%m-%%d",crashreports_heartbeat.date) as date, |
| 38 | count(crashreports_heartbeat.id) as heartbeats, |
| 39 | ( |
| 40 | select count(id) from crashreports_crashreport |
| 41 | where |
| 42 | boot_reason in ("RTC alarm") |
| 43 | and strftime("%%Y-%%m-%%d",crashreports_crashreport.date) == strftime("%%Y-%%m-%%d",crashreports_heartbeat.date) |
| 44 | and crashreports_device.id == crashreports_crashreport.device_id |
| 45 | ) as smpl, |
| 46 | ( |
| 47 | select count(id) from crashreports_crashreport |
| 48 | where |
| 49 | boot_reason in ("UNKNOWN", "keyboard power on") |
| 50 | and strftime("%%Y-%%m-%%d",crashreports_crashreport.date) == strftime("%%Y-%%m-%%d",crashreports_heartbeat.date) |
| 51 | and crashreports_device.id == crashreports_crashreport.device_id |
| 52 | ) as prob_crashes, |
| 53 | ( |
| 54 | select count(id) from crashreports_crashreport |
| 55 | where |
| 56 | boot_reason not in ("RTC alarm", "UNKNOWN", "keyboard power on") |
| 57 | and strftime("%%Y-%%m-%%d",crashreports_crashreport.date) == strftime("%%Y-%%m-%%d",crashreports_heartbeat.date) |
| 58 | and crashreports_device.id == crashreports_crashreport.device_id |
| 59 | ) as other |
| 60 | from crashreports_device |
| 61 | join |
| 62 | crashreports_heartbeat on crashreports_device.id == crashreports_heartbeat.device_id |
| 63 | where |
| 64 | crashreports_device.uuid = %s |
| 65 | group by date; |
| 66 | ''' |
| 67 | uuid = params.get('uuid', '18f530d7-e9c3-4dcf-adba-3dddcd7d3155') |
| 68 | param_array = [uuid] |
| 69 | cursor.execute(query, param_array) |