@@ -116,6 +116,8 @@ internal class GetLastTransportTimeUseCaseImpl @Inject constructor(
116
116
117
117
// 승차지, 도착지, 고유 번호를 알아내는데 필요한 정보로만 구성된 데이터 클래스로 변환하기
118
118
private suspend fun createTransportIdRequests (itinerary : Itinerary ): List <TransportIdRequest ?> {
119
+ var cumulativeSectionTime = 0
120
+
119
121
return itinerary.routes.fold(listOf ()) { transportIdRequests, route ->
120
122
when (route) {
121
123
is WalkRoute -> transportIdRequests + null
@@ -124,6 +126,9 @@ internal class GetLastTransportTimeUseCaseImpl @Inject constructor(
124
126
val transportMoveType = TransportMoveType .getMoveTypeByName(route.mode.name)
125
127
? : return @fold transportIdRequests
126
128
129
+ val sectionTime = route.sectionTime.toInt()
130
+ cumulativeSectionTime + = sectionTime
131
+
127
132
transportIdRequests + TransportIdRequest (
128
133
transportMoveType = transportMoveType,
129
134
stationId = startStation.stationId,
@@ -136,6 +141,8 @@ internal class GetLastTransportTimeUseCaseImpl @Inject constructor(
136
141
term = NOT_YET_CALCULATED ,
137
142
destinationStation = route.end,
138
143
destinationStationId = UNKNOWN_ID ,
144
+ sectionTime = sectionTime,
145
+ cumulativeSectionTime = cumulativeSectionTime,
139
146
)
140
147
}
141
148
else -> transportIdRequests + null
@@ -232,6 +239,10 @@ internal class GetLastTransportTimeUseCaseImpl @Inject constructor(
232
239
transportMoveType = transportIdRequest.transportMoveType,
233
240
area = transportIdRequest.area,
234
241
lastTime = result,
242
+ timeToBoard = subtractSectionTimeFromLastTime(
243
+ transportIdRequest.cumulativeSectionTime,
244
+ result
245
+ ),
235
246
destinationStationName = transportIdRequest.destinationStation.name,
236
247
stationsUntilStart = stationsUntilStart.map {
237
248
TransportStation (
@@ -250,6 +261,19 @@ internal class GetLastTransportTimeUseCaseImpl @Inject constructor(
250
261
)
251
262
}
252
263
264
+ private fun subtractSectionTimeFromLastTime (sectionTime : Int , lastTime : String ): String {
265
+ val (hour, minute, second) = lastTime.split(" :" ).map { it.toInt() }
266
+ val lastTimeSecond = hour * 60 * 60 + minute * 60 + second
267
+
268
+ val realLastTimeSecond = lastTimeSecond - sectionTime
269
+
270
+ val realHour = realLastTimeSecond / 60 / 60
271
+ val realMinute = ((realLastTimeSecond / 60 ) % 60 ).toString().padStart(TIME_DIGIT , ' 0' )
272
+ val realSeconds = (realLastTimeSecond % 60 ).toString().padStart(TIME_DIGIT , ' 0' )
273
+
274
+ return " $realHour :$realMinute :$realSeconds "
275
+ }
276
+
253
277
private fun checkInnerOrOuter (
254
278
stationType : Int ,
255
279
startStationIndex : Int ,
@@ -335,10 +359,16 @@ internal class GetLastTransportTimeUseCaseImpl @Inject constructor(
335
359
lastTime + = TIME_CORRECTION_VALUE
336
360
}
337
361
362
+ val lastTimeString = lastTime.toString().chunked(2 ).joinToString(" :" )
363
+
338
364
return TransportLastTime (
339
365
transportMoveType = TransportMoveType .BUS ,
340
366
area = Area .SEOUL ,
341
- lastTime = lastTime.toString().chunked(2 ).joinToString(" :" ),
367
+ lastTime = lastTimeString,
368
+ timeToBoard = subtractSectionTimeFromLastTime(
369
+ transportIdRequest.cumulativeSectionTime,
370
+ lastTimeString
371
+ ),
342
372
destinationStationName = transportIdRequest.destinationStation.name,
343
373
stationsUntilStart = listOf (),
344
374
enableDestinationStation = listOf (),
@@ -389,6 +419,10 @@ internal class GetLastTransportTimeUseCaseImpl @Inject constructor(
389
419
area = newTransportIdRequest.area,
390
420
transportDirectionType = directionType,
391
421
lastTime = time,
422
+ timeToBoard = subtractSectionTimeFromLastTime(
423
+ newTransportIdRequest.cumulativeSectionTime,
424
+ time
425
+ ),
392
426
destinationStationName = newTransportIdRequest.destinationStation.name,
393
427
stationsUntilStart = stationsUntilStart,
394
428
enableDestinationStation = listOf (),
@@ -435,6 +469,10 @@ internal class GetLastTransportTimeUseCaseImpl @Inject constructor(
435
469
area = transportIdRequest.area,
436
470
transportDirectionType = directionType,
437
471
lastTime = time,
472
+ timeToBoard = subtractSectionTimeFromLastTime(
473
+ transportIdRequest.cumulativeSectionTime,
474
+ time
475
+ ),
438
476
destinationStationName = transportIdRequest.destinationStation.name,
439
477
stationsUntilStart = stationsUntilStart,
440
478
enableDestinationStation = listOf (),
@@ -459,10 +497,16 @@ internal class GetLastTransportTimeUseCaseImpl @Inject constructor(
459
497
lastTime + = TIME_CORRECTION_VALUE
460
498
}
461
499
500
+ val lastTimeString = lastTime.toString().chunked(2 ).joinToString(" :" )
501
+
462
502
return TransportLastTime (
463
503
transportMoveType = TransportMoveType .BUS ,
464
504
area = Area .SEOUL ,
465
- lastTime = lastTime.toString().chunked(2 ).joinToString(" :" ),
505
+ lastTime = lastTimeString,
506
+ timeToBoard = subtractSectionTimeFromLastTime(
507
+ newTransportIdRequest.cumulativeSectionTime,
508
+ lastTimeString
509
+ ),
466
510
destinationStationName = transportIdRequest.destinationStation.name,
467
511
stationsUntilStart = listOf (),
468
512
enableDestinationStation = listOf (),
@@ -683,6 +727,7 @@ internal class GetLastTransportTimeUseCaseImpl @Inject constructor(
683
727
private const val KOREA_LONGITUDE = 127
684
728
private const val KOREA_LATITUDE = 37
685
729
private const val CORRECTION_VALUE = 100_000
730
+ private const val TIME_DIGIT = 2
686
731
687
732
private const val EMPIRICAL_DISTINCTION = 20
688
733
0 commit comments