From fb47f981ada9631607e83bfc75cad9d0278c219d Mon Sep 17 00:00:00 2001 From: Dan Reale Date: Mon, 23 Sep 2024 09:34:39 -0400 Subject: [PATCH 1/4] fix issue where user tries to access site between mightnight and seven --- app/routes/_index.tsx | 7 +- app/routes/today._index.tsx | 171 +++++++++++++++++-------------- app/routes/yesterday._index.tsx | 174 +++++++++++++++++--------------- app/utils.ts | 15 +++ 4 files changed, 209 insertions(+), 158 deletions(-) diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index 3aa31ba..f85af83 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -37,6 +37,11 @@ export default function Index() { Data is not updated on Saturday/Sunday*

+

+ + Data is updated at 7:00 am EST Monday-Friday* + +

Access up to the past 1 years worth of data* @@ -78,7 +83,7 @@ export default function Index() { } export async function loader({}: LoaderFunctionArgs) { - const dates = await getTransplantDates(); + const dates = (await getTransplantDates()).splice(2); return { dates }; } diff --git a/app/routes/today._index.tsx b/app/routes/today._index.tsx index 525d289..eec4fc7 100644 --- a/app/routes/today._index.tsx +++ b/app/routes/today._index.tsx @@ -15,6 +15,7 @@ import { getCenterData, getSettingsDates, } from "~/data/db.server"; +import { isBetweenMidnightAndSeven } from "~/utils"; const todaysDate = DateTime.now() .setZone("America/New_York") @@ -43,6 +44,8 @@ export default function Today() { const pageLoading = transition.state !== "idle"; const [, setSearchParams] = useSearchParams(); + const currentTime = DateTime.now().setZone("America/New_York"); + return (

@@ -54,6 +57,14 @@ export default function Today() { ).toLocaleString(DateTime.DATE_MED_WITH_WEEKDAY)} + {isBetweenMidnightAndSeven() && ( +

+ + The current time is {currentTime.toFormat("h:mm a")}. Please check + back after 7:00 am EST for updated data.* + +

+ )}

*Based on data through @@ -71,90 +82,94 @@ export default function Today() {

)} -
- {/*
*/} -
-
- - -
- - {/* */} -
- {/*
*/} -
- -

- {params.get("waitListType")} -

+ + {/* */} + - {/* Render Region Change Data */} - {changeDataList.map((data, index) => ( - d.region === `Region ${index + 1}` - )} - /> - ))} - -
-
- - -
-
- {todaysCenterChange === 0 && ( -

- Center Change: ({todaysCenterChange}) -

- )} - {todaysCenterChange > 0 && ( -

- Center Change: ({todaysCenterChange}) -

- )} - {todaysCenterChange < 0 && ( -

- Center Change: ({todaysCenterChange}) -

- )} -
-
+

+ {params.get("waitListType")} +

+ + {/* Render Region Change Data */} + {changeDataList.map((data, index) => ( + d.region === `Region ${index + 1}` + )} + /> + ))} + +
+
+ + +
+
+ {todaysCenterChange === 0 && ( +

+ Center Change: ({todaysCenterChange}) +

+ )} + {todaysCenterChange > 0 && ( +

+ Center Change: ({todaysCenterChange}) +

+ )} + {todaysCenterChange < 0 && ( +

+ Center Change: ({todaysCenterChange}) +

+ )} +
+
+ + )} ); } diff --git a/app/routes/yesterday._index.tsx b/app/routes/yesterday._index.tsx index 5548017..bee6d7d 100644 --- a/app/routes/yesterday._index.tsx +++ b/app/routes/yesterday._index.tsx @@ -14,6 +14,7 @@ import { DateTime } from "luxon"; import Header from "~/components/Header"; import RegionDataV2 from "~/components/RegionDataV2"; import { getChangeData } from "~/data/change-data.server"; +import { isBetweenMidnightAndSeven } from "~/utils"; const todaysDate = DateTime.now() .setZone("America/New_York") @@ -42,6 +43,8 @@ export default function Yesterday() { const pageLoading = transition.state !== "idle"; const [, setSearchParams] = useSearchParams(); + const currentTime = DateTime.now().setZone("America/New_York"); + return (
@@ -53,96 +56,109 @@ export default function Yesterday() { ).toLocaleString(DateTime.DATE_MED_WITH_WEEKDAY)} + {isBetweenMidnightAndSeven() && ( +

+ + The current time is {currentTime.toFormat("h:mm a")}. Please check + back after 7:00 am EST for updated data.* + +

+ )} + {pageLoading && (
Transplant Data Loading.....
)} -
- {/*
*/} -
-
- - -
- - {/* */} -
- {/*
*/} -
- -

- {params.get("waitListType")} -

- - {/* Render Region Change Data */} - {changeDataList.map((data, index) => ( - d.region === `Region ${index + 1}` - )} - /> - ))} - -
-
- - -
-
- {todaysCenterChange === 0 && ( -

- Center Change: ({todaysCenterChange}) -

- )} - {todaysCenterChange > 0 && ( -

- Center Change: ({todaysCenterChange}) -

- )} - {todaysCenterChange < 0 && ( -

- Center Change: ({todaysCenterChange}) -

- )} -
-
+
+ {/* */} + + +

