-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat] 여행의 총 시간과 거리를 계산한다 (#289) #328
base: develop-backend
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
방학인데 열일하시네요.. 👍 시간과 거리 계산 로직 뚝딱 만들어주셨네요 👍👍
방학 겸 시간도 조금 널널해서 리뷰 자세하게 남겨보았습니다. 😄
확인 부탁드립니다~ 🙇
6시 30분 추가 코멘트
계산 로직과 시간 구하는 로직이 비교적 간단하여 Route 클래스가 거리와 시간을 계산하는 책임을 가지게 하는 건 어떨까요?
backend/src/main/java/dev/tripdraw/domain/trip/RouteLength.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/dev/tripdraw/domain/trip/RouteLength.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/dev/tripdraw/domain/trip/RouteLength.java
Outdated
Show resolved
Hide resolved
backend/src/main/java/dev/tripdraw/domain/trip/RouteLength.java
Outdated
Show resolved
Hide resolved
double theta = startPoint.longitude() - endPoint.longitude(); | ||
Double latitude1 = startPoint.latitude(); | ||
Double latitude2 = endPoint.latitude(); | ||
|
||
double unitDistance = sin(toRadians(latitude1)) * sin(toRadians(latitude2)) | ||
+ cos(toRadians(latitude1)) * cos(toRadians(latitude2)) * cos(toRadians(theta)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다음과 같이 메서드를 분리해보면 어떨까요?
private double calculateUnitDistance(Point startPoint, Point endPoint) {
double start = startPoint.latitude();
double end = endPoint.latitude();
double theta = start - end;
return sin(toRadians(start)) * sin(toRadians(end)) +
cos(toRadians(start)) * cos(toRadians(end)) * cos(toRadians(theta));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
추가로 double startRadians = toRadians(startPoint.latitude());
와 같이 radians로 변수 추출 한다면 조금 더 최적화 할 수 있겠네요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
theta는 경도를 사용해서 구하기 때문에 제시해주신 방법은 오류가 있네요!
저도 변수명을 많이 고민했는데,
오히려 이런 부분은 수학적인 도메인이기 때문에 startLatitude, endLatitude 보다 1,2를 뒤에 붙이는 네이밍을 선택했습니다
이 부분은 어떻게 생각하실까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
근거만 있다면 취사선택 하시면 될 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 startLatitude, endLatitude 를 더 선호합니다만, 리오의 선택에 맡기겠습니다!
} | ||
|
||
public String lengthInKm() { | ||
return String.format("%.2f" + "km", length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
km도 view의 영역 아닐까 싶은데 어떻게 생각하시나요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
근데 이 부분 그러면 어떤 단위로 날아가는지는 api에 담는 것이 좋을까요 아니면 팀 내부 회의에서 정하는 것이 좋을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
단위는 변수명으로 정해도 되고, 팀 내부 회의에서 정해도 좋을 것 같습니다~
backend/src/test/java/dev/tripdraw/domain/trip/RouteLengthTest.java
Outdated
Show resolved
Hide resolved
backend/src/test/java/dev/tripdraw/domain/trip/RouteLengthTest.java
Outdated
Show resolved
Hide resolved
backend/src/test/java/dev/tripdraw/domain/trip/TripDurationTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 관련 코멘트 재확인 부탁드립니다.
https://google.github.io/styleguide/javaguide.html#s3.3.1-wildcard-imports
import jakarta.persistence.ManyToOne; | ||
import java.time.Duration; | ||
import java.util.List; | ||
import jakarta.persistence.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 사용하지 않는 것이 저희 컨벤션입니다. 확인부탁드립니다~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
실례지만, 혹시 짜증내신 건가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다 혹시 관련한 공식에 대한 내용 자료를 어디서 볼 수 있을까요? 저도 궁금하네요!
import java.util.List; | ||
|
||
import static dev.tripdraw.exception.member.MemberExceptionType.MEMBER_NOT_FOUND; | ||
import static dev.tripdraw.exception.trip.TripExceptionType.TRIP_NOT_FOUND; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제 눈에는 이미 위에 있는데, 왜 또 보이죠..? 그림자 분신술...
private static final double AVERAGE_DISTANCE_FOR_ONE_DEGREE_DIFFERENCE_IN_LATITUDE_ON_KOREA_REGION = 111.1; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
영어 좀 치시네요 파파고 돌리셨나요?
double theta = startPoint.longitude() - endPoint.longitude(); | ||
Double latitude1 = startPoint.latitude(); | ||
Double latitude2 = endPoint.latitude(); | ||
|
||
double unitDistance = sin(toRadians(latitude1)) * sin(toRadians(latitude2)) | ||
+ cos(toRadians(latitude1)) * cos(toRadians(latitude2)) * cos(toRadians(theta)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 startLatitude, endLatitude 를 더 선호합니다만, 리오의 선택에 맡기겠습니다!
📌 관련 이슈
📁 작업 설명
여행의 총 시간을 계산합니다.
여행의 총 거리를 계산합니다.