Click up link: here
Implement an Express API endpoint to query the database and generate an Excel sheet of the results, based on user input.
- The endpoint which accept a device name, a group of sensors, a start time, and an end time.
- Return all the data points present in the time range in Excel format.
- The Excel file must have the following columns: Sensor, time, value.
- The rows of the Excel file should contain the data from the time range.
- The device name must be shown in a row above the headers as merged cells.
- Accept the user-provided parameters from the API request: deviceName, sensors, startTime, endTime.
- Connect to the InfluxDB database.
- Construct an InfluxDB query to retrieve data points:
- Set the measurement to the deviceName.
- Filter data points based on the sensors and time range.
- Execute the query and retrieve the result set.
- Create a new Excel workbook.
- Add a worksheet to the workbook.
- Set up the column headers: Sensor, Time, Value.
- Merge cells for the device name row and add it to the worksheet.
- Iterate over the result set:
- Populate the worksheet with data points: Sensor, Time, Value.
- Save the Excel workbook as a file.
- Return the file as a response from the API endpoint.
- Request Method: GET
- Request URL: http://localhost:3000/export-data
- Query Parameters:
- deviceName (string): The name of the device.
- sensors (string): A comma-separated list of sensors.
- startTime (string): The start time in unix format.
- endTime (string): The end time in unix format.
GET http://localhost:8000/export-data?deviceName=DeviceName&sensors=
sensor1,sensor2&startTime=2023-06-15T09:00:00Z&endTime=2023-06-15T10:00:00Z