malgleam/short_term

단기예보 조회서비스 (VilageFcstInfoService_2.0). 초단기실황, 초단기예보, 단기예보, 예보버전 4개 엔드포인트를 제공한다.

Types

초단기예보 / 단기예보 개별 아이템.

category 코드 목록:

  • 초단기: T1H(기온), RN1(강수량), SKY(하늘), UUU, VVV, REH(습도), PTY(강수형태), LGT(낙뢰), VEC(풍향), WSD(풍속)
  • 단기: POP(강수확률), PTY, PCP(1시간강수), REH, SNO(신적설), SKY, TMP(기온), TMN(최저), TMX(최고), UUU, VVV, WAV(파고), VEC, WSD

parse_sky, parse_precipitation_type, parse_float_value, parse_wind_direction 헬퍼로 값을 해석할 수 있다.

pub type ForecastItem {
  ForecastItem(
    base_date: String,
    base_time: String,
    fcst_date: String,
    fcst_time: String,
    category: String,
    fcst_value: String,
    nx: Int,
    ny: Int,
  )
}

Constructors

  • ForecastItem(
      base_date: String,
      base_time: String,
      fcst_date: String,
      fcst_time: String,
      category: String,
      fcst_value: String,
      nx: Int,
      ny: Int,
    )

    Arguments

    category

    카테고리 코드 (TMP, POP, SKY, PTY 등)

    fcst_value

    예보값 (문자열). 해석 헬퍼 함수 사용 권장.

예보버전 정보.

pub type ForecastVersion {
  ForecastVersion(
    file_type: weather.ForecastType,
    version: String,
  )
}

Constructors

초단기실황 관측 데이터. 8개 카테고리(T1H, RN1, UUU, VVV, REH, PTY, VEC, WSD)를 하나의 레코드로 집약.

pub type Observation {
  Observation(
    base_date: String,
    base_time: String,
    nx: Int,
    ny: Int,
    temperature: Float,
    rainfall: Float,
    humidity: Int,
    precipitation_type: weather.PrecipitationType,
    wind_u: Float,
    wind_v: Float,
    wind_direction: weather.WindDirection,
    wind_direction_degrees: Float,
    wind_speed: Float,
  )
}

Constructors

  • Observation(
      base_date: String,
      base_time: String,
      nx: Int,
      ny: Int,
      temperature: Float,
      rainfall: Float,
      humidity: Int,
      precipitation_type: weather.PrecipitationType,
      wind_u: Float,
      wind_v: Float,
      wind_direction: weather.WindDirection,
      wind_direction_degrees: Float,
      wind_speed: Float,
    )

    Arguments

    temperature

    기온 (℃)

    rainfall

    1시간 강수량 (mm)

    humidity

    습도 (%)

    precipitation_type

    강수형태

    wind_u

    동서바람성분 (m/s, 동쪽 양수)

    wind_v

    남북바람성분 (m/s, 북쪽 양수)

    wind_direction

    풍향 (16방위)

    wind_direction_degrees

    풍향 원본값 (도)

    wind_speed

    풍속 (m/s)

Values

pub fn decode_fcst_version(
  response: response.Response(String),
) -> Result(List(ForecastVersion), error.ApiError)

예보버전 응답을 디코딩한다.

pub fn decode_ultra_srt_fcst(
  response: response.Response(String),
) -> Result(List(ForecastItem), error.ApiError)

초단기예보 응답을 디코딩한다.

pub fn decode_ultra_srt_ncst(
  response: response.Response(String),
) -> Result(Observation, error.ApiError)

초단기실황 응답을 디코딩한다. 8개 카테고리 아이템을 하나의 Observation 레코드로 합산한다.

pub fn decode_vilage_fcst(
  response: response.Response(String),
) -> Result(List(ForecastItem), error.ApiError)

단기예보 응답을 디코딩한다.

pub fn fcst_version(
  service_key key: String,
  forecast_type ftype: weather.ForecastType,
  base_datetime datetime: String,
) -> request.Request(String)

예보버전조회 요청을 생성한다.

pub fn group_by_time(
  items: List(ForecastItem),
) -> List(#(String, String, List(ForecastItem)))

ForecastItem 리스트를 예보시각(fcst_date, fcst_time) 기준으로 그룹핑한다. 같은 시각의 여러 카테고리 아이템이 하나의 그룹으로 묶인다.

반환: List(#(fcst_date, fcst_time, List(ForecastItem)))

pub fn parse_float_value(
  item: ForecastItem,
) -> Result(Float, Nil)

ForecastItem에서 기온/수치값을 Float로 파싱한다. TMP, T1H, TMN, TMX, UUU, VVV, WSD, WAV, POP, REH 등에 사용 가능.

pub fn parse_precipitation_type(
  item: ForecastItem,
) -> Result(weather.PrecipitationType, Nil)

ForecastItem에서 강수형태를 파싱한다. category가 “PTY“일 때 사용한다.

pub fn parse_sky(item: ForecastItem) -> Result(weather.Sky, Nil)

ForecastItem에서 하늘상태를 파싱한다. category가 “SKY“일 때 사용한다.

case short_term.parse_sky(item) {
  Ok(Clear) -> "맑음"
  Ok(MostlyCloudy) -> "구름많음"
  Ok(Overcast) -> "흐림"
  Error(Nil) -> "해당 없음"
}
pub fn parse_wind_direction(
  item: ForecastItem,
) -> Result(weather.WindDirection, Nil)

ForecastItem에서 풍향(16방위)을 파싱한다. category가 “VEC“일 때 사용한다.

pub fn ultra_srt_fcst(
  service_key key: String,
  location loc: location.Location,
  base_date date: String,
  base_time time: String,
) -> request.Request(String)

초단기예보조회 요청을 생성한다.

pub fn ultra_srt_ncst(
  service_key key: String,
  location loc: location.Location,
  base_date date: String,
  base_time time: String,
) -> request.Request(String)

초단기실황조회 요청을 생성한다.

pub fn vilage_fcst(
  service_key key: String,
  location loc: location.Location,
  base_date date: String,
  base_time time: String,
) -> request.Request(String)

단기예보조회 요청을 생성한다.

pub fn with_page(
  req: request.Request(String),
  page: Int,
) -> request.Request(String)

페이지 번호를 설정한다 (기본값: 1).

pub fn with_rows(
  req: request.Request(String),
  rows: Int,
) -> request.Request(String)

한 페이지 결과 수를 설정한다 (기본값: 10).

short_term.vilage_fcst(key, location.seoul, "20240101", "0500")
|> short_term.with_rows(100)
Search Document