From 9afce0fef2ab6da30eab35559097e99cc8fbab2b Mon Sep 17 00:00:00 2001 From: Jean-Christophe Jameux Date: Fri, 10 Dec 2021 07:37:43 +0100 Subject: [PATCH] Export des notes sous forme de tableau OrgMode --- elm-stuff/0.19.1/CalculateurDeNotes.elmi | Bin 13099 -> 15118 bytes elm-stuff/0.19.1/CalculateurDeNotes.elmo | Bin 23065 -> 26447 bytes elm-stuff/0.19.1/d.dat | Bin 3422 -> 3283 bytes elm-stuff/0.19.1/i.dat | Bin 295013 -> 296416 bytes elm.json | 2 +- src/CalculateurDeNotes.elm | 805 +++++++----- src/Fraction.elm | 262 ++-- src/GenerateurDeProblemes.elm | 1467 ++++++++++++---------- src/ParserMaths.elm | 64 +- src/Test.elm | 45 +- 10 files changed, 1558 insertions(+), 1087 deletions(-) diff --git a/elm-stuff/0.19.1/CalculateurDeNotes.elmi b/elm-stuff/0.19.1/CalculateurDeNotes.elmi index f69a7fb974d3686f15e2593e6b7fa4a95c98a81a..7404f5c9a0174a7f273703041bb4da364e236463 100644 GIT binary patch delta 891 zcmZ3T)>k$`j9Hd1X>uZ?=tjK;W;WL3jKti6$?>u}lQ*-rZC=ML%EHRVotK|Gd7`S) zefu^GX<)CM&W@u(RX=UB$pUIgu-Qa;=`2AT;5@ vRWXB9adQ-<7Ubs@rxr7?On#_pGWoor-X#4v>KZuN$KWvaOx%3lFoqETg25Xl delta 423 zcmeAxTb(vRj9Hp5X>uZ?=tjK;=FMp=qAZLolN+TQCL8b^-pt1p#0cSTHsCR4;$~t@ zWXmhfO-e0dnAj_!#0cf^=O&hxC1w_<2Bj9{=M|?iFu-Ic@8>h+fN?f+^K&Ci&z(F~ zs1a^g?q)%;8fFA{@&vic$pP}>NFvi^_8{>l$X!S9HZM^KVuEuIPv+wi**sUp2w5me z<2i}~m&pp+pAjOPm+7iNy$bYs?qqg@6_aNh$uKfc-eGi+g8>4VH}5j`W8`3A$;&TE tWni9s(X5i2qX^>XVg{zki2^2*Z(8Y1b~TG5tmuLHVSBmkqbgQBg0mG!{LYpKP;^o!lTv{sIiVEE~G%K_yOC?(3 zB)LpIO#Kn|ui*C&kRdUD69?ZoR=*&BkZ$`t&C~3)w6a2#ghpLrb#4Lh@b4Ygj@LkA7&f?QhjGV)g{|IJAdfcp=H)WK9Sm&vS(S#?lZfuAAB&OkdJ#|QX zA-%em&XwrJCe+B(0RVk-W>3-d%M?x36jgWnKZ>f#U#Tc`_7#dW9e94I>Z27OhAM=? z!)~vMrPuMS*N^W;AH#9ciJ!v*#_>C>p?xN< zMD7^Fo%Z3|(Ft`iy4}i}80@r%FgofZoVqaj3E?>{NFA6M?@{@&>jZaC2l4cR7wh9K zR^vqLkOvc9b$xt+uw6XTll^a)XuiN*&E=_eT6;yNA(UEVDXGv>3A2J9H^h*w zv99s#)FA$u86W}8%TBz%DB{6M3+BysWRqWln+!S{7ig5&h`aEs%Z|uwS5-t-7~_Q;Jf_&DTD* z`kc`M9Son(tw^*Hi>*W-?j_7DsZ`C*m#=L?IdxP+i#&j+vGFz%1%v#abA|_X?MBj> zD%d&U!p8~E8DAx_TG-uGrq<9kyG$#WC7V!7t*oq2VXl_YLROZt>9RqK zcU-<6z8(SIQjJnPPuFNkpXcyi!s9uB1CM9BaoN>Hg0QDTS~3@hK&4t`s%! zadDQuloI147nY+^%F#(K4#F~d^?JR-tM}gh9qpY^CPW&p4Gw&o<(;iV5^zlQs<^}w zaXrbBf*wyXwWt6AyX4~^^h&sBXy87fuYzZll}fU}qSnFRYQ{s`DiQW;-TbuuNyJx0 z51PpctE&@{`YIf0EqTiDnk(UVwIZuX7;Du2RqnOo(Y5*O;r8I5PDH|~@SOX?M8&Xr zHH0T6WCvt2@cV&n%FCQLLqd_F>bM@S<`cdk84Gn$?rg%PUHYAu8@ffn=)ih^8D54R z+%@tlK~<}f8*M>zxP;FJ=Lt6+4QpW&otY=wVw(A_26-`(UXH|)EKoQRIcBRVk@WN;TZ#{*(hISOp8AUy-3#bDE zgePBT3<+j+EGkN@WOpjcFE36lVt36+%}vcK;f2zAo_PhOCA@B#IjMRs`Q>>z`H3kk z9woUsYypWyK=sVQsUcr0D9@Y3XSj0IdUcd(02p2#dZ*@HQU z!(p@DuD;t@mnQFFPMuuD5|YH>R+N}rl9`_eHlM{Ov$zCm2{*(p-^7xPVz!{fyp;T0 z9tfr9T2WGz$PMLyw16DM7F<%4nU@Z87u@p6*IDv77>;za?Q;Qld7}DI}U<*#oNlh++OKvXZc*z0)&@On! delta 399 zcmcaCc~8oMk&yucI1dO2W#q9%os3|B2{9KJB|~Ll)G{c8b)rR$pu(96=C=cdk3~QQ zg(g?BgiN+!=CEb)D9O!Xcg;!7P0cIeh0=PSc?G2<%)zN8td2!RiIr>tiABY!MKIf7 zRxnJ?Va(uIAS&9HTd8_+@*Tzk>1wE4HK$uqVsc4leqJ$D#BVYmi{s>dj2z;{dZ{_N z2;U@JU7zsie8)VHeomMbjFUr|nm7);=9F_=VRmuyeWp}Hs3TZ>GK;}ZQ3RrBKH0+t*VkYAw| Wz1!{P=bcybbp zOMLTFGSf0sQ=l3c7}()vAXGxcN-}d(SwesWYe0T+W(7+wkcm&*WJV83MV7ooVpJ7p zR^c^kx}YMHm^yn&zEfpMYBAJSM#c)P&YjF?r963Ekoa`N6c!l}LxZCvKe(hQGcTPO zoranc5S08|#ly-9GH|k>D_pq{rt;|vw=#)OZm47911UzNC8#01)9vb* X*}!gW=ZRnhVkRJF-p&)j5~%?IOuES# delta 103 zcmaFRE%dZOs9_6ZcsLg$b81d5OIl`5>h!EAMw#h_QH=W24K^^bPG1|vD1 (Model, Cmd Msg) + +init : () -> ( Model, Cmd Msg ) init _ = - ( { bareme = "" - , reponsesCorrectes = "" - , reponsesEleves = "" - , eleves = [] - } - , Cmd.none - ) + ( { bareme = "" + , reponsesCorrectes = "" + , reponsesEleves = "" + , eleves = [] + } + , Cmd.none + ) {- - ██ ██ ██████ ██████ █████ ████████ ███████ - ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ - ██ ██ ██████ ██ ██ ███████ ██ █████ - ██ ██ ██ ██ ██ ██ ██ ██ ██ - ██████ ██ ██████ ██ ██ ██ ███████ + ██ ██ ██████ ██████ █████ ████████ ███████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ██ ██ ██████ ██ ██ ███████ ██ █████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ + ██████ ██ ██████ ██ ██ ██ ███████ -} + type Msg - = NouveauBareme String - | NouvellesReponsesCorrectes String - | NouvellesReponsesEleves String - -- | CalculerNotes + = NouveauBareme String + | NouvellesReponsesCorrectes String + | NouvellesReponsesEleves String + | TelechargerNotes + update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = - let - brms = unsafeRun baremeSujet [] model.bareme - rpnCorrectes = unsafeRun reponsesCorrectes Array.empty model.reponsesCorrectes - rpnEleves = unsafeRun reponsesEleves [] model.reponsesEleves - in - case msg of - NouveauBareme nouveauBareme -> - let - brmss = unsafeRun baremeSujet [] nouveauBareme - in - ( { model - | bareme = nouveauBareme - , eleves = notes brmss rpnCorrectes rpnEleves - } - , Cmd.none - ) - NouvellesReponsesCorrectes nouvellesReponsesCorrectes -> - let - rpnCorrectess = unsafeRun reponsesCorrectes Array.empty nouvellesReponsesCorrectes - in - ( { model - | reponsesCorrectes = nouvellesReponsesCorrectes - , eleves = notes brms rpnCorrectess rpnEleves - } - , Cmd.none - ) - NouvellesReponsesEleves nouvellesReponsesEleves -> - let - rpnElevess = unsafeRun reponsesEleves [] nouvellesReponsesEleves - in - ( { model - | reponsesEleves = nouvellesReponsesEleves - , eleves = notes brms rpnCorrectes rpnElevess - } - , Cmd.none - ) + let + brms = + unsafeRun baremeSujet [] model.bareme + + rpnCorrectes = + unsafeRun reponsesCorrectes Array.empty model.reponsesCorrectes + + rpnEleves = + unsafeRun reponsesEleves [] model.reponsesEleves + in + case msg of + NouveauBareme nouveauBareme -> + let + brmss = + unsafeRun baremeSujet [] nouveauBareme + in + ( { model + | bareme = nouveauBareme + , eleves = notes brmss rpnCorrectes rpnEleves + } + , Cmd.none + ) + + NouvellesReponsesCorrectes nouvellesReponsesCorrectes -> + let + rpnCorrectess = + unsafeRun reponsesCorrectes Array.empty nouvellesReponsesCorrectes + in + ( { model + | reponsesCorrectes = nouvellesReponsesCorrectes + , eleves = notes brms rpnCorrectess rpnEleves + } + , Cmd.none + ) + + NouvellesReponsesEleves nouvellesReponsesEleves -> + let + rpnElevess = + unsafeRun reponsesEleves [] nouvellesReponsesEleves + in + ( { model + | reponsesEleves = nouvellesReponsesEleves + , eleves = notes brms rpnCorrectes rpnElevess + } + , Cmd.none + ) + + TelechargerNotes -> + ( model + , File.Download.string "Notes.org" "text/org" <| voirNotesOrg model.eleves + ) + unsafeRun prsr defaut texte = - case run prsr texte of - Ok x -> x - _ -> defaut + case run prsr texte of + Ok x -> + x + + _ -> + defaut + -- SUBSCRIPTIONS + subscriptions : Model -> Sub Msg subscriptions model = - Sub.none + Sub.none + {- - ██ ██ ██ ███████ ██ ██ - ██ ██ ██ ██ ██ ██ - ██ ██ ██ █████ ██ █ ██ - ██ ██ ██ ██ ██ ███ ██ - ████ ██ ███████ ███ ███ + ██ ██ ██ ███████ ██ ██ + ██ ██ ██ ██ ██ ██ + ██ ██ ██ █████ ██ █ ██ + ██ ██ ██ ██ ██ ███ ██ + ████ ██ ███████ ███ ███ -} + view : Model -> Html Msg view model = - layout [ width fill, height fill ] <| - row [spacing grandEspacement, padding tresGrandEspacement, height fill, width fill, clip, scrollbars] - [ column [spacing petitEspacement, height fill, width fill, clip, scrollbars] - [ Input.multiline [height <| maximum 300 fill, clip, scrollbars] - { onChange = NouveauBareme - , label = Input.labelAbove [] <| text "Barème" - , placeholder = - Just - <| Input.placeholder [] - <| text "Entrer le barème sous la forme +3 -1, +2 -1" - , text = model.bareme - , spellcheck = False - } - , Input.multiline [height <| maximum 300 fill, clip, scrollbars] - { onChange = NouvellesReponsesCorrectes - , label = Input.labelAbove [] <| text "Réponses correctes" - , placeholder = - Just - <| Input.placeholder [] - <| text "Entrer les réponses correctes pour chaque sujet" - , text = model.reponsesCorrectes - , spellcheck = False - } - , Input.multiline [height <| maximum 300 fill, clip, scrollbars] - { onChange = NouvellesReponsesEleves - , label = Input.labelAbove [] <| text "Réponses des élèves" - , placeholder = - Just - <| Input.placeholder [] - <| text "Entrer les réponses des élèves" - , text = model.reponsesEleves - , spellcheck = False - } - ] - , column [spacing petitEspacement, height fill, width fill] - [ {-- Input.button [] - { onPress = Just CalculerNotes - , label = text "Calculer les notes" - } - --} - text - <| "Moyenne : " ++ String.fromFloat (moyenne model.eleves) - ++ " Écart type : " ++ String.fromFloat (ecartType model.eleves) - , voirNotes model.eleves - ] - ] + layout [ width fill, height fill ] <| + row + [ spacing grandEspacement + , padding tresGrandEspacement + , height fill + , width fill + , clip + , scrollbars + ] + [ column + [ spacing petitEspacement + , height fill + , width fill + , clip + , scrollbars + ] + [ Input.multiline [ height <| maximum 300 fill, clip, scrollbars ] + { onChange = NouveauBareme + , label = Input.labelAbove [] <| text "Barème" + , placeholder = + Just <| + Input.placeholder [] <| + text "Entrer le barème sous la forme +3 -1, +2 -1" + , text = model.bareme + , spellcheck = False + } + , Input.multiline [ height <| maximum 300 fill, clip, scrollbars ] + { onChange = NouvellesReponsesCorrectes + , label = Input.labelAbove [] <| text "Réponses correctes" + , placeholder = + Just <| + Input.placeholder [] <| + text "Entrer les réponses correctes pour chaque sujet" + , text = model.reponsesCorrectes + , spellcheck = False + } + , Input.multiline [ height <| maximum 300 fill, clip, scrollbars ] + { onChange = NouvellesReponsesEleves + , label = Input.labelAbove [] <| text "Réponses des élèves" + , placeholder = + Just <| + Input.placeholder [] <| + text "Entrer les réponses des élèves" + , text = model.reponsesEleves + , spellcheck = False + } + ] + , column [ spacing petitEspacement, height fill, width fill ] + [ text <| + "Moyenne : " + ++ String.fromFloat (moyenne model.eleves) + ++ " Écart type : " + ++ String.fromFloat (ecartType model.eleves) + , Input.button [] + { onPress = Just TelechargerNotes + , label = text "Télécharger le fichier de notes" + } + , voirNotes model.eleves + ] + ] + voirNotes : Eleves -> Element Msg voirNotes rpnsEleves = - table [] - { data = rpnsEleves - , columns = - [ { header = Element.text "Numéro étudiant" - , width = fill - , view = - \rpns -> - Element.text rpns.numeroEtudiant - } - , { header = Element.text "Note" - , width = fill - , view = - \rpns -> - case rpns.note of - Nothing -> Element.text "" - Just nt -> Element.text <| String.fromFloat nt - } - ] - } + table [] + { data = rpnsEleves + , columns = + [ { header = Element.text "Numéro étudiant" + , width = fill + , view = + \rpns -> + Element.text rpns.numeroEtudiant + } + , { header = Element.text "Note" + , width = fill + , view = + \rpns -> + case rpns.note of + Nothing -> + Element.text "" + + Just nt -> + Element.text <| String.fromFloat nt + } + ] + } -petitEspacement = 20 -grandEspacement = 5*petitEspacement // 4 +voirNotesOrg : Eleves -> String +voirNotesOrg rpnsEleves = + let + numero rpns = + rpns.numeroEtudiant -tresGrandEspacement = 25*petitEspacement // 16 + voirNote rpns = + case rpns.note of + Nothing -> + "" -{- - ██████ █████ ██████ ███████ ███ ███ ███████ - ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ - ██████ ███████ ██████ █████ ██ ████ ██ █████ - ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ - ██████ ██ ██ ██ ██ ███████ ██ ██ ███████ --} + Just nt -> + String.fromFloat nt + + ligne rpns = + "|" + ++ rpns.numeroEtudiant + ++ "|" + ++ rpns.nomEtudiant + ++ "|" + ++ rpns.prenomEtudiant + ++ "|" + ++ voirNote rpns + ++ "|\n" + in + "|Numéro|Nom|Prénom|Note|\n" + ++ String.concat (List.map ligne rpnsEleves) + + +petitEspacement = + 20 +grandEspacement = + 5 * petitEspacement // 4 + + +tresGrandEspacement = + 25 * petitEspacement // 16 + + + +{- + ██████ █████ ██████ ███████ ███ ███ ███████ + ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ + ██████ ███████ ██████ █████ ██ ████ ██ █████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ██████ ██ ██ ██ ██ ███████ ██ ██ ███████ +-} {-- baremeEtReponses = succeed (\brm rpn -> BaremeEtReponses brm (List.map (String.split "") rpn)) @@ -224,220 +306,301 @@ baremeEtReponses = --} -type alias BaremeSujet = List BaremeQuestion +type alias BaremeSujet = + List BaremeQuestion + baremeSujet = - sequence - { start = "" - , separator = "," - , end = "" - , spaces = espaces - , item = baremeQuestion - , trailing = Forbidden - } + sequence + { start = "" + , separator = "," + , end = "" + , spaces = espaces + , item = baremeQuestion + , trailing = Forbidden + } + espaces = - chompWhile <| (==) ' ' + chompWhile <| (==) ' ' type alias BaremeQuestion = - { bonneReponse : Float - , mauvaiseReponse : Float - } + { bonneReponse : Float + , mauvaiseReponse : Float + } + baremeQuestion = - succeed BaremeQuestion - |= nombre - |. spaces - |= nombre + succeed BaremeQuestion + |= nombre + |. spaces + |= nombre + nombre : Parser Float nombre = - oneOf - [ succeed negate - |. symbol "-" - |= float - , succeed identity - |. symbol "+" - |= float - ] + oneOf + [ succeed negate + |. symbol "-" + |= float + , succeed identity + |. symbol "+" + |= float + ] + + {- - ██████ ███████ ██████ ██████ ███ ██ ███████ ███████ ███████ - ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ - ██████ █████ ██████ ██ ██ ██ ██ ██ ███████ █████ ███████ - ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ - ██ ██ ███████ ██ ██████ ██ ████ ███████ ███████ ███████ + ██████ ███████ ██████ ██████ ███ ██ ███████ ███████ ███████ + ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ + ██████ █████ ██████ ██ ██ ██ ██ ██ ███████ █████ ███████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ██ ██ ███████ ██ ██████ ██ ████ ███████ ███████ ███████ -} -type alias ReponsesCorrectes = Array Reponses + + +type alias ReponsesCorrectes = + Array Reponses + reponsesCorrectes : Parser ReponsesCorrectes reponsesCorrectes = - succeed Array.fromList - |= sequence - { start = "" - , separator = "\n" - , end = "" - , spaces = espaces - , item = reponses - , trailing = Optional - } + succeed Array.fromList + |= sequence + { start = "" + , separator = "\n" + , end = "" + , spaces = espaces + , item = reponses + , trailing = Optional + } -type alias Reponses = List String +type alias Reponses = + List String + reponses = - sequence - { start = "" - , separator = "" - , end = "" - , spaces = espaces - , item = variable - { start = ( \ x -> x /= '\n' && x /= ';' ) - , inner = \_ -> False - , reserved = Set.fromList [] - } - , trailing = Optional - } + sequence + { start = "" + , separator = "" + , end = "" + , spaces = espaces + , item = + variable + { start = \x -> x /= '\n' && x /= ';' + , inner = \_ -> False + , reserved = Set.fromList [] + } + , trailing = Optional + } + +type alias Eleves = + List Eleve -type alias Eleves = List Eleve reponsesEleves : Parser Eleves reponsesEleves = - sequence - { start = "" - , separator = "\n" - , end = "" - , spaces = espaces - , item = reponsesEleve - , trailing = Optional - } + sequence + { start = "" + , separator = "\n" + , end = "" + , spaces = espaces + , item = reponsesEleve + , trailing = Optional + } {- - ███████ ██ ███████ ██ ██ ███████ ███████ - ██ ██ ██ ██ ██ ██ ██ - █████ ██ █████ ██ ██ █████ ███████ - ██ ██ ██ ██ ██ ██ ██ - ███████ ███████ ███████ ████ ███████ ███████ + ███████ ██ ███████ ██ ██ ███████ ███████ + ██ ██ ██ ██ ██ ██ ██ + █████ ██ █████ ██ ██ █████ ███████ + ██ ██ ██ ██ ██ ██ ██ + ███████ ███████ ███████ ████ ███████ ███████ -} type alias Eleve = - { numeroEtudiant : String - , numeroSujet : Int - , reponses : Reponses - , note : Maybe Float - } + { numeroEtudiant : String + , numeroSujet : Int + , nomEtudiant : String + , prenomEtudiant : String + , reponses : Reponses + , note : Maybe Float + } + reponsesEleve = - succeed Eleve - |= etudiant - |= int - |. champzInteret - |. champzInteret - |= reponsesQuizScan - |= champzInteret + succeed Eleve + |= etudiant + |= int + |= champ + |= champ + |= reponsesQuizScan + |= champzInteret + etudiant = - getChompedString - <| chompIf Char.isDigit - |. chompIf Char.isDigit - |. chompIf Char.isDigit - |. chompIf Char.isDigit - |. chompIf Char.isDigit + getChompedString <| + chompIf Char.isDigit + |. chompIf Char.isDigit + |. chompIf Char.isDigit + |. chompIf Char.isDigit + |. chompIf Char.isDigit + + +champ = + succeed identity + |. symbol ";" + |= getChompedString (chompWhile ((/=) ';')) + champzInteret = - succeed Nothing - |. symbol ";" - |. chompWhile ( \ x -> x /= '\n' && x /= ';' ) + succeed Nothing + |. symbol ";" + |. chompWhile (\x -> x /= '\n' && x /= ';') + reponsesQuizScan = - sequence - { start = ";" - , separator = ";" - , end = "" - , spaces = espaces - , item = variable - { start = ( \ x -> x /= '\n' && x /= ';' ) - , inner = \_ -> False - , reserved = Set.fromList [] - } - , trailing = Mandatory - } + sequence + { start = ";" + , separator = ";" + , end = "" + , spaces = espaces + , item = + variable + { start = \x -> x /= '\n' && x /= ';' + , inner = \_ -> False + , reserved = Set.fromList [] + } + , trailing = Mandatory + } + notes : BaremeSujet -> ReponsesCorrectes -> Eleves -> Eleves notes brms rpnCorrectes rpnEleves = - let - f rpnEleve = - case Array.get (rpnEleve.numeroSujet - 11) rpnCorrectes of - Nothing -> rpnEleve - Just bonneRpns -> - { rpnEleve | note = noteSujet brms bonneRpns rpnEleve.reponses } - in - List.map f rpnEleves + let + f rpnEleve = + case Array.get (rpnEleve.numeroSujet - 11) rpnCorrectes of + Nothing -> + rpnEleve + + Just bonneRpns -> + { rpnEleve | note = noteSujet brms bonneRpns rpnEleve.reponses } + in + List.map f rpnEleves + noteSujet : BaremeSujet -> Reponses -> Reponses -> Maybe Float noteSujet brms bonneRpns rpnsEleve = - case brms of - [] -> Just 0 - brm :: brmss -> - let - bonneRpn = List.head bonneRpns - bonneRpnSuite = List.tail bonneRpns - rpnEleve = List.head rpnsEleve - rpnEleveSuite = List.tail rpnsEleve - in - case ( (bonneRpn, bonneRpnSuite), (rpnEleve, rpnEleveSuite) ) of - ( (Just bnRpn, Just bnRpnSuite), (Just rpnElv, Just rpnElvSuite) ) -> - noteSujet brmss bnRpnSuite rpnElvSuite - |> Maybe.andThen ( Just << (+) ( noteQuestion brm bnRpn rpnElv ) ) - _ -> Nothing + case brms of + [] -> + Just 0 + + brm :: brmss -> + let + bonneRpn = + List.head bonneRpns + + bonneRpnSuite = + List.tail bonneRpns + + rpnEleve = + List.head rpnsEleve + + rpnEleveSuite = + List.tail rpnsEleve + in + case ( ( bonneRpn, bonneRpnSuite ), ( rpnEleve, rpnEleveSuite ) ) of + ( ( Just bnRpn, Just bnRpnSuite ), ( Just rpnElv, Just rpnElvSuite ) ) -> + noteSujet brmss bnRpnSuite rpnElvSuite + |> Maybe.andThen (Just << (+) (noteQuestion brm bnRpn rpnElv)) + + _ -> + Nothing + noteQuestion brm bonneRpn rpnEleve = - case bonneRpn of - "V" -> - if rpnEleve == "A" then brm.bonneReponse - else if rpnEleve == "B" then 2*brm.bonneReponse/3 - else if rpnEleve == "C" then brm.mauvaiseReponse/3 - else if rpnEleve == "D" then brm.mauvaiseReponse - else 0 - "F" -> - if rpnEleve == "D" then brm.bonneReponse - else if rpnEleve == "C" then 2*brm.bonneReponse/3 - else if rpnEleve == "B" then brm.mauvaiseReponse/3 - else if rpnEleve == "A" then brm.mauvaiseReponse - else 0 - _ -> - if bonnerpn == rpneleve then - brm.bonnereponse - else if rpneleve == "-" then - 0 - else - brm.mauvaisereponse + case bonneRpn of + "V" -> + if rpnEleve == "A" then + brm.bonneReponse + + else if rpnEleve == "B" then + 2 * brm.bonneReponse / 3 + + else if rpnEleve == "C" then + brm.mauvaiseReponse / 3 + + else if rpnEleve == "D" then + brm.mauvaiseReponse + + else + 0 + + "F" -> + if rpnEleve == "D" then + brm.bonneReponse + + else if rpnEleve == "C" then + 2 * brm.bonneReponse / 3 + + else if rpnEleve == "B" then + brm.mauvaiseReponse / 3 + + else if rpnEleve == "A" then + brm.mauvaiseReponse + + else + 0 + + _ -> + if bonneRpn == rpnEleve then + brm.bonneReponse + + else if rpnEleve == "-" then + 0 + + else + brm.mauvaiseReponse + moyenne elvs = - let - moy nts = List.sum nts / toFloat (List.length nts) - in - List.map .note elvs - |> expurgerNotesManquantes - |> moy + let + moy nts = + List.sum nts / toFloat (List.length nts) + in + List.map .note elvs + |> expurgerNotesManquantes + |> moy + ecartType elvs = - let - moy nts = List.sum nts / toFloat (List.length nts) - moyCarre = moy << List.map (\x -> x^2) - ecTp nts = sqrt <| moyCarre nts - (moy nts)^2 - in - List.map .note elvs - |> expurgerNotesManquantes - |> ecTp + let + moy nts = + List.sum nts / toFloat (List.length nts) + + moyCarre = + moy << List.map (\x -> x ^ 2) + + ecTp nts = + sqrt <| moyCarre nts - moy nts ^ 2 + in + List.map .note elvs + |> expurgerNotesManquantes + |> ecTp + expurgerNotesManquantes nts = - case nts of - [] -> [] - Nothing :: ntss -> expurgerNotesManquantes ntss - Just nt :: ntss -> nt :: expurgerNotesManquantes ntss \ No newline at end of file + case nts of + [] -> + [] + + Nothing :: ntss -> + expurgerNotesManquantes ntss + + (Just nt) :: ntss -> + nt :: expurgerNotesManquantes ntss diff --git a/src/Fraction.elm b/src/Fraction.elm index 4fcb289..b2b9ee2 100644 --- a/src/Fraction.elm +++ b/src/Fraction.elm @@ -1,130 +1,206 @@ module Fraction exposing - ( Fraction - , Resultat - , Erreur - , frac - , num - , den - , estEntier - , opp - , add - , neg - , sub - , mul - , inv - , div - , exp - , teX - , raw - ) + ( Erreur + , Fraction + , Resultat + , add + , den + , div + , estEntier + , exp + , frac + , inv + , mul + , neg + , num + , opp + , raw + , sub + , teX + ) import Arithmetic exposing (gcd) +type alias Fraction = + { num : Int, den : Int } -type alias Fraction = { num : Int, den : Int } -type alias Resultat = Result Erreur Fraction -type alias Erreur = String +type alias Resultat = + Result Erreur Fraction + + +type alias Erreur = + String + frac : Int -> Int -> Resultat frac a b = - let - min = 1 - 2^31 - max = 2^31 - 1 - in - case b of - 0 -> Err "Division par zéro." - _ -> - if a > max || b > max || a < min || b < min then - Err "Certains calculs font intervenir des valeurs trop grandes pour être prises en charge." - else - Ok <| simplifier <| Fraction a b + let + min = + 1 - 2 ^ 31 + + max = + 2 ^ 31 - 1 + in + case b of + 0 -> + Err "Division par zéro." + + _ -> + if a > max || b > max || a < min || b < min then + Err "Certains calculs font intervenir des valeurs trop grandes pour être prises en charge." + + else + Ok <| simplifier <| Fraction a b + simplifier : Fraction -> Fraction simplifier a = - let - pgcd = gcd a.num a.den - sgnDuDen = - if a.den < 0 then -1 else 1 - in - { a - | num = sgnDuDen*(a.num // pgcd) - , den = sgnDuDen*(a.den // pgcd) - } + let + pgcd = + gcd a.num a.den + + sgnDuDen = + if a.den < 0 then + -1 + + else + 1 + in + { a + | num = sgnDuDen * (a.num // pgcd) + , den = sgnDuDen * (a.den // pgcd) + } + + +num a = + a.num -num a = a.num -den a = a.den +den a = + a.den + + +estEntier a = + a.den == 1 -estEntier a = a.den == 1 opp : (Fraction -> Fraction -> Resultat) -> Resultat -> Resultat -> Resultat opp operation resultat1 resultat2 = - case (resultat1, resultat2) of - (Ok fraction1, Ok fraction2) -> operation fraction1 fraction2 - (Err erreur, _) -> Err erreur - (_, Err erreur) -> Err erreur + case ( resultat1, resultat2 ) of + ( Ok fraction1, Ok fraction2 ) -> + operation fraction1 fraction2 + + ( Err erreur, _ ) -> + Err erreur + + ( _, Err erreur ) -> + Err erreur + add : Fraction -> Fraction -> Resultat add a b = - let - pgcd = gcd a.den b.den - aDenBis = a.den // pgcd - bDenBis = b.den // pgcd - in - frac (a.num*bDenBis + b.num*aDenBis) (a.den*bDenBis) + let + pgcd = + gcd a.den b.den + + aDenBis = + a.den // pgcd + + bDenBis = + b.den // pgcd + in + frac (a.num * bDenBis + b.num * aDenBis) (a.den * bDenBis) + neg : Fraction -> Fraction -neg a = Fraction (-a.num) a.den +neg a = + Fraction -a.num a.den + sub : Fraction -> Fraction -> Resultat -sub a b = add a (neg b) +sub a b = + add a (neg b) + mul : Fraction -> Fraction -> Resultat mul a b = - let - pgcd = gcd a.num b.den - pgcdBis = gcd b.num a.den - aNum = a.num // pgcd - aDen = a.den // pgcdBis - bNum = b.num // pgcdBis - bDen = b.den // pgcd - in - frac (aNum*bNum) (aDen*bDen) + let + pgcd = + gcd a.num b.den + + pgcdBis = + gcd b.num a.den + + aNum = + a.num // pgcd + + aDen = + a.den // pgcdBis + + bNum = + b.num // pgcdBis + + bDen = + b.den // pgcd + in + frac (aNum * bNum) (aDen * bDen) + inv : Fraction -> Resultat inv a = - case a.num of - 0 -> Err "Division par zéro" - _ -> Ok <| Fraction a.den a.num + case a.num of + 0 -> + Err "Division par zéro" + + _ -> + Ok <| Fraction a.den a.num + div : Fraction -> Fraction -> Resultat -div a b = Result.andThen (mul a) <| inv b +div a b = + Result.andThen (mul a) <| inv b + exp : Fraction -> Fraction -> Resultat exp a b = - let - sgnDeA = - if a.num < 0 then -1 else 1 - sgnDeB = - if b.num < 0 then -1 else 1 - in - if b.den == 1 && b.num < 0 then - frac ((sgnDeA*a.den)^(sgnDeB*b.num)) ((sgnDeA*a.num)^(sgnDeB*b.num)) - else if b.den == 1 then - frac (a.num^b.num) (a.den^b.num) - else - Err "Extraction de racine impossible" - - -teX a - = case a.den of - 1 -> String.fromInt a.num - _ -> - if a.num < 0 then - "-\\frac{" ++ String.fromInt (-a.num) ++ "}{" ++ String.fromInt a.den ++ "}" - else - "\\frac{" ++ String.fromInt a.num ++ "}{" ++ String.fromInt a.den ++ "}" - -raw a = "(" ++ String.fromInt a.num ++ "/" ++ String.fromInt a.den ++ ")" \ No newline at end of file + let + sgnDeA = + if a.num < 0 then + -1 + + else + 1 + + sgnDeB = + if b.num < 0 then + -1 + + else + 1 + in + if b.den == 1 && b.num < 0 then + frac ((sgnDeA * a.den) ^ (sgnDeB * b.num)) ((sgnDeA * a.num) ^ (sgnDeB * b.num)) + + else if b.den == 1 then + frac (a.num ^ b.num) (a.den ^ b.num) + + else + Err "Extraction de racine impossible" + + +teX a = + case a.den of + 1 -> + String.fromInt a.num + + _ -> + if a.num < 0 then + "-\\frac{" ++ String.fromInt -a.num ++ "}{" ++ String.fromInt a.den ++ "}" + + else + "\\frac{" ++ String.fromInt a.num ++ "}{" ++ String.fromInt a.den ++ "}" + + +raw a = + "(" ++ String.fromInt a.num ++ "/" ++ String.fromInt a.den ++ ")" diff --git a/src/GenerateurDeProblemes.elm b/src/GenerateurDeProblemes.elm index 7f034ed..5e28979 100644 --- a/src/GenerateurDeProblemes.elm +++ b/src/GenerateurDeProblemes.elm @@ -1,774 +1,924 @@ module GenerateurDeProblemes exposing (..) import Browser -import Parser as P exposing (..) -import List as L -import Set -import ParserMaths as PM -import String as S -import Fraction as F exposing (Fraction) -import Html exposing (Html, Attribute, button, div, textarea, input, p, iframe, section) ---import Html.Attributes as A -- exposing (..) ---import Html.Events -import Random -import Random.Extra -import Random.List import Element exposing (..) import Element.Background as Background import Element.Border as Border import Element.Events exposing (..) import Element.Font as Font import Element.Input as Input +import Fraction as F exposing (Fraction) +import Html exposing (Attribute, Html, button, div, iframe, input, p, section, textarea) +import List as L +import Parser as P exposing (..) +import ParserMaths as PM +import Random +import Random.Extra +import Random.List +import Set +import String as S + {- - ███ ███ █████ ██ ███ ██ - ████ ████ ██ ██ ██ ████ ██ - ██ ████ ██ ███████ ██ ██ ██ ██ - ██ ██ ██ ██ ██ ██ ██ ██ ██ - ██ ██ ██ ██ ██ ██ ████ + ███ ███ █████ ██ ███ ██ + ████ ████ ██ ██ ██ ████ ██ + ██ ████ ██ ███████ ██ ██ ██ ██ + ██ ██ ██ ██ ██ ██ ██ ██ ██ + ██ ██ ██ ██ ██ ██ ████ -} + main = - Browser.element - { init = init - , update = update - , subscriptions = subscriptions - , view = view - } + Browser.element + { init = init + , update = update + , subscriptions = subscriptions + , view = view + } + {- - ███ ███ ██████ ██████ ███████ ██ - ████ ████ ██ ██ ██ ██ ██ ██ - ██ ████ ██ ██ ██ ██ ██ █████ ██ - ██ ██ ██ ██ ██ ██ ██ ██ ██ - ██ ██ ██████ ██████ ███████ ███████ + ███ ███ ██████ ██████ ███████ ██ + ████ ████ ██ ██ ██ ██ ██ ██ + ██ ████ ██ ██ ██ ██ ██ █████ ██ + ██ ██ ██ ██ ██ ██ ██ ██ ██ + ██ ██ ██████ ██████ ███████ ███████ -} + type alias Model = - { structureDuSujet : String - , sujetGenere : String - } + { structureDuSujet : String + , sujetGenere : String + } + -init : () -> (Model, Cmd Msg) +init : () -> ( Model, Cmd Msg ) init _ = - ( { structureDuSujet = "" - , sujetGenere = "" - } - , Cmd.none - ) + ( { structureDuSujet = "" + , sujetGenere = "" + } + , Cmd.none + ) + + {- - ██ ██ ██████ ██████ █████ ████████ ███████ - ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ - ██ ██ ██████ ██ ██ ███████ ██ █████ - ██ ██ ██ ██ ██ ██ ██ ██ ██ - ██████ ██ ██████ ██ ██ ██ ███████ + ██ ██ ██████ ██████ █████ ████████ ███████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ██ ██ ██████ ██ ██ ███████ ██ █████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ + ██████ ██ ██████ ██ ██ ██ ███████ -} + type Msg - = StructureDuSujet String - | GenererSujetAleatoire - | GenererVariantesSujet - | SujetGenere String + = StructureDuSujet String + | GenererSujetAleatoire + | GenererVariantesSujet + | SujetGenere String + update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = - case msg of - StructureDuSujet nouvelleStructure -> - ( { model | structureDuSujet = nouvelleStructure } - , Cmd.none - ) - SujetGenere nouveauSujetGenere -> - ( { model | sujetGenere = nouveauSujetGenere } - , Cmd.none - ) - GenererSujetAleatoire -> - let - f strSuj = - case P.run (withIndent -1 sujet) strSuj of - Ok sjt -> Random.map quizScanVoirBlocs <| sujetsAleatoires sjt - Err erreurs -> Random.constant <| deadEndsToStringBis erreurs - in - ( model - , Random.generate SujetGenere (f model.structureDuSujet) - ) - GenererVariantesSujet -> - let - f strSuj = - case P.run (withIndent -1 sujet) strSuj of - Ok sjt -> evalBoxVoirBlocs <| variantesBlocs sjt - Err erreurs -> deadEndsToStringBis erreurs - in - ( { model | sujetGenere = f model.structureDuSujet } - , Cmd.none - ) + case msg of + StructureDuSujet nouvelleStructure -> + ( { model | structureDuSujet = nouvelleStructure } + , Cmd.none + ) + + SujetGenere nouveauSujetGenere -> + ( { model | sujetGenere = nouveauSujetGenere } + , Cmd.none + ) + + GenererSujetAleatoire -> + let + f strSuj = + case P.run (withIndent -1 sujet) strSuj of + Ok sjt -> + Random.map quizScanVoirBlocs <| sujetsAleatoires sjt + + Err erreurs -> + Random.constant <| deadEndsToStringBis erreurs + in + ( model + , Random.generate SujetGenere (f model.structureDuSujet) + ) + + GenererVariantesSujet -> + let + f strSuj = + case P.run (withIndent -1 sujet) strSuj of + Ok sjt -> + evalBoxVoirBlocs <| variantesBlocs sjt + + Err erreurs -> + deadEndsToStringBis erreurs + in + ( { model | sujetGenere = f model.structureDuSujet } + , Cmd.none + ) + -- SUBSCRIPTIONS + subscriptions : Model -> Sub Msg subscriptions model = - Sub.none + Sub.none + {- - ██ ██ ██ ███████ ██ ██ - ██ ██ ██ ██ ██ ██ - ██ ██ ██ █████ ██ █ ██ - ██ ██ ██ ██ ██ ███ ██ - ████ ██ ███████ ███ ███ + ██ ██ ██ ███████ ██ ██ + ██ ██ ██ ██ ██ ██ + ██ ██ ██ █████ ██ █ ██ + ██ ██ ██ ██ ██ ███ ██ + ████ ██ ███████ ███ ███ -} + view : Model -> Html Msg view model = - layout [] <| - row [spacing grandEspacement, padding tresGrandEspacement, height fill, width fill, clip, scrollbars] - [ Input.multiline [height <| maximum 800 fill, clip, scrollbars] - { onChange = StructureDuSujet - , label = Input.labelHidden "chose" - , placeholder = Just <| Input.placeholder [] <| text "Structure du sujet" - , text = model.structureDuSujet - , spellcheck = True - } - , column [spacing petitEspacement, height fill, width fill] - [ Input.button [] - { onPress = Just GenererSujetAleatoire - , label = text "Générer 89 sujets alétoires pour QuizScan" - } - , Input.button [] - { onPress = Just GenererVariantesSujet - , label = text "Générer les variantes du sujet pour EvalBox" - } - , el [height <| maximum 800 fill, clip, scrollbars] <| text model.sujetGenere - ] - ] - -petitEspacement = 20 - -grandEspacement = 5*petitEspacement // 4 - -tresGrandEspacement = 25*petitEspacement // 16 + layout [] <| + row [ spacing grandEspacement, padding tresGrandEspacement, height fill, width fill, clip, scrollbars ] + [ Input.multiline [ height <| maximum 800 fill, clip, scrollbars ] + { onChange = StructureDuSujet + , label = Input.labelHidden "chose" + , placeholder = Just <| Input.placeholder [] <| text "Structure du sujet" + , text = model.structureDuSujet + , spellcheck = True + } + , column [ spacing petitEspacement, height fill, width fill ] + [ Input.button [] + { onPress = Just GenererSujetAleatoire + , label = text "Générer 89 sujets alétoires pour QuizScan" + } + , Input.button [] + { onPress = Just GenererVariantesSujet + , label = text "Générer les variantes du sujet pour EvalBox" + } + , el [ height <| maximum 800 fill, clip, scrollbars ] <| text model.sujetGenere + ] + ] + + +petitEspacement = + 20 + + +grandEspacement = + 5 * petitEspacement // 4 + + +tresGrandEspacement = + 25 * petitEspacement // 16 + {- -██████ █████ ██████ ███████ ███████ ██████ ███████ ██ ██ ██ ███████ ████████ -██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -██████ ███████ ██████ ███████ █████ ██████ ███████ ██ ██ ██ █████ ██ -██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -██ ██ ██ ██ ██ ███████ ███████ ██ ██ ███████ ██████ █████ ███████ ██ + ██████ █████ ██████ ███████ ███████ ██████ ███████ ██ ██ ██ ███████ ████████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ██████ ███████ ██████ ███████ █████ ██████ ███████ ██ ██ ██ █████ ██ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ██ ██ ██ ██ ██ ███████ ███████ ██ ██ ███████ ██████ █████ ███████ ██ -} -type alias Blocs = List Bloc -type Bloc = - Sujet Blocs - | VariableAremplacer Aremplacer Blocs - | Entete Macro Blocs - | QCM Macro Propositions - | VraiFaux Propositions +type alias Blocs = + List Bloc -type alias Propositions = List Proposition -type Proposition = - Vrai Macro - | Faux Macro +type Bloc + = Sujet Blocs + | VariableAremplacer Aremplacer Blocs + | Entete Macro Blocs + | QCM Macro Propositions + | VraiFaux Propositions -type alias NombreDeLigne = Int -{-- -voirBlocsParse blocsPotentiel = - case P.run (withIndent -1 blocs) blocsPotentiel of - Ok sjt -> voirBlocs sjt - Err erreurs -> deadEndsToStringBis erreurs ---} +type alias Propositions = + List Proposition + + +type Proposition + = Vrai Macro + | Faux Macro + + +type alias NombreDeLigne = + Int + voirBlocsParseAleatoire blocsPotentiel = - case P.run (withIndent -1 blocs) blocsPotentiel of - Ok sjt -> Random.map quizScanVoirBlocs <| blocsAleatoires sjt - Err erreurs -> Random.constant <| deadEndsToStringBis erreurs + case P.run (withIndent -1 blocs) blocsPotentiel of + Ok sjt -> + Random.map quizScanVoirBlocs <| blocsAleatoires sjt + + Err erreurs -> + Random.constant <| deadEndsToStringBis erreurs + deadEndsToStringBis errs = - errs - |> List.map voirErreur - |> String.concat - |> (++) "Il y a des problèmes aux endroits suivants :\n" + errs + |> List.map voirErreur + |> String.concat + |> (++) "Il y a des problèmes aux endroits suivants :\n" + voirErreur err = - "Ligne : " ++ String.fromInt err.row - ++ " | Colonne : " ++ String.fromInt err.col + "Ligne : " + ++ String.fromInt err.row + ++ " | Colonne : " + ++ String.fromInt err.col -{-- -voirBlocs = S.join "\n" << L.map voirBloc - -voirBloc prblm = - -- Debug.log "voirBloc " <| - case prblm of - Entete mcr sjt -> - voirMacro mcr - ++ "\n" - ++ voirBlocs sjt - VraiFaux prps -> - let - f prp = - case prp of - Vrai mcr -> voirMacro mcr - Faux mcr -> voirMacro mcr - in - S.join "\n" <| L.map f prps - VariableAremplacer ar sjt -> "" ++ voirBlocs sjt ---} sujet : Parser Blocs sujet = - succeed (L.singleton << Sujet) - |= blocs + succeed (L.singleton << Sujet) + |= blocs + blocs : Parser Blocs blocs = - let - problemes prblms = - let - boucle = - -- Debug.log "Boucle sur un bloc (bis) " <| - succeed ( \prblm -> Loop (prblm :: prblms) ) - |= bloc - fin = - P.map (\_ -> Done (List.reverse prblms)) - suite col_ind = - oneOf - [ succeed () - |. end - |> fin - , if Tuple.first col_ind > Tuple.second col_ind then -- if col > ind - boucle -- |> Debug.log "Boucle sur un bloc " - else - succeed () - |> fin - ] - -- |> Debug.log ( "Choix de l'embrachement dans la boucle (position " ++ S.fromInt (Tuple.first col_ind) ++ "x" ++ S.fromInt (Tuple.second col_ind) ++ ")" ) - in - succeed Tuple.pair - |. spaces - |= getCol - |= getIndent - |> andThen suite - in - loop [] problemes + let + problemes prblms = + let + boucle = + -- Debug.log "Boucle sur un bloc (bis) " <| + succeed (\prblm -> Loop (prblm :: prblms)) + |= bloc + + fin = + P.map (\_ -> Done (List.reverse prblms)) + + suite col_ind = + oneOf + [ succeed () + |. end + |> fin + , if Tuple.first col_ind > Tuple.second col_ind then + -- if col > ind + boucle + -- |> Debug.log "Boucle sur un bloc " + + else + succeed () + |> fin + ] + + -- |> Debug.log ( "Choix de l'embrachement dans la boucle (position " ++ S.fromInt (Tuple.first col_ind) ++ "x" ++ S.fromInt (Tuple.second col_ind) ++ ")" ) + in + succeed Tuple.pair + |. spaces + |= getCol + |= getIndent + |> andThen suite + in + loop [] problemes + bloc : Parser Bloc bloc = - let - suite = - flip withIndent - <| oneOf - [ vraiFaux - , qcm - , backtrackable variableAremplacer - , entete ] - in - getCol - |> andThen suite - -flip f a b = f b a + let + suite = + flip withIndent <| + oneOf + [ vraiFaux + , qcm + , backtrackable variableAremplacer + , entete + ] + in + getCol + |> andThen suite + + +flip f a b = + f b a + + +reserve = + Set.fromList + [ "qcm" + , "vrfx" + ] -reserve = Set.fromList - [ "qcm" - , "vrfx" - ] sousBlocs = - let - suite col_ind = - if Tuple.first col_ind > Tuple.second col_ind then -- if col > ind - withIndent (Tuple.first col_ind) ( lazy (\_ -> blocs) ) -- Aucune idée de l'effet du lazy, ça marche sans... - else - succeed [] - in - succeed Tuple.pair - |. spaces - |= getCol - |= getIndent - |> andThen suite + let + suite col_ind = + if Tuple.first col_ind > Tuple.second col_ind then + -- if col > ind + withIndent (Tuple.first col_ind) (lazy (\_ -> blocs)) + -- Aucune idée de l'effet du lazy, ça marche sans... + + else + succeed [] + in + succeed Tuple.pair + |. spaces + |= getCol + |= getIndent + |> andThen suite + entete : Parser Bloc entete = - -- Debug.log "entete " <| - succeed Entete - |= macro - |= blocs -- sousBlocs + -- Debug.log "entete " <| + succeed Entete + |= macro + |= blocs + + + +-- sousBlocs + vraiFaux = - -- Debug.log "vraiFaux " <| - succeed VraiFaux - |. keyword "vrfx" - |= propositions + -- Debug.log "vraiFaux " <| + succeed VraiFaux + |. keyword "vrfx" + |= propositions + qcm = - -- Debug.log "vraiFaux " <| - succeed QCM - |. keyword "qcm" - |. espaces - |= macro - |= propositions + -- Debug.log "vraiFaux " <| + succeed QCM + |. keyword "qcm" + |. espaces + |= macro + |= propositions + propositions = - let - suiteBis prps = - let - boucle = - oneOf - [ succeed ( \mcr -> Loop ( Vrai mcr :: prps ) ) - |. symbol "+" - |= macro - , succeed ( \mcr -> Loop ( Faux mcr :: prps ) ) - |. symbol "-" - |= macro - ] - fin = - P.map (\_ -> Done prps) - suite col_ind = - oneOf - [ succeed () - |. end - |> fin - , if Tuple.first col_ind > Tuple.second col_ind then -- if col > ind - boucle - else - succeed () - |> fin - ] - in - succeed Tuple.pair - |. spaces - |= getCol - |= getIndent - |> andThen suite - in - loop [] suiteBis + let + suiteBis prps = + let + boucle = + oneOf + [ succeed (\mcr -> Loop (Vrai mcr :: prps)) + |. symbol "+" + |= macro + , succeed (\mcr -> Loop (Faux mcr :: prps)) + |. symbol "-" + |= macro + ] + + fin = + P.map (\_ -> Done prps) + + suite col_ind = + oneOf + [ succeed () + |. end + |> fin + , if Tuple.first col_ind > Tuple.second col_ind then + -- if col > ind + boucle + + else + succeed () + |> fin + ] + in + succeed Tuple.pair + |. spaces + |= getCol + |= getIndent + |> andThen suite + in + loop [] suiteBis + {- -██████ █████ ██████ ███████ ███████ ██████ ███ ███ █████ ██████ ██████ ██████ -██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██ ██ -██████ ███████ ██████ ███████ █████ ██████ ██ ████ ██ ███████ ██ ██████ ██ ██ -██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -██ ██ ██ ██ ██ ███████ ███████ ██ ██ ██ ██ ██ ██ ██████ ██ ██ ██████ + ██████ █████ ██████ ███████ ███████ ██████ ███ ███ █████ ██████ ██████ ██████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██ ██ + ██████ ███████ ██████ ███████ █████ ██████ ██ ████ ██ ███████ ██ ██████ ██ ██ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ██ ██ ██ ██ ██ ███████ ███████ ██ ██ ██ ██ ██ ██ ██████ ██ ██ ██████ -} + type TexteVariable - = Texte String - | Variable String + = Texte String + | Variable String + -type alias Macro - = List TexteVariable +type alias Macro = + List TexteVariable + + +voirMacro = + S.concat << L.map voirTexteVariable -voirMacro = S.concat << L.map voirTexteVariable voirTexteVariable txtvar = - case txtvar of - Texte txt -> txt - Variable var -> - let - expressionParseePotentielle = PM.parseMaths var - in - case expressionParseePotentielle of - Err erreur -> "L'expression est mal formée." - Ok expressionParsee -> - case Result.map F.teX <| PM.evaluer <| expressionParsee of - Ok a -> a - Err erreur -> erreur + case txtvar of + Texte txt -> + txt + + Variable var -> + let + expressionParseePotentielle = + PM.parseMaths var + in + case expressionParseePotentielle of + Err erreur -> + "L'expression est mal formée." + + Ok expressionParsee -> + case Result.map F.teX <| PM.evaluer <| expressionParsee of + Ok a -> + a + + Err erreur -> + erreur + texteSansVariables : Parser TexteVariable texteSansVariables = - let - condition caractere = caractere /= '#' && caractere /= '\n' - in - succeed Texte - |= P.getChompedString ( - succeed () - |. P.chompIf condition - |. P.chompWhile condition + let + condition caractere = + caractere /= '#' && caractere /= '\n' + in + succeed Texte + |= P.getChompedString + (succeed () + |. P.chompIf condition + |. P.chompWhile condition + ) - ) expressionVariable : Parser TexteVariable -expressionVariable - = succeed Variable - |. symbol "#" - |= P.getChompedString ( P.chompUntil "#" ) - |. symbol "#" +expressionVariable = + succeed Variable + |. symbol "#" + |= P.getChompedString (P.chompUntil "#") + |. symbol "#" + macro : Parser Macro macro = - let - suite ls = - P.oneOf - [ succeed (\l -> P.Loop (l :: ls)) - |= P.oneOf - [ expressionVariable - , texteSansVariables - , backtrackable retourAlaLigne - ] - , succeed () - |> P.map (\_ -> P.Done (List.reverse ls)) - ] - in - P.loop [] suite + let + suite ls = + P.oneOf + [ succeed (\l -> P.Loop (l :: ls)) + |= P.oneOf + [ expressionVariable + , texteSansVariables + , backtrackable retourAlaLigne + ] + , succeed () + |> P.map (\_ -> P.Done (List.reverse ls)) + ] + in + P.loop [] suite + retourAlaLigne = - let - suite ind = - succeed (Texte "\n") - |. token "\n" - |. token (S.repeat (ind - 1) " ") - in - getIndent - |> andThen suite + let + suite ind = + succeed (Texte "\n") + |. token "\n" + |. token (S.repeat (ind - 1) " ") + in + getIndent + |> andThen suite + {- - ██████ █████ ██████ ███████ ███████ ██████ ██ ██ █████ ██████ - ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ - ██████ ███████ ██████ ███████ █████ ██████ ██ ██ ███████ ██████ - ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ - ██ ██ ██ ██ ██ ███████ ███████ ██ ██ ████ ██ ██ ██ ██ + ██████ █████ ██████ ███████ ███████ ██████ ██ ██ █████ ██████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ██████ ███████ ██████ ███████ █████ ██████ ██ ██ ███████ ██████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ██ ██ ██ ██ ██ ███████ ███████ ██ ██ ████ ██ ██ ██ ██ -} -type alias Variables = List Aremplacer + +type alias Variables = + List Aremplacer + type alias Aremplacer = - { var : String - , vals : List String - } + { var : String + , vals : List String + } + parserAremplacer variables = - case P.run aRemplacer variables of - Ok ars -> ars - Err _ -> Aremplacer "" [] + case P.run aRemplacer variables of + Ok ars -> + ars + + Err _ -> + Aremplacer "" [] + espaces = - chompWhile <| (==) ' ' + chompWhile <| (==) ' ' + variableAremplacer : Parser Bloc variableAremplacer = - -- Debug.log "variableAremplacer " <| - succeed VariableAremplacer - |= aRemplacer - |= blocs -- sousBlocs + -- Debug.log "variableAremplacer " <| + succeed VariableAremplacer + |= aRemplacer + |= blocs + + + +-- sousBlocs + aRemplacer : Parser Aremplacer aRemplacer = - succeed ( \x y -> Aremplacer x (L.map (F.raw << PM.evaluerBis) y) ) - |. espaces - |= variable - { start = Char.isAlpha - , inner = Char.isAlpha - , reserved = reserve - } - |. espaces - |. symbol ":" - |= sequence - { start = "" - , separator = "," - , end = "" - , spaces = espaces - , item = PM.expr - , trailing = P.Optional - } + succeed (\x y -> Aremplacer x (L.map (F.raw << PM.evaluerBis) y)) + |. espaces + |= variable + { start = Char.isAlpha + , inner = Char.isAlpha + , reserved = reserve + } + |. espaces + |. symbol ":" + |= sequence + { start = "" + , separator = "," + , end = "" + , spaces = espaces + , item = PM.expr + , trailing = P.Optional + } + + {- -███████ ██ ████████ █████ ██ ███████ █████ ████████ ██████ ██ ██████ ███████ -██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -███████ ██ ██ ███████ ██ █████ ███████ ██ ██ ██ ██ ██████ █████ - ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -███████ █████ ██ ██ ██ ███████ ███████ ██ ██ ██ ██████ ██ ██ ██ ███████ + ███████ ██ ████████ █████ ██ ███████ █████ ████████ ██████ ██ ██████ ███████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ███████ ██ ██ ███████ ██ █████ ███████ ██ ██ ██ ██ ██████ █████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ███████ █████ ██ ██ ██ ███████ ███████ ██ ██ ██ ██████ ██ ██ ██ ███████ -} + sujetsAleatoires : Blocs -> Random.Generator Blocs sujetsAleatoires sjt = - blocsAleatoires sjt - |> Random.list 89 - |> Random.map L.concat + blocsAleatoires sjt + |> Random.list 89 + |> Random.map L.concat + blocsAleatoires : Blocs -> Random.Generator Blocs blocsAleatoires sjt = - Random.map L.concat - <| Random.Extra.sequence - <| L.map blocAleatoire sjt + Random.map L.concat <| + Random.Extra.sequence <| + L.map blocAleatoire sjt + blocAleatoire : Bloc -> Random.Generator Blocs blocAleatoire prblm = - case prblm of - Sujet blcs -> - Random.map (L.singleton << Sujet) (blocsAleatoires blcs) - VariableAremplacer ar sjt -> - let - vrbl = ar.var - vlr = valeurAleatoire "" ar.vals - f sj vl = remplacerLaVariableDansLesBlocsAleatoires vrbl vl sj - in - Random.andThen (f sjt) vlr - Entete mcr sjt -> - Random.map (L.singleton << Entete mcr) (blocsAleatoires sjt) - VraiFaux prps -> - Random.map - (L.singleton << VraiFaux << L.singleton) - ( valeurAleatoire ( Vrai [ Texte "Le prof de maths est le meilleur." ] ) prps ) - QCM mcr prps -> - Random.map - (L.singleton << QCM mcr) - (Random.List.shuffle prps ) + case prblm of + Sujet blcs -> + Random.map (L.singleton << Sujet) (blocsAleatoires blcs) + + VariableAremplacer ar sjt -> + let + vrbl = + ar.var + + vlr = + valeurAleatoire "" ar.vals + + f sj vl = + remplacerLaVariableDansLesBlocsAleatoires vrbl vl sj + in + Random.andThen (f sjt) vlr + + Entete mcr sjt -> + Random.map (L.singleton << Entete mcr) (blocsAleatoires sjt) + + VraiFaux prps -> + Random.map + (L.singleton << VraiFaux << L.singleton) + (valeurAleatoire (Vrai [ Texte "Le prof de maths est le meilleur." ]) prps) + + QCM mcr prps -> + Random.map + (L.singleton << QCM mcr) + (Random.List.shuffle prps) + {-| Permet de prendre un élément aléatoire dans une liste - avec une valeur par défaut si la liste est vide. +avec une valeur par défaut si la liste est vide. -} valeurAleatoire : a -> List a -> Random.Generator a valeurAleatoire f fs = - case fs of - [] -> - Random.constant f - ff :: fss -> - Random.uniform ff fss - -remplacerLaVariableDansLeBlocAleatoire : - String -> String -> Bloc -> Random.Generator Blocs + case fs of + [] -> + Random.constant f + + ff :: fss -> + Random.uniform ff fss + + +remplacerLaVariableDansLeBlocAleatoire : String -> String -> Bloc -> Random.Generator Blocs remplacerLaVariableDansLeBlocAleatoire vrbl vlr prblm = - case prblm of - Sujet blcs -> - remplacerLaVariableDansLesBlocsAleatoires vrbl vlr blcs - VariableAremplacer ar sjt -> - blocAleatoire (VariableAremplacer ar sjt) - |> Random.andThen (remplacerLaVariableDansLesBlocsAleatoires vrbl vlr) - Entete mcr sjt -> - Random.map L.singleton - <| Random.map2 Entete - ( Random.constant <| remplacerLaVariableParLaValeurDansLaMacro vrbl vlr mcr ) - ( remplacerLaVariableDansLesBlocsAleatoires vrbl vlr sjt ) - QCM mcr prps -> - Random.map L.singleton - <| Random.map2 QCM - ( Random.constant <| remplacerLaVariableParLaValeurDansLaMacro vrbl vlr mcr ) - ( Random.List.shuffle - <| L.map (remplacerLaVariableParLaValeurDansLaProposition vrbl vlr) prps - ) - VraiFaux prps -> - Random.map - ( L.singleton - << VraiFaux - << L.singleton - << remplacerLaVariableParLaValeurDansLaProposition vrbl vlr - ) - <| valeurAleatoire ( Vrai [ Texte "Le prof de maths est le meilleur." ] ) prps - -remplacerLaVariableDansLesBlocsAleatoires : - String -> String -> Blocs -> Random.Generator Blocs + case prblm of + Sujet blcs -> + remplacerLaVariableDansLesBlocsAleatoires vrbl vlr blcs + + VariableAremplacer ar sjt -> + blocAleatoire (VariableAremplacer ar sjt) + |> Random.andThen (remplacerLaVariableDansLesBlocsAleatoires vrbl vlr) + + Entete mcr sjt -> + Random.map L.singleton <| + Random.map2 Entete + (Random.constant <| remplacerLaVariableParLaValeurDansLaMacro vrbl vlr mcr) + (remplacerLaVariableDansLesBlocsAleatoires vrbl vlr sjt) + + QCM mcr prps -> + Random.map L.singleton <| + Random.map2 QCM + (Random.constant <| remplacerLaVariableParLaValeurDansLaMacro vrbl vlr mcr) + (Random.List.shuffle <| + L.map (remplacerLaVariableParLaValeurDansLaProposition vrbl vlr) prps + ) + + VraiFaux prps -> + Random.map + (L.singleton + << VraiFaux + << L.singleton + << remplacerLaVariableParLaValeurDansLaProposition vrbl vlr + ) + <| + valeurAleatoire (Vrai [ Texte "Le prof de maths est le meilleur." ]) prps + + +remplacerLaVariableDansLesBlocsAleatoires : String -> String -> Blocs -> Random.Generator Blocs remplacerLaVariableDansLesBlocsAleatoires vrbl vlr sjt = - Random.map L.concat - <| Random.Extra.sequence - <| L.map (remplacerLaVariableDansLeBlocAleatoire vrbl vlr) sjt + Random.map L.concat <| + Random.Extra.sequence <| + L.map (remplacerLaVariableDansLeBlocAleatoire vrbl vlr) sjt + remplacerLaVariableParLaValeurDansLaProposition vrbl vlr prp = - case prp of - Vrai mcr -> Vrai <| remplacerLaVariableParLaValeurDansLaMacro vrbl vlr mcr - Faux mcr -> Faux <| remplacerLaVariableParLaValeurDansLaMacro vrbl vlr mcr + case prp of + Vrai mcr -> + Vrai <| remplacerLaVariableParLaValeurDansLaMacro vrbl vlr mcr + + Faux mcr -> + Faux <| remplacerLaVariableParLaValeurDansLaMacro vrbl vlr mcr {- - ██ ██ █████ ██████ ██ █████ ███ ██ ████████ ███████ ███████ - ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ - ██ ██ ███████ ██████ ██ ███████ ██ ██ ██ ██ █████ ███████ - ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ - ████ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ███████ ███████ + ██ ██ █████ ██████ ██ █████ ███ ██ ████████ ███████ ███████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ + ██ ██ ███████ ██████ ██ ███████ ██ ██ ██ ██ █████ ███████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ████ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ███████ ███████ -} -variantesBlocs : Blocs -> Blocs -variantesBlocs = L.concat << L.map variantesBloc +variantesBlocs : Blocs -> Blocs +variantesBlocs = + L.concat << L.map variantesBloc + variantesBloc : Bloc -> Blocs variantesBloc blcs = - case blcs of - Sujet blcss -> - L.singleton <| Sujet <| variantesBlocs blcss - VariableAremplacer ar blcss -> - remplacerLaVariableDansLesBlocs ar blcss - Entete mcr blcss -> - case qcmsDepuisVraiFauxx mcr blcss of - Just qcms -> qcms - Nothing -> [ Entete [ Texte "Je ne peux pas prendre en charge une telle imbrication :(" ] [] ] - VraiFaux prps -> [ VraiFaux prps ] - QCM mcr prps -> [ QCM mcr prps ] + case blcs of + Sujet blcss -> + L.singleton <| Sujet <| variantesBlocs blcss + + VariableAremplacer ar blcss -> + remplacerLaVariableDansLesBlocs ar blcss + + Entete mcr blcss -> + case qcmsDepuisVraiFauxx mcr blcss of + Just qcms -> + qcms + + Nothing -> + [ Entete [ Texte "Je ne peux pas prendre en charge une telle imbrication :(" ] [] ] + + VraiFaux prps -> + [ VraiFaux prps ] + + QCM mcr prps -> + [ QCM mcr prps ] + qcmsDepuisVraiFauxx : Macro -> Blocs -> Maybe Blocs qcmsDepuisVraiFauxx mcr blcs = - let - alternativesDuVraiFaux blc = - case blc of - VraiFaux prps -> Just prps - _ -> Nothing - listeDesAlternatives listePartielle listeDeMaybePropositions = - case listeDeMaybePropositions of - [] -> Just <| List.reverse listePartielle - Nothing :: lstMbPrps -> Nothing - Just prps :: lstMbPrps -> listeDesAlternatives (prps :: listePartielle) lstMbPrps - in - List.map alternativesDuVraiFaux blcs - |> listeDesAlternatives [] - |> Maybe.map mix - |> Maybe.map ( List.map (QCM mcr) ) + let + alternativesDuVraiFaux blc = + case blc of + VraiFaux prps -> + Just prps + + _ -> + Nothing + + listeDesAlternatives listePartielle listeDeMaybePropositions = + case listeDeMaybePropositions of + [] -> + Just <| List.reverse listePartielle + + Nothing :: lstMbPrps -> + Nothing + + (Just prps) :: lstMbPrps -> + listeDesAlternatives (prps :: listePartielle) lstMbPrps + in + List.map alternativesDuVraiFaux blcs + |> listeDesAlternatives [] + |> Maybe.map mix + |> Maybe.map (List.map (QCM mcr)) {-| mix [ [1,2] , [3,4] , [5,6] ] == [ [1,3,5] , [1,3,6] , [1,4,5] , [1,4,6] , [2,3,5] , ... ] -} mix : List (List a) -> List (List a) mix lls = - case lls of - [] -> [] - [] :: llss -> [] - l :: [] -> List.map List.singleton l - (a :: ls) :: llss -> ( List.map ( (::) a ) ( mix llss ) ) ++ mix ( ls :: llss ) + case lls of + [] -> + [] + + [] :: llss -> + [] + + l :: [] -> + List.map List.singleton l + + (a :: ls) :: llss -> + List.map ((::) a) (mix llss) ++ mix (ls :: llss) + + +queDesVraiFaux blcs = + List.foldl (&&) True <| List.map estUnVraiFaux blcs -queDesVraiFaux blcs = List.foldl (&&) True <| List.map estUnVraiFaux blcs estUnVraiFaux blc = - case blc of - VraiFaux _ -> True - _ -> False + case blc of + VraiFaux _ -> + True + + _ -> + False + remplacerLaVariableDansLeBloc : Aremplacer -> Bloc -> Blocs remplacerLaVariableDansLeBloc ar blc = - case blc of - Sujet blcs -> - remplacerLaVariableDansLesBlocs ar blcs - VariableAremplacer arr sjt -> - variantesBloc (VariableAremplacer arr sjt) - |> remplacerLaVariableDansLesBlocs ar - Entete mcr blcs -> - List.map (\x -> Entete x []) ( remplacerLaVariableDansLaMacro ar mcr ) - --( remplacerLaVariableDansLesBlocs ar blcs ) - QCM mcr prps -> - List.map (\x -> QCM x []) ( remplacerLaVariableDansLaMacro ar mcr ) - --( L.map (remplacerLaVariableParLaValeurDansLaProposition vrbl vlr) prps ) - VraiFaux prps -> [] - {-- - L.singleton - <| VraiFaux - <| L.singleton - <| remplacerLaVariableParLaValeurDansLaProposition vrbl vlr - <| prps - --} + case blc of + Sujet blcs -> + remplacerLaVariableDansLesBlocs ar blcs + + VariableAremplacer arr sjt -> + variantesBloc (VariableAremplacer arr sjt) + |> remplacerLaVariableDansLesBlocs ar + + Entete mcr blcs -> + List.map (\x -> Entete x []) (remplacerLaVariableDansLaMacro ar mcr) + + --( remplacerLaVariableDansLesBlocs ar blcs ) + QCM mcr prps -> + List.map (\x -> QCM x []) (remplacerLaVariableDansLaMacro ar mcr) + + --( L.map (remplacerLaVariableParLaValeurDansLaProposition vrbl vlr) prps ) + VraiFaux prps -> + [] + remplacerLaVariableDansLesBlocs : Aremplacer -> Blocs -> Blocs remplacerLaVariableDansLesBlocs ar blcs = - L.concat <| L.map (remplacerLaVariableDansLeBloc ar) blcs + L.concat <| L.map (remplacerLaVariableDansLeBloc ar) blcs {- - ██████ ██ ██ ██ ███████ ███████ ██████ █████ ███ ██ - ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ████ ██ - ██ ██ ██ ██ ██ ███ ███████ ██ ███████ ██ ██ ██ - ██ ▄▄ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ██ - ██████ ██████ ██ ███████ ███████ ██████ ██ ██ ██ ████ - ▀▀ + ██████ ██ ██ ██ ███████ ███████ ██████ █████ ███ ██ + ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ████ ██ + ██ ██ ██ ██ ██ ███ ███████ ██ ███████ ██ ██ ██ + ██ ▄▄ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ██ + ██████ ██████ ██ ███████ ███████ ██████ ██ ██ ██ ████ + ▀▀ -} + quizScanVoirBlocs : Blocs -> String quizScanVoirBlocs blcs = - S.join "\n" <| L.map quizScanVoirBloc blcs + S.join "\n" <| L.map quizScanVoirBloc blcs + quizScanVoirBloc prblm = - case prblm of - Sujet blcs -> - "\n\\begin{Sujet}\n" - ++ quizScanVoirBlocs blcs - ++ "\n\\end{Sujet}" - Entete mcr sjt -> - -- "\n \\begin{itemize}\n \\item " - voirMacro mcr - ++ "\n" - ++ quizScanVoirBlocs sjt - -- ++ " \\end{itemize}" - QCM mcr prps -> - let - f prp = - case prp of - Vrai mc -> - " \\Vrai{" ++ voirMacro mc ++ "}" - Faux mc -> - " \\Faux{" ++ voirMacro mc ++ "}" - in - "\n \\begin{QCM}\n" - ++ voirMacro mcr - ++ "\n \\begin{enumerate}\n" - ++ ( S.join "\n" <| L.map f prps ) - ++ "\n \\end{enumerate}\n \\end{QCM}" - VraiFaux prps -> - let - f prp = - case prp of - Vrai mc -> - "\n \\begin{VraiFaux}\n \\Vrai{" ++ voirMacro mc ++ "}\n \\end{VraiFaux}" - Faux mc -> - "\n \\begin{VraiFaux}\n \\Faux{" ++ voirMacro mc ++ "}\n \\end{VraiFaux}" - in - S.concat <| L.map f prps - VariableAremplacer ar sjt -> - "" ++ quizScanVoirBlocs sjt + case prblm of + Sujet blcs -> + "\n\\begin{Sujet}\n" + ++ quizScanVoirBlocs blcs + ++ "\n\\end{Sujet}" + + Entete mcr sjt -> + -- "\n \\begin{itemize}\n \\item " + voirMacro mcr + ++ "\n" + ++ quizScanVoirBlocs sjt + + -- ++ " \\end{itemize}" + QCM mcr prps -> + let + f prp = + case prp of + Vrai mc -> + " \\Vrai{" ++ voirMacro mc ++ "}" + + Faux mc -> + " \\Faux{" ++ voirMacro mc ++ "}" + in + "\n \\begin{QCM}\n" + ++ voirMacro mcr + ++ "\n \\begin{enumerate}\n" + ++ (S.join "\n" <| L.map f prps) + ++ "\n \\end{enumerate}\n \\end{QCM}" + + VraiFaux prps -> + let + f prp = + case prp of + Vrai mc -> + "\n \\begin{VraiFaux}\n \\Vrai{" ++ voirMacro mc ++ "}\n \\end{VraiFaux}" + + Faux mc -> + "\n \\begin{VraiFaux}\n \\Faux{" ++ voirMacro mc ++ "}\n \\end{VraiFaux}" + in + S.concat <| L.map f prps + + VariableAremplacer ar sjt -> + "" ++ quizScanVoirBlocs sjt {- - ███████ ██ ██ █████ ██ ██████ ██████ ██ ██ - ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ - █████ ██ ██ ███████ ██ ██████ ██ ██ ███ - ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ - ███████ ████ ██ ██ ███████ ██████ ██████ ██ ██ + ███████ ██ ██ █████ ██ ██████ ██████ ██ ██ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + █████ ██ ██ ███████ ██ ██████ ██ ██ ███ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ███████ ████ ██ ██ ███████ ██████ ██████ ██ ██ -} evalBoxVoirBlocs : Blocs -> String evalBoxVoirBlocs blcs = - S.join "\n" <| L.map evalBoxVoirBloc blcs + S.join "\n" <| L.map evalBoxVoirBloc blcs + evalBoxVoirBloc blc = - let - f prp = - case prp of - Vrai mc -> - "+" ++ voirMacro mc - Faux mc -> - "-" ++ voirMacro mc - in - case blc of - Sujet blcs -> - evalBoxVoirBlocs blcs - Entete mcr sjt -> - voirMacro mcr - ++ evalBoxVoirBlocs sjt - QCM mcr prps -> - voirMacro mcr - ++ "\n" - ++ ( S.join "\n" <| L.map f prps ) - VraiFaux prps -> - S.concat <| L.map f prps - VariableAremplacer ar sjt -> - "" ++ evalBoxVoirBlocs sjt + let + f prp = + case prp of + Vrai mc -> + "+" ++ voirMacro mc + + Faux mc -> + "-" ++ voirMacro mc + in + case blc of + Sujet blcs -> + evalBoxVoirBlocs blcs + + Entete mcr sjt -> + voirMacro mcr + ++ evalBoxVoirBlocs sjt + + QCM mcr prps -> + voirMacro mcr + ++ "\n" + ++ (S.join "\n" <| L.map f prps) + + VraiFaux prps -> + S.concat <| L.map f prps + + VariableAremplacer ar sjt -> + "" ++ evalBoxVoirBlocs sjt {- - ███ ███ ██ ██ ██ ███████ ██ ██ ██████ - ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ - ██ ████ ██ ██ ███ █████ ██ ██ ██████ - ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ - ██ ██ ██ ██ ██ ███████ ██████ ██ ██ + ███ ███ ██ ██ ██ ███████ ██ ██ ██████ + ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ + ██ ████ ██ ██ ███ █████ ██ ██ ██████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ██ ██ ██ ██ ██ ███████ ██████ ██ ██ -} - {-- remplacer : String -> String -> List String remplacer variables question = @@ -796,86 +946,145 @@ remplacerLesVariablesDansLaMacroBis ars macros = |> remplacerLesVariablesDansLaMacroBis arss --} + remplacerLaVariableDansLaMacro : Aremplacer -> Macro -> List Macro remplacerLaVariableDansLaMacro ar mcr = - let - f val = remplacerLaVariableParLaValeurDansLaMacro ar.var val mcr - in - L.map f ar.vals + let + f val = + remplacerLaVariableParLaValeurDansLaMacro ar.var val mcr + in + L.map f ar.vals + remplacerLaVariableParLaValeurDansLaMacro : String -> String -> Macro -> Macro remplacerLaVariableParLaValeurDansLaMacro var val mcr = - L.map (remplacerLaVariableParLaValeurDansLeTexteVariable var val) mcr + L.map (remplacerLaVariableParLaValeurDansLeTexteVariable var val) mcr + remplacerLaVariableParLaValeurDansLeTexteVariable var val tv = - case tv of - Texte chaine -> Texte chaine - Variable chaine -> Variable <| S.replace var val chaine ---} + case tv of + Texte chaine -> + Texte chaine + Variable chaine -> + Variable <| S.replace var val chaine -{- - ███████ ██ ██ ██████ ██████ ███████ ███████ ███████ ██ ██████ ███ ██ ███████ - ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ - █████ ███ ██████ ██████ █████ ███████ ███████ ██ ██ ██ ██ ██ ██ ███████ - ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ - ███████ ██ ██ ██ ██ ██ ███████ ███████ ███████ ██ ██████ ██ ████ ███████ - - +{- + ███████ ██ ██ ██████ ██████ ███████ ███████ ███████ ██ ██████ ███ ██ ███████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ + █████ ███ ██████ ██████ █████ ███████ ███████ ██ ██ ██ ██ ██ ██ ███████ + ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ + ███████ ██ ██ ██ ██ ██ ███████ ███████ ███████ ██ ██████ ██ ████ ███████ -} + monome a n = - if a == 0 then "" - else if n == 0 then ( String.fromInt a ) - else if (n,a) == (1,1) then "x" - else if (n,a) == (1,-1) then "-x" - else if n == 1 then ( String.fromInt a ) ++ "x" - else if a == 1 then "x^{" ++ ( String.fromInt n ) ++ "}" - else if a == -1 then "-x^{" ++ ( String.fromInt n ) ++ "}" - else ( String.fromInt a ) ++ "x^{" ++ ( String.fromInt n ) ++ "}" + if a == 0 then + "" + + else if n == 0 then + String.fromInt a + + else if ( n, a ) == ( 1, 1 ) then + "x" + + else if ( n, a ) == ( 1, -1 ) then + "-x" + + else if n == 1 then + String.fromInt a ++ "x" + + else if a == 1 then + "x^{" ++ String.fromInt n ++ "}" + + else if a == -1 then + "-x^{" ++ String.fromInt n ++ "}" + + else + String.fromInt a ++ "x^{" ++ String.fromInt n ++ "}" + poly a_ks = - if a_ks == [] then "0" - else polyBis a_ks ( List.length a_ks - 1 ) + if a_ks == [] then + "0" + + else + polyBis a_ks (List.length a_ks - 1) + polyBis a_ks n = - case a_ks of - [] -> "" - a_n :: a_kss -> - if a_n == 0 then polyBis a_kss ( n - 1 ) - else ( monome a_n n ) ++ ( polyGen a_kss ( n - 1 ) ) + case a_ks of + [] -> + "" + + a_n :: a_kss -> + if a_n == 0 then + polyBis a_kss (n - 1) + + else + monome a_n n ++ polyGen a_kss (n - 1) + polyGen a_ks n = - case a_ks of - [] -> "" - a_i :: a_is -> - if a_i <= 0 then ( monome a_i n ) ++ ( polyGen a_is ( n - 1 ) ) - else "+" ++ ( monome a_i n ) ++ ( polyGen a_is ( n - 1 ) ) + case a_ks of + [] -> + "" + + a_i :: a_is -> + if a_i <= 0 then + monome a_i n ++ polyGen a_is (n - 1) + + else + "+" ++ monome a_i n ++ polyGen a_is (n - 1) + + +polyD a_ks = + polyDbis a_ks (List.length a_ks - 1) -polyD a_ks = polyDbis a_ks ( List.length a_ks - 1 ) polyDbis a_ks n = - case a_ks of - [] -> [] - a_0 :: [] -> [] - a_k :: a_kss -> ( n*a_k ) :: polyDbis a_kss ( n - 1 ) + case a_ks of + [] -> + [] + + a_0 :: [] -> + [] + + a_k :: a_kss -> + (n * a_k) :: polyDbis a_kss (n - 1) + dl a_ks = - if a_ks == [] then "0" - else dlBis a_ks 0 + if a_ks == [] then + "0" + + else + dlBis a_ks 0 + dlBis a_ks n = - case a_ks of - [] -> "" - premierCoef :: suite -> - if premierCoef == 0 then dlBis suite ( n + 1 ) - else ( monome premierCoef n ) ++ ( dlGen suite ( n + 1 ) ) + case a_ks of + [] -> + "" + + premierCoef :: suite -> + if premierCoef == 0 then + dlBis suite (n + 1) + + else + monome premierCoef n ++ dlGen suite (n + 1) + dlGen a_ks n = - case a_ks of - [] -> "" - a_i :: a_is -> - if a_i <= 0 then ( monome a_i n ) ++ ( dlGen a_is ( n + 1 ) ) - else "+" ++ ( monome a_i n ) ++ ( dlGen a_is ( n + 1 ) ) \ No newline at end of file + case a_ks of + [] -> + "" + + a_i :: a_is -> + if a_i <= 0 then + monome a_i n ++ dlGen a_is (n + 1) + + else + "+" ++ monome a_i n ++ dlGen a_is (n + 1) diff --git a/src/ParserMaths.elm b/src/ParserMaths.elm index 1680da8..70ae215 100644 --- a/src/ParserMaths.elm +++ b/src/ParserMaths.elm @@ -1,9 +1,9 @@ -module ParserMaths exposing (parseMaths, evaluer, evaluerBis, montrerErreurs, expr) +module ParserMaths exposing (evaluer, evaluerBis, expr, montrerErreurs, parseMaths) import Fraction as F exposing (Fraction, Resultat, frac, opp) import Maybe as M -import Set import Parser exposing (..) +import Set montrerErreurs : String -> List DeadEnd -> String @@ -11,6 +11,7 @@ montrerErreurs source errs = case List.head errs of Nothing -> "" + Just firstErr -> source ++ "\n" @@ -27,16 +28,23 @@ montrerAttendu err = case err.problem of ExpectingNumber -> "un nombre entier" + ExpectingSymbol s -> "un \"" ++ s ++ "\"" + _ -> "une expression" + evaluerBis : Expr -> Fraction evaluerBis expression = case evaluer expression of - Err _ -> { num = 666, den = 1 } - Ok a -> a + Err _ -> + { num = 666, den = 1 } + + Ok a -> + a + evaluer : Expr -> Resultat evaluer expression = @@ -68,13 +76,14 @@ evaluer expression = Poly a_i x -> Err "Les polynômes ne sont pas encore pris en charge." + + {-- appliquerAuResultat f a b = case (a,b) of (Ok aa, Ok bb) -> Ok <| f aa bb (Err aa, _) -> Err aa --} - {-- type Expr = Const Fraction @@ -92,6 +101,7 @@ type Expr | Opp Expr --} + type Expr = Add Expr Expr | Sub Expr Expr @@ -127,10 +137,13 @@ type Operand | Operand Operator Expr + {- - En quelque sorte, décurryfie une expression binaire - binary e_1 (Operand MulOp e_2) == Mul e_1 e_2 + En quelque sorte, décurryfie une expression binaire + binary e_1 (Operand MulOp e_2) == Mul e_1 e_2 -} + + binary : Expr -> Operand -> Expr binary a b = case b of @@ -164,13 +177,16 @@ add = |= loop [] addHelper --- + +-- + + foldBinary : Expr -> List Operand -> Expr foldBinary left operands = List.foldr - (\operand expression -> binary expression operand) - left - operands + (\operand expression -> binary expression operand) + left + operands addHelper : List Operand -> Parser (Step (List Operand) (List Operand)) @@ -231,7 +247,8 @@ exp = primary : Parser Expr primary = - succeed (\op literal -> + succeed + (\op literal -> case op of Nothing -> literal @@ -239,16 +256,16 @@ primary = Just _ -> Neg literal ) - |= oneOf - [ succeed Just - |= symbol "-" - , succeed Nothing - ] - |= oneOf - [ grouping - , poly - , nombre - ] + |= oneOf + [ succeed Just + |= symbol "-" + , succeed Nothing + ] + |= oneOf + [ grouping + , poly + , nombre + ] nombre : Parser Expr @@ -262,6 +279,7 @@ nombre = , float = Nothing } + poly : Parser Expr poly = succeed Poly @@ -290,4 +308,4 @@ grouping = |. spaces |= lazy (\_ -> expr) |. spaces - |. symbol ")" \ No newline at end of file + |. symbol ")" diff --git a/src/Test.elm b/src/Test.elm index a038730..e9e273d 100644 --- a/src/Test.elm +++ b/src/Test.elm @@ -1,31 +1,29 @@ module Test exposing (..) import Browser -import Html exposing (Html, button, div, text) -import Html.Events exposing (onClick) -import MiniLatex ---import MiniLatex.Render exposing(MathJaxRenderOption(..)) +import Element exposing (..) +import Element.Input as Input +import Html exposing (Html) + -- MAIN main = - Browser.sandbox { init = init, update = update, view = view } - -texteLaTeX = "Pythagoras says: $a^2 + b^2 = c^2$" + Browser.sandbox { init = init, update = update, view = view } -- MODEL -type alias Model = Int +type alias Model = + { texte : String } -init : Model init = - 0 + { texte = "" } @@ -33,18 +31,12 @@ init = type Msg - = Increment - | Decrement + = NouveauTexte String update : Msg -> Model -> Model -update msg model = - case msg of - Increment -> - model + 1 - - Decrement -> - model - 1 +update (NouveauTexte texte) model = + { texte = texte } @@ -53,4 +45,17 @@ update msg model = view : Model -> Html Msg view model = - MiniLatex.render "" NoDelay texteLaTeX + layout [ width fill, height fill ] <| + row [] + [ Input.multiline [ height <| maximum 300 fill, clip, scrollbars ] + { onChange = NouveauTexte + , label = Input.labelAbove [] <| text "Test" + , placeholder = + Just <| + Input.placeholder [] <| + text "Entrer le texte" + , text = String.toUpper model.texte + , spellcheck = False + } + , text model.texte + ]