<commit_before>module Data.Entry exposing (Entry, EntryId, entryIdDecoder, decodeEntry, idToString)

import Date exposing (Date)
import Json.Encode
import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Extra
import Json.Decode.Pipeline as Pipeline exposing (decode, required)


type alias Entry =
    { id : EntryId
    , content : String
    , translation : String
    , addedAt : Date
    , location : EntryLocation
    }


type alias EntryLocation =
    { latitude : Float
    , longitude : Float
    , accuracy : Int
    }



-- SERIALISATION --


decodeEntry : Decoder Entry
decodeEntry =
    decode Entry
        |> required "id" entryIdDecoder
        |> required "content" (Decode.string)
        |> required "translation" (Decode.string)
        |> required "added_at" (Json.Decode.Extra.date)
        |> required "location" (decodeEntryLocation)


decodeEntryLocation : Decoder EntryLocation
decodeEntryLocation =
    decode EntryLocation
        |> required "latitude" (Decode.float)
        |> required "longitude" (Decode.float)
        |> required "accuracy" (Decode.int)


encodeEntry : Entry -> Json.Encode.Value
encodeEntry record =
    Json.Encode.object
        [ ( "content", Json.Encode.string <| record.content )
        , ( "translation", Json.Encode.string <| record.translation )
        , ( "added_at", Json.Encode.string <| toString record.addedAt )
        , ( "location", encodeEntryLocation <| record.location )
        ]


encodeEntryLocation : EntryLocation -> Json.Encode.Value
encodeEntryLocation record =
    Json.Encode.object
        [ ( "latitude", Json.Encode.float <| record.latitude )
        , ( "longitude", Json.Encode.float <| record.longitude )
        , ( "accuracy", Json.Encode.int <| record.accuracy )
        ]



-- IDENTIFIERS --
<commit_msg>Fix location decoder; damn floats!<commit_after>module Data.Entry exposing (..)

import Date exposing (Date)
import Json.Encode
import Json.Decode as Decode exposing (Decoder)
import Json.Decode.Extra
import Json.Decode.Pipeline as Pipeline exposing (decode, required)


type alias Entry =
    { id : EntryId
    , content : String
    , translation : String
    , addedAt : Date
    , location : EntryLocation
    }


type alias EntryLocation =
    { latitude : Float
    , longitude : Float
    , accuracy : Int
    }



-- SERIALISATION --


decodeEntry : Decoder Entry
decodeEntry =
    decode Entry
        |> required "id" entryIdDecoder
        |> required "content" (Decode.string)
        |> required "translation" (Decode.string)
        |> required "added_at" (Json.Decode.Extra.date)
        |> required "location" (decodeEntryLocation)


decodeEntryLocation : Decoder EntryLocation
decodeEntryLocation =
    decode EntryLocation
        |> required "latitude" (Json.Decode.Extra.parseFloat)
        |> required "longitude" (Json.Decode.Extra.parseFloat)
        |> required "accuracy" (Decode.int)


encodeEntry : Entry -> Json.Encode.Value
encodeEntry record =
    Json.Encode.object
        [ ( "content", Json.Encode.string <| record.content )
        , ( "translation", Json.Encode.string <| record.translation )
        , ( "added_at", Json.Encode.string <| toString record.addedAt )
        , ( "location", encodeEntryLocation <| record.location )
        ]


encodeEntryLocation : EntryLocation -> Json.Encode.Value
encodeEntryLocation record =
    Json.Encode.object
        [ ( "latitude", Json.Encode.float <| record.latitude )
        , ( "longitude", Json.Encode.float <| record.longitude )
        , ( "accuracy", Json.Encode.int <| record.accuracy )
        ]



-- IDENTIFIERS --

{'fraction_non_alphanumeric': 0.11283185840707964, 'fraction_numerical': 0.0, 'mean_word_length': 2.9187432286023833, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 1, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1157465', 'n_tokens_mistral': 1042, 'n_tokens_neox': 995, 'n_words': 245}