Skip to content

Commit

Permalink
cleanup warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
bacalj committed Aug 13, 2024
1 parent 45c9c17 commit 30b152a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
31 changes: 16 additions & 15 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const App: React.FC = () => {
const [activeTab, setActiveTab] = useState<"location" | "simulation">("location");
const [latitude, setLatitude] = useState("");
const [longitude, setLongitude] = useState("");
const [dayOfYear, setDayOfYear] = useState(171);
const [dayOfYear, /*setDayOfYear */] = useState(171);
const [locations, setLocations] = useState<ILocation[]>([]);
const [locationSearch, setLocationSearch] = useState<string>("");
const [selectedAttrs, setSelectedAttributes] = useState<string[]>(kDefaultOnAttributes);
Expand All @@ -34,20 +34,21 @@ export const App: React.FC = () => {
// of the sync process, when user select a row in CODAP and we want to update the day in the simulation tab.
};

const handleCaseSelectionInCodap = (_latitude: string, _longitude: string, day: number) => {
// Option 1. Update as much of the plugin state as we can when user selects a case in CODAP. I think this might
// be too much, as it'll clear all the inputs in all the tabs and the user will have to re-enter everything
// if they were in the middle of something.
// setDayOfYear(day);
// setLatitude(_latitude);
// setLongitude(_longitude);
// ...OR...
// Option 2. Update only the day of the year, as that's reasonably unobtrusive and useful. We can first check
// if user actually selected the case from the same location, and only then update the day of the year.
if (latitude === _latitude && longitude === _longitude) {
setDayOfYear(day);
}
}
// TODO: Handle case selection - sync sim tab with CODAP selection
// const handleCaseSelectionInCodap = (_latitude: string, _longitude: string, day: number) => {
// // Option 1. Update as much of the plugin state as we can when user selects a case in CODAP. I think this might
// // be too much, as it'll clear all the inputs in all the tabs and the user will have to re-enter everything
// // if they were in the middle of something.
// // setDayOfYear(day);
// // setLatitude(_latitude);
// // setLongitude(_longitude);
// // ...OR...
// // Option 2. Update only the day of the year, as that's reasonably unobtrusive and useful. We can first check
// // if user actually selected the case from the same location, and only then update the day of the year.
// if (latitude === _latitude && longitude === _longitude) {
// setDayOfYear(day);
// }
// }

const { getUniqueLocationsInCodapData } = useCodapData();
// Store a ref to getUniqueLocationsInCodapData so we can call inside useEffect without triggering unnecessary re-runs
Expand Down
17 changes: 9 additions & 8 deletions src/utils/daylight-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ function getDayLength(sunrise: Dayjs, sunset: Dayjs): number {
return dayLength;
}

function hasDST(latitude: number, longitude: number, year: number): boolean {
const timeZone = tzlookup(latitude, longitude);
const winterDate = dayjs.tz(`${year}-01-01`, timeZone);
const summerDate = dayjs.tz(`${year}-07-01`, timeZone);
// Uncomment this to use in the DST adjustment commented out below
// function hasDST(latitude: number, longitude: number, year: number): boolean {
// const timeZone = tzlookup(latitude, longitude);
// const winterDate = dayjs.tz(`${year}-01-01`, timeZone);
// const summerDate = dayjs.tz(`${year}-07-01`, timeZone);

return winterDate.utcOffset() !== summerDate.utcOffset();
}
// return winterDate.utcOffset() !== summerDate.utcOffset();
// }

function getSeasonName(dayJsDay: Dayjs, latitude: number): string {
const year = dayJsDay.year();
Expand Down Expand Up @@ -73,7 +74,7 @@ function getSeasonName(dayJsDay: Dayjs, latitude: number): string {
return season;
}

export function getSolarNoonIntensity(dayNum: number, latitude: number): number | null {
export function getSolarNoonIntensity(dayNum: number, latitude: number): number {
const solarConstant = 1361;
const latitudeRad = latitude * Math.PI / 180;
const declination = 23.45 * Math.sin((360/365) * (dayNum - 81) * Math.PI / 180);
Expand All @@ -87,7 +88,7 @@ export function getSolarNoonIntensity(dayNum: number, latitude: number): number
return solarNoonIntensity;
}

export function getSunrayAngleInDegrees(dayNum: number, earthTilt: number, lat:number): number | null {
export function getSunrayAngleInDegrees(dayNum: number, earthTilt: number, lat:number): number {
const tiltAxisZRadians = 2 * Math.PI * (dayNum - kBasicSummerSolstice) / 365;
const orbitalTiltDegrees = earthTilt ? earthTilt : 0;
const effectiveTiltDegrees = -Math.cos(tiltAxisZRadians) * orbitalTiltDegrees;
Expand Down

0 comments on commit 30b152a

Please sign in to comment.