Skip to content

Commit

Permalink
Images not generated due to errors (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnScolaro authored Nov 16, 2023
1 parent 2ce9d69 commit bafa406
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 77 deletions.
41 changes: 34 additions & 7 deletions backend/active_statistics/gui/image_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,50 @@ def get_plot_function(tab: ImageTab):
def plot_function() -> Response:
athlete_id = int(session["athlete_id"])

response_data: dict[str, list[str]] = defaultdict(list)
response_data: list[dict[str, str]] = []

if evm.use_s3():
tab_images = get_pre_signed_urls_for_tab_images(
athlete_id, tab.get_key()
)
tab_captions = get_captions_for_tab_images(
athlete_id, tab.get_key()
)

if not tab_images:
return make_response(
jsonify(
{
"key": tab.get_key(),
"status": "Failure",
"tab_data": [],
"type": self.__class__.__name__,
}
)
)

try:
tab_captions = get_captions_for_tab_images(
athlete_id, tab.get_key()
)
except:
return make_response(
jsonify(
{
"key": tab.get_key(),
"status": "Failure",
"tab_data": [],
"type": self.__class__.__name__,
}
)
)

for k, v in tab_images.items():
response_data[k].append(v)
for k, v in tab_captions.items():
response_data[k].append(v)
response_data.append(
{"presigned_url": v, "caption": tab_captions[k]}
)

# Add the key to the response so that the frontend knows which tab the data is for.
response_json = {
"key": tab.get_key(),
"status": "Success",
"tab_data": response_data,
"type": self.__class__.__name__,
}
Expand Down
1 change: 1 addition & 0 deletions backend/active_statistics/gui/plot_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def plot_function() -> Response:
# Add the key to the response so that the frontend knows which tab the data is for.
response_json = {
"key": tab.get_key(),
"status": "Success",
"tab_data": chart_dict,
"type": self.__class__.__name__,
}
Expand Down
1 change: 1 addition & 0 deletions backend/active_statistics/gui/table_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def data_function() -> Response:
# Add the key to the response so that the frontend knows which tab the data is for.
response_json = {
"key": tab.get_key(),
"status": "Success",
"tab_data": table_data,
"type": self.__class__.__name__,
}
Expand Down
14 changes: 7 additions & 7 deletions frontend/app/home/[key]/components/image/image.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
interface Data {
[key: string]: string[];
interface ImageData {
presigned_url: string;
caption: string;
}

export default function ImagePage({ data }: { data: Data }) {
console.log(data);
export default function ImagePage({ data }: { data: ImageData[] }) {
return (
<>
<div className="flex flex-col gap-2">
{Object.keys(data).map((key: string, index: number) => (
{data.map((image, index) => (
<div key={index} className="p-2 border-2 border-green-500 rounded-lg">
<div className="flex justify-center">
<img
src={data[key][0]}
src={image.presigned_url}
alt="Image"
className="h-auto w-auto max-h-[780px]"
/>
</div>
<div className="text-center text-sm">{data[key][1]}</div>
<div className="text-center text-sm">{image.caption}</div>
</div>
))}
</div>
Expand Down
1 change: 1 addition & 0 deletions frontend/app/home/[key]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function Page({ params }: { params: { key: string } }) {
url,
(data) => {
setData(data);
setError(data.status != "Success");
setLoaded(true);
},
(err) => {
Expand Down
63 changes: 0 additions & 63 deletions frontend/app/home/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,6 @@ export default function HomeLayout({ children }: { children: React.ReactNode })
},
router
);
// fetch(url)
// .then((response) => {
// if (response.status == 401) {
// console.log("ohh shit whadup boi1");
// router.push("/");
// }
// return response.json();
// })
// .then((data) => {
// updateDisabledSidebarSteps(type, data.status, setDisabledSidebarSteps);
// setDataStatus(data);
// if (!data.stop_polling) {
// // If stopPolling is not true, poll again after 2 seconds
// setTimeout(() => pollDataStatus(type, callback), 2000);
// } else {
// if (callback) {
// callback(data.status);
// }
// }
// })
// .catch((err) => {
// console.log("oopsie, an error happened.");
// });
}

function updateDisabledSidebarSteps(
Expand Down Expand Up @@ -162,22 +139,6 @@ export default function HomeLayout({ children }: { children: React.ReactNode })
},
router
);
// fetch("/api/paid")
// .then((response) => {
// if (response.status == 401) {
// console.log("ohh shit whadup boi2");
// router.push("/");
// }
// return response.json();
// })
// .then((data) => {
// setPaidUser(data);
// })
// .catch((err) => {
// console.log(
// "An unhandled error occurred while fetching whether or not the user is paid."
// );
// });
}

useEffect(() => {
Expand Down Expand Up @@ -215,30 +176,6 @@ export default function HomeLayout({ children }: { children: React.ReactNode })
() => {},
router
);
// fetch(url)
// .then((response) => {
// if (response.status == 401) {
// console.log("ohh shit whadup boi3");
// router.push("/");
// }
// return response.json();
// })
// .then((data) => {
// if (data.refresh_accepted) {
// setSummaryDataStatus({
// message: "Attempting to refresh data.",
// status: "",
// stopPolling: false,
// });
// pollDataStatus("summary");
// } else {
// setSummaryDataStatus({
// message: data.message,
// status: "too_recent",
// stopPolling: true,
// });
// }
// });
}
});
}
Expand Down

0 comments on commit bafa406

Please sign in to comment.