module ReadActual
  where

import WeatherData
import ListUtils

--To read from the input string ls the actual weather recorded
readActual :: [String] -> Actual
readActual ls =
 let date = dataForDate ls
     tempInput = tail (stripTo "(F)" ls)
     percipInput = stripTo "TODAY" tempInput
     windInput = stripTo "AVERAGE" percipInput
     skyInput = stripTo "AVERAGE" windInput in
  Actual date (readTemp tempInput) (readPrecip percipInput) 
         (readSky skyInput) (readWind windInput)

--To read the temperature recordeds after the words (F) TODAY
readTemp :: [String] -> Temp
readTemp ls =
 let max = read (head (stripTo "MAXIMUM" ls))
     min = read (head (stripTo "MINIMUM" ls))
     avg = read (head (stripTo "AVERAGE" ls)) in
  Temp avg min max
{-readTemp ["MAXIMUM","42","310","PM","54","1953","39","3","52",
          "MINIMUM","31","105","AM","-12","1949","22","9","29",       
          "AVERAGE","37"] => Temp 42 31 37  
-}

--To read the percipitation recorded after the words (IN) TODAY
readPrecip :: [String] -> Percip
readPrecip ls =
 case (head ls) of
  "T" -> Trace
  "MM" -> NoData
  n -> Amount (read n)

--readPercip ["T","0.49"] => Trace
--readPercip ["MM","0.40"] => NoData
--readPercip ["0.001","0.49"] => Amount 0.49

--To read the amount of sky cover after AVERAGE SKY COVER
readSky :: [String] -> SkyCover
readSky ("SKY":"COVER":d:r) = SkyCover (read d)

--readSky ["SKY","COVER","1.0","WEATHER"] => SkyCover 1.0

--To read the amount of wind after AVERAGE WIND SPEED
readWind :: [String] -> Wind
readWind ("WIND":"SPEED":d:r) = Wind (read d)

--readWind ["WIND","SPEED","6.6","SKY"] => Wind 6.6
