> module Project5DataConversion > (unpack, display) > where > import IOutilities(isEmptyLine, > realFloatFromString, standardFormatRealFloat) parse table file into its components: [(year1, rJan1, rFeb1, ... rDec1), (year2, rJan2, rFeb2, ... rDec2), ... (year20, rJan20, rFeb20, ... rDec20)] strings^^^ ^^^^^^^^^^^^^^^^^^^^^^numbers > unpack :: (RealFloat r, Read r) => > String -> ([(String, [r])], [(String, [r])]) > unpack tableFile = (preArmisticeData, postArmisticeData) > where > dataLines = > (drop 1 . dropWhile(not . isEmptyLine) . lines) tableFile > dataByYear = (map yearAndRainfall . map words) dataLines > (preArmisticeData, postArmisticeData) = > break ((> "1918") . fst) dataByYear unpack one line data file and convert rainfall numerals to numbers > yearAndRainfall:: (RealFloat r, Read r) => > [String] -> (String, [r]) > yearAndRainfall(year : rainfallAsStrings) = > (year, map realFloatFromString rainfallAsStrings) build display lines from selected data > display :: (RealFloat r, Show r) => > (String, [(String, r)]) -> [String] > display(postArmisticeYear, closestPreArmisticeYears) = > ["Closest Three Matches From Pre-armistice Years to " ++ > postArmisticeYear ++ " Rainfall:"] ++ > map displayYearAndResemblance closestPreArmisticeYears make string for display of (year, resemblance) pair > displayYearAndResemblance :: RealFloat r => (String, r) -> String > displayYearAndResemblance(year, resemblance) = > " " ++ year ++ > " (" ++ standardFormatRealFloat 2 resemblance ++ ")"