Skip to content

Commit

Permalink
add fields for sunRiseMinSinceMidnight and sunSetMinSinceMidnight, to…
Browse files Browse the repository at this point in the history
… allow for meaningful graphs of sunrise and sunset times
  • Loading branch information
bacalj committed Aug 12, 2024
1 parent 2505a0b commit 696525c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ export const kChildCollectionAttributes = [
title: "Season",
type: "categorical",
hasToken: true
},
{
name: "sunriseMinSinceMidnight",
title: "Sunrise Minutes Since Midnight",
type: "numeric",
hasToken: true
},
{
name: "sunsetMinSinceMidnight",
title: "Sunset Minutes Since Midnight",
type: "numeric",
hasToken: true
}
];

Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useCodapData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export const useCodapData = () => {
dayLength: solarEvent.dayLength,
season: solarEvent.season,
sunlightAngle: solarEvent.sunlightAngle,
solarIntensity: solarEvent.solarIntensity
solarIntensity: solarEvent.solarIntensity,
sunriseMinSinceMidnight: solarEvent.sunriseMinSinceMidnight,
sunsetMinSinceMidnight: solarEvent.sunsetMinSinceMidnight
};

return record;
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface DaylightInfo {
season: string;
sunlightAngle: number;
solarIntensity: number;
sunriseMinSinceMidnight: number;
sunsetMinSinceMidnight: number;
}

export interface GeoNameSearchOptions {
Expand Down
9 changes: 8 additions & 1 deletion src/utils/daylight-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export function getSunrayAngleInDegrees(dayNum: number, earthTilt: number, lat:n
return degrees;
}

export function getMinutesSinceMidnight(time: Dayjs): number {
return time.hour() * 60 + time.minute();
}

export function getDayLightInfo(options: DaylightCalcOptions): DaylightInfo[] {
const { latitude, longitude, year } = options;
const results: DaylightInfo[] = [];
Expand Down Expand Up @@ -109,8 +113,11 @@ export function getDayLightInfo(options: DaylightCalcOptions): DaylightInfo[] {
dayAsInteger: currentDay.dayOfYear(),
season: getSeasonName(currentDay, latitude),
sunlightAngle: getSunrayAngleInDegrees(currentDay.dayOfYear(), kEarthTilt, latitude),
solarIntensity: getSolarNoonIntensity(currentDay.dayOfYear(), latitude)
solarIntensity: getSolarNoonIntensity(currentDay.dayOfYear(), latitude),
sunriseMinSinceMidnight: getMinutesSinceMidnight(localSunrise),
sunsetMinSinceMidnight: getMinutesSinceMidnight(localSunset)
};
console.log("| record: ", record);

Check warning on line 120 in src/utils/daylight-utils.ts

View workflow job for this annotation

GitHub Actions / Build and Run Jest Tests

Unexpected console statement

Check warning on line 120 in src/utils/daylight-utils.ts

View workflow job for this annotation

GitHub Actions / S3 Deploy

Unexpected console statement
results.push(record);
currentDay = currentDay.add(1, "day");
}
Expand Down

0 comments on commit 696525c

Please sign in to comment.