<commit_before>port module Main exposing (..)

import Array exposing (Array)
import Char
import Date exposing (Date)
import Dict exposing (Dict)
import Html exposing (Html)
import Html.Attributes as Attributes
import Html.Events as Events
import Http
import Json.Decode as Json
import Random

import Constituencies
import Country
import Float
import PetitionList exposing (PetitionList)


-- MODEL


type AppState
    = Initial
    | Loading
    | Loaded Petition
    | Failed Http.Error


type View
    = Detail
    | Summary
    | CountryData
    | ConstituencyData


type Modal
    = NoModal
    | FAQ
    | MyPetitions


type MenuState
    = Hidden
    | Expanded


type PetitionState
    = Open Date
    | Closed Date
    | Rejected Date


type alias Country =
    { name : String
    , signatures : Int
    , isUK : Bool
    , isEU : Bool
    }


countryDecoder : Json.Decoder Country
countryDecoder =
    Json.map4 Country
        (Json.field "name" Json.string)
        (Json.field "signature_count" Json.int)
        -- Look up UK membership using the country code.
        (Json.field "code" (Json.map Country.isUK Json.string))
        -- Look up EU membership using the country code.
        (Json.field "code" (Json.map Country.isEU Json.string))


type alias Constituency =
    { name : String
    -- MP can be null (due to death, resignation etc).
    , mp : Maybe String
    , signatures : Int
    , info : Constituencies.Item
    }


constituencyDecoder : Json.Decoder Constituency
constituencyDecoder =
    Json.map4 Constituency
        (Json.field "name" Json.string)
        (Json.field "mp" (Json.nullable Json.string))
        (Json.field "signature_count" Json.int)
        -- Look up constituency info using the ONS code.
        ((Json.field "ons_code" Json.string)
            |> Json.andThen constituencyItemDecoder
        )


constituencyItemDecoder : String -> Json.Decoder Constituencies.Item
constituencyItemDecoder code =
    case Constituencies.get code of
        Just item ->
            Json.succeed item
        Nothing ->
            Json.fail ("Unknown constituency " ++ code)


type alias Petition =
    { url : String
    , title : String
    , description : List String
    -- Creator is null for closed/rejected petitions.
    , creator : Maybe String
    , created : Date
    , state : PetitionState
    , signatures : Int
    , countries : List Country
    , constituencies : List Constituency
    }


petitionDecoder : Json.Decoder Petition
petitionDecoder =
    let
        andMap : Json.Decoder a -> Json.Decoder (a -> b) -> Json.Decoder b
        andMap =
            Json.map2 (|>)
    in
    Json.succeed Petition
        |> andMap (Json.at [ "links", "self" ] Json.string)<commit_msg>Extract petition id from the JSON data.<commit_after>port module Main exposing (..)

import Array exposing (Array)
import Char
import Date exposing (Date)
import Dict exposing (Dict)
import Html exposing (Html)
import Html.Attributes as Attributes
import Html.Events as Events
import Http
import Json.Decode as Json
import Random

import Constituencies
import Country
import Float
import PetitionList exposing (PetitionList)


-- MODEL


type AppState
    = Initial
    | Loading
    | Loaded Petition
    | Failed Http.Error


type View
    = Detail
    | Summary
    | CountryData
    | ConstituencyData


type Modal
    = NoModal
    | FAQ
    | MyPetitions


type MenuState
    = Hidden
    | Expanded


type PetitionState
    = Open Date
    | Closed Date
    | Rejected Date


type alias Country =
    { name : String
    , signatures : Int
    , isUK : Bool
    , isEU : Bool
    }


countryDecoder : Json.Decoder Country
countryDecoder =
    Json.map4 Country
        (Json.field "name" Json.string)
        (Json.field "signature_count" Json.int)
        -- Look up UK membership using the country code.
        (Json.field "code" (Json.map Country.isUK Json.string))
        -- Look up EU membership using the country code.
        (Json.field "code" (Json.map Country.isEU Json.string))


type alias Constituency =
    { name : String
    -- MP can be null (due to death, resignation etc).
    , mp : Maybe String
    , signatures : Int
    , info : Constituencies.Item
    }


constituencyDecoder : Json.Decoder Constituency
constituencyDecoder =
    Json.map4 Constituency
        (Json.field "name" Json.string)
        (Json.field "mp" (Json.nullable Json.string))
        (Json.field "signature_count" Json.int)
        -- Look up constituency info using the ONS code.
        ((Json.field "ons_code" Json.string)
            |> Json.andThen constituencyItemDecoder
        )


constituencyItemDecoder : String -> Json.Decoder Constituencies.Item
constituencyItemDecoder code =
    case Constituencies.get code of
        Just item ->
            Json.succeed item
        Nothing ->
            Json.fail ("Unknown constituency " ++ code)


type alias Petition =
    { id : Int
    , url : String
    , title : String
    , description : List String
    -- Creator is null for closed/rejected petitions.
    , creator : Maybe String
    , created : Date
    , state : PetitionState
    , signatures : Int
    , countries : List Country
    , constituencies : List Constituency
    }


petitionDecoder : Json.Decoder Petition
petitionDecoder =
    let
        andMap : Json.Decoder a -> Json.Decoder (a -> b) -> Json.Decoder b
        andMap =
            Json.map2 (|>)
    in
    Json.succeed Petition
        |> andMap (Json.at [ "data", "id" ] Json.int)
        |> andMap (Json.at [ "links", "self" ] Json.string)
{'fraction_non_alphanumeric': 0.08364746006103034, 'fraction_numerical': 0.0010770059235325794, 'mean_word_length': 2.4268142681426816, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4354952', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1567, 'n_words': 516}