-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEVPowerOptimization
More file actions
35 lines (29 loc) · 1.08 KB
/
EVPowerOptimization
File metadata and controls
35 lines (29 loc) · 1.08 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
import SimulatorPlugins from "./SimulatorPlugins.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 = ({simulator, vehicle}) => {
fetchRowsFromSpreadsheet("1EwOggp2Hg95gZeDj751Cz7a_kgZBn8PxOZtCbII_DhI", "AIzaSyA1otn2KKfYB3Svdfv30BhgJHPpWjVVrvw")
.then((rows) => {
SimulatorPlugins(rows, simulator)
console.log(vehicle)
})
}
export default plugin;