Created
March 15, 2017 19:46
-
-
Save martinlechner1/28582919439f6346ef78658c984397f4 to your computer and use it in GitHub Desktop.
Some random elm code to process a large list...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
convertRecordsTask : Task Http.Error (List (List String)) -> Task Http.Error (List TrajectoryPoint) | |
convertRecordsTask task = | |
Task.map convertRecords task | |
convertRecords : List (List String) -> List TrajectoryPoint | |
convertRecords records = | |
List.take 10000 records | |
|> List.map convertRecord | |
convertRecord : List String -> TrajectoryPoint | |
convertRecord list = | |
case list of | |
sessionId :: orderId :: longitude :: latitude :: _ :: velocity :: timeOfOccurrence :: _ -> | |
{ sessionId = Result.withDefault 0 (String.toInt sessionId) | |
, latitude = Result.withDefault 0.0 (String.toFloat latitude) | |
, longitude = Result.withDefault 0.0 (String.toFloat longitude) | |
, velocity = Result.withDefault 0.0 (String.toFloat velocity) | |
, timeOfOccurrence = Result.withDefault 0.0 (String.toFloat timeOfOccurrence) | |
} | |
_ -> | |
{ sessionId = 0 | |
, latitude = 0.0 | |
, longitude = 0.0 | |
, velocity = 0.0 | |
, timeOfOccurrence = 0.0 | |
} | |
loadTrajectories : String -> Task Http.Error (List TrajectoryPoint) | |
loadTrajectories path = | |
CsvLoader.loadAndParseCsv path | |
|> convertRecordsTask |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment