een-api-toolkit 0.3.15 → 0.3.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,6 +28,7 @@ ChartJS.register(
28
28
  const props = defineProps<{
29
29
  camera: Camera
30
30
  timeRange: string
31
+ aggregateMinutes?: number
31
32
  }>()
32
33
 
33
34
  interface DataPoint {
@@ -48,7 +49,8 @@ function getTimeRangeMs(range: string): number {
48
49
  case '6h': return 6 * 60 * 60 * 1000
49
50
  case '24h': return 24 * 60 * 60 * 1000
50
51
  case '7d': return 7 * 24 * 60 * 60 * 1000
51
- default: return 24 * 60 * 60 * 1000
52
+ case 'none': return 7 * 24 * 60 * 60 * 1000 // Default to 7 days when "none"
53
+ default: return 7 * 24 * 60 * 60 * 1000
52
54
  }
53
55
  }
54
56
 
@@ -59,7 +61,8 @@ function getAggregationMinutes(range: string): number {
59
61
  case '6h': return 60 // 1 hour buckets (6 data points)
60
62
  case '24h': return 60 // 1 hour buckets (24 data points)
61
63
  case '7d': return 360 // 6 hour buckets (28 data points)
62
- default: return 60
64
+ case 'none': return 360 // 6 hour buckets for 7 days default
65
+ default: return 360
63
66
  }
64
67
  }
65
68
 
@@ -96,6 +99,11 @@ async function fetchEventTypes() {
96
99
  }
97
100
 
98
101
  eventTypes.value = result.data?.type ?? []
102
+ // Auto-select first event type if available
103
+ if (eventTypes.value.length > 0) {
104
+ selectedEventType.value = eventTypes.value[0]
105
+ fetchMetrics()
106
+ }
99
107
  loadingEventTypes.value = false
100
108
  }
101
109
 
@@ -109,7 +117,8 @@ async function fetchMetrics() {
109
117
  const now = new Date()
110
118
  const rangeMs = getTimeRangeMs(props.timeRange)
111
119
  const startTime = new Date(now.getTime() - rangeMs)
112
- const aggregateByMinutes = getAggregationMinutes(props.timeRange)
120
+ // Use provided aggregateMinutes prop, or fall back to auto-calculated value
121
+ const aggregateByMinutes = props.aggregateMinutes ?? getAggregationMinutes(props.timeRange)
113
122
 
114
123
  const result = await getEventMetrics({
115
124
  actor: `camera:${props.camera.id}`,
@@ -127,15 +136,19 @@ async function fetchMetrics() {
127
136
 
128
137
  // Transform API data to chart data points
129
138
  const metrics = result.data ?? []
139
+ const nowMs = now.getTime()
130
140
  if (metrics.length > 0) {
131
141
  // Use the first metric's data points (for count target)
132
142
  const metric = metrics.find((m: EventMetric) => m.target === 'count') ?? metrics[0]
133
143
  // Defensive check for dataPoints array
134
144
  if (metric.dataPoints && Array.isArray(metric.dataPoints)) {
135
- dataPoints.value = metric.dataPoints.map(([timestamp, count]) => ({
136
- timestamp,
137
- count
138
- }))
145
+ // Filter out future data points
146
+ dataPoints.value = metric.dataPoints
147
+ .filter(([timestamp]) => timestamp <= nowMs)
148
+ .map(([timestamp, count]) => ({
149
+ timestamp,
150
+ count
151
+ }))
139
152
  }
140
153
  }
141
154
 
@@ -159,6 +172,7 @@ const chartData = computed(() => {
159
172
  return {
160
173
  labels: dataPoints.value.map(({ timestamp }) => {
161
174
  const date = new Date(timestamp)
175
+ // Use time-only format for short ranges, date+time for longer ranges (including 'none' which defaults to 7 days)
162
176
  if (props.timeRange === '1h' || props.timeRange === '6h') {
163
177
  return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
164
178
  }
@@ -216,9 +230,9 @@ watch(
216
230
  { immediate: true }
217
231
  )
218
232
 
219
- // Fetch metrics when time range changes (if event type is selected)
233
+ // Fetch metrics when time range or aggregate changes (if event type is selected)
220
234
  watch(
221
- () => props.timeRange,
235
+ () => [props.timeRange, props.aggregateMinutes],
222
236
  () => {
223
237
  if (selectedEventType.value) {
224
238
  fetchMetrics()