-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRouteMonitoring.js
More file actions
130 lines (110 loc) · 3.02 KB
/
RouteMonitoring.js
File metadata and controls
130 lines (110 loc) · 3.02 KB
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
import SimulatorPlugins from "./reusable/SimulatorPlugins.js"
import SignalPills from "./reusable/SignalPills.js"
import GoogleMapsFromSignal from "./reusable/GoogleMapsFromSignal.js"
import SignalTile from "./reusable/SignalTile.js"
import LineChart from "./reusable/LineChart.js"
import { PLUGINS_APIKEY } from "./reusable/apikey.js";
async function fetchRowsFromSpreadsheet(spreadsheetId, apiKey) {
// Set the range to A1:Z1000
const range = "A1:Z1000";
// Fetch the rows from the Google Spreadsheet API
const response = await fetch(
`https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${range}?key=${encodeURIComponent(apiKey)}`
);
const json = await response.json();
// Get the headers from the first row
const headers = json.values[0];
// Convert the remaining rows to an array of objects
const rows = json.values.slice(1).map(row => {
const rowObject = {};
for (let i = 0; i < row.length; i++) {
rowObject[headers[i]] = row[i];
}
return rowObject;
});
return rows;
}
const plugin = ({widgets, simulator, vehicle}) => {
fetchRowsFromSpreadsheet("1P1YrDvAf_9MEGolYuZe8oz8NxNpvku8UB-nSa-gIIRU", PLUGINS_APIKEY)
.then((rows) => {
SimulatorPlugins(rows, simulator)
console.log(rows)
})
const LatitudeTile = {
signal: "Vehicle.CurrentLocation.Latitude",
label: "Latitude",
icon: "satellite",
}
const LongitudeTile = {
signal: "Vehicle.CurrentLocation.Longitude",
label: "Longitude",
icon: "satellite"
}
const ETATile = {
signal: "Vehicle.Cabin.Infotainment.Navigation.DestinationSet.ETA",
label: "ETA",
icon: "flag-checkered",
suffix: "s"
}
widgets.register(
"LatitudeTile",
SignalTile(
LatitudeTile,
vehicle
)
)
widgets.register(
"LongitudeTile",
SignalTile(
LongitudeTile,
vehicle
)
)
widgets.register(
"ETATile",
SignalTile(
ETATile,
vehicle
)
)
widgets.register(
"LatLongPills",
SignalPills(
[
LatitudeTile,
LongitudeTile,
],
vehicle
)
)
widgets.register(
"SpeedLineChart",
LineChart(
[
{
signal: "Vehicle.Speed",
suffix: " km/h"
}
],
vehicle
)
)
widgets.register(
"GoogleMapDirections",
GoogleMapsFromSignal(
[
{
"lat": 48.149497,
"lng": 11.523194
},
{
"lat": 50.445168,
"lng": 11.020569
},
],
vehicle,
{ iterate: true }
)
)
}
export default plugin