Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge commit
  • Loading branch information
audaciouscode committed Dec 21, 2016
2 parents 07dccdb + 7ef4f52 commit b6fb058
Show file tree
Hide file tree
Showing 191 changed files with 12,551 additions and 3,183 deletions.
53 changes: 42 additions & 11 deletions admin.py
@@ -1,3 +1,5 @@
# pylint: disable=line-too-long, unused-argument

from django.contrib import admin

from purple_robot_app.models import PurpleRobotConfiguration, PurpleRobotPayload, \
Expand All @@ -7,55 +9,63 @@
PurpleRobotDevice, PurpleRobotAlert, \
PurpleRobotDeviceNote


class PurpleRobotConfigurationAdmin(admin.ModelAdmin):
list_display = ('name', 'slug', 'added')
list_filter = ['added',]
list_filter = ['added', ]
search_fields = ['name', 'slug', 'contents']

admin.site.register(PurpleRobotConfiguration, PurpleRobotConfigurationAdmin)


class PurpleRobotPayloadAdmin(admin.ModelAdmin):
list_display = ('user_id', 'added', 'process_tags',)
list_filter = ['added', 'user_id']
search_fields = ['payload', 'errors', 'process_tags']

admin.site.register(PurpleRobotPayload, PurpleRobotPayloadAdmin)


class PurpleRobotEventAdmin(admin.ModelAdmin):
list_display = ('event', 'event_name', 'logged', 'user_id')
list_filter = ['event', 'logged', 'user_id']
search_fields = ['event', 'user_id', 'payload']

admin.site.register(PurpleRobotEvent, PurpleRobotEventAdmin)


class PurpleRobotReadingAdmin(admin.ModelAdmin):
list_display = ('probe_name', 'user_id', 'guid', 'logged', 'size', 'attachment',)
list_filter = ['probe', 'user_id', 'logged']
search_fields = ['probe', 'user_id', 'payload']

admin.site.register(PurpleRobotReading, PurpleRobotReadingAdmin)


class PurpleRobotReportAdmin(admin.ModelAdmin):
list_display = ('probe', 'user_id', 'generated', 'mime_type')
list_filter = ['probe', 'user_id', 'generated', 'mime_type']

admin.site.register(PurpleRobotReport, PurpleRobotReportAdmin)


class PurpleRobotTestAdmin(admin.ModelAdmin):
list_display = ('probe', 'user_id', 'slug', 'frequency', 'last_updated', 'active')
list_filter = ['probe', 'user_id', 'last_updated', 'active']

admin.site.register(PurpleRobotTest, PurpleRobotTestAdmin)


class PurpleRobotExportJobAdmin(admin.ModelAdmin):
list_display = ('start_date', 'end_date', 'destination', 'state')
list_filter = ['start_date', 'end_date', 'state']

admin.site.register(PurpleRobotExportJob, PurpleRobotExportJobAdmin)


class PurpleRobotDeviceGroupAdmin(admin.ModelAdmin):
list_display = ('group_id', 'configuration',)
list_display = ('name', 'group_id', 'configuration',)

admin.site.register(PurpleRobotDeviceGroup, PurpleRobotDeviceGroupAdmin)


Expand All @@ -66,13 +76,15 @@ def clear_performance_metadata(modeladmin, request, queryset):

clear_performance_metadata.description = 'Reset cached metadata'


def mute_alerts(modeladmin, request, queryset):
for device in queryset:
device.mute_alerts = True
device.save()

mute_alerts.description = 'Mute alerts'


def unmute_alerts(modeladmin, request, queryset):
for device in queryset:
device.mute_alerts = False
Expand All @@ -81,21 +93,40 @@ def unmute_alerts(modeladmin, request, queryset):
unmute_alerts.description = 'Unmute alerts'


def mark_testing(modeladmin, request, queryset):
for device in queryset:
device.test_device = True
device.save()

mark_testing.description = 'Mark as test device'


def unmark_testing(modeladmin, request, queryset):
for device in queryset:
device.test_device = False
device.save()

unmark_testing.description = 'Mark as regular device'


class PurpleRobotDeviceAdmin(admin.ModelAdmin):
list_display = ('device_id', 'name', 'configuration', 'config_last_fetched', 'config_last_user_agent', 'hash_key', 'mute_alerts')
list_filter = ['device_group', 'configuration', 'mute_alerts']

actions = [ clear_performance_metadata, mute_alerts, unmute_alerts ]

list_display = ('device_id', 'name', 'device_group', 'configuration', 'config_last_fetched', 'config_last_user_agent', 'hash_key', 'mute_alerts', 'test_device', ) # 'earliest_reading_date', 'latest_reading_date',)
list_filter = ['device_group', 'test_device', 'configuration', 'mute_alerts']
search_fields = ['device_id', 'name', 'hash_key']

actions = [clear_performance_metadata, mute_alerts, unmute_alerts, mark_testing, unmark_testing]

admin.site.register(PurpleRobotDevice, PurpleRobotDeviceAdmin)


class PurpleRobotDeviceNoteAdmin(admin.ModelAdmin):
list_display = ('device', 'added',)
list_filter = ['added']
search_fields = ['note']

