Say where the station being worked is
N1MM writes a line under its entry window with the beam heading, the heading the long way round, the distance and the sun times at the other end. This writes the same line. SunTimes is the published sunrise equation, with the usual -0.833 degrees for the sun's radius and refraction at the horizon, and it returns nothing on the days inside the polar circles when the sun does not rise or set. It agrees with published times for London at both solstices, Sydney in June and the equator at the equinox, to within three minutes. StationPath picks the position: the grid square when the contest exchanges one and it has been copied, then the call history file, then the country file, which puts the station in the middle of its country. That is close enough to point a beam with. Our own end comes from the station grid square, or from the country file for our own call. One thing to know when reading the times: they are that station's own sunrise and sunset in UTC, so for Japan the sun rises late the evening before. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -105,6 +105,9 @@
|
||||
<TextBlock Name="VerdictText" FontSize="12" Text="" />
|
||||
</Border>
|
||||
|
||||
<TextBlock Name="PathText" FontSize="11" Opacity="0.75" Margin="2,4,0,0" Text=""
|
||||
TextTrimming="CharacterEllipsis" />
|
||||
|
||||
<TextBlock Name="StatusText" FontSize="11" Opacity="0.7" Margin="2,4,0,0" Text="" />
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
|
||||
@@ -409,6 +409,8 @@ public sealed partial class EntryWindow : Window
|
||||
RunBorder.Background = Logging.IsRunning ? Verdicts.Worth : new SolidColorBrush(Color.FromArgb(0x22, 0x80, 0x80, 0x80));
|
||||
ContestText.Text = ContestLine();
|
||||
|
||||
PathText.Text = PathLine();
|
||||
|
||||
Verdict? verdict = Logging.Verdict();
|
||||
VerdictBorder.Background = Verdicts.Colour(verdict);
|
||||
VerdictText.Text = VerdictLine(verdict);
|
||||
@@ -434,6 +436,21 @@ public sealed partial class EntryWindow : Window
|
||||
$"{Logging.Log.Tally.Points} pts · {mults} · {Logging.Log.TotalScore:N0}{radio}";
|
||||
}
|
||||
|
||||
/// Where the station being worked is: the beam heading, the heading the
|
||||
/// long way round, the distance, and the sun there. N1MM writes the same
|
||||
/// line under its entry window.
|
||||
private string PathLine()
|
||||
{
|
||||
if (Logging is null || StationPath.For(Logging, DateTime.UtcNow) is not { } path)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
string sun = path.Sunrise is { } rise && path.Sunset is { } set
|
||||
? $" · SR {rise:HH:mm}Z SS {set:HH:mm}Z"
|
||||
: " · no sunrise or sunset today";
|
||||
return $"Hdg {path.Heading:0}° · LP {path.LongPath:0}° · {path.DistanceKm:N0} km{sun}";
|
||||
}
|
||||
|
||||
private string VerdictLine(Verdict? verdict)
|
||||
{
|
||||
if (Logging is null || Logging.Entry.Call.Trim().Length == 0)
|
||||
|
||||
53
src/Nonemm.Core/SunTimes.cs
Normal file
53
src/Nonemm.Core/SunTimes.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
namespace Nonemm.Core;
|
||||
|
||||
/// Sunrise and sunset for a place, in UTC. Contest operators watch them: a band
|
||||
/// opens along the grey line, and knowing when the sun rises over the station
|
||||
/// being called says whether to keep calling.
|
||||
///
|
||||
/// The equations are the published sunrise equation, with the standard
|
||||
/// −0.833° for the sun's radius and refraction at the horizon. Accurate to
|
||||
/// about a minute, which is as much as anyone reads off the screen.
|
||||
public static class SunTimes
|
||||
{
|
||||
private const double Zenith = -0.833;
|
||||
private const double Obliquity = 23.4397;
|
||||
private const double JulianDay2000 = 2451545.0;
|
||||
|
||||
/// Null when the sun does not rise or set that day, which is what happens
|
||||
/// inside the polar circles.
|
||||
public static (DateTime Rise, DateTime Set)? For(double latitude, double longitude, DateTime dayUtc)
|
||||
{
|
||||
// the day number the equation wants counts from noon, not midnight
|
||||
double day = Math.Ceiling(JulianDayOf(dayUtc) - JulianDay2000 + 0.0008);
|
||||
double noon = day - (longitude / 360.0);
|
||||
double anomaly = Radians((357.5291 + (0.98560028 * noon)) % 360.0);
|
||||
double centre = (1.9148 * Math.Sin(anomaly))
|
||||
+ (0.02 * Math.Sin(2 * anomaly))
|
||||
+ (0.0003 * Math.Sin(3 * anomaly));
|
||||
double longitudeOfSun = Radians((Degrees(anomaly) + centre + 282.9372) % 360.0);
|
||||
double transit = JulianDay2000 + noon
|
||||
+ (0.0053 * Math.Sin(anomaly))
|
||||
- (0.0069 * Math.Sin(2 * longitudeOfSun));
|
||||
double declination = Math.Asin(Math.Sin(longitudeOfSun) * Math.Sin(Radians(Obliquity)));
|
||||
|
||||
double hourAngle = (Math.Sin(Radians(Zenith)) - (Math.Sin(Radians(latitude)) * Math.Sin(declination)))
|
||||
/ (Math.Cos(Radians(latitude)) * Math.Cos(declination));
|
||||
if (hourAngle is < -1 or > 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
double half = Degrees(Math.Acos(hourAngle)) / 360.0;
|
||||
return (DateOf(transit - half), DateOf(transit + half));
|
||||
}
|
||||
|
||||
private static double JulianDayOf(DateTime utc) =>
|
||||
(utc.Date - new DateTime(2000, 1, 1, 12, 0, 0, DateTimeKind.Utc)).TotalDays + JulianDay2000;
|
||||
|
||||
private static DateTime DateOf(double julianDay) =>
|
||||
new DateTime(2000, 1, 1, 12, 0, 0, DateTimeKind.Utc)
|
||||
.AddDays(julianDay - JulianDay2000);
|
||||
|
||||
private static double Radians(double degrees) => degrees * Math.PI / 180.0;
|
||||
|
||||
private static double Degrees(double radians) => radians * 180.0 / Math.PI;
|
||||
}
|
||||
59
src/Nonemm.Session/StationPath.cs
Normal file
59
src/Nonemm.Session/StationPath.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Nonemm.Core;
|
||||
using Nonemm.Core.Country;
|
||||
|
||||
namespace Nonemm.Session;
|
||||
|
||||
/// Where the station being worked is from here: the beam heading, the heading
|
||||
/// the long way round, how far away it is, and when the sun rises and sets
|
||||
/// there. N1MM writes the same line under its entry window.
|
||||
///
|
||||
/// The position comes from the grid square if the contest exchanges one and the
|
||||
/// operator has copied it, and from the country file otherwise, which puts the
|
||||
/// station in the middle of its country. That is close enough to point a beam
|
||||
/// with, and it is what N1MM does.
|
||||
public sealed record StationPath(
|
||||
double Heading,
|
||||
double DistanceKm,
|
||||
DateTime? Sunrise,
|
||||
DateTime? Sunset)
|
||||
{
|
||||
/// The heading the long way round, which a big antenna is sometimes better
|
||||
/// off using.
|
||||
public double LongPath => (Heading + 180.0) % 360.0;
|
||||
|
||||
/// Null when there is nothing to work out a path from: no station in the
|
||||
/// callsign box, no country file, or no position for either end.
|
||||
public static StationPath? For(RadioPosition session, DateTime nowUtc)
|
||||
{
|
||||
if (Mine(session) is not { } here || Theirs(session) is not { } there)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
(DateTime Rise, DateTime Set)? sun = SunTimes.For(there.Latitude, there.Longitude, nowUtc);
|
||||
return new StationPath(
|
||||
GridSquare.Bearing(here.Latitude, here.Longitude, there.Latitude, there.Longitude),
|
||||
GridSquare.DistanceKm(here.Latitude, here.Longitude, there.Latitude, there.Longitude),
|
||||
sun?.Rise,
|
||||
sun?.Set);
|
||||
}
|
||||
|
||||
private static (double Latitude, double Longitude)? Mine(RadioPosition session) =>
|
||||
Place(session.Me.GridSquare) ?? Place(session.Session.Countries?.Find(session.Me.Callsign));
|
||||
|
||||
private static (double Latitude, double Longitude)? Theirs(RadioPosition session)
|
||||
{
|
||||
if (session.Entry.Call.Trim().Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return Place(session.Entry.ValueOf(Contests.ExchangeSlot.GridSquare))
|
||||
?? Place(session.Session.History.Find(session.Entry.Call)?.GridSquare ?? "")
|
||||
?? Place(session.Country());
|
||||
}
|
||||
|
||||
private static (double Latitude, double Longitude)? Place(string grid) =>
|
||||
GridSquare.TryParse(grid, out GridSquare square) ? (square.Latitude, square.Longitude) : null;
|
||||
|
||||
private static (double Latitude, double Longitude)? Place(CountryLookup? country) =>
|
||||
country is null ? null : (country.Latitude, country.Longitude);
|
||||
}
|
||||
Reference in New Issue
Block a user