Skip to content

Commit 78cf5f9

Browse files
authored
Merge pull request #109 from badgerloop-software/strategy-integration
Strategy integration - I updated the dashboard API’s `get-processed-data` route to support an optional output format parameter, defaulting to an Excel file but now allowing JSON responses, and also fixed a Docker issue by upgrading Poetry to resolve build problems and ensure the GitHub Actions test workflow runs smoothly.
2 parents 7eb66be + 3ae402e commit 78cf5f9

8 files changed

Lines changed: 44 additions & 19235 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
/**/.idea
2222
/**/.vscode
2323
/recordedData
24+
venv/
2425

2526
npm-debug.log*
2627
yarn-debug.log*

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
[submodule "Backend/file_sync"]
66
path = Backend/file_sync
77
url = git@github.com:badgerloop-software/file_sync
8+
[submodule "race-profile"]
9+
path = race-profile
10+
url = git@github.com:badgerloop-software/race-profile.git

Backend/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
node_modules
22
dist
33
__pycache__/
4+
venv/
45

56
# Data recording
67
recordedData/sessions/*.bin
78
recordedData/processedData/*.csv
89

910
# Python
10-
*.egg-info
11+
*.egg-info

Backend/components/record_data.py

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,39 @@
66
router = APIRouter()
77

88
@router.get("/get-processed-data")
9-
async def get_processed_data(start_time, end_time):
10-
all_keys = list(config.FORMAT.keys())
11-
all_keys.remove('tstamp_ms')
12-
all_keys.remove('tstamp_sc')
13-
all_keys.remove('tstamp_mn')
14-
all_keys.remove('tstamp_hr')
15-
all_keys.remove('tstamp_unix')
9+
async def get_processed_data(start_time, end_time, output_format: str = 'xlsx'):
10+
try:
11+
all_keys = list(config.FORMAT.keys())
12+
all_keys.remove('tstamp_ms')
13+
all_keys.remove('tstamp_sc')
14+
all_keys.remove('tstamp_mn')
15+
all_keys.remove('tstamp_hr')
16+
all_keys.remove('tstamp_unix')
1617

17-
result = await db.query_without_aggregation(all_keys, start_time, end_time)
18+
result = await db.query_without_aggregation(all_keys, start_time, end_time)
1819

20+
if output_format == 'json':
21+
json_data = result.to_json(orient='records', lines=True, date_format='iso', double_precision=3)
22+
return Response(
23+
content=json_data,
24+
media_type="application/json",
25+
# Only needed if you want to force download
26+
# headers={"Content-Disposition": "attachment; filename=\"download.json\""}
27+
)
28+
else:
29+
# see https://stackoverflow.com/a/63989481
30+
output = io.BytesIO()
31+
writer = pd.ExcelWriter(output, engine='xlsxwriter', datetime_format='MM-DD HH:MM:SS')
32+
result.to_excel(writer, sheet_name='Sheet1')
1933

20-
# see https://stackoverflow.com/a/63989481
21-
output = io.BytesIO()
22-
writer = pd.ExcelWriter(output, engine='xlsxwriter', datetime_format='MM-DD HH:MM:SS')
23-
result.to_excel(writer, sheet_name='Sheet1')
24-
25-
writer.close()
26-
xlsx_data = output.getvalue()
27-
28-
29-
return Response(
30-
content=xlsx_data,
31-
media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
32-
headers={"Content-Disposition": "attachment; filename=\"download.xlsx\""})
34+
writer.close()
35+
xlsx_data = output.getvalue()
36+
return Response(
37+
content=xlsx_data,
38+
media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
39+
headers={"Content-Disposition": "attachment; filename=\"download.xlsx\""})
40+
except Exception as e:
41+
raise Exception(
42+
status_code=500,
43+
detail="Unknown error occurred: " + str(e)
44+
)

Backend/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
name = "chase-car-dashboard-backend"
33
version = "5.2.0"
44
package-mode = false
5+
description = ""
6+
authors = []
57

68
[tool.poetry.dependencies]
79
python = "^3.10"

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
FROM nikolaik/python-nodejs:python3.10-nodejs16
2+
RUN pip install --upgrade pip && pip install poetry
23
WORKDIR /chase-car-dashboard
34
COPY . .
45
RUN npm install

0 commit comments

Comments
 (0)