-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathearthquake_usgs_template.yml
880 lines (834 loc) · 31 KB
/
earthquake_usgs_template.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
apiVersion: influxdata.com/v2alpha1
kind: Label
metadata:
name: cool-rubin-a05001
spec:
color: '#BF3D5E'
name: earthquake
---
apiVersion: influxdata.com/v2alpha1
kind: Bucket
metadata:
name: righteous-bardeen-e05001
spec:
associations:
- kind: Label
name: cool-rubin-a05001
name: apis
retentionRules:
- everySeconds: 2.592e+06
type: expire
---
apiVersion: influxdata.com/v2alpha1
kind: Task
metadata:
name: busy-lewin-205001
spec:
associations:
- kind: Label
name: cool-rubin-a05001
every: 1m
name: Earthquake Alerts
offset: 20s
query: |-
import "influxdata/influxdb/schema"
import "strings"
import "experimental/geo"
import "slack"
import "date"
import "math"
import "regexp"
import "experimental"
import "dict"
global_mag_threshold = 6
regional_mag_threshold = 3
units = "mile"
tz = "PST"
city = "San Francisco:37.7576948:-122.4726194"
city_radius = 1000.0
alert_delay_min = 5
slack_webhook = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
sendSlackMessage = (text) =>
(slack.message(
url: slack_webhook,
token: "",
channel: "",
text: text,
color: "danger",
))
distance_to_string = (distance, place) =>
(if distance > 0.0 then if units == "km" then string(v: distance) + " km " + place else string(v: math.round(x: distance * 0.621371)) + " mi " + place else place)
depth_to_string = (n) =>
(if n > 0.0 then if units == "km" then string(v: math.round(x: n)) + " km" else string(v: math.round(x: n * 0.621371)) + " mi" else "")
tz_dictionary = dict.fromList(pairs: [{key: "PST", value: "-8h"}, {key: "PDT", value: "-7h"}, {key: "CST", value: "-6h"}, {key: "EST", value: "-5h"}, {key: "EDT", value: "-4h"}, {key: "UTC", value: "0h"}])
tz_dur = duration(v: dict.get(dict: tz_dictionary, key: tz, default: "0h"))
city_coordinates = strings.split(v: city, t: ":")
city_name = city_coordinates[1]
city_lat = float(v: city_coordinates[1])
city_lon = float(v: city_coordinates[2])
alert_delay = duration(v: string(v: alert_delay_min * (-2)) + "m")
stop = experimental.addDuration(to: now(), d: task.offset)
alerted_ids = from(bucket: "apis")
|> range(start: -2d, stop: stop)
|> filter(fn: (r) =>
(r._measurement == "earthquake_alert_log"))
|> group()
|> unique()
|> findColumn(fn: (key) =>
(true), column: "id")
global = from(bucket: "apis")
|> range(start: -30m, stop: alert_delay)
|> filter(fn: (r) =>
(r["_measurement"] == "earthquake_stats"))
|> schema.fieldsAsCols()
|> filter(fn: (r) =>
(r["type"] == "earthquake" and r["status"] != "deleted"))
|> filter(fn: (r) =>
(r["mag"] >= global_mag_threshold))
regional = from(bucket: "apis")
|> range(start: -30m, stop: alert_delay)
|> filter(fn: (r) =>
(r["_measurement"] == "earthquake_stats"))
|> schema.fieldsAsCols()
|> filter(fn: (r) =>
(r["type"] == "earthquake" and r["status"] != "deleted"))
|> filter(fn: (r) =>
(r["mag"] >= regional_mag_threshold))
|> geo.strictFilter(region: {lat: city_lat, lon: city_lon, radius: city_radius})
union(tables: [global, regional])
|> filter(fn: (r) =>
(not contains(set: alerted_ids, value: r["id"])))
|> group(columns: ["id"])
|> last(column: "id")
|> group()
|> map(fn: (r) =>
({r with local_time: experimental.addDuration(d: tz_dur, to: r._time)}))
|> map(fn: (r) =>
({r with mag: math.round(x: r.mag * 10.0) / 10.0}))
|> map(fn: (r) =>
({r with place: distance_to_string(distance: r.distance, place: r.place)}))
|> map(fn: (r) =>
({r with depth: depth_to_string(n: r.depth)}))
|> map(fn: (r) =>
({r with newColumn: sendSlackMessage(text: "*Earthquake Alert*
M *${string(v: r.mag)}* — *${string(v: r.place)}*
*${regexp.replaceAllString(r: /:\d{2}\..*/, v: string(v: r.local_time), t: "")}* (${tz}) | *${string(v: r.depth)}* depth
:globe_with_meridians: <https://earthquake.usgs.gov/earthquakes/eventpage/${r.id}/executive|USGS Earthquake Summary> | <https://www.google.com/maps/@?api=1&map_action=map¢er=${string(v: r.lat)},${string(v: r.lon)}&zoom=6&basemap=terrain|Google Maps>")}))
|> keep(columns: ["_time", "id"])
|> set(key: "_measurement", value: "earthquake_alert_log")
|> set(key: "processed_at", value: string(v: now()))
|> group(columns: ["id"])
|> to(bucket: "apis", fieldFn: (r) =>
({"processed_at": r.processed_at}))
status: inactive
---
apiVersion: influxdata.com/v2alpha1
kind: Task
metadata:
name: cool-goldwasser-605001
spec:
associations:
- kind: Label
name: cool-rubin-a05001
every: 1m
name: Earthquake Feed Ingestion
query: |-
import "experimental/http"
import "experimental"
import "csv"
import "strings"
import "regexp"
import "experimental/geo"
import "experimental/array"
import "date"
import "math"
import "dict"
onedayago = strings.trimSuffix(v: string(v: date.truncate(t: experimental.subDuration(d: 1d, from: now()), unit: 1m)), suffix: ".000000000Z")
csv_data_url = "https://earthquake.usgs.gov/fdsnws/event/1/query?format=csv&starttime=" + onedayago + "&includedeleted=true&orderby=time-asc"
csv_data = string(v: http.get(url: csv_data_url).body)
states = ["Alaska", "California", "CA", "Hawaii", "Idaho", "Kansas", "New Mexico", "Nevada", "North Carolina", "Oklahoma", "Oregon", "Washington", "Utah"]
countries_dictionary = dict.fromList(pairs: [{key: "MX", value: "Mexico"}])
csv.from(csv: csv_data, mode: "raw")
|> map(fn: (r) =>
({
_measurement: "earthquake_stats",
_time: time(v: r.time),
lat: float(v: r.latitude),
lon: float(v: r.longitude),
depth: float(v: r.depth),
depthError: float(v: r.depthError),
mag: float(v: r.mag),
magType: string(v: r.magType),
net: string(v: r.net),
id: string(v: r.id),
updated: int(v: time(v: r.updated)) / 1000000,
place: if exists r.place then string(v: r.place) else "null",
type: string(v: r.type),
magSource: string(v: r.magSource),
status: string(v: r.status),
}))
|> truncateTimeColumn(unit: 1s)
|> map(fn: (r) =>
({r with place_km: regexp.replaceAllString(r: /^0\s?km /, v: r.place, t: "")}))
|> map(fn: (r) =>
({r with s2_cell_id: geo.s2CellIDToken(point: {lon: r.lon, lat: r.lat}, level: 10)}))
|> map(fn: (r) =>
({r with place: if strings.containsStr(v: r.place_km, substr: "km") then regexp.replaceAllString(r: /\d+\s?km/, v: r.place_km, t: "") else r.place_km, distance: if strings.containsStr(v: r.place_km, substr: "km") then float(v: regexp.replaceAllString(r: /(\d+)\s?km.*/, v: r.place_km, t: "$1")) else 0.0, country: regexp.replaceAllString(r: /^.*,\s?/, v: r.place_km, t: "")}))
|> map(fn: (r) =>
({r with country: if contains(value: r.country, set: states) then "United States" else r.country}))
|> map(fn: (r) =>
({r with magType: if exists r.magType then r.magType else "null"}))
|> map(fn: (r) =>
({r with net: if exists r.net then r.net else "null"}))
|> map(fn: (r) =>
({r with type: if exists r.type then r.type else "null"}))
|> map(fn: (r) =>
({r with status: if exists r.status then r.status else "null"}))
|> map(fn: (r) =>
({r with country: if exists r.country then r.country else "null"}))
|> map(fn: (r) =>
({r with country: dict.get(dict: countries_dictionary, key: r.country, default: r.country)}))
|> group(columns: ["_measurement", "magSource"])
|> filter(fn: (r) => r.place != "null")
|> experimental.to(bucket: "apis")
array.from(rows: [{_time: date.truncate(t: now(), unit: 1d), id: "abc", _measurement: "earthquake_alert_log"}])
|> group(columns: ["id"])
|> to(bucket: "apis", fieldFn: (r) =>
({"processed_at": string(v: now())}))
status: active
---
apiVersion: influxdata.com/v2alpha1
kind: Variable
metadata:
name: exciting-khorana-605009
spec:
associations:
- kind: Label
name: cool-rubin-a05001
name: Radius
selected:
- "1000"
type: constant
values:
- "50"
- "100"
- "500"
- "1000"
- "2000"
---
apiVersion: influxdata.com/v2alpha1
kind: Variable
metadata:
name: gallant-faraday-605011
spec:
associations:
- kind: Label
name: cool-rubin-a05001
name: Magnitude_Threshold
selected:
- "1"
type: map
values:
"0": "0"
"1": "1"
"2": "2"
"3": "3"
"4": "4"
"5": "5"
"6": "6"
"7": "7"
---
apiVersion: influxdata.com/v2alpha1
kind: Variable
metadata:
name: pensive-hypatia-60500d
spec:
associations:
- kind: Label
name: cool-rubin-a05001
name: Units
selected:
- mi
type: map
values:
km: km
mi: mile
---
apiVersion: influxdata.com/v2alpha1
kind: Variable
metadata:
name: ridiculous-dhawan-605005
spec:
associations:
- kind: Label
name: cool-rubin-a05001
name: Location
selected:
- San Francisco, CA
type: map
values:
Hilo, HI: Hilo, HI:19.6865946:-155.124954
Los Angeles, CA: Los Angeles, CA:34.0201613:-118.6919149
Oklahoma City, OK: Oklahoma City, OK:35.482567:-97.6192807
San Francisco, CA: San Francisco, CA:37.7576948:-122.4726194
Tokyo, Japan: Tokyo, Japan:35.48847:137.5263065
World: World:0.0:0.0
---
apiVersion: influxdata.com/v2alpha1
kind: Dashboard
metadata:
name: tender-franklin-205001
spec:
associations:
- kind: Label
name: cool-rubin-a05001
charts:
- colors:
- hex: '#292933'
id: base
name: castle
type: background
decimalPlaces: 2
height: 1
kind: Single_Stat
name: Location
queries:
- query: |-
import "strings"
import "dict"
import "experimental/array"
globe_dictionary = dict.fromList(pairs: [
{key: "Hilo, HI", value: "🌋"},
{key: "Los Angeles, CA", value: "🏖️"},
{key: "Oklahoma City, OK", value: "🌪️"},
{key: "San Francisco, CA", value: "🌉"},
{key: "Tokyo, Japan", value: "🗾"}
])
city_name = strings.split(v: v.Location, t: ":")[0]
full_location = dict.get(dict: globe_dictionary, key: city_name, default: "🌐") + " " + city_name
array.from(rows: [{_value: full_location}])
width: 3
- height: 3
kind: Markdown
name: Name this Cell
note: |-
# Earthquakes
Latest earthquake data reported by United States Geological Survey (USGS).
Filter by _magnitude_, _location_, _radius (km/mi)_, and _time_.
https://www.usgs.gov/natural-hazards/earthquake-hazards/earthquakes
width: 3
yPos: 1
- axes:
- base: "10"
name: x
scale: linear
- label: Richter Magnitude
name: y
scale: linear
colors:
- hex: '#DC4E58'
id: 724cfce2-7781-4589-968c-3435e90e45f0
name: Solid Red
type: scale
- hex: '#DC4E58'
id: 083e1a67-9db1-4155-a003-976e43b0de23
name: Solid Red
type: scale
- hex: '#DC4E58'
id: 67870962-fd23-4c64-b4dd-663ee83ab099
name: Solid Red
type: scale
geom: step
height: 4
hoverDimension: auto
kind: Xy
legendColorizeRows: true
legendOpacity: 1
legendOrientationThreshold: 1e+08
name: Earthquake Magnitudes
position: overlaid
queries:
- query: |-
import "influxdata/influxdb/schema"
import "experimental/geo"
import "strings"
option geo.units = {distance: v.Units}
city_coordinates = strings.split(v: v.Location, t: ":")
city_lat = float(v: city_coordinates[1])
city_lon = float(v: city_coordinates[2])
city_radius = if city_lat == 0.0 then 100000.0 else float(v: v.Radius)
mag_threshold = float(v: v.Magnitude_Threshold)
from(bucket: "apis")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "earthquake_stats")
|> schema.fieldsAsCols()
|> filter(fn: (r) => r["type"] == "earthquake" and r["status"] != "deleted")
|> filter(fn: (r) => r["mag"] >= mag_threshold, onEmpty: "keep")
|> geo.strictFilter(region: {lat: city_lat, lon: city_lon, radius: city_radius})
|> group(columns: ["id"])
|> last(column: "id")
|> group()
|> rename(columns: {mag: "_value"})
|> aggregateWindow(every: v.windowPeriod, fn: max, createEmpty: false)
width: 7
xCol: _time
yCol: _value
yPos: 4
- colors:
- hex: '#7CE490'
id: "0"
name: honeydew
type: min
- hex: '#FFD255'
id: 14bce210-963e-45a7-aa6c-022f918de120
name: thunder
type: threshold
value: 2
- hex: '#FFB94A'
id: 159e2f90-c190-4441-a047-34973ce4d1d0
name: pineapple
type: threshold
value: 3
- hex: '#F48D38'
id: fc136d13-af0d-4f9f-af0f-ab6f77253993
name: tiger
type: threshold
value: 4
- hex: '#F95F53'
id: 5adb5c02-73da-44ba-acce-4235febdf4c8
name: curacao
type: threshold
value: 5
- hex: '#DC4E58'
id: e3d3a708-d87b-4359-9d79-6c107ac051f4
name: fire
type: threshold
value: 6
- hex: '#BF3D5E'
id: b3ff1863-906e-4eaa-be5d-a99df2cdc665
name: ruby
type: threshold
value: 7
- hex: '#9394FF'
id: "1"
name: comet
type: max
value: 10
decimalPlaces: 1
height: 3
kind: Gauge
name: Highest Magnitude Earthquake
queries:
- query: |-
import "influxdata/influxdb/schema"
import "experimental/geo"
import "strings"
option geo.units = {distance: v.Units}
city_coordinates = strings.split(v: v.Location, t: ":")
city_lat = float(v: city_coordinates[1])
city_lon = float(v: city_coordinates[2])
city_radius = if city_lat == 0.0 then 100000.0 else float(v: v.Radius)
mag_threshold = float(v: v.Magnitude_Threshold)
from(bucket: "apis")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "earthquake_stats")
|> schema.fieldsAsCols()
|> filter(fn: (r) => r["type"] == "earthquake" and r["status"] != "deleted")
|> filter(fn: (r) => r["mag"] >= mag_threshold, onEmpty: "keep")
|> geo.strictFilter(region: { lat: city_lat, lon: city_lon, radius: city_radius })
|> group(columns: ["id"])
|> last(column: "id")
|> group()
|> max(column: "mag")
|> keep(columns: ["mag"])
width: 3
xPos: 3
- colors:
- hex: '#22ADF6'
id: base
name: pool
type: text
decimalPlaces: 2
height: 1
kind: Single_Stat
name: Highest Magnitude Location
queries:
- query: |-
import "influxdata/influxdb/schema"
import "experimental/geo"
import "experimental"
import "strings"
import "regexp"
import "math"
option geo.units = {distance: v.Units}
city_coordinates = strings.split(v: v.Location, t: ":")
city_lat = float(v: city_coordinates[1])
city_lon = float(v: city_coordinates[2])
city_radius = if city_lat == 0.0 then 100000.0 else float(v: v.Radius)
mag_threshold = float(v: v.Magnitude_Threshold)
distance_to_string = (distance, place, country) =>
if distance > 0.0 then
if v.Units == "km" then
string(v: distance) + " km " + place
else
string(v: math.round(x: distance * 0.621371)) + " mi " + place
else
place
from(bucket: "apis")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "earthquake_stats")
|> schema.fieldsAsCols()
|> filter(fn: (r) => r["type"] == "earthquake" and r["status"] != "deleted")
|> filter(fn: (r) => r["mag"] >= mag_threshold, onEmpty: "keep")
|> geo.strictFilter(region: {lat: city_lat, lon: city_lon, radius: city_radius})
|> group(columns: ["id"])
|> last(column: "id")
|> group()
|> max(column: "mag")
|> map(fn: (r) => ({ r with place: distance_to_string(distance: r.distance, place: r.place, country: r.country) }))
|> keep(columns: ["place"])
width: 4
xPos: 3
yPos: 3
- colors:
- hex: '#22ADF6'
id: base
name: pool
type: background
decimalPlaces: 0
height: 1
kind: Single_Stat
name: '# Quakes'
queries:
- query: |-
import "influxdata/influxdb/schema"
import "experimental/geo"
import "strings"
option geo.units = {distance: v.Units}
city_coordinates = strings.split(v: v.Location, t: ":")
city_lat = float(v: city_coordinates[1])
city_lon = float(v: city_coordinates[2])
city_radius = if city_lat == 0.0 then 100000.0 else float(v: v.Radius)
mag_threshold = float(v: v.Magnitude_Threshold)
from(bucket: "apis")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "earthquake_stats")
|> schema.fieldsAsCols()
|> filter(fn: (r) => r["type"] == "earthquake" and r["status"] != "deleted")
|> filter(fn: (r) => r["mag"] >= mag_threshold, onEmpty: "keep")
|> geo.strictFilter(region: {lat: city_lat, lon: city_lon, radius: city_radius})
|> group(columns: ["id"])
|> last(column: "id")
|> group()
|> count(column: "mag")
width: 1
xPos: 6
- colors:
- hex: '#7CE490'
id: base
name: honeydew
type: text
- hex: '#FFD255'
id: 0a6448ef-3c5d-49f3-8fb1-08491c3a0e3f
name: thunder
type: text
value: 2
- hex: '#FFB94A'
id: f6d517be-87e7-4c6d-8eca-142adcc4ed36
name: pineapple
type: text
value: 3
- hex: '#F48D38'
id: 5de2478b-5b70-463c-928d-be374a1ad1b5
name: tiger
type: text
value: 4
- hex: '#F95F53'
id: 7b606088-50bd-4ab5-a6eb-53435f0cbbde
name: curacao
type: text
value: 5
- hex: '#DC4E58'
id: 6d523420-9b54-4341-8276-73b8a5ff9527
name: fire
type: text
value: 6
- hex: '#BF3D5E'
id: e0c31ae2-3b98-4fdc-af59-b410f9329cfd
name: ruby
type: text
value: 7
decimalPlaces: 1
height: 1
kind: Single_Stat
name: Avg. Magnitude
queries:
- query: |-
import "influxdata/influxdb/schema"
import "experimental/geo"
import "strings"
option geo.units = {distance: v.Units}
city_coordinates = strings.split(v: v.Location, t: ":")
city_lat = float(v: city_coordinates[1])
city_lon = float(v: city_coordinates[2])
city_radius = if city_lat == 0.0 then 100000.0 else float(v: v.Radius)
mag_threshold = float(v: v.Magnitude_Threshold)
from(bucket: "apis")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "earthquake_stats")
|> schema.fieldsAsCols()
|> filter(fn: (r) => r["type"] == "earthquake" and r["status"] != "deleted")
|> filter(fn: (r) => r["mag"] >= mag_threshold, onEmpty: "keep")
|> geo.strictFilter(region: {lat: city_lat, lon: city_lon, radius: city_radius})
|> group(columns: ["id"])
|> last(column: "id")
|> group()
|> mean(column: "mag")
width: 1
xPos: 6
yPos: 1
- colors:
- hex: '#7CE490'
id: base
name: honeydew
type: text
- hex: '#FFD255'
id: 0a6448ef-3c5d-49f3-8fb1-08491c3a0e3f
name: thunder
type: text
value: 2
- hex: '#FFB94A'
id: f6d517be-87e7-4c6d-8eca-142adcc4ed36
name: pineapple
type: text
value: 3
- hex: '#F48D38'
id: 5de2478b-5b70-463c-928d-be374a1ad1b5
name: tiger
type: text
value: 4
- hex: '#F95F53'
id: 7b606088-50bd-4ab5-a6eb-53435f0cbbde
name: curacao
type: text
value: 5
- hex: '#DC4E58'
id: 6d523420-9b54-4341-8276-73b8a5ff9527
name: fire
type: text
value: 6
- hex: '#BF3D5E'
id: e0c31ae2-3b98-4fdc-af59-b410f9329cfd
name: ruby
type: text
value: 7
decimalPlaces: 1
height: 1
kind: Single_Stat
name: Avg. Depth
queries:
- query: |-
import "influxdata/influxdb/schema"
import "experimental/geo"
import "strings"
import "math"
option geo.units = {distance: v.Units}
city_coordinates = strings.split(v: v.Location, t: ":")
city_lat = float(v: city_coordinates[1])
city_lon = float(v: city_coordinates[2])
city_radius = if city_lat == 0.0 then 100000.0 else float(v: v.Radius)
mag_threshold = float(v: v.Magnitude_Threshold)
depth_to_string = (n) =>
if n > 0.0 then
if v.Units == "km" then
string(v: math.round(x: n)) + " km"
else
string(v: math.round(x: n * 0.621371)) + " mi"
else
""
from(bucket: "apis")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "earthquake_stats")
|> schema.fieldsAsCols()
|> filter(fn: (r) => r["type"] == "earthquake" and r["status"] != "deleted")
|> filter(fn: (r) => r["mag"] >= mag_threshold, onEmpty: "keep")
|> geo.strictFilter(region: {lat: city_lat, lon: city_lon, radius: city_radius})
|> group(columns: ["id"])
|> last(column: "id")
|> group()
|> mean(column: "depth")
|> map(fn: (r) => ({ r with depth: depth_to_string(n: r.depth) }))
width: 1
xPos: 6
yPos: 2
- colors:
- hex: '#7CE490'
id: base
name: honeydew
type: background
- hex: '#FFD255'
id: eeddc270-082c-4b6f-88e4-ae991b4c6ee4
name: thunder
type: background
value: 2
- hex: '#FFB94A'
id: ff426588-93d6-4280-b8c1-15f7814b70cc
name: pineapple
type: background
value: 3
- hex: '#F48D38'
id: 809e3435-efb7-4cb2-ac9e-a9939039b3bd
name: tiger
type: background
value: 4
- hex: '#F95F53'
id: b7e59a75-69b5-4c31-aa1d-09a64c76855a
name: curacao
type: background
value: 5
- hex: '#DC4E58'
id: 3e8ff02e-1c44-48d3-84ba-341602ff45e2
name: fire
type: background
value: 6
- hex: '#BF3D5E'
id: 30659068-3458-4a11-bf73-c201e5a472e9
name: ruby
type: background
value: 7
fieldOptions:
- displayName: Time
fieldName: Time
visible: true
- displayName: Magnitude
fieldName: Magnitude
visible: true
- displayName: Location
fieldName: Location
visible: true
- displayName: id
fieldName: id
visible: true
- displayName: updated
fieldName: updated
visible: true
- displayName: _measurement
fieldName: _measurement
visible: true
- displayName: _start
fieldName: _start
visible: true
- displayName: _stop
fieldName: _stop
visible: true
- displayName: country
fieldName: country
visible: true
- displayName: depth
fieldName: depth
visible: true
- displayName: depthError
fieldName: depthError
visible: true
- displayName: distance
fieldName: distance
visible: true
- displayName: dmin
fieldName: dmin
visible: true
- displayName: gap
fieldName: gap
visible: true
- displayName: horizontalError
fieldName: horizontalError
visible: true
- displayName: lat
fieldName: lat
visible: true
- displayName: locationSource
fieldName: locationSource
visible: true
- displayName: lon
fieldName: lon
visible: true
- displayName: magError
fieldName: magError
visible: true
- displayName: magNst
fieldName: magNst
visible: true
- displayName: magSource
fieldName: magSource
visible: true
- displayName: magType
fieldName: magType
visible: true
- displayName: net
fieldName: net
visible: true
- displayName: nst
fieldName: nst
visible: true
- displayName: place_km
fieldName: place_km
visible: true
- displayName: rms
fieldName: rms
visible: true
- displayName: s2_cell_id
fieldName: s2_cell_id
visible: true
- displayName: status
fieldName: status
visible: true
- displayName: type
fieldName: type
visible: true
height: 8
kind: Table
name: Recent Earthquakes
queries:
- query: |-
import "influxdata/influxdb/schema"
import "experimental/geo"
import "experimental"
import "strings"
import "math"
import "regexp"
option geo.units = {distance: v.Units}
city_coordinates = strings.split(v: v.Location, t: ":")
city_lat = float(v: city_coordinates[1])
city_lon = float(v: city_coordinates[2])
city_radius = if city_lat == 0.0 then 100000.0 else float(v: v.Radius)
mag_threshold = float(v: v.Magnitude_Threshold)
distance_to_string = (distance, place, country) =>
if distance > 0.0 then
if v.Units == "km" then
string(v: distance) + " km " + place
else
string(v: math.round(x: distance * 0.621371)) + " mi " + place
else
place
from(bucket: "apis")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "earthquake_stats")
|> schema.fieldsAsCols()
|> filter(fn: (r) => exists r["s2_cell_id"])
|> filter(fn: (r) => r["type"] == "earthquake" and r["status"] != "deleted")
|> filter(fn: (r) => r["mag"] >= mag_threshold, onEmpty: "keep")
|> geo.strictFilter(region: {lat: city_lat, lon: city_lon, radius: city_radius})
|> group(columns: ["id"])
|> last(column: "id")
|> group()
|> map(fn: (r) => ({ r with mag: math.round(x: r.mag * 10.0) / 10.0 }))
|> map(fn: (r) => ({ r with place: distance_to_string(distance: r.distance, place: r.place, country: r.country) }))
|> keep(columns: ["mag", "place", "_time"])
|> rename(columns: {mag: "Magnitude", place: "Location", _time: "Time"})
|> sort(columns: ["Time"], desc: true)
tableOptions:
verticalTimeAxis: true
timeFormat: YYYY-MM-DD HH:mm:ss
width: 5
xPos: 7
description: via USGS earthquake feed
name: Earthquake Command Center