Skip to content

Commit dc0767b

Browse files
jpr5claude
andcommitted
Fix tide/current classification for subordinate stations
Subordinate stations with different high/low corrections (time offsets or level multipliers) were incorrectly classified as current stations. The simple? method checked if high/low corrections were identical, and current? returned !simple?. This incorrectly assumed that any asymmetry in corrections meant the station was a current station. In reality, subordinate tide stations can have different corrections for high vs low tides. Current stations are identified by having current-specific data: flood/ebb slack times or direction fields. Changes: - Updated current? to check for flood/ebb times or direction data - Updated tide? to simply return !current? - Removed dependency on simple? for classification - Added test for asymmetric tide stations - Updated existing test to correctly identify current stations Fixes issue where stations like Meadow Point, Shilshole Bay with high_time=0min, low_time=-1min were marked as current instead of tide. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent d3c25a0 commit dc0767b

4 files changed

Lines changed: 61 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.0.1] - 2026-01-20
9+
10+
### Fixed
11+
12+
- Fixed tide/current classification for subordinate stations with asymmetric corrections
13+
- Previously, subordinate stations with different high/low time offsets or level multipliers were incorrectly classified as current stations
14+
- Now correctly classifies stations based on presence of current-specific indicators (flood/ebb times, direction data)
15+
- Subordinate tide stations can have different corrections for high vs low tides and are now properly identified as tide stations
16+
817
## [1.0.0] - 2026-01-20
918

1019
### Added

lib/tcd/station.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,26 @@ def simple?
9090

9191
# Check if this station has current (not tide) data.
9292
# Current stations have direction fields and/or flood/ebb slack times.
93+
# These are the definitive indicators of current data.
9394
#
9495
# @return [Boolean] true if this is a current station
9596
def current?
96-
return false if reference?
97-
!simple?
97+
# Reference stations with direction data are current stations
98+
return true if min_direction || max_direction
99+
100+
# Subordinate stations with flood/ebb times are current stations
101+
return true if flood_begins || ebb_begins
102+
103+
false
98104
end
99105

100106
# Check if this station has tide (not current) data.
101-
# Tide stations are either reference stations or simple subordinates.
107+
# Tide stations do not have current-specific indicators (direction, flood/ebb).
108+
# Note: subordinate tide stations may have different high/low corrections.
102109
#
103110
# @return [Boolean] true if this is a tide station
104111
def tide?
105-
reference? || simple?
112+
!current?
106113
end
107114

108115
def to_s

lib/tcd/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module TCD
4-
VERSION = "1.0.0"
4+
VERSION = "1.0.1"
55
end

test/tcd_file_test.rb

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,49 @@ def test_simple_and_current_station_types
278278
refute simple_sub.current?
279279
end
280280

281-
# Find a non-simple subordinate (current station)
282-
current_sub = db.subordinate_stations.find { |s| !s.simple? }
281+
# Find a non-simple subordinate with different high/low corrections (tide station)
282+
# These are tide stations that happen to have asymmetric corrections
283+
tide_with_corrections = db.subordinate_stations.find { |s|
284+
!s.simple? && s.flood_begins.nil? && s.ebb_begins.nil?
285+
}
286+
if tide_with_corrections
287+
refute tide_with_corrections.simple?
288+
assert tide_with_corrections.tide?, "Station with asymmetric corrections but no current data should be tide station"
289+
refute tide_with_corrections.current?
290+
end
291+
292+
# Find an actual current station (has flood/ebb or direction data)
293+
current_sub = db.subordinate_stations.find { |s|
294+
s.flood_begins || s.ebb_begins || s.min_direction || s.max_direction
295+
}
283296
if current_sub
284-
refute current_sub.simple?
285-
assert current_sub.current?
297+
assert current_sub.current?, "Station with flood/ebb/direction data should be current station"
286298
refute current_sub.tide?
287299
end
288300
end
289301
end
302+
303+
# Regression test for tide/current classification bug
304+
# Some subordinate stations have different high/low corrections but no current data
305+
# These should be classified as tide stations, not current stations
306+
def test_subordinate_tide_with_asymmetric_corrections
307+
TCD.open(TCD_TEST_FILE) do |db|
308+
# Find subordinate stations with different time/level corrections but no current data
309+
asymmetric_tides = db.subordinate_stations.select { |s|
310+
(s.max_time_add != s.min_time_add ||
311+
s.max_level_multiply != s.min_level_multiply) &&
312+
s.flood_begins.nil? &&
313+
s.ebb_begins.nil? &&
314+
s.min_direction.nil? &&
315+
s.max_direction.nil?
316+
}
317+
318+
skip "No asymmetric tide stations in test file" if asymmetric_tides.empty?
319+
320+
sample = asymmetric_tides.first
321+
assert sample.tide?, "#{sample.name} should be tide station (no current indicators)"
322+
refute sample.current?, "#{sample.name} should not be current station"
323+
refute sample.simple?, "#{sample.name} should not be simple (has asymmetric corrections)"
324+
end
325+
end
290326
end

0 commit comments

Comments
 (0)