admin.site.register(PurpleRobotDeviceNote, PurpleRobotDeviceNoteAdmin)


class PurpleRobotAlertAdmin(admin.ModelAdmin):
list_display = ('user_id', 'probe', 'tags', 'message', 'severity', 'generated', 'dismissed', 'manually_dismissed',)

Expand Down
45 changes: 45 additions & 0 deletions device_info.py
@@ -0,0 +1,45 @@
# pylint: disable=line-too-long

DEVICE_PROBES = {
'LGE: LGLS740': {
'name': 'LG Volt (LGLS740)',
'missing_probes': [
'edu.northwestern.cbits.purple_robot_manager.probes.sensors.LightSensorProbe',
]
},
'LGE: LGL34C': {
'name': 'Optimus Fuel (LGL34C)',
'missing_probes': [
'edu.northwestern.cbits.purple_robot_manager.probes.sensors.LightSensorProbe',
]
},
'LGE: LGLS660': {
'name': 'LG Tribute (LGLS660)',
'missing_probes': [
'edu.northwestern.cbits.purple_robot_manager.probes.sensors.LightSensorProbe',
]
},
'LGE: LGL41C': {
'name': 'LG Ultimate 2 (LGL41C)',
'missing_probes': [
'edu.northwestern.cbits.purple_robot_manager.probes.sensors.LightSensorProbe',
]
}
}


def can_sense(manufacturer, model, probe):
if manufacturer is None or model is None or probe is None:
return None

# Until contrary evidence surfaces, assume that all devices have all sensors.

key = manufacturer + ': ' + model

if key in DEVICE_PROBES:
device = DEVICE_PROBES[key]

if probe in device['missing_probes']:
return False

return True
52 changes: 27 additions & 25 deletions formatters/builtin_applicationlaunchprobe.py
@@ -1,35 +1,37 @@
import math
# pylint: disable=line-too-long, unused-argument

import json

from django.template.loader import render_to_string

def format(probe_name, json_payload):

def format_reading(probe_name, json_payload):
item = json.loads(json_payload)
app = item['CURRENT_APP_NAME']
category = item['CURRENT_CATEGORY']

return app + ' (' + category + ')'


def visualize(probe_name, readings):
return ''
'''
report = []
for reading in readings:
payload = json.loads(reading.payload)
timestamp = payload['TIMESTAMP']
device_active = payload['DEVICE_ACTIVE']
if device_active == True:
device_active = 1
elif device_active == False:
device_active = 0
rep_dict = {}
rep_dict["y"] = device_active
rep_dict["x"] = timestamp
report.append(rep_dict)
return render_to_string('visualization_device.html', { 'probe_name' : probe_name, 'readings' : readings, 'device_report' : json.dumps(report) })
'''

#
# report = []
#
# for reading in readings:
# payload = json.loads(reading.payload)
#
# timestamp = payload['TIMESTAMP']
# device_active = payload['DEVICE_ACTIVE']
#
# if device_active == True:
# device_active = 1
# elif device_active == False:
# device_active = 0
#
# rep_dict = {}
# rep_dict["y"] = device_active
# rep_dict["x"] = timestamp
# report.append(rep_dict)
#
# return render_to_string('visualization_device.html', { 'probe_name' : probe_name, 'readings' : readings, 'device_report' : json.dumps(report) })
14 changes: 9 additions & 5 deletions formatters/builtin_batteryprobe.py
@@ -1,20 +1,24 @@
# pylint: disable=line-too-long, unused-argument

import json

from django.template.loader import render_to_string

def format(probe_name, json_payload):

def format_reading(probe_name, json_payload):
item = json.loads(json_payload)

status = 'Unknown'

if item['status'] == 2:
status = 'Charging'
elif item['status'] == 3:
status = 'Discharging'
elif item['status'] == 5:
status = 'Full'

return str(item['level']) + '% (' + status + ')'


def visualize(probe_name, readings):
return render_to_string('visualization_probe.html', { 'probe_name': probe_name, 'readings': readings })
return render_to_string('visualization_probe.html', {'probe_name': probe_name, 'readings': readings})
21 changes: 12 additions & 9 deletions formatters/builtin_callstateprobe.py
@@ -1,33 +1,36 @@
import math
# pylint: disable=line-too-long, unused-argument

import json

from django.template.loader import render_to_string

def format(probe_name, json_payload):

def format_reading(probe_name, json_payload):
item = json.loads(json_payload)
state = item['CALL_STATE']

return state


def visualize(probe_name, readings):
report = []

for reading in readings:
payload = json.loads(reading.payload)

timestamp = payload['TIMESTAMP']
call_state = payload['CALL_STATE']

if call_state == "Off-Hook":
call_state = 2
elif call_state == "Ringing":
call_state = 1
elif call_state == "Idle":
call_state = 0

rep_dict = {}
rep_dict["y"] = call_state
rep_dict["x"] = timestamp
report.append(rep_dict)
return render_to_string('visualization_callstate.html', { 'probe_name' : probe_name, 'readings' : readings, 'callstate_report' : json.dumps(report) })

return render_to_string('visualization_callstate.html', {'probe_name': probe_name, 'readings': readings, 'callstate_report': json.dumps(report)})

0 comments on commit b6fb058

Please sign in to comment.