Skip to content

Instantly share code, notes, and snippets.

@martinlechner1
Created March 15, 2017 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinlechner1/28582919439f6346ef78658c984397f4 to your computer and use it in GitHub Desktop.
Save martinlechner1/28582919439f6346ef78658c984397f4 to your computer and use it in GitHub Desktop.
Some random elm code to process a large list...
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