Hi Esri Community,
Goal is to return the 12 most recent hours per sensor($feature) from another hosted table inside a pop-up on my map.
On my map I have about 30 sensors that are point features.
The sensors have a unique sensor_id that is common across my map and the other hosted table.
The other hosted table is an archive of historical data, it contains many previous sensor values.
The map only contains the most recent hour and is live according to a regularly scheduled task.
I can't seem to filter down my variable "last_twelve_hrs" by "sensor_id." I am stuck where I am getting the most recent hourly averages from all sensors in the hosted table instead of per sensor($feature).
The next step, which I am also unsure about is how to present the most recent 12 hours per sensor($feature) so it can fit in a bar or line graph in a pop-up.
Thanks for your help and time Esri Community!
ARCADE SCRIPT:
var table = FeatureSetByPortalItem(
p, "0749f4597e054caf809b5b55d0b869d4",
0,
['sensor_id','time_stamp','pm25calibrated','avg_'],
false
)
var last_twelve_hrs = []
//function right_sensor(i) {return i table_twelve['sensor_id'] = '$feature.sensor_id'}
var table_twelve = Filter(table, "avg_ = '12'")
for (var t in table_twelve) {
//table_twelve = Filter(table_twelve, right_sensor)
last_twelve_hrs = Top(OrderBy(table_twelve,"time_stamp desc"),12)
}
return last_twelve_hrs
OUTPUT:
featureSet:
OBJECTID sensor_id time_stamp pm25calibrated avg_
| 281981 | "ANPZ34P3" | Dec 15, 2023, 12:00:00 PM Pacific Standard Time | 54 | 12 |
| 281982 | "AYF7FWBQ" | Dec 15, 2023, 12:00:00 PM Pacific Standard Time | 85 | 12 |
| 281983 | "AGFL7RGG" | Dec 15, 2023, 12:00:00 PM Pacific Standard Time | 17 | 12 |
| 281984 | "ACCGJ2KB" | Dec 15, 2023, 12:00:00 PM Pacific Standard Time | 31 | 12 |
| 281985 | "APPWHRLG" | Dec 15, 2023, 12:00:00 PM Pacific Standard Time | 38 | 12 |
| 281986 | "AHLN14H6" | Dec 15, 2023, 12:00:00 PM Pacific Standard Time | 61 | 12 |
| 281987 | "AWL3RVGH" | Dec 15, 2023, 12:00:00 PM Pacific Standard Time | 43 | 12 |
| 281988 | "AYW1PRKD" | Dec 15, 2023, 12:00:00 PM Pacific Standard Time | 19 | 12 |
| 281989 | "A4RRSN0B" | Dec 15, 2023, 12:00:00 PM Pacific Standard Time | 30 | 12 |
| 281990 | "A9BHX0FH" | Dec 15, 2023, 12:00:00 PM Pacific Standard Time | 22 | 12 |
| 281991 | "AQQ4M3SG" | Dec 15, 2023, 12:00:00 PM Pacific Standard Time | 37 | 12 |
| 281992 | "A3T32W43" | Dec 15, 2023, 12:00:00 PM Pacific Standard Time | 47 | 12 |