% ' Top 10 Longest Incidents - by time period (week/month/year) Dim periodFilterTop, periodLabelTop, sqlDateFilterTop periodFilterTop = Request.QueryString("period") ' Default to current month if no filter specified If periodFilterTop = "" Or periodFilterTop = "month" Then periodFilterTop = "month" periodLabelTop = "This Month" sqlDateFilterTop = "n.starttime >= DATE_SUB(NOW(), INTERVAL 30 DAY)" ElseIf periodFilterTop = "week" Then periodLabelTop = "This Week" sqlDateFilterTop = "n.starttime >= DATE_SUB(NOW(), INTERVAL 7 DAY)" ElseIf periodFilterTop = "year" Then periodLabelTop = "This Year" sqlDateFilterTop = "n.starttime >= DATE_SUB(NOW(), INTERVAL 1 YEAR)" Else ' Default fallback periodFilterTop = "month" periodLabelTop = "This Month" sqlDateFilterTop = "n.starttime >= DATE_SUB(NOW(), INTERVAL 30 DAY)" End If ' Query to get top 10 longest incidents strSQL_TopIncidents = "SELECT " & _ "n.notificationid, " & _ "n.notification, " & _ "nt.typename, " & _ "n.starttime, " & _ "n.endtime, " & _ "TIMESTAMPDIFF(MINUTE, n.starttime, n.endtime) as duration_minutes " & _ "FROM notifications n " & _ "INNER JOIN notificationtypes nt ON n.notificationtypeid = nt.notificationtypeid " & _ "WHERE " & sqlDateFilterTop & " " & _ "AND n.starttime IS NOT NULL " & _ "AND n.endtime IS NOT NULL " & _ "AND n.endtime > n.starttime " & _ "AND nt.typename <> 'TBD' " & _ "ORDER BY duration_minutes DESC " & _ "LIMIT 10" Set rsTopIncidents = objconn.Execute(strSQL_TopIncidents) ' Build arrays for chart data Dim incidentNames(), incidentDurations() ReDim incidentNames(9) ' Top 10 ReDim incidentDurations(9) Dim topIndex topIndex = 0 Do While Not rsTopIncidents.EOF And topIndex < 10 ' Truncate long notification names Dim notifText notifText = rsTopIncidents("notification") & "" If Len(notifText) > 30 Then notifText = Left(notifText, 27) & "..." End If incidentNames(topIndex) = notifText incidentDurations(topIndex) = CLng(rsTopIncidents("duration_minutes")) topIndex = topIndex + 1 rsTopIncidents.MoveNext Loop rsTopIncidents.Close Set rsTopIncidents = Nothing Dim actualTopCount actualTopCount = topIndex ' Build data strings for chart Dim chartLabelsTop, chartDataTop, chartColorsTop chartLabelsTop = "" chartDataTop = "" chartColorsTop = "" Dim j For j = 0 To actualTopCount - 1 If chartLabelsTop <> "" Then chartLabelsTop = chartLabelsTop & ", " chartDataTop = chartDataTop & ", " chartColorsTop = chartColorsTop & ", " End If chartLabelsTop = chartLabelsTop & """" & Replace(incidentNames(j), """", "\""") & """" chartDataTop = chartDataTop & incidentDurations(j) ' Use white/semi-transparent colors Dim topOpacity If j = 0 Then chartColorsTop = chartColorsTop & """#ffffff""" Else topOpacity = FormatNumber(1 - (j * 0.1), 2) chartColorsTop = chartColorsTop & """rgba(255, 255, 255, " & topOpacity & ")""" End If Next ' Check if we have data Dim hasTopData hasTopData = (actualTopCount > 0) %> <% If hasTopData Then %> <% End If %>