From c700aef3288d1f91dd68473bf90e1113d408c39d Mon Sep 17 00:00:00 2001 From: John Scolaro Date: Tue, 7 Nov 2023 14:38:05 +1000 Subject: [PATCH] Images not generated due to errors --- backend/active_statistics/gui/image_tab.py | 41 +++++++++--- backend/active_statistics/gui/plot_tabs.py | 1 + backend/active_statistics/gui/table_tab.py | 1 + .../app/home/[key]/components/image/image.tsx | 14 ++--- frontend/app/home/[key]/page.tsx | 1 + frontend/app/home/layout.tsx | 63 ------------------- 6 files changed, 44 insertions(+), 77 deletions(-) diff --git a/backend/active_statistics/gui/image_tab.py b/backend/active_statistics/gui/image_tab.py index f071aa9..a2296b4 100644 --- a/backend/active_statistics/gui/image_tab.py +++ b/backend/active_statistics/gui/image_tab.py @@ -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__, } diff --git a/backend/active_statistics/gui/plot_tabs.py b/backend/active_statistics/gui/plot_tabs.py index f5dbc50..32f7329 100644 --- a/backend/active_statistics/gui/plot_tabs.py +++ b/backend/active_statistics/gui/plot_tabs.py @@ -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__, } diff --git a/backend/active_statistics/gui/table_tab.py b/backend/active_statistics/gui/table_tab.py index 1888d8a..d1ced94 100644 --- a/backend/active_statistics/gui/table_tab.py +++ b/backend/active_statistics/gui/table_tab.py @@ -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__, } diff --git a/frontend/app/home/[key]/components/image/image.tsx b/frontend/app/home/[key]/components/image/image.tsx index f1357fd..95392bd 100644 --- a/frontend/app/home/[key]/components/image/image.tsx +++ b/frontend/app/home/[key]/components/image/image.tsx @@ -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 ( <>
- {Object.keys(data).map((key: string, index: number) => ( + {data.map((image, index) => (
Image
-
{data[key][1]}
+
{image.caption}
))}
diff --git a/frontend/app/home/[key]/page.tsx b/frontend/app/home/[key]/page.tsx index 2c0820b..3719dc8 100644 --- a/frontend/app/home/[key]/page.tsx +++ b/frontend/app/home/[key]/page.tsx @@ -20,6 +20,7 @@ export default function Page({ params }: { params: { key: string } }) { url, (data) => { setData(data); + setError(data.status != "Success"); setLoaded(true); }, (err) => { diff --git a/frontend/app/home/layout.tsx b/frontend/app/home/layout.tsx index 71ef836..36adb15 100644 --- a/frontend/app/home/layout.tsx +++ b/frontend/app/home/layout.tsx @@ -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( @@ -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(() => { @@ -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, - // }); - // } - // }); } }); }