+ {params.get("waitListType")} +

+ + {/* Render Region Change Data */} + {changeDataList.map((data, index) => ( + d.region === `Region ${index + 1}` + )} + /> + ))} + +
+
+ + +
+
+ {todaysCenterChange === 0 && ( +

+ Center Change: ({todaysCenterChange}) +

+ )} + {todaysCenterChange > 0 && ( +

+ Center Change: ({todaysCenterChange}) +

+ )} + {todaysCenterChange < 0 && ( +

+ Center Change: ({todaysCenterChange}) +

+ )} +
+
+ + )} ); } diff --git a/app/utils.ts b/app/utils.ts index f3cd1b0..82e999a 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -1,3 +1,5 @@ +import { DateTime } from "luxon"; + export function SortByRegionNumber(data) { return data.sort((a, b) => { let aNumber = Number(a.region.split(" ")[1]); @@ -29,3 +31,16 @@ export type TimeBreakdown = { blood_type_b: number | null | undefined; blood_type_o: number | null | undefined; }; + +export const isBetweenMidnightAndSeven = () => { + // Get the current time in the US Eastern timezone + const currentTime = DateTime.now().setZone("America/New_York"); + + // Define the start and end times + const start = currentTime.startOf("day"); // 12:00 AM + const end = start.plus({ hours: 7 }); // 7:00 AM + + // Check if the current time is between 12:00 AM and 7:00 AM + const isBetween = currentTime >= start && currentTime < end; + return isBetween; +}; From f952faf0c6e3e390c02f065ccce5a42e53baeabe Mon Sep 17 00:00:00 2001 From: Dan Reale Date: Tue, 24 Sep 2024 05:40:03 -0400 Subject: [PATCH 2/4] fixed bug --- app/data/change-data.server.ts | 47 +++++++++++++++++----------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/app/data/change-data.server.ts b/app/data/change-data.server.ts index 1145f54..770017a 100644 --- a/app/data/change-data.server.ts +++ b/app/data/change-data.server.ts @@ -1,26 +1,30 @@ -import { SortByRegionNumber } from "~/utils" -import { getAllTransplantData } from "./db.server" +import { SortByRegionNumber } from "~/utils"; +import { getAllTransplantData } from "./db.server"; // current is the initial date, previous is the day before, changing the terminology to apply to the other routes -export async function getChangeData(currentDate: string, previousDate: string, waitListType: string) { +export async function getChangeData( + currentDate: string, + previousDate: string, + waitListType: string +) { const [currentData, previousData] = await Promise.all([ getAllTransplantData(currentDate, waitListType), - getAllTransplantData(previousDate, waitListType) - ]) + getAllTransplantData(previousDate, waitListType), + ]); - const sortedCurrentData = SortByRegionNumber(currentData) - const sortedPreviousData = SortByRegionNumber(previousData) + const sortedCurrentData = SortByRegionNumber(currentData); + const sortedPreviousData = SortByRegionNumber(previousData); - const N_REGIONS = 11 - let changeDataList = [] + const N_REGIONS = 11; + let changeDataList = []; // Compare current and previous date for (let i = 0; i < N_REGIONS; i++) { - let change = changeData(sortedCurrentData[i], sortedPreviousData[i]) - changeDataList.push(change) + let change = changeData(sortedCurrentData[i], sortedPreviousData[i]); + changeDataList.push(change); } - return changeDataList + return changeDataList; } export function changeData(regionDataToday: any, regionDataYesterday: any) { @@ -28,20 +32,17 @@ export function changeData(regionDataToday: any, regionDataYesterday: any) { { ...regionDataToday, blood_type_a_change: - regionDataToday.blood_type_a - - regionDataYesterday?.blood_type_a || 0, + regionDataToday?.blood_type_a - regionDataYesterday?.blood_type_a || 0, blood_type_b_change: - regionDataToday.blood_type_b - - regionDataYesterday?.blood_type_b || 0, + regionDataToday?.blood_type_b - regionDataYesterday?.blood_type_b || 0, blood_type_o_change: - regionDataToday.blood_type_o - - regionDataYesterday?.blood_type_o || 0, + regionDataToday?.blood_type_o - regionDataYesterday?.blood_type_o || 0, blood_type_ab_change: - regionDataToday.blood_type_ab - - regionDataYesterday?.blood_type_ab || 0, + regionDataToday?.blood_type_ab - regionDataYesterday?.blood_type_ab || + 0, blood_type_all_change: - regionDataToday.blood_type_all - - regionDataYesterday?.blood_type_all || 0, + regionDataToday?.blood_type_all - regionDataYesterday?.blood_type_all || + 0, }, ]; -}; \ No newline at end of file +} From 0371ffa7a40f416a358375b4d4df0f8a50e0b38a Mon Sep 17 00:00:00 2001 From: Dan Reale Date: Tue, 24 Sep 2024 05:49:05 -0400 Subject: [PATCH 3/4] fixed stuff --- app/routes/_index.tsx | 3 +- app/routes/charts.$region._index.tsx | 4 - app/routes/charts._index.tsx | 8 +- app/routes/day.$day._index.tsx | 1 - app/routes/today._index.tsx | 1 - app/routes/yesterday._index.tsx | 174 ++++++++++++--------------- 6 files changed, 82 insertions(+), 109 deletions(-) diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index f85af83..869ccac 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -5,7 +5,6 @@ import Header from "~/components/Header"; import RegionStates from "~/components/RegionStates"; import { getTransplantDates } from "~/data/db.server"; -import { regionStates } from "~/data/states"; import { range } from "~/utils"; export const meta: MetaFunction = () => { @@ -83,7 +82,7 @@ export default function Index() { } export async function loader({}: LoaderFunctionArgs) { - const dates = (await getTransplantDates()).splice(2); + const dates = await getTransplantDates(); return { dates }; } diff --git a/app/routes/charts.$region._index.tsx b/app/routes/charts.$region._index.tsx index 6731681..f151a49 100644 --- a/app/routes/charts.$region._index.tsx +++ b/app/routes/charts.$region._index.tsx @@ -1,13 +1,10 @@ import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node"; import { useLoaderData, useNavigation, useParams } from "@remix-run/react"; import CenterDataChart from "~/components/CenterDataChart"; -import DonorDataChart from "~/components/DonorChart"; import Header from "~/components/Header"; import RegionChartV2 from "~/components/RegionChartV2"; -import RegionChart from "~/components/RegionChartV2"; import RegionChartV3 from "~/components/RegionChartV3"; import RegionStates from "~/components/RegionStates"; -import TransplantChart from "~/components/TransplantChart"; import { bloodTypeTotalsChart, centerDataTotalsChart, @@ -15,7 +12,6 @@ import { getTransplantDates, getTransplantStatusCountDatesForRegion, } from "~/data/db.server"; -import { regionStates } from "~/data/states"; export const meta: MetaFunction = () => { return [ diff --git a/app/routes/charts._index.tsx b/app/routes/charts._index.tsx index e9d6a9b..2a9f6b2 100644 --- a/app/routes/charts._index.tsx +++ b/app/routes/charts._index.tsx @@ -1,6 +1,5 @@ import { LoaderFunctionArgs, MetaFunction } from "@remix-run/node"; -import { Link, useLoaderData, useNavigation } from "@remix-run/react"; -import DonorDataChart from "~/components/DonorChart"; +import { useLoaderData, useNavigation } from "@remix-run/react"; import Header from "~/components/Header"; import RegionChartV2 from "~/components/RegionChartV2"; @@ -10,7 +9,6 @@ import { getTransplantCountDates, getTransplantStatusCountDates, } from "~/data/db.server"; -import { regionStates } from "~/data/states"; export const meta: MetaFunction = () => { return [ @@ -51,7 +49,7 @@ export default function Index() { export async function loader({}: LoaderFunctionArgs) { const bloodTypeTotals = await getTransplantCountDates(); - // console.log(bloodTypeTotals); + const donorData = await getDonorCountDatesB(); const heartStatus1A = await getTransplantStatusCountDates("Heart Status 1A"); const heartStatus1B = await getTransplantStatusCountDates("Heart Status 1B"); @@ -78,7 +76,5 @@ export async function loader({}: LoaderFunctionArgs) { statusData.push(obj); } - // console.log(statusData); - return { bloodTypeTotals, donorData, statusData }; } diff --git a/app/routes/day.$day._index.tsx b/app/routes/day.$day._index.tsx index e67fb14..85b04b6 100644 --- a/app/routes/day.$day._index.tsx +++ b/app/routes/day.$day._index.tsx @@ -1,6 +1,5 @@ import { LoaderFunctionArgs, MetaFunction } from "@remix-run/node"; import { - Form, useLoaderData, useNavigation, useParams, diff --git a/app/routes/today._index.tsx b/app/routes/today._index.tsx index eec4fc7..87ae07d 100644 --- a/app/routes/today._index.tsx +++ b/app/routes/today._index.tsx @@ -1,6 +1,5 @@ import { LoaderFunctionArgs, MetaFunction } from "@remix-run/node"; import { - Form, useLoaderData, useNavigation, useSearchParams, diff --git a/app/routes/yesterday._index.tsx b/app/routes/yesterday._index.tsx index bee6d7d..5f24e32 100644 --- a/app/routes/yesterday._index.tsx +++ b/app/routes/yesterday._index.tsx @@ -2,10 +2,8 @@ import { LoaderFunctionArgs, MetaFunction } from "@remix-run/node"; import { getAllTransplantDataWithWaitListTime, getCenterData, - getTransplantData, } from "~/data/db.server"; import { - Form, useLoaderData, useNavigation, useSearchParams, @@ -14,7 +12,6 @@ import { DateTime } from "luxon"; import Header from "~/components/Header"; import RegionDataV2 from "~/components/RegionDataV2"; import { getChangeData } from "~/data/change-data.server"; -import { isBetweenMidnightAndSeven } from "~/utils"; const todaysDate = DateTime.now() .setZone("America/New_York") @@ -56,109 +53,96 @@ export default function Yesterday() { ).toLocaleString(DateTime.DATE_MED_WITH_WEEKDAY)} - {isBetweenMidnightAndSeven() && ( -

- - The current time is {currentTime.toFormat("h:mm a")}. Please check - back after 7:00 am EST for updated data.* - -

- )} - {pageLoading && (
Transplant Data Loading.....
)} - {!isBetweenMidnightAndSeven() && ( - <> -
- {/*
*/} -
-
- - -
- - {/* */} -
- {/*
*/} -
- -

- {params.get("waitListType")} -

- - {/* Render Region Change Data */} - {changeDataList.map((data, index) => ( - d.region === `Region ${index + 1}` - )} - /> - ))} - -
-
- - -
-
- {todaysCenterChange === 0 && ( -

- Center Change: ({todaysCenterChange}) -

- )} - {todaysCenterChange > 0 && ( -

- Center Change: ({todaysCenterChange}) -

- )} - {todaysCenterChange < 0 && ( -

- Center Change: ({todaysCenterChange}) -

- )} -
-
- - )} + + {/* */} + + +

+ {params.get("waitListType")} +

+ + {/* Render Region Change Data */} + {changeDataList.map((data, index) => ( + d.region === `Region ${index + 1}` + )} + /> + ))} + +
+
+ + +
+
+ {todaysCenterChange === 0 && ( +

+ Center Change: ({todaysCenterChange}) +

+ )} + {todaysCenterChange > 0 && ( +

+ Center Change: ({todaysCenterChange}) +

+ )} + {todaysCenterChange < 0 && ( +

+ Center Change: ({todaysCenterChange}) +

+ )} +
+
); } From 74d2bd187a5e5407dd3293a1e356b44776096644 Mon Sep 17 00:00:00 2001 From: Dan Reale Date: Tue, 24 Sep 2024 05:52:57 -0400 Subject: [PATCH 4/4] removed var --- app/routes/yesterday._index.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/routes/yesterday._index.tsx b/app/routes/yesterday._index.tsx index 5f24e32..7840bc3 100644 --- a/app/routes/yesterday._index.tsx +++ b/app/routes/yesterday._index.tsx @@ -40,8 +40,6 @@ export default function Yesterday() { const pageLoading = transition.state !== "idle"; const [, setSearchParams] = useSearchParams(); - const currentTime = DateTime.now().setZone("America/New_York"); - return (