Skip to content
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: 체감온도 계산식 구현 및 api 구현 #155

Merged
merged 6 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,4 @@ public void airKoreaTest(@RequestBody AirTestRequest request) throws URISyntaxEx
public void accuweatherTest(@RequestBody AccuweatherTestRequest request) throws URISyntaxException, IOException {
weatherService.convertLocation(request.latitude(), request.longitude());
}

@GetMapping("/converㅅ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 오타 주의해주세요 ㅡㅡ

public LocalDateTime convertTest() {

LocalDateTime specificDateTime = LocalDateTime.of(2024, 7, 5, 23, 0);
log.info("Changed : {}", specificDateTime);
return weatherService.convertLocalDateTimeToDailyWeatherTime(specificDateTime);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LocalDateTime을 문자열로 변환하는 로직이 있는데, 이를 별도의 유틸리티 클래스로 분리하면 좋을 것 같습니다!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public class DateTimeUtil {
public static String convertLocalDateTimeToString(LocalDateTime time) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmm");
return time.format(formatter);
}

public static LocalDateTime convertLocalDateTimeToDailyWeatherTime(LocalDateTime time) {
    List<Integer> scheduledHours = Arrays.asList(0, 3, 6, 9, 12, 15, 18, 21);
    int currentHour = time.getHour();
    int adjustedHour = scheduledHours.stream()
        .filter(hour -> hour <= currentHour)
        .reduce((first, second) -> second)
        .orElse(scheduledHours.get(scheduledHours.size() - 1));

    if (currentHour < scheduledHours.get(0)) {
        time = time.minusDays(1);
    }
    return time.withHour(adjustedHour).withMinute(0).withSecond(0).withNano(0);
}

}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아이디어 감사합니당 🥵

Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public void createDailyWeather(
KafkaMessage kafkaMessage = KafkaMessage.of(regionName, dailyWeather.getWindDegree());
producer.produceMessage("alarm-wind", kafkaMessage);

double windChill = calculateWindChill(Double.valueOf(tmp), Double.valueOf(wsd));
KafkaMessage kafkaMessageWindChill = KafkaMessage.of(regionName, String.valueOf(windChill));
producer.produceMessage("alarm-temp", kafkaMessageWindChill);

DailyWeather save = dailyWeatherRepository.save(dailyWeather);
log.info("[*] 하루 온도 : {}", save);

Expand Down Expand Up @@ -242,4 +246,11 @@ public List<Region> getRegionList() {
public String convertGpsToRegionName(double latitude, double longitude) {
return regionRepository.findRegionByLatAndLong(latitude, longitude).get(0).getRegionName();
}

public double calculateWindChill(double temp, double wind) {
if (temp > 10 || wind < 4.8) {
return temp;
}
return 13.12 + 0.6215 * temp - 11.37 * Math.pow(wind, 0.16) + 0.3965 * temp * Math.pow(wind, 0.16);
}
}
Loading