Skip to content

Commit

Permalink
resolve sonarcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewpeng02 committed May 12, 2024
1 parent 37acfa1 commit dbfb728
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 68 deletions.
8 changes: 5 additions & 3 deletions frontend/src/pages/train/[train_space_id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const TrainSpace = () => {
const { train_space_id } = useRouter().query;
const { data, isLoading, refetch, error } = useGetTrainspaceQuery({
trainspaceId: train_space_id,
withResults: true
withResults: true,
});

const user = useAppSelector((state) => state.currentUser.user);
Expand All @@ -65,15 +65,17 @@ const TrainSpace = () => {
return <></>;
}

const charts = mapTrainResultsDataToCharts(data.trainspace.detailedTrainResultsData);
const charts = mapTrainResultsDataToCharts(
data.trainspace.detailedTrainResultsData
);
return (
<div style={{ height: "100vh" }}>
<NavbarMain />
<Container>
<h1>{train_space_id}</h1>
<Grid container spacing={2}>
{charts.map((chart) => (
<Grid item>
<Grid item key={chart.name}>
<Paper>{chart}</Paper>
</Grid>
))}
Expand Down
104 changes: 53 additions & 51 deletions frontend/src/pages/train/metrics_to_charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ const mapMetricToAucRocPlot = (metric: AucRocChart) => {
},
...(metric.values.map((x) => ({
name: `(AUC: ${x[2]})`,
x: x[0] as number[],
y: x[1] as number[],
x: x[0],
y: x[1],
type: "scatter",
})) as Data[]),
]}
Expand All @@ -77,55 +77,57 @@ const mapMetricToAucRocPlot = (metric: AucRocChart) => {
};

const mapMetricToConfusionMatrixPlot = (metric: ConfusionMatrixChart) => {
<Plot
data={[
{
z: metric.values,
type: "heatmap",
colorscale: [
[0, "#e6f6fe"],
[1, "#003058"],
],
},
]}
layout={{
height: 525,
width: 525,
title: "Confusion Matrix (Last Epoch)",
xaxis: {
title: "Predicted",
},
yaxis: {
title: "Actual",
autorange: "reversed",
},
showlegend: true,
annotations: metric.values
.map((row, i) =>
row.map((_, j) => ({
xref: "x1" as XAxisName,
yref: "y1" as YAxisName,
x: j,
y: (i + metric.values.length - 1) % metric.values.length,
text: metric.values[
(i + metric.values.length - 1) % metric.values.length
][j].toString(),
font: {
color:
metric.values[
(i + metric.values.length - 1) % metric.values.length
][j] > 0
? "white"
: "black",
},
showarrow: false,
}))
)
.flat(),
paper_bgcolor: "rgba(0,0,0,0)",
plot_bgcolor: "rgba(0,0,0,0)",
}}
/>;
return (
<Plot
data={[
{
z: metric.values,
type: "heatmap",
colorscale: [
[0, "#e6f6fe"],
[1, "#003058"],
],
},
]}
layout={{
height: 525,
width: 525,
title: "Confusion Matrix (Last Epoch)",
xaxis: {
title: "Predicted",
},
yaxis: {
title: "Actual",
autorange: "reversed",
},
showlegend: true,
annotations: metric.values
.map((row, i) =>
row.map((_, j) => ({
xref: "x1" as XAxisName,
yref: "y1" as YAxisName,
x: j,
y: (i + metric.values.length - 1) % metric.values.length,
text: metric.values[
(i + metric.values.length - 1) % metric.values.length
][j].toString(),
font: {
color:
metric.values[
(i + metric.values.length - 1) % metric.values.length
][j] > 0
? "white"
: "black",
},
showarrow: false,
}))
)
.flat(),
paper_bgcolor: "rgba(0,0,0,0)",
plot_bgcolor: "rgba(0,0,0,0)",
}}
/>
);
};

export {
Expand Down
6 changes: 3 additions & 3 deletions training/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM condaforge/miniforge3 AS base
FROM condaforge/miniforge3:24.1.2-0 AS base

WORKDIR /usr/src/build

Expand Down Expand Up @@ -30,7 +30,7 @@ RUN mamba run --live-stream -n dlp poetry install

# we previously mounted training/ to APP_HOME
WORKDIR $APP_HOME
RUN chown -R app:app $APP_HOME
RUN chown -R app:app "$APP_HOME"
USER app

CMD mamba run --live-stream -n dlp poetry run python manage.py runserver 0.0.0.0:8000
Expand All @@ -47,7 +47,7 @@ RUN mamba run --live-stream -n dlp poetry install --without dev
WORKDIR $APP_HOME
COPY . $APP_HOME

RUN chown -R app:app $APP_HOME
RUN chown -R app:app "$APP_HOME"
USER app

CMD mamba run --live-stream -n dlp gunicorn training.wsgi:application --bind 0.0.0.0:8000
6 changes: 4 additions & 2 deletions training/training/celery_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@


@celery_app.task(name="tabularTrainTask")
def tabularTrainTask(tabularParams: dict, trainspaceId: str, uid: str):
def tabularTrainTask(tabularParams: dict, uid: str):
# implementation located in worker.py
pass


@celery_app.task(name="imageTrainTask")
def imageTrainTask(imageParams: dict, trainspaceId: str, uid: str):
def imageTrainTask(imageParams: dict, uid: str):
# implementation located in worker.py
pass
8 changes: 4 additions & 4 deletions training/training/core/celery/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM condaforge/miniforge3 AS base
FROM condaforge/miniforge3:24.1.2-0 AS base

WORKDIR /usr/src/build

Expand All @@ -17,7 +17,7 @@ RUN addgroup --system app && adduser --system --group app
# create the appropriate directories
ARG HOME=/home/app
ARG APP_HOME=/home/app/training
RUN mkdir $APP_HOME
RUN mkdir "$APP_HOME"



Expand All @@ -30,7 +30,7 @@ RUN mamba run --live-stream -n dlp poetry install

# we previously mounted training/ to APP_HOME
WORKDIR $APP_HOME
RUN chown -R app:app $APP_HOME
RUN chown -R app:app "$APP_HOME"
USER app

CMD mamba run --live-stream -n dlp celery -A training.core.celery.worker worker --loglevel=INFO
Expand All @@ -45,7 +45,7 @@ RUN mamba run --live-stream -n dlp poetry install --without dev
WORKDIR $APP_HOME
COPY . $APP_HOME

RUN chown -R app:app $APP_HOME
RUN chown -R app:app "$APP_HOME"
USER app

CMD mamba run --live-stream -n dlp celery -A training.core.celery.worker worker --loglevel=INFO
5 changes: 1 addition & 4 deletions training/training/routes/image/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
from training.core.authenticator import FirebaseAuth, Request
from training.celery_app import celery_app

import uuid

router = Router()


@router.post("", auth=FirebaseAuth())
def imageTrain(request: Request, imageParams: ImageParams):
trainspaceId = str(uuid.uuid4())
task = celery_app.send_task(
celery_app.send_task(
"imageTrainTask", [imageParams.dict(), request.auth["uid"]]
)

Expand Down
2 changes: 1 addition & 1 deletion training/training/routes/tabular/tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

@router.post("", auth=FirebaseAuth())
def tabularTrain(request: Request, tabularParams: TabularParams):
task = celery_app.send_task(
celery_app.send_task(
"tabularTrainTask", [tabularParams.dict(), request.auth["uid"]]
)

Expand Down

0 comments on commit dbfb728

Please sign in to comment.