jxxcarlson / elm-stat / RawData

The purpose of the RawData module is to intelligently extract a data table, column headers, and metadata from a string representing data in one of several formats — csv, tab-delimited, or space-delimited. With the second, one can extract a list of Points in the xy plane from a data table.


type alias RawData =
{ metadata : List String
, columnHeaders : List String
, data : Table String 
}

A RawData value consists of metadata, columnHeaders, and data. The first two are lists of strings, while the last is a list of records, where a record is a lest of strings.

empty : RawData

Empty RawData value

get : String -> Maybe RawData

Example:

> import SampleData
> import RawData
> RawData.get SampleData.temperature
     Just {
         columnHeaders = ["Year","Value"]
       , metadata = ["Global Land and Ocean Temperature Anomalies"
                     ,"January-December 1880-2016"
                     ,"Units: Degrees Celsius"
                    ]
       , rawData = [["1880","-0.12"],["1881","-0.07"],["1882","-0.08"]
                    ["1883","-0.15"], ...

toData : Basics.Int -> Basics.Int -> RawData -> List ( Basics.Float, Basics.Float )

Extracts two columns as a tuple list, usefull when checking for correlation between data.

>RawData.toData 0 1 (Maybe.withDefault (RawData.RawData [] [] [[]]) data) == [(1880,-0.12),(1881,-0.07),(1882,-0.08),(1883,-0.15),(1884,-0.22), ...]

dataToFloatList : Maybe RawData -> Basics.Int -> List Basics.Float

Function to extract a column of values from the given data

> firstColumn = RawData.dataToFloatList data 1

minimum : (data -> Basics.Float) -> List data -> Maybe Basics.Float

Compute the minimum of a column in a list of data, e.g.,

minimum xCoord data

which computes the minimum of the x-values.

maximum : (data -> Basics.Float) -> List data -> Maybe Basics.Float

Compute the maximum of a column in a list of data, e.g.,

maximum xCoord data

which computes the maximum of the x-values.