Skip to content

Commit

Permalink
Merge pull request #19 from danreale/midnight-fix
Browse files Browse the repository at this point in the history
Midnight fix
  • Loading branch information
danreale authored Sep 24, 2024
2 parents 38b97f5 + 74d2bd1 commit 1d67c93
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 116 deletions.
47 changes: 24 additions & 23 deletions app/data/change-data.server.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
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) {
return [
{
...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,
},
];
};
}
6 changes: 5 additions & 1 deletion app/routes/_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -37,6 +36,11 @@ export default function Index() {
Data is not updated on Saturday/Sunday*
</span>
</p>
<p className="italic">
<span className="italic">
Data is updated at 7:00 am EST Monday-Friday*
</span>
</p>
<p>
<span className="italic">
Access up to the past 1 years worth of data*
Expand Down
4 changes: 0 additions & 4 deletions app/routes/charts.$region._index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
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,
getDonorCountDatesB,
getTransplantDates,
getTransplantStatusCountDatesForRegion,
} from "~/data/db.server";
import { regionStates } from "~/data/states";

export const meta: MetaFunction = () => {
return [
Expand Down
8 changes: 2 additions & 6 deletions app/routes/charts._index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -10,7 +9,6 @@ import {
getTransplantCountDates,
getTransplantStatusCountDates,
} from "~/data/db.server";
import { regionStates } from "~/data/states";

export const meta: MetaFunction = () => {
return [
Expand Down Expand Up @@ -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");
Expand All @@ -78,7 +76,5 @@ export async function loader({}: LoaderFunctionArgs) {
statusData.push(obj);
}

// console.log(statusData);

return { bloodTypeTotals, donorData, statusData };
}
1 change: 0 additions & 1 deletion app/routes/day.$day._index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
import {
Form,
useLoaderData,
useNavigation,
useParams,
Expand Down
172 changes: 93 additions & 79 deletions app/routes/today._index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
import {
Form,
useLoaderData,
useNavigation,
useSearchParams,
Expand All @@ -15,6 +14,7 @@ import {
getCenterData,
getSettingsDates,
} from "~/data/db.server";
import { isBetweenMidnightAndSeven } from "~/utils";

const todaysDate = DateTime.now()
.setZone("America/New_York")
Expand Down Expand Up @@ -43,6 +43,8 @@ export default function Today() {
const pageLoading = transition.state !== "idle";
const [, setSearchParams] = useSearchParams();

const currentTime = DateTime.now().setZone("America/New_York");

return (
<div>
<Header />
Expand All @@ -54,6 +56,14 @@ export default function Today() {
).toLocaleString(DateTime.DATE_MED_WITH_WEEKDAY)}
</h2>

{isBetweenMidnightAndSeven() && (
<p className="text-center font-semibold grid justify-center">
<span className="italic">
The current time is {currentTime.toFormat("h:mm a")}. Please check
back after 7:00 am EST for updated data.*
</span>
</p>
)}
<p className="text-center font-semibold grid justify-center">
<span className="italic">*Based on data through</span>
<span className="italic">
Expand All @@ -71,90 +81,94 @@ export default function Today() {
</div>
)}

<div className="grid justify-center text-center py-5">
{/* <Form> */}
<div className="grid justify-center text-center">
<div className="grid justify-center text-center">
<label htmlFor="" className="font-bold py-1">
Choose Wait List Type
</label>
<select
name="waitListType"
id="waitListType"
className="text-center"
defaultValue={params.get("waitListType") || "All Types"}
onChange={(e) => {
setSearchParams((prev) => {
prev.set("waitListType", e.target.value);
return prev;
});
}}
>
<option value="Heart Status 1A">Heart Status 1A</option>
<option value="Heart Status 1B">Heart Status 1B</option>
<option value="Heart Status 2">Heart Status 2</option>
<option value="Heart Status 7 (Inactive)">
Heart Status 7 (Inactive)
</option>
<option value="All Types">All Types</option>
</select>
</div>

{/* <button
{!isBetweenMidnightAndSeven() && (
<>
<div className="grid justify-center text-center py-5">
{/* <Form> */}
<div className="grid justify-center text-center">
<div className="grid justify-center text-center">
<label htmlFor="" className="font-bold py-1">
Choose Wait List Type
</label>
<select
name="waitListType"
id="waitListType"
className="text-center"
defaultValue={params.get("waitListType") || "All Types"}
onChange={(e) => {
setSearchParams((prev) => {
prev.set("waitListType", e.target.value);
return prev;
});
}}
>
<option value="Heart Status 1A">Heart Status 1A</option>
<option value="Heart Status 1B">Heart Status 1B</option>
<option value="Heart Status 2">Heart Status 2</option>
<option value="Heart Status 7 (Inactive)">
Heart Status 7 (Inactive)
</option>
<option value="All Types">All Types</option>
</select>
</div>

{/* <button
type="submit"
className="text-blue-500 font-bold border-2 border-blue-500 rounded-xl"
>
Filter
</button> */}
</div>
{/* </Form> */}
</div>

<p className="text-center text-rose-500 font-bold pb-5">
{params.get("waitListType")}
</p>
</div>
{/* </Form> */}
</div>

{/* Render Region Change Data */}
{changeDataList.map((data, index) => (
<RegionDataV2
transplantData={data}
regionNumber={index + 1}
key={`region-${index + 1}`}
timeData={waitListTimeData.filter(
(d) => d.region === `Region ${index + 1}`
)}
/>
))}

<div className="py-5 text-center">
<div className="grid justify-center text-center space-x-2">
<label htmlFor="" className="">
Today's Center Count:{" "}
{todayCenterData[0]?.heart?.toString() || "NA"}
</label>
<label htmlFor="" className="">
Yesterday's Center Count:{" "}
{yesterdayCenterData[0]?.heart?.toString() || "NA"}
</label>
</div>
<div className="flex justify-center text-center space-x-2">
{todaysCenterChange === 0 && (
<p className="text-yellow-600 font-bold">
Center Change: ({todaysCenterChange})
</p>
)}
{todaysCenterChange > 0 && (
<p className="text-red-500 font-bold">
Center Change: ({todaysCenterChange})
</p>
)}
{todaysCenterChange < 0 && (
<p className="text-green-500 font-bold">
Center Change: ({todaysCenterChange})
</p>
)}
</div>
</div>
<p className="text-center text-rose-500 font-bold pb-5">
{params.get("waitListType")}
</p>

{/* Render Region Change Data */}
{changeDataList.map((data, index) => (
<RegionDataV2
transplantData={data}
regionNumber={index + 1}
key={`region-${index + 1}`}
timeData={waitListTimeData.filter(
(d) => d.region === `Region ${index + 1}`
)}
/>
))}

<div className="py-5 text-center">
<div className="grid justify-center text-center space-x-2">
<label htmlFor="" className="">
Today's Center Count:{" "}
{todayCenterData[0]?.heart?.toString() || "NA"}
</label>
<label htmlFor="" className="">
Yesterday's Center Count:{" "}
{yesterdayCenterData[0]?.heart?.toString() || "NA"}
</label>
</div>
<div className="flex justify-center text-center space-x-2">
{todaysCenterChange === 0 && (
<p className="text-yellow-600 font-bold">
Center Change: ({todaysCenterChange})
</p>
)}
{todaysCenterChange > 0 && (
<p className="text-red-500 font-bold">
Center Change: ({todaysCenterChange})
</p>
)}
{todaysCenterChange < 0 && (
<p className="text-green-500 font-bold">
Center Change: ({todaysCenterChange})
</p>
)}
</div>
</div>
</>
)}
</div>
);
}
Expand Down
2 changes: 0 additions & 2 deletions app/routes/yesterday._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
import {
getAllTransplantDataWithWaitListTime,
getCenterData,
getTransplantData,
} from "~/data/db.server";
import {
Form,
useLoaderData,
useNavigation,
useSearchParams,
Expand Down
Loading

0 comments on commit 1d67c93

Please sign in to comment.