1818from controller .sentry .choices import EventType , MetricType
1919from controller .sentry .forms import BumpForm , MetricForm
2020from controller .sentry .inlines import AppEventInline , ProjectEventInline
21- from controller .sentry .mixins import PrettyTypeMixin , ProjectLinkMixin
21+ from controller .sentry .mixins import ChartMixin , PrettyTypeMixin , ProjectLinkMixin
2222from controller .sentry .models import App , Event , Project
2323from controller .sentry .utils import invalidate_cache
2424
2525
2626@admin .register (Project )
2727class ProjectAdmin (
28+ ChartMixin ,
2829 AdminConfirmMixin ,
2930 ActionFormMixin ,
3031 DjangoObjectActions ,
@@ -41,18 +42,76 @@ class ProjectAdmin(
4142 ordering = search_fields
4243
4344 formfield_overrides = {
44- models .JSONField : {"widget" : JSONEditorWidget },
45+ models .JSONField : {"widget" : JSONEditorWidget ( width = "100%" ) },
4546 }
4647
4748 fieldsets = [
4849 [
4950 None ,
50- {"fields" : ("sentry_id" , "sentry_project_slug" , "detection_param" )},
51+ {
52+ "fields" : (
53+ "sentry_id" ,
54+ "sentry_project_slug" ,
55+ ("detection_param" , "detection_result" ),
56+ )
57+ },
5158 ]
5259 ]
5360
5461 inlines = [ProjectEventInline ]
5562
63+ def get_chart_data (self , sentry_id ):
64+ project = Project .objects .get (sentry_id = sentry_id )
65+ if project .detection_result is None :
66+ return None
67+
68+ threshold = project .detection_param ["threshold" ]
69+
70+ options = {
71+ "aspectRatio" : 4 ,
72+ "scales" : {
73+ "xAxis" : {"type" : "timeseries" },
74+ "series" : {"position" : "left" },
75+ "signal" : {"position" : "right" },
76+ },
77+ "plugins" : {"legend" : {"position" : "bottom" }, "title" : {"display" : True , "text" : "Detection Result" }},
78+ "elements" : {"line" : {"stepped" : True }, "point" : {"radius" : 0 }},
79+ "interaction" : {"mode" : "index" , "intersect" : False },
80+ }
81+ data = {
82+ "datasets" : [
83+ {
84+ "label" : "Series" ,
85+ "backgroundColor" : "#36a2eb" ,
86+ "borderColor" : "#36a2eb" ,
87+ "data" : project .detection_result ["series" ],
88+ "yAxisID" : "series" ,
89+ },
90+ {
91+ "label" : "Signal" ,
92+ "backgroundColor" : "#ff6384" ,
93+ "borderColor" : "#ff6384" ,
94+ "data" : project .detection_result ["signal" ],
95+ "yAxisID" : "signal" ,
96+ },
97+ {
98+ "label" : "Threshold" ,
99+ "backgroundColor" : "#9966ff" ,
100+ "borderColor" : "#9966ff" ,
101+ "data" : [
102+ avg_filter + threshold * std_filter
103+ for avg_filter , std_filter in zip (
104+ project .detection_result ["avg_filter" ],
105+ project .detection_result ["std_filter" ],
106+ )
107+ ],
108+ "yAxisID" : "series" ,
109+ },
110+ ],
111+ "labels" : project .detection_result ["intervals" ],
112+ }
113+ return data , options
114+
56115
57116@admin .register (Event )
58117class EventAdmin (
@@ -71,7 +130,7 @@ class EventAdmin(
71130 ordering = search_fields
72131
73132 formfield_overrides = {
74- models .JSONField : {"widget" : JSONEditorWidget },
133+ models .JSONField : {"widget" : JSONEditorWidget ( width = "100%" ) },
75134 }
76135
77136 fieldsets = [
@@ -109,7 +168,7 @@ class AppAdmin(
109168 ordering = search_fields
110169
111170 formfield_overrides = {
112- models .JSONField : {"widget" : JSONEditorWidget },
171+ models .JSONField : {"widget" : JSONEditorWidget ( width = "100%" ) },
113172 }
114173
115174 fieldsets = [
0 commit comments