Skip to content

stations(ids) でも trackDistanceFromPrevious を返す #1707

Closed

Description

@TinyKitten

概要

#1705 で追加した Station.trackDistanceFromPrevious を、stations(ids) の問い合わせでも返すようにしたいです。不具合ではなく、#1705 では値を入れる問い合わせを lineStations・lineGroupStations・trainRoute に絞っていたためです。

MobileApp は、sids 形式のディープリンクで開いた経路の駅を stations(ids) で取得しています。

https://github.com/TrainLCD/MobileApp/blob/9d06fb48b4bc87982453bafd935e809bbff39307/src/hooks/useDeepLink.ts#L234-L236

この問い合わせでは線路の長さが返らないので、ディープリンクで開いた乗車は、振り返り機能で直線距離のまま記録されています(TrainLCD/MobileApp#7110)。

想定されている解決策

stations(ids) でも、ほかの3つの問い合わせと同じく attach_track_distances を呼び、隣り合う2駅のあいだの線路の長さを入れます。

/// `track_distance_from_previous` に入れる。先頭の駅は `None` のまま。
///
/// 並びが確定してから呼ぶこと (長さは並びの隣どうしで決まる)。
async fn attach_track_distances(&self, stations: &mut [Station]) -> Result<(), UseCaseError> {
if stations.len() < 2 {
return Ok(());
}
let pairs: Vec<(u32, u32)> = stations
.windows(2)
.map(|w| (w[0].station_cd as u32, w[1].station_cd as u32))
.collect();
let distances = self.station_repository.get_track_distances(&pairs).await?;
for (station, distance) in stations[1..].iter_mut().zip(distances) {
station.track_distance_from_previous = distance;
}
Ok(())
}

ただし、並びの扱いに注意が要ります。

  • attach_track_distances は、返す並びで隣り合う2駅の組に値を付けます。
  • MobileApp は stations(ids) の返す並びを当てにせず、指定した ID の順に並べ直しています。コードに「server response order is not guaranteed」というコメントがあります。
  • MobileApp が必要としているのは、指定した ID の順(経路の順)で隣り合う2駅の値です。

そのため、次のどちらかにしていただけると助かります。

  1. stations(ids) が、指定した ID の順に駅を返すようにする(そのうえで attach_track_distances を呼ぶ)。
  2. 返す並びはそのままにして、指定した ID の順で隣り合う組の値を、後ろの駅に入れる。

指定した順で隣り合う2駅が、線路のデータ上で隣り合っていない組(途中の駅を省いた ID の並びなど)は、ほかの問い合わせと同じく null で構いません。

その他

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Needs: Triage 🔍feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions