From dda945f12bc5e16ad49f0c972ab33862f8e9ed7f Mon Sep 17 00:00:00 2001 From: Miguel Barão Date: Thu, 8 Jul 2021 19:09:38 +0100 Subject: [PATCH] fixed most errors reported by pyright and mypy other changes and cleanup --- BUGS.md | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------- QUESTIONS.md | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------- README.md | 56 ++++++++++++++++++++++++++++++++++++-------------------- aprendizations/__init__.py | 4 ++-- aprendizations/initdb.py | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------- aprendizations/learnapp.py | 602 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- aprendizations/main.py | 77 ++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- aprendizations/questions.py | 468 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- aprendizations/serve.py | 338 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------- aprendizations/static/css/animate.min.css | 11 ----------- aprendizations/static/css/topic.css | 12 ------------ aprendizations/student.py | 264 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------ aprendizations/templates/courses.html | 24 ++++++++++++------------ aprendizations/templates/login.html | 16 ++++++++-------- aprendizations/templates/maintopics-table.html | 20 ++++++++++---------- aprendizations/templates/rankings.html | 59 +++++++++++++++++++++++++++-------------------------------- aprendizations/templates/topic.html | 62 ++++++++++++++++++++++++++++++-------------------------------- aprendizations/tools.py | 2 +- package-lock.json | 49 +++++++++++++++++++++++++++++++++++++++---------- package.json | 6 +++--- setup.py | 4 ++-- 21 files changed, 1358 insertions(+), 1053 deletions(-) delete mode 100644 aprendizations/static/css/animate.min.css diff --git a/BUGS.md b/BUGS.md index 6d08bb4..062bd43 100644 --- a/BUGS.md +++ b/BUGS.md @@ -1,7 +1,21 @@ # BUGS -- nao esta a seguir o max_tries definido no ficheiro de dependencias. +- internal server error ao fazer logout no macos python3.8 +- GET can get filtered by browser cache +- topicos chapter devem ser automaticamente completos assim que as dependencias + são satisfeitas. Nao devia ser necessario (ou possivel?) clicar neles. +- topicos do tipo learn deviam por defeito nao ser randomizados e assumir + ficheiros `learn.yaml`. +- internal server error 500... experimentar cenario: aluno tem login efectuado, + prof muda pw e faz login/logout. aluno obtem erro 500. +- radio sem options rebenta com aprendizations --check +- chapters deviam ser mostrados unlocked, antes de mostrar a medalha. alunos + pensam que já terminaram e não conseguem progredir por causa das + dependencias. +- if topic deps on invalid ref terminates server with "Unknown error". +- warning nos topics que não são usados em nenhum curso +- nao esta a seguir o `max_tries` definido no ficheiro de dependencias. - devia mostrar timeout para o aluno saber a razao. - permitir configuracao para escolher entre static files locais ou remotos - shift-enter não está a funcionar @@ -9,67 +23,93 @@ # TODO -- alterar tabelas para incluir email de recuperacao de password (e outros avisos) -- registar last_seen e remover os antigos de cada vez que houver um login. +- shuffle das perguntas dentro de um topico +- alterar tabelas para incluir email de recuperacao de password (e outros + avisos) +- registar `last_seen` e remover os antigos de cada vez que houver um login. - indicar qtos topicos faltam (>=50%) para terminar o curso. - ao fim de 3 tentativas com password errada, envia email com nova password. -- mostrar capitulos e subtopicos de forma hierarquica. clicar no capitulo expande as dependencias. -- mostrar rankings alunos/perguntas respondidas/% correctas/valor esperado topicos. +- mostrar capitulos e subtopicos de forma hierarquica. clicar no capitulo + expande as dependencias. +- mostrar rankings alunos/perguntas respondidas/% correctas/valor esperado + topicos. - botão não sei... - mostrar icon "loading..." enquanto está a corrigir uma pergunta. - session management. close after inactive time. - radio e checkboxes, aceitar numeros como seleccao das opcoes. -- reload das perguntas enquanto online. ver signal em http://stackabuse.com/python-async-await-tutorial/ +- reload das perguntas enquanto online. ver signal em + [](http://stackabuse.com/python-async-await-tutorial/) - tabela de progresso de todos os alunos por topico. - tabela com perguntas / quantidade de respostas certas/erradas. - tabela com topicos / quantidade de estrelas. - pymips: activar/desactivar instruções - titulos das perguntas não suportam markdown. -- pagina report que permita ver tabela alunos/topicos, estatisticas perguntas mais falhadas, tempo médio por pergunta. +- pagina report que permita ver tabela alunos/topicos, estatisticas perguntas + mais falhadas, tempo médio por pergunta. - normalizar com perguntations. # FIXED -- templates question-*.html tem input hidden question_ref que não é usado. remover? +- templates question-*.html tem input hidden question_ref que não é usado. + remover? - goals se forem do tipo chapter deve importar todas as dependencias do chapter. -- initdb da integrity error se no mesmo comando existirem alunos repetidos (p.ex em ficheiros csv diferentes ou entre csv e opcao -a) -- dependencias que não são goals de um curso, só devem aparecer se ainda não tiverem sido feitas. +- initdb da integrity error se no mesmo comando existirem alunos repetidos + (p.ex em ficheiros csv diferentes ou entre csv e opcao -a) +- dependencias que não são goals de um curso, só devem aparecer se ainda não + tiverem sido feitas. - ir para inicio da pagina quando le nova pergunta. - CRITICAL nao esta a guardar o progresso na base de dados. - mesma ref no mesmo ficheiro não é detectado. - enter nas respostas mostra json -- apos clicar no botao responder, inactivar o input (importante quando o tempo de correcção é grande) +- apos clicar no botao responder, inactivar o input (importante quando o tempo + de correcção é grande) - double click submits twice. -- checkbox devia ter correct no intervalo [0,1] tal como radio. em caso de desconto a correccção faz 2*x-1. isto permite a mesma semantica nos dois tipos de perguntas. +- checkbox devia ter correct no intervalo [0,1] tal como radio. em caso de + desconto a correccção faz 2*x-1. isto permite a mesma semantica nos dois + tipos de perguntas. - marking all options right in a radio question breaks! - implementar servidor http com redirect para https. - tabelas nas perguntas radio/checkbox não ocupam todo o espaço como em question. - click numa opcao checkbox fora da checkbox+label não está a funcionar. -- mathjax, formulas $$f(x)$$ nas opções de escolha multipla, não ficam centradas em toda a coluna mas apenas na largura do parágrafo. -- QFactory.generate() devia fazer run da gen_async, ou remover. +- mathjax, formulas $$f(x)$$ nas opções de escolha multipla, não ficam + centradas em toda a coluna mas apenas na largura do parágrafo. +- QFactory.generate() devia fazer run da `gen_async,` ou remover. - classificacoes so devia mostrar os que ja fizeram alguma coisa - impedir que quando students.db não é encontrado, crie um ficheiro vazio. -- permite definir goal, mas nao verifica se esta no grafo. rebenta no start_topic. -- se num topico, a ultima pergunta tem imagens, o servidor nao fornece as imagengs porque o current_topic passa a None antes de carregar no botao continuar. O caminho é prefix+None e dá erro. +- permite definir goal, mas nao verifica se esta no grafo. rebenta no + `start_topic`. +- se num topico, a ultima pergunta tem imagens, o servidor nao fornece as + imagengs porque o `current_topic` passa a None antes de carregar no botao + continuar. O caminho é prefix+None e dá erro. - caixas com os cursos não se ajustam bem com ecran estreito. -- obter rankings por curso GET course=course_id -- no curso de linear algebra, as perguntas estao shuffled, mas nao deviam estar... nao esta a obedecer a keyword shuffle. +- obter rankings por curso `GET course=course_id` +- no curso de linear algebra, as perguntas estao shuffled, mas nao deviam + estar... nao esta a obedecer a keyword shuffle. - menu nao mostra as opcoes correctamente - finish topic vai para a lista de cursos. devia ficar no mesmo curso. - mathjax nao esta a correr sobre o titulo. - forgetting factor is hardcoded in student.py - add aprendizatons --version -- se aluno abre dois tabs no browser, conseque navegar em simultaneo para perguntas diferentes. quando submete uma delas dá asneira. Tem de haver um campo hidden que tenha um céodigo único que indique qual a pergunta. do lado do servidor apnas há o codigo da pergunta corrente, se forem diferentes faz redirect para /. +- se aluno abre dois tabs no browser, conseque navegar em simultaneo para + perguntas diferentes. quando submete uma delas dá asneira. Tem de haver um + campo hidden que tenha um céodigo único que indique qual a pergunta. do lado + do servidor apnas há o codigo da pergunta corrente, se forem diferentes faz + redirect para /. - nos topicos learn.yaml, qd falha acrescenta no fim. nao faz sentido. -- não esta a fazer render correcto de tabelas nas opcoes checkbox. e.g. information-theory/source-coding-theory/block-codes +- não esta a fazer render correcto de tabelas nas opcoes checkbox. e.g. + `information-theory/source-coding-theory/block-codes` - max tries nas perguntas. - mostrar feedback/solucoes quando acerta, ou excede max tries. -- quando se pressiona "responde" rapido (enquanto a animacao dura), a pergunta passa para a seguinte sem haver o correspondente redraw, ou seja a proxima resposta nao é a da pergunta mostrada. +- quando se pressiona "responde" rapido (enquanto a animacao dura), a pergunta + passa para a seguinte sem haver o correspondente redraw, ou seja a proxima + resposta nao é a da pergunta mostrada. - botao para mostrar a solução quando se acerta. - não está a guardar o resultado no final do topico -- esta a permitir 2 logins em simultaneo do mesmo user. fica tudo baralhado se mxerem em simultaneo... +- esta a permitir 2 logins em simultaneo do mesmo user. fica tudo baralhado se + mxerem em simultaneo... - errar no ultimo topico nao mostra solucao? -- quando a pergunta devolve comments, este é apresentado, mas fica persistente nas tentativas seguintes. devia ser limpo apos a segunda submissao. +- quando a pergunta devolve comments, este é apresentado, mas fica persistente + nas tentativas seguintes. devia ser limpo apos a segunda submissao. - na definicao dos topicos, indicar: "file: questions.yaml" (default questions.yaml) "shuffle: True/False" (default False) @@ -84,9 +124,11 @@ - each topic only loads a sample of K questions (max) in random order. - change password modal nao aparece no ipad (safari e firefox) - detect questions in questions.yaml without ref -> error ou generate default. -- generators e correct scripts que durem muito tempo bloqueiam o eventloop do tornado. +- generators e correct scripts que durem muito tempo bloqueiam o eventloop do + tornado. - servir imagens/ficheiros. -- radio: suporte para multiplas opcoes correctas e erradas, escolhendo-se uma selecção aleatoria destas (so com 1 certa). +- radio: suporte para multiplas opcoes correctas e erradas, escolhendo-se uma + selecção aleatoria destas (so com 1 certa). - checkbox: cada opção pode ser uma dupla (certo, errado) sendo escolhida uma aleatória. - async/threadpool no bcrypt do initdb. - numero de estrelas depende da proporcao entre certas e erradas. @@ -97,10 +139,12 @@ - remover learn.css uma vez que nao é usado em lado nenhum? - check if user already logged in - mover javascript para ficheiros externos e carregar com script defer src -- implementar xsrf. Ver [http://www.tornadoweb.org/en/stable/guide/security.html#cross-site-request-forgery-protection]() -- se refs de um topic estao invalidos, nao carrega esse topico. devia haver um error nos logs a indicar qual o ref invalido. +- implementar xsrf. Ver [](http://www.tornadoweb.org/en/stable/guide/security.html#cross-site-request-forgery-protection) +- se refs de um topic estao invalidos, nao carrega esse topico. devia haver um + error nos logs a indicar qual o ref invalido. - link directo para topico nao valida se topico esta unlocked. -- templates not working: quesntion-information, question-warning (remove all informative panels??) +- templates not working: quesntion-information, question-warning (remove all + informative panels??) - enderecos errados dao internal error. - barra de progresso nao está visível. - tabs em textarea nao funcionam correctamente (insere 1 espaco em vez de 4) @@ -110,14 +154,15 @@ - animação no final de cada topico para se perceber a transição - "<" is not escaped in markdown. - Está a mostrar a solução em 'comments'!!! -- database: answers não tem referencia para o topico, so para question_ref +- database: answers não tem referencia para o topico, so para `question_ref` - melhorar markdown das tabelas. - gravar evolucao na bd no final de cada topico. - submeter questoes radio, da erro se nao escolher nenhuma opção. - indentação da primeira linha de código não funciona. - markdown com o mistune. - change password in maintopics.html, falta menu para lançar modal -- ver documentacao de migracao para networkx 2.0 https://networkx.github.io/documentation/stable/release/migration_guide_from_1.x_to_2.0.html +- ver documentacao de migracao para networkx 2.0 + [](https://networkx.github.io/documentation/stable/release/migration_guide_from_1.x_to_2.0.html) - script para adicionar users/reset passwords. - os topicos locked devem estar inactivos no sidebar. - enter faz GET /question, que responde com json no ecran. (solution: disabled enter) @@ -126,7 +171,8 @@ - indicar o topico actual no sidebar - reload da página rebenta o estado. - text deve mostrar no html os valores iniciais de ans, se existir -- nao permite perguntas repetidas. iterar questions da configuracao em vez das do ficheiro. ver app.py linha 223. +- nao permite perguntas repetidas. iterar questions da configuracao em vez das + do ficheiro. ver app.py linha 223. - level depender do numero de respostas correctas - pymips a funcionar - logs mostram que está a gerar cada pergunta 2 vezes...?? @@ -138,15 +184,18 @@ - se students.db não existe, rebenta. - não entra à primeira - configuração e linha de comando. -- o browser é redireccionado para /question em vez de fazer um post?? quando se pressiona enter numa caixa text edit. +- o browser é redireccionado para /question em vez de fazer um post?? quando se + pressiona enter numa caixa text edit. - load/save the knowledge state of the student - servir ficheiros de public temporariamente - path dos generators scripts mal construido - questions hardcoded in LearnApp. - Factory para cada pergunta individual em vez de pool -- implementar navegacao radio/checkbox. cursor cima/baixo, espaco selecciona, enter submete. +- implementar navegacao radio/checkbox. cursor cima/baixo, espaco selecciona, + enter submete. - logging -- textarea tem codigo para preencher o texto, mas ja não é necessário porque pergunta não é reloaded. +- textarea tem codigo para preencher o texto, mas ja não é necessário porque + pergunta não é reloaded. - gravar answers -> db - como gerar key para secure cookie. - https. certificados selfsigned, no-ip nao suporta certificados @@ -161,4 +210,5 @@ - clicar texto selecciona checkboxes/radio. - focar text/textarea - implementar template base das perguntas base e estender para cada tipo. -- submissão com enter em perguntas text faz get? provavelmente está a fazer o submit do form em vez de ir pelo ajax. +- submissão com enter em perguntas text faz get? provavelmente está a fazer o + submit do form em vez de ir pelo ajax. diff --git a/QUESTIONS.md b/QUESTIONS.md index e5fdfda..0c22800 100644 --- a/QUESTIONS.md +++ b/QUESTIONS.md @@ -1,6 +1,7 @@ # Questions -Questions are saved in files in the [YAML](http://www.yaml.org/start.html) format. Each file contains a list of questions like +Questions are saved in files in the [YAML](http://www.yaml.org/start.html) +format. Each file contains a list of questions like ```yaml - type: radio @@ -12,10 +13,11 @@ Questions are saved in files in the [YAML](http://www.yaml.org/start.html) forma ... ``` -where each question is specified in a dictionary. -The `type` key is mandatory and specifies the type of question (multiple choice, text, etc). -The other keys available will depend on the type of question. -The field `ref` is not strictly required but still recommended, if not defined it will default to a string with the filename and the question index, e.g., `questions.yaml:12`. +where each question is specified in a dictionary. The `type` key is mandatory +and specifies the type of question (multiple choice, text, etc). The other +keys available will depend on the type of question. The field `ref` is not +strictly required but still recommended, if not defined it will default to a +string with the filename and the question index, e.g., `questions.yaml:12`. The following types of questions are supported: @@ -34,15 +36,16 @@ type | kind of answer ### radio -Only one option can be selected as the answer. If no option is selected, the question is considered unanswered. +Only one option can be selected as the answer. If no option is selected, the +question is considered unanswered. The general format is ```yaml - type: radio - ref: question_reference + ref: question_reference title: My first question - text: | + text: | Please select one option. options: - this one is the correct one @@ -54,30 +57,37 @@ The general format is discount: yes # default: yes ``` -All fields are optional except `type` and `options`. `title` and `text` default to empty strings, `shuffle` and `discount` to `true`. +All fields are optional except `type` and `options`. `title` and `text` default +to empty strings, `shuffle` and `discount` to `true`. -The `correct` field can be used in multiple ways and in combination with `shuffle`, `discount` and `choose` fields: +The `correct` field can be used in multiple ways and in combination with +`shuffle`, `discount` and `choose` fields: -- if not present, the first option is considered correct (options are shuffled by default when presented to the student). -- it can be the index (0-based) of the correct option, e.g., `correct: 0` for the first option. -- it can be a list of numbers between 0 and 1, e.g., `correct: [1, 0, 0]`. In this case, the first option is 100% correct while the others are 0%. If `discount: true` (the default), then the wrong ones will be penalized by $-1/(n-1)=-\tfrac{1}{2}$, where $n$ is the number of options. +- if not present, the first option is considered correct (options are shuffled + by default when presented to the student). +- it can be the index (0-based) of the correct option, e.g., `correct: 0` for + the first option. +- it can be a list of numbers between 0 and 1, e.g., `correct: [1, 0, 0]`. In + this case, the first option is 100% correct while the others are 0%. If `discount: true` (the default), then the wrong ones will be penalized by $-1/(n-1)=-\tfrac{1}{2}$, where $n$ is the number of options. - there can be more than one correct option in the list, which is then marked in the correct field, e.g. `correct: [1, 1, 0]`. In this case, one of the correct options will be randomly selected, and the remaining wrong ones appended. - there can also be a long list of right and wrong options from which to build the question options. E.g. if `correct: [1,1,1,0,0,0,0]` and `choose: 3` is defined, then 1 correct option and 2 wrong ones are randomly selected from the list. - finally it's also possible to have a question that is *"not-completely-right"* or *"not-completely-wrong"*. This can be done using numbers between 0 and 1, e.g., `correct: [1, 0.3, 0]`. This practice is discouraged. -In some situations one may not want the options to be shuffled. In that case use `shuffle: false`. +In some situations one may not want the options to be shuffled. In that case +use `shuffle: false`. ### checkbox -Zero, one or multiple options can be selected. The question is always considered as answered, even if no options are selected. +Zero, one or multiple options can be selected. The question is always +considered as answered, even if no options are selected. -The simplest format is +The simplest format is ```yaml - type: checkbox ref: question_reference title: My second question - text: | + text: | Please mark the correct options. options: - this one is correct @@ -89,16 +99,22 @@ The simplest format is discount: yes # default: yes ``` -All fields are optional except `type` and `options`. `title` and `text` default to empty strings, `shuffle` and `discount` to `true` and `choose` to the total number of options. +All fields are optional except `type` and `options`. `title` and `text` default +to empty strings, `shuffle` and `discount` to `true` and `choose` to the total +number of options. -When correcting an answer, each correctly marked/unmarked option gets the corresponding value from the list `correct: [1, -1, 1]` and each wrong gets its symmetrical. So in the previous example, to have a completely right answer the checboxes should be: marked, unmarked, marked. +When correcting an answer, each correctly marked/unmarked option gets the +corresponding value from the list `correct: [1, -1, 1]` and each wrong gets its +symmetrical. So in the previous example, to have a completely right answer the +checboxes should be: marked, unmarked, marked. -If `discount: no` then wrong options are given a value of 0. -Options are shuffled by default. A smaller number of options may be randomly selected by setting the option `choose`. +If `discount: no` then wrong options are given a value of 0. Options are +shuffled by default. A smaller number of options may be randomly selected by +setting the option `choose`. -A more advanced format is to have two versions for each option, one right and one wrong. -One of the versions is randomly selected when the question is generated. -For example, +A more advanced format is to have two versions for each option, one right and +one wrong. One of the versions is randomly selected when the question is +generated. For example, ```yaml options: @@ -108,11 +124,12 @@ For example, correct: [1, -1, -1] ``` -If the first version is selected then the corresponding `correct` value is used, otherwise if -the second version is selected, then the symmetrical value is used instead. +If the first version is selected then the corresponding `correct` value is +used, otherwise if the second version is selected, then the symmetrical value +is used instead. -This format is useful to write questions that are presented in different ways to different students. -It also minimizes solution memorization. Example: +This format is useful to write questions that are presented in different ways +to different students. It also minimizes solution memorization. Example: ```yaml options: @@ -122,7 +139,8 @@ It also minimizes solution memorization. Example: ### text -The answer is a single line of text. Just compare the answered text with the strings provided in a list of answers considered to be right. +The answer is a single line of text. Just compare the answered text with the +strings provided in a list of answers considered to be right. ```yaml - type: text @@ -144,12 +162,14 @@ Similar to text, but answers are validated by a regular expression. correct: !regex '[wW]eek' # default: '$.^' always wrong ``` -The regular expression is in a string and must be prefixed by the keyword `!regex`. +The regular expression is in a string and must be prefixed by the keyword +`!regex`. ### numeric-interval -Similar to text, but expects an integer or floating point number. -The answer is converted to a float and is considered correct if the number is in the given closed interval. +Similar to text, but expects an integer or floating point number. The answer +is converted to a float and is considered correct if the number is in the given +closed interval. ```yaml - type: numeric-interval @@ -161,9 +181,10 @@ The answer is converted to a float and is considered correct if the number is in ### textarea -Provides a multiline textarea for the answer. -The answered text is sent to the standard input of an external program for grading. -The printed output to standard output of the program is parsed as YAML to get the grade and optional comments. +Provides a multiline textarea for the answer. The answered text is sent to the +standard input of an external program for grading. The printed output to +standard output of the program is parsed as YAML to get the grade and optional +comments. ```yaml - type: textarea @@ -185,7 +206,6 @@ comments: Almost there It can also just print the grade as a single number. - ### information, warning, alert and success These are not really questions, but just provides information for the student. @@ -201,8 +221,8 @@ Grading these type of "questions" yields always correct. ### generator -Questions can be generated by external programs instead of being defined directly. -This allows great flexibility, and allows each instance of a question to be always different. +This allows great flexibility, and allows each instance of a question to be +always different. ```yaml type: generator @@ -211,16 +231,18 @@ script: executable_program arg: 10,20 ``` -A generator is an external program that generates a question dynamically. +A generator is an external program that generates a question dynamically. In the example above, the program to be run is `executable_program`. The `arg` is sent to the standard input of the `executable_program`. -Questions should be printed to the stdout in YAML format, similarly to how they are defined above (but without the list dash). -The printed question is then parsed to a dictionary which is then used to update the question. -The `type` is redefined from generator to something else and the other fields are also updated. +Questions should be printed to the stdout in YAML format, similarly to how they +are defined above (but without the list dash). The printed question is then +parsed to a dictionary which is then used to update the question. The `type` +is redefined from generator to something else and the other fields are also +updated. -A generator can be any executable program (written in any language) that prints to the standard output. -Example of a generator written in python: +A generator can be any executable program (written in any language) that prints +to the standard output. Example of a generator written in python: ```python #!/usr/bin/env python3 @@ -234,7 +256,8 @@ a,b = (int(n) for n in arg.split(',')) q = fr''' type: checkbox text: | - Indique quais das seguintes adições resultam em overflow quando se considera a adição de números com sinal (complemento para 2) em registos de 8 bits. + Indique quais das seguintes adições resultam em overflow quando se considera + a adição de números com sinal (complemento para 2) em registos de 8 bits. Os números foram gerados aleatoriamente no intervalo de {a} a {b}. options: @@ -254,14 +277,14 @@ print(q) A generator cannot generate another generator, only real questions are acceptable. -# Writing text +## Writing text The text in the questions is interpreted as markdown with support for LaTeX formulas. The best way to write text is to use indentation like this: ```yaml text: | - Yes. this is ok: If not indented, "Yes" would be a boolean + Yes. this is ok: If not indented, "Yes" would be a boolean and colon would be interpreted as a dictionary key. Images placed in the `public` subdirectory are accessible by diff --git a/README.md b/README.md index 9fffa75..345ded3 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ sudo port install python37 npm6 # MacOS ``` #### Installing from source - + Make sure that the build tools and libraries are installed: ```sh @@ -54,7 +54,7 @@ This will install python locally under `~/.local/bin`. Make sure to add it to yo ### Install pip -Python usually includes pip which is accessible through `python -m pip install something`, but it's also convenient to have the `pip` command directly available in the terminal. +Python usually includes pip which is accessible through `python -m pip install something`, but it's also convenient to have the `pip` command directly available in the terminal. To install `pip` from the system package manager: ```sh @@ -70,12 +70,12 @@ python3.7 -m pip install pip # install in user area ``` The latter will install `pip` in your user account under `~/.local/bin`. -In the end you should be able to run `pip --version` and +In the end you should be able to run `pip --version` and `python3 -c "import sqlite3"` without errors. -Sometimes the `pip` command is named `pip3`, +Sometimes the `pip` command is named `pip3`, `pip3.7` or `pip-3.7`. -Edit the configuration file `~/.config/pip/pip.conf` (FreeBSD, Linux) or +Edit the configuration file `~/.config/pip/pip.conf` (FreeBSD, Linux) or `Library/Application Support/pip/pip.conf` (MacOS) and add the lines ```ini @@ -121,7 +121,7 @@ aprendizations --help We need certificates for https. Certificates can be self-signed or validated by a trusted authority. -Self-signed can be used locally for development and testing, but browsers will +Self-signed can be used locally for development and testing, but browsers will complain. LetsEncrypt issues trusted and free certificates, but the server must have a registered publicly accessible domain name. #### Generating selfsigned certificates @@ -141,7 +141,7 @@ sudo pkg install py36-certbot # FreeBSD sudo apt install certbot # Ubuntu ``` -To generate or renew the certificates, ports 80 and 443 have to be accessible. The firewall and webserver have to be stopped. +To generate or renew the certificates, ports 80 and 443 have to be accessible. **The firewall and webserver have to be stopped**. ```sh sudo certbot certonly --standalone -d www.example.com # first time @@ -151,6 +151,7 @@ sudo certbot renew # renew Certificates are saved under `/usr/local/etc/letsencrypt/live/www.example.com/`. Copy them to `~/.local/share/certs` and change permissions to be readable: ```sh +cd ~/.local/share/certs sudo cp /usr/local/etc/letsencrypt/live/www.example.com/cert.pem . sudo cp /usr/local/etc/letsencrypt/live/www.example.com/privkey.pem . chmod 400 cert.pem privkey.pem @@ -162,7 +163,7 @@ chmod 400 cert.pem privkey.pem ### Database User data is maintained in a sqlite3 database which has to be created manually using the `initdb-aprendizations` command. -The database file should be located in the same directory as the main +The database file should be located in the same directory as the main YAML configuration file. For example, to run the included demo do: @@ -189,16 +190,16 @@ cd demo aprendizations demo.yaml ``` -Open the browser at [https://127.0.0.1:8443](https://127.0.0.1:8443). -If everything looks good, check at the correct address +Open the browser at [https://127.0.0.1:8443](https://127.0.0.1:8443). +If everything looks good, check at the correct address `https://www.example.com:8443`. -The option `--debug` provides more verbose logging and might +The option `--debug` provides more verbose logging and might be useful during testing. ### Firewall configuration -Ports 80 and 443 are only usable by root. For security reasons the server runs as an unprivileged user on port 8443 for https. -To access the server in the default https port (443), port forwarding can be configured in the firewall. +Ports 80 and 443 are only usable by root. For security reasons the server runs as an unprivileged user on port 8443 for https. +To access the server in the default https port (443), port forwarding can be configured in the firewall. #### FreeBSD and pf @@ -253,20 +254,20 @@ pip install -U . # updates installed version to latest ## Troubleshooting -To help with troubleshooting, use the option `--debug` when running the server. -This will increase logs in the terminal and will present the python exception +To help with troubleshooting, use the option `--debug` when running the server. +This will increase logs in the terminal and will present the python exception errors in the browser. -Logging levels can be adjusted in `~/.config/aprendizations/logger.yaml` and +Logging levels can be adjusted in `~/.config/aprendizations/logger.yaml` and `~/.config/aprendizations/logger-debug.yaml`. If these files do not yet exist, there are examples in `aprendizations/config` that can be copied to `~/.config/aprendizations`. #### UnicodeEncodeError -The server should not generate this error, but when using external scripts to -generate questions or to correct, these scripts can print unicode strings to -stdout. If the terminal does not support unicode, python will generate this +The server should not generate this error, but when using external scripts to +generate questions or to correct, these scripts can print unicode strings to +stdout. If the terminal does not support unicode, python will generate this exception. - FreeBSD fix: edit `~/.login_conf` to use UTF-8, for example: @@ -279,6 +280,22 @@ me:\ - Debian fix: check `locale`... + +#### The application runs but questions do not show up + +Some operating systems have an option to disable animations to try to avoid +motion sickness in some people. Browsers will check this option with the OS and +prevent animate.css library to work. Since questions have several animations, +these will will not work and nothing is shown on the page. + +To fix this issue you need to allow animations in the Operating System: + +- On windows 10, go to System Preferences, search for "Show animations in + windows" and turn it **ON**. +- On MacOS or iOS search for reduced motion and switch it **OFF** + (Preferences -> Acessibility -> Display -> Reduce motion). + + ## FAQ Common database manipulations: @@ -300,4 +317,3 @@ sqlite3 students.db "select student_id, count(topic_id) from studenttopic group # Which questions have more wrong answers? sqlite3 students.db "select count(ref), ref from answers where grade<1.0 group by ref order by count(ref) desc" ``` - diff --git a/aprendizations/__init__.py b/aprendizations/__init__.py index 3ad2dbe..3c029b5 100644 --- a/aprendizations/__init__.py +++ b/aprendizations/__init__.py @@ -30,10 +30,10 @@ are progressively uncovered as the students progress. ''' APP_NAME = 'aprendizations' -APP_VERSION = '2020.01.dev4' +APP_VERSION = '2021.07.dev1' APP_DESCRIPTION = __doc__ __author__ = 'Miguel Barão' -__copyright__ = 'Copyright 2020, Miguel Barão' +__copyright__ = 'Copyright 2021, Miguel Barão' __license__ = 'MIT license' __version__ = APP_VERSION diff --git a/aprendizations/initdb.py b/aprendizations/initdb.py index 9288ebb..11c99bf 100644 --- a/aprendizations/initdb.py +++ b/aprendizations/initdb.py @@ -1,5 +1,9 @@ #!/usr/bin/env python3 +''' +Initializes or updates database +''' + # python standard libraries import csv import argparse @@ -10,14 +14,18 @@ from concurrent.futures import ThreadPoolExecutor # third party libraries import bcrypt import sqlalchemy as sa +import sqlalchemy.orm as orm +from sqlalchemy.exc import IntegrityError # this project -from .models import Base, Student +from aprendizations.models import Base, Student # =========================================================================== # Parse command line options def parse_commandline_arguments(): + '''Parse command line arguments''' + argparser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter, description='Insert new users into a database. Users can be imported ' @@ -65,9 +73,12 @@ def parse_commandline_arguments(): # =========================================================================== -# SIIUE names have alien strings like "(TE)" and are sometimes capitalized -# We remove them so that students dont keep asking what it means def get_students_from_csv(filename): + '''Reads CSV file with enrolled students in SIIUE format. + SIIUE names can have suffixes like "(TE)" and are sometimes capitalized. + These suffixes are removed.''' + + # SIIUE format for CSV files csv_settings = { 'delimiter': ';', 'quotechar': '"', @@ -75,8 +86,8 @@ def get_students_from_csv(filename): } try: - with open(filename, encoding='iso-8859-1') as f: - csvreader = csv.DictReader(f, **csv_settings) + with open(filename, encoding='iso-8859-1') as file: + csvreader = csv.DictReader(file, **csv_settings) students = [{ 'uid': s['N.º'], 'name': capwords(re.sub(r'\(.*\)', '', s['Nome']).strip()) @@ -92,52 +103,51 @@ def get_students_from_csv(filename): # =========================================================================== -# replace password by hash for a single student -def hashpw(student, pw=None): +def hashpw(student, passw=None): + '''replace password by hash for a single student''' print('.', end='', flush=True) - pw = (pw or student.get('pw', None) or student['uid']).encode('utf-8') - student['pw'] = bcrypt.hashpw(pw, bcrypt.gensalt()) + passw = (passw or student.get('pw', None) or student['uid']).encode('utf-8') + student['pw'] = bcrypt.hashpw(passw, bcrypt.gensalt()) # =========================================================================== def show_students_in_database(session, verbose=False): - try: - users = session.query(Student).all() - except Exception: - raise + '''print students that are in the database''' + users = session.query(Student).all() + total = len(users) + + print('\nRegistered users:') + if total == 0: + print(' -- none --') else: - n = len(users) - print(f'\nRegistered users:') - if n == 0: - print(' -- none --') + users.sort(key=lambda u: f'{u.id:>12}') # sort by number + if verbose: + for user in users: + print(f'{user.id:>12} {user.name}') else: - users.sort(key=lambda u: f'{u.id:>12}') # sort by number - if verbose: - for u in users: - print(f'{u.id:>12} {u.name}') - else: - print(f'{users[0].id:>12} {users[0].name}') - if n > 1: - print(f'{users[1].id:>12} {users[1].name}') - if n > 3: - print(' | |') - if n > 2: - print(f'{users[-1].id:>12} {users[-1].name}') - print(f'Total: {n}.') + print(f'{users[0].id:>12} {users[0].name}') + if total > 1: + print(f'{users[1].id:>12} {users[1].name}') + if total > 3: + print(' | |') + if total > 2: + print(f'{users[-1].id:>12} {users[-1].name}') + print(f'Total: {total}.') # =========================================================================== def main(): + '''performs the main functions''' + args = parse_commandline_arguments() # --- database stuff - print(f'Using database: ', args.db) + print(f'Using database: {args.db}') engine = sa.create_engine(f'sqlite:///{args.db}', echo=False) Base.metadata.create_all(engine) # Creates schema if needed - Session = sa.orm.sessionmaker(bind=engine) - session = Session() + session = orm.sessionmaker(bind=engine)() - # --- make list of students to insert/update + # --- build list of students to insert/update students = [] for csvfile in args.csvfile: @@ -159,13 +169,13 @@ def main(): if new_students: # --- password hashing - print(f'Generating password hashes', end='') + print('Generating password hashes', end='') with ThreadPoolExecutor() as executor: executor.map(lambda s: hashpw(s, args.pw), new_students) print('\nAdding students:') - for s in new_students: - print(f' + {s["uid"]}, {s["name"]}') + for student in new_students: + print(f' + {student["uid"]}, {student["name"]}') try: session.add_all([Student(id=s['uid'], @@ -173,7 +183,7 @@ def main(): password=s['pw']) for s in new_students]) session.commit() - except sa.exc.IntegrityError: + except IntegrityError: print('!!! Integrity error. Aborted !!!\n') session.rollback() @@ -182,15 +192,15 @@ def main(): print('There are no new students to add.') # --- update data for student in the database - for s in args.update: - print(f'Updating password of: {s}') - u = session.query(Student).get(s) - if u is not None: - pw = (args.pw or s).encode('utf-8') - u.password = bcrypt.hashpw(pw, bcrypt.gensalt()) + for student_id in args.update: + print(f'Updating password of: {student_id}') + student = session.query(Student).get(student_id) + if student is not None: + passw = (args.pw or student_id).encode('utf-8') + student.password = bcrypt.hashpw(passw, bcrypt.gensalt()) session.commit() else: - print(f'!!! Student {s} does not exist. Skipping update !!!') + print(f'!!! Student {student_id} does not exist. Skipped!!!') show_students_in_database(session, args.verbose) diff --git a/aprendizations/learnapp.py b/aprendizations/learnapp.py index c542f3a..dddc325 100644 --- a/aprendizations/learnapp.py +++ b/aprendizations/learnapp.py @@ -1,3 +1,7 @@ +''' +Learn application. +This is the main controller of the application. +''' # python standard library import asyncio @@ -6,19 +10,20 @@ from contextlib import contextmanager # `with` statement in db sessions from datetime import datetime import logging from random import random -from os import path +from os.path import join, exists from typing import Any, Dict, Iterable, List, Optional, Tuple, Set, DefaultDict # third party libraries import bcrypt import networkx as nx import sqlalchemy as sa +import sqlalchemy.orm as orm # this project -from .models import Student, Answer, Topic, StudentTopic -from .questions import Question, QFactory, QDict, QuestionException -from .student import StudentState -from .tools import load_yaml +from aprendizations.models import Student, Answer, Topic, StudentTopic +from aprendizations.questions import Question, QFactory, QDict, QuestionException +from aprendizations.student import StudentState +from aprendizations.tools import load_yaml # setup logger for this module @@ -27,33 +32,37 @@ logger = logging.getLogger(__name__) # ============================================================================ class LearnException(Exception): - pass + '''Exceptions raised from the LearnApp class''' class DatabaseUnusableError(LearnException): - pass + '''Exception raised if the database fails in the initialization''' # ============================================================================ -# LearnApp - application logic -# -# self.deps - networkx topic dependencies -# self.courses - dict {course_id: {'title': ..., -# 'description': ..., -# 'goals': ...,}, ...} -# self.factory = dict {qref: QFactory()} -# self.online - dict {student_id: {'number': ..., -# 'name': ..., -# 'state': StudentState(), -# 'counter': ...}, ...} -# ============================================================================ -class LearnApp(object): - # ------------------------------------------------------------------------ - # helper to manage db sessions using the `with` statement, for example - # with self.db_session() as s: s.query(...) +class LearnApp(): + ''' + LearnApp - application logic + + self.deps - networkx topic dependencies + self.courses - dict {course_id: {'title': ..., + 'description': ..., + 'goals': ...,}, ...} + self.factory = dict {qref: QFactory()} + self.online - dict {student_id: {'number': ..., + 'name': ..., + 'state': StudentState(), + 'counter': ...}, ...} + ''' + + # ------------------------------------------------------------------------ @contextmanager - def db_session(self, **kw): + def _db_session(self, **kw): + ''' + helper to manage db sessions using the `with` statement, for example + with self._db_session() as s: s.query(...) + ''' session = self.Session(**kw) try: yield session @@ -66,142 +75,150 @@ class LearnApp(object): session.close() # ------------------------------------------------------------------------ - # init - # ------------------------------------------------------------------------ def __init__(self, courses: str, # filename with course configurations prefix: str, # path to topics db: str, # database filename check: bool = False) -> None: - self.db_setup(db) # setup database and check students + self._db_setup(db) # setup database and check students self.online: Dict[str, Dict] = dict() # online students try: config: Dict[str, Any] = load_yaml(courses) - except Exception: + except Exception as exc: msg = f'Failed to load yaml file "{courses}"' logger.error(msg) - raise LearnException(msg) + raise LearnException(msg) from exc # --- topic dependencies are shared between all courses self.deps = nx.DiGraph(prefix=prefix) logger.info('Populating topic graph:') - t = config.get('topics', {}) # topics defined directly in courses file - self.populate_graph(t) - logger.info(f'{len(t):>6} topics in {courses}') - for f in config.get('topics_from', []): - c = load_yaml(f) # course configuration + # topics defined directly in the courses file, usually empty + base_topics = config.get('topics', {}) + self._populate_graph(base_topics) + logger.info('%6d topics in %s', len(base_topics), courses) + + # load other course files with the topics the their deps + for course_file in config.get('topics_from', []): + course_conf = load_yaml(course_file) # course configuration # FIXME set defaults?? - logger.info(f'{len(c["topics"]):>6} topics imported from {f}') - self.populate_graph(c) - logger.info(f'Graph has {len(self.deps)} topics') + logger.info('%6d topics imported from %s', + len(course_conf["topics"]), course_file) + self._populate_graph(course_conf) + logger.info('Graph has %d topics', len(self.deps)) # --- courses dict self.courses = config['courses'] - logger.info(f'Courses: {", ".join(self.courses.keys())}') - for c, d in self.courses.items(): - d.setdefault('title', '') # course title undefined - for goal in d['goals']: + logger.info('Courses: %s', ', '.join(self.courses.keys())) + for cid, course in self.courses.items(): + course.setdefault('title', cid) # course title undefined + for goal in course['goals']: if goal not in self.deps.nodes(): - msg = f'Goal "{goal}" from course "{c}" does not exist' + msg = f'Goal "{goal}" from course "{cid}" does not exist' logger.error(msg) raise LearnException(msg) - elif self.deps.nodes[goal]['type'] == 'chapter': - d['goals'] += [g for g in self.deps.predecessors(goal) - if g not in d['goals']] + if self.deps.nodes[goal]['type'] == 'chapter': + course['goals'] += [g for g in self.deps.predecessors(goal) + if g not in course['goals']] # --- factory is a dict with question generators for all topics - self.factory: Dict[str, QFactory] = self.make_factory() + self.factory: Dict[str, QFactory] = self._make_factory() # if graph has topics that are not in the database, add them - self.add_missing_topics(self.deps.nodes()) + self._add_missing_topics(self.deps.nodes()) if check: - self.sanity_check_questions() + self._sanity_check_questions() # ------------------------------------------------------------------------ - def sanity_check_questions(self) -> None: + def _sanity_check_questions(self) -> None: + ''' + Unity tests for all questions + + Generates all questions, give right and wrong answers and corrects. + ''' logger.info('Starting sanity checks (may take a while...)') errors: int = 0 for qref in self.factory: - logger.debug(f'checking {qref}...') + logger.debug('checking %s...', qref) try: - q = self.factory[qref].generate() - except QuestionException as e: - logger.error(e) + question = self.factory[qref].generate() + except QuestionException as exc: + logger.error(exc) errors += 1 continue # to next question - if 'tests_right' in q: - for t in q['tests_right']: - q['answer'] = t - q.correct() - if q['grade'] < 1.0: - logger.error(f'Failed right answer in "{qref}".') + if 'tests_right' in question: + for right_answer in question['tests_right']: + question['answer'] = right_answer + question.correct() + if question['grade'] < 1.0: + logger.error('Failed right answer in "%s".', qref) errors += 1 continue # to next test - - if 'tests_wrong' in q: - for t in q['tests_wrong']: - q['answer'] = t - q.correct() - if q['grade'] >= 1.0: - logger.error(f'Failed wrong answer in "{qref}".') + elif question['type'] == 'textarea': + msg = f'- consider adding tests to {question["ref"]}' + logger.warning(msg) + + if 'tests_wrong' in question: + for wrong_answer in question['tests_wrong']: + question['answer'] = wrong_answer + question.correct() + if question['grade'] >= 1.0: + logger.error('Failed wrong answer in "%s".', qref) errors += 1 continue # to next test if errors > 0: - logger.error(f'{errors:>6} error(s) found.') + logger.error('%6d error(s) found.', errors) # {errors:>6} raise LearnException('Sanity checks') - else: - logger.info(' 0 errors found.') + logger.info(' 0 errors found.') # ------------------------------------------------------------------------ - # login - # ------------------------------------------------------------------------ - async def login(self, uid: str, pw: str) -> bool: + async def login(self, uid: str, password: str) -> bool: + '''user login''' - with self.db_session() as s: - found = s.query(Student.name, Student.password) \ - .filter_by(id=uid) \ - .one_or_none() + with self._db_session() as sess: + found = sess.query(Student.name, Student.password) \ + .filter_by(id=uid) \ + .one_or_none() # wait random time to minimize timing attacks await asyncio.sleep(random()) loop = asyncio.get_running_loop() if found is None: - logger.info(f'User "{uid}" does not exist') + logger.info('User "%s" does not exist', uid) await loop.run_in_executor(None, bcrypt.hashpw, b'', bcrypt.gensalt()) # just spend time return False - else: - name, hashed_pw = found - pw_ok: bool = await loop.run_in_executor(None, - bcrypt.checkpw, - pw.encode('utf-8'), - hashed_pw) + name, hashed_pw = found + pw_ok: bool = await loop.run_in_executor(None, + bcrypt.checkpw, + password.encode('utf-8'), + hashed_pw) if pw_ok: if uid in self.online: - logger.warning(f'User "{uid}" already logged in') + logger.warning('User "%s" already logged in', uid) counter = self.online[uid]['counter'] else: - logger.info(f'User "{uid}" logged in') + logger.info('User "%s" logged in', uid) counter = 0 # get topics of this student and set its current state - with self.db_session() as s: - tt = s.query(StudentTopic).filter_by(student_id=uid) + with self._db_session() as sess: + student_topics = sess.query(StudentTopic) \ + .filter_by(student_id=uid) state = {t.topic_id: { 'level': t.level, 'date': datetime.strptime(t.date, "%Y-%m-%d %H:%M:%S.%f") - } for t in tt} + } for t in student_topics} self.online[uid] = { 'number': uid, @@ -213,178 +230,194 @@ class LearnApp(object): } else: - logger.info(f'User "{uid}" wrong password') + logger.info('User "%s" wrong password', uid) return pw_ok # ------------------------------------------------------------------------ - # logout - # ------------------------------------------------------------------------ def logout(self, uid: str) -> None: + '''User logout''' del self.online[uid] - logger.info(f'User "{uid}" logged out') + logger.info('User "%s" logged out', uid) # ------------------------------------------------------------------------ - # change_password. returns True if password is successfully changed. - # ------------------------------------------------------------------------ - async def change_password(self, uid: str, pw: str) -> bool: - if not pw: + async def change_password(self, uid: str, password: str) -> bool: + ''' + Change user Password. + Returns True if password is successfully changed + ''' + if not password: return False loop = asyncio.get_running_loop() - pw = await loop.run_in_executor(None, bcrypt.hashpw, - pw.encode('utf-8'), bcrypt.gensalt()) + pw = await loop.run_in_executor(None, + bcrypt.hashpw, + password.encode('utf-8'), + bcrypt.gensalt()) - with self.db_session() as s: - u = s.query(Student).get(uid) - u.password = pw + with self._db_session() as sess: + user = sess.query(Student).get(uid) + user.password = pw - logger.info(f'User "{uid}" changed password') + logger.info('User "%s" changed password', uid) return True # ------------------------------------------------------------------------ - # Checks answer and update database. Returns corrected question. - # ------------------------------------------------------------------------ async def check_answer(self, uid: str, answer) -> Question: + ''' + Checks answer and update database. + Returns corrected question. + ''' student = self.online[uid]['state'] await student.check_answer(answer) - q: Question = student.get_current_question() - logger.info(f'User "{uid}" got {q["grade"]:.2} in "{q["ref"]}"') + topic_id = student.get_current_topic() + question: Question = student.get_current_question() + grade = question["grade"] + ref = question["ref"] + + logger.info('User "%s" got %.2f in "%s"', uid, grade, ref) # always save grade of answered question - with self.db_session() as s: - s.add(Answer( - ref=q['ref'], - grade=q['grade'], - starttime=str(q['start_time']), - finishtime=str(q['finish_time']), - student_id=uid, - topic_id=student.get_current_topic())) + with self._db_session() as sess: + sess.add(Answer(ref=ref, + grade=grade, + starttime=str(question['start_time']), + finishtime=str(question['finish_time']), + student_id=uid, + topic_id=topic_id)) - return q + return question # ------------------------------------------------------------------------ - # get the question to show (current or new one) - # if no more questions, save/update level in database - # ------------------------------------------------------------------------ async def get_question(self, uid: str) -> Optional[Question]: + ''' + Get the question to show (current or new one) + If no more questions, save/update level in database + ''' student = self.online[uid]['state'] - q: Optional[Question] = await student.get_question() + question: Optional[Question] = await student.get_question() # save topic to database if finished if student.topic_has_finished(): topic: str = student.get_previous_topic() level: float = student.get_topic_level(topic) date: str = str(student.get_topic_date(topic)) - logger.info(f'User "{uid}" finished "{topic}" (level={level:.2})') + logger.info('User "%s" finished "%s" (level=%.2f)', + uid, topic, level) + + with self._db_session() as sess: + student_topic = sess.query(StudentTopic) \ + .filter_by(student_id=uid, topic_id=topic)\ + .one_or_none() - with self.db_session() as s: - a = s.query(StudentTopic) \ - .filter_by(student_id=uid, topic_id=topic) \ - .one_or_none() - if a is None: + if student_topic is None: # insert new studenttopic into database logger.debug('db insert studenttopic') - t = s.query(Topic).get(topic) - u = s.query(Student).get(uid) + tid = sess.query(Topic).get(topic) + uid = sess.query(Student).get(uid) # association object - a = StudentTopic(level=level, date=date, topic=t, - student=u) - u.topics.append(a) + student_topic = StudentTopic(level=level, date=date, + topic=tid, student=uid) + uid.topics.append(student_topic) else: # update studenttopic in database - logger.debug(f'db update studenttopic to level {level}') - a.level = level - a.date = date + logger.debug('db update studenttopic to level %f', level) + student_topic.level = level + student_topic.date = date - s.add(a) + sess.add(student_topic) - return q + return question # ------------------------------------------------------------------------ - # Start course - # ------------------------------------------------------------------------ def start_course(self, uid: str, course_id: str) -> None: + '''Start course''' + student = self.online[uid]['state'] try: student.start_course(course_id) - except Exception: - logger.warning(f'"{uid}" could not start course "{course_id}"') - raise + except Exception as exc: + logger.warning('"%s" could not start course "%s"', uid, course_id) + raise LearnException() from exc else: - logger.info(f'User "{uid}" started course "{course_id}"') + logger.info('User "%s" started course "%s"', uid, course_id) # ------------------------------------------------------------------------ - # Start new topic + # # ------------------------------------------------------------------------ async def start_topic(self, uid: str, topic: str) -> None: + '''Start new topic''' + student = self.online[uid]['state'] - if uid == '0': - logger.warning(f'Reloading "{topic}"') # FIXME should be an option - self.factory.update(self.factory_for(topic)) + # if uid == '0': + # logger.warning('Reloading "%s"', topic) # FIXME should be an option + # self.factory.update(self._factory_for(topic)) try: await student.start_topic(topic) - except Exception as e: - logger.warning(f'User "{uid}" could not start "{topic}": {e}') + except Exception as exc: + logger.warning('User "%s" could not start "%s": %s', + uid, topic, str(exc)) else: - logger.info(f'User "{uid}" started topic "{topic}"') + logger.info('User "%s" started topic "%s"', uid, topic) # ------------------------------------------------------------------------ - # Fill db table 'Topic' with topics from the graph if not already there. + # # ------------------------------------------------------------------------ - def add_missing_topics(self, topics: List[str]) -> None: - with self.db_session() as s: - new_topics = [Topic(id=t) for t in topics - if (t,) not in s.query(Topic.id)] + def _add_missing_topics(self, topics: Iterable[str]) -> None: + ''' + Fill db table 'Topic' with topics from the graph, if new + ''' + with self._db_session() as sess: + new = [Topic(id=t) for t in topics + if (t,) not in sess.query(Topic.id)] - if new_topics: - s.add_all(new_topics) - logger.info(f'Added {len(new_topics)} new topic(s) to the ' - f'database') + if new: + sess.add_all(new) + logger.info('Added %d new topic(s) to the database', len(new)) # ------------------------------------------------------------------------ - # setup and check database contents - # ------------------------------------------------------------------------ - def db_setup(self, db: str) -> None: + def _db_setup(self, database: str) -> None: + '''setup and check database contents''' - logger.info(f'Checking database "{db}":') - if not path.exists(db): + logger.info('Checking database "%s":', database) + if not exists(database): raise LearnException('Database does not exist. ' 'Use "initdb-aprendizations" to create') - engine = sa.create_engine(f'sqlite:///{db}', echo=False) - self.Session = sa.orm.sessionmaker(bind=engine) + engine = sa.create_engine(f'sqlite:///{database}', echo=False) + self.Session = orm.sessionmaker(bind=engine) try: - with self.db_session() as s: - n: int = s.query(Student).count() - m: int = s.query(Topic).count() - q: int = s.query(Answer).count() - except Exception: - logger.error(f'Database "{db}" not usable!') - raise DatabaseUnusableError() + with self._db_session() as sess: + count_students: int = sess.query(Student).count() + count_topics: int = sess.query(Topic).count() + count_answers: int = sess.query(Answer).count() + except Exception as exc: + logger.error('Database "%s" not usable!', database) + raise DatabaseUnusableError() from exc else: - logger.info(f'{n:6} students') - logger.info(f'{m:6} topics') - logger.info(f'{q:6} answers') + logger.info('%6d students', count_students) + logger.info('%6d topics', count_topics) + logger.info('%6d answers', count_answers) - # ======================================================================== - # Populates a digraph. - # - # Nodes are the topic references e.g. 'my/topic' - # g.nodes['my/topic']['name'] name of the topic - # g.nodes['my/topic']['questions'] list of question refs - # - # Edges are obtained from the deps defined in the YAML file for each topic. # ------------------------------------------------------------------------ - def populate_graph(self, config: Dict[str, Any]) -> None: - g = self.deps # dependency graph + def _populate_graph(self, config: Dict[str, Any]) -> None: + ''' + Populates a digraph. + + Nodes are the topic references e.g. 'my/topic' + g.nodes['my/topic']['name'] name of the topic + g.nodes['my/topic']['questions'] list of question refs + + Edges are obtained from the deps defined in the YAML file for each topic. + ''' + defaults = { - 'type': 'topic', + 'type': 'topic', # chapter 'file': 'questions.yaml', 'shuffle_questions': True, - 'choose': 9999, + 'choose': 99, 'forgetting_factor': 1.0, # no forgetting 'max_tries': 1, # in every question 'append_wrong': True, @@ -394,20 +427,21 @@ class LearnApp(object): # iterate over topics and populate graph topics: Dict[str, Dict] = config.get('topics', {}) - g.add_nodes_from(topics.keys()) + self.deps.add_nodes_from(topics.keys()) for tref, attr in topics.items(): - logger.debug(f' + {tref}') - for d in attr.get('deps', []): - g.add_edge(d, tref) + logger.debug(' + %s', tref) + for dep in attr.get('deps', []): + self.deps.add_edge(dep, tref) - t = g.nodes[tref] # get current topic node - t['name'] = attr.get('name', tref) - t['questions'] = attr.get('questions', []) + topic = self.deps.nodes[tref] # get current topic node + topic['name'] = attr.get('name', tref) + topic['questions'] = attr.get('questions', []) # FIXME unused?? for k, default in defaults.items(): - t[k] = attr.get(k, default) + topic[k] = attr.get(k, default) - t['path'] = path.join(g.graph['prefix'], tref) # prefix/topic + # prefix/topic + topic['path'] = join(self.deps.graph['prefix'], tref) # ======================================================================== @@ -415,48 +449,45 @@ class LearnApp(object): # ======================================================================== # ------------------------------------------------------------------------ - # Buils dictionary of question factories - # - visits each topic in the graph, - # - adds factory for each topic. - # ------------------------------------------------------------------------ - def make_factory(self) -> Dict[str, QFactory]: + def _make_factory(self) -> Dict[str, QFactory]: + ''' + Buils dictionary of question factories + - visits each topic in the graph, + - adds factory for each topic. + ''' logger.info('Building questions factory:') factory = dict() - g = self.deps - for tref in g.nodes(): - factory.update(self.factory_for(tref)) + for tref in self.deps.nodes: + factory.update(self._factory_for(tref)) - logger.info(f'Factory has {len(factory)} questions') + logger.info('Factory has %s questions', len(factory)) return factory # ------------------------------------------------------------------------ # makes factory for a single topic # ------------------------------------------------------------------------ - def factory_for(self, tref: str) -> Dict[str, QFactory]: + def _factory_for(self, tref: str) -> Dict[str, QFactory]: factory: Dict[str, QFactory] = dict() - g = self.deps - t = g.nodes[tref] # get node + topic = self.deps.nodes[tref] # get node # load questions as list of dicts - topicpath: str = path.join(g.graph['prefix'], tref) try: - fullpath: str = path.join(topicpath, t['file']) - except Exception: - msg1 = f'Invalid topic "{tref}"' - msg2 = f'Check dependencies of: {", ".join(g.successors(tref))}' - msg = f'{msg1}. {msg2}' + fullpath: str = join(topic['path'], topic['file']) + except Exception as exc: + msg = f'Invalid topic "{tref}". Check dependencies of: ' + \ + ', '.join(self.deps.successors(tref)) logger.error(msg) - raise LearnException(msg) - logger.debug(f' Loading {fullpath}') + raise LearnException(msg) from exc + logger.debug(' Loading %s', fullpath) try: questions: List[QDict] = load_yaml(fullpath) - except Exception: - if t['type'] == 'chapter': + except Exception as exc: + if topic['type'] == 'chapter': return factory # chapters may have no "questions" - else: - msg = f'Failed to load "{fullpath}"' - logger.error(msg) - raise LearnException(msg) + msg = f'Failed to load "{fullpath}"' + logger.error(msg) + raise LearnException(msg) from exc + if not isinstance(questions, list): msg = f'File "{fullpath}" must be a list of questions' logger.error(msg) @@ -467,134 +498,163 @@ class LearnApp(object): # undefined are set to topic:n, where n is the question number # within the file localrefs: Set[str] = set() # refs in current file - for i, q in enumerate(questions): - qref = q.get('ref', str(i)) # ref or number + for i, question in enumerate(questions): + qref = question.get('ref', str(i)) # ref or number if qref in localrefs: - msg = f'Duplicate ref "{qref}" in "{topicpath}"' + msg = f'Duplicate ref "{qref}" in "{topic["path"]}"' + logger.error(msg) raise LearnException(msg) localrefs.add(qref) - q['ref'] = f'{tref}:{qref}' - q['path'] = topicpath - q.setdefault('append_wrong', t['append_wrong']) + question['ref'] = f'{tref}:{qref}' + question['path'] = topic['path'] + question.setdefault('append_wrong', topic['append_wrong']) # if questions are left undefined, include all. - if not t['questions']: - t['questions'] = [q['ref'] for q in questions] + if not topic['questions']: + topic['questions'] = [q['ref'] for q in questions] - t['choose'] = min(t['choose'], len(t['questions'])) + topic['choose'] = min(topic['choose'], len(topic['questions'])) - for q in questions: - if q['ref'] in t['questions']: - factory[q['ref']] = QFactory(q) - logger.debug(f' + {q["ref"]}') + for question in questions: + if question['ref'] in topic['questions']: + factory[question['ref']] = QFactory(question) + logger.debug(' + %s', question["ref"]) - logger.info(f'{len(t["questions"]):6} questions in {tref}') + logger.info('%6d questions in %s', len(topic["questions"]), tref) return factory # ------------------------------------------------------------------------ def get_login_counter(self, uid: str) -> int: + '''login counter''' # FIXME return int(self.online[uid]['counter']) # ------------------------------------------------------------------------ def get_student_name(self, uid: str) -> str: + '''Get the username''' return self.online[uid].get('name', '') # ------------------------------------------------------------------------ def get_student_state(self, uid: str) -> List[Dict[str, Any]]: + '''Get the knowledge state of a given user''' return self.online[uid]['state'].get_knowledge_state() # ------------------------------------------------------------------------ def get_student_progress(self, uid: str) -> float: + '''Get the current topic progress of a given user''' return float(self.online[uid]['state'].get_topic_progress()) # ------------------------------------------------------------------------ def get_current_question(self, uid: str) -> Optional[Question]: - q: Optional[Question] = self.online[uid]['state'].get_current_question() - return q + '''Get the current question of a given user''' + question: Optional[Question] = self.online[uid]['state'].get_current_question() + return question # ------------------------------------------------------------------------ def get_current_question_id(self, uid: str) -> str: + '''Get id of the current question for a given user''' return str(self.online[uid]['state'].get_current_question()['qid']) # ------------------------------------------------------------------------ def get_student_question_type(self, uid: str) -> str: + '''Get type of the current question for a given user''' return str(self.online[uid]['state'].get_current_question()['type']) # ------------------------------------------------------------------------ - def get_student_topic(self, uid: str) -> str: - return str(self.online[uid]['state'].get_current_topic()) + # def get_student_topic(self, uid: str) -> str: + # return str(self.online[uid]['state'].get_current_topic()) # ------------------------------------------------------------------------ def get_student_course_title(self, uid: str) -> str: + '''get the title of the current course for a given user''' return str(self.online[uid]['state'].get_current_course_title()) # ------------------------------------------------------------------------ def get_current_course_id(self, uid: str) -> Optional[str]: + '''get the current course (id) of a given user''' cid: Optional[str] = self.online[uid]['state'].get_current_course_id() return cid # ------------------------------------------------------------------------ - def get_topic_name(self, ref: str) -> str: - return str(self.deps.nodes[ref]['name']) + # def get_topic_name(self, ref: str) -> str: + # return str(self.deps.nodes[ref]['name']) # ------------------------------------------------------------------------ def get_current_public_dir(self, uid: str) -> str: + ''' + Get the path for the 'public' directory of the current topic of the + given user. + E.g. if the user has the active topic 'xpto', + then returns 'path/to/xpto/public'. + ''' topic: str = self.online[uid]['state'].get_current_topic() prefix: str = self.deps.graph['prefix'] - return path.join(prefix, topic, 'public') + return join(prefix, topic, 'public') # ------------------------------------------------------------------------ def get_courses(self) -> Dict[str, Dict[str, Any]]: + ''' + Get dictionary with all courses {'course1': {...}, 'course2': {...}} + ''' return self.courses # ------------------------------------------------------------------------ def get_course(self, course_id: str) -> Dict[str, Any]: + ''' + Get dictionary {'title': ..., 'description':..., 'goals':...} + ''' return self.courses[course_id] # ------------------------------------------------------------------------ def get_rankings(self, uid: str, course_id: str) -> Iterable[Tuple[str, str, float, float]]: - - logger.info(f'User "{uid}" get rankings for {course_id}') - with self.db_session() as s: - students = s.query(Student.id, Student.name).all() - - # topic progress - student_topics = s.query(StudentTopic.student_id, - StudentTopic.topic_id, - StudentTopic.level, - StudentTopic.date).all() + ''' + Returns rankings for a certain course_id. + User where uid have <=2 chars are considered ghosts are hidden from + the rankings. This is so that there can be users for development or + testing purposes, which are not real users. + The user_id of real students must have >2 chars. + ''' + + logger.info('User "%s" get rankings for %s', uid, course_id) + with self._db_session() as sess: + # all students in the database FIXME only with answers of this course + students = sess.query(Student.id, Student.name).all() + + # topic levels FIXME only topics of this course + student_topics = sess.query(StudentTopic.student_id, + StudentTopic.topic_id, + StudentTopic.level, + StudentTopic.date).all() # answer performance - total = dict(s.query(Answer.student_id, sa.func.count(Answer.ref)). - group_by(Answer.student_id). - all()) - right = dict(s.query(Answer.student_id, sa.func.count(Answer.ref)). - filter(Answer.grade == 1.0). - group_by(Answer.student_id). - all()) + total = dict(sess.query(Answer.student_id, + sa.func.count(Answer.ref)) \ + .group_by(Answer.student_id) \ + .all()) + right = dict(sess.query(Answer.student_id, + sa.func.count(Answer.ref)) \ + .filter(Answer.grade == 1.0) \ + .group_by(Answer.student_id) \ + .all()) # compute percentage of right answers - perf: Dict[str, float] = {u: right.get(u, 0.0)/total[u] + perf: Dict[str, float] = {u: right.get(u, 0.0) / total[u] for u in total} # compute topic progress now = datetime.now() goals = self.courses[course_id]['goals'] - prog: DefaultDict[str, float] = defaultdict(int) + progress: DefaultDict[str, float] = defaultdict(int) - for u, topic, level, date in student_topics: + for student, topic, level, date in student_topics: if topic in goals: date = datetime.strptime(date, "%Y-%m-%d %H:%M:%S.%f") - prog[u] += level**(now - date).days / len(goals) - - ghostuser = len(uid) <= 2 # ghosts are invisible to students - rankings = [(u, name, prog[u], perf.get(u, 0.0)) - for u, name in students - if u in prog - and (len(u) > 2 or ghostuser) and u != '0' ] - rankings.sort(key=lambda x: x[2], reverse=True) - return rankings + progress[student] += level**(now - date).days / len(goals) + + return sorted(((u, name, progress[u], perf.get(u, 0.0)) + for u, name in students + if u in progress and (len(u) > 2 or len(uid) <= 2)), + key=lambda x: x[2], reverse=True) # ------------------------------------------------------------------------ diff --git a/aprendizations/main.py b/aprendizations/main.py index daacbed..3b6efb4 100644 --- a/aprendizations/main.py +++ b/aprendizations/main.py @@ -1,41 +1,55 @@ #!/usr/bin/env python3 +''' +Setup configurations and then runs the application. +''' + + # python standard library import argparse -import logging +import logging.config from os import environ, path import ssl import sys from typing import Any, Dict # this project -from .learnapp import LearnApp, DatabaseUnusableError, LearnException -from .serve import run_webserver -from .tools import load_yaml -from . import APP_NAME, APP_VERSION +from aprendizations.learnapp import LearnApp, DatabaseUnusableError, LearnException +from aprendizations.serve import run_webserver +from aprendizations.tools import load_yaml +from aprendizations import APP_NAME, APP_VERSION # ---------------------------------------------------------------------------- def parse_cmdline_arguments(): + ''' + Parses command line arguments. Uses the argparse package. + ''' + argparser = argparse.ArgumentParser( - description='Server for online learning. Students and topics ' - 'have to be previously configured. Please read the documentation ' - 'included with this software before running the server.' + description='Webserver for interactive learning and practice. ' + 'Please read the documentation included with this software before ' + 'using it.' + ) + + argparser.add_argument( + 'courses', type=str, nargs='?', default='courses.yaml', + help='configuration file in YAML format.' ) argparser.add_argument( - 'courses', type=str, # nargs='*', - help='Courses configuration file in YAML format.' + '-v', '--version', action='store_true', + help='show version information and exit' ) argparser.add_argument( '--prefix', type=str, default='.', - help='Path where the topic directories can be found (default: .)' + help='path where the topic directories can be found (default: .)' ) argparser.add_argument( '--port', type=int, default=8443, - help='Port to be used by the HTTPS server (default: 8443)' + help='port for the HTTPS server (default: 8443)' ) argparser.add_argument( @@ -44,18 +58,13 @@ def parse_cmdline_arguments(): ) argparser.add_argument( - '--check', action='store_true', - help='Sanity check questions (can take awhile)' + '-c', '--check', action='store_true', + help='sanity check questions (can take awhile)' ) argparser.add_argument( '--debug', action='store_true', - help='Enable debug mode' - ) - - argparser.add_argument( - '--version', action='store_true', - help='Print version information' + help='enable debug mode' ) return argparser.parse_args() @@ -63,6 +72,12 @@ def parse_cmdline_arguments(): # ---------------------------------------------------------------------------- def get_logger_config(debug: bool = False) -> Any: + ''' + Loads logger configuration in yaml format from a file, otherwise sets up a + default configuration. + Returns the configuration. + ''' + if debug: filename, level = 'logger-debug.yaml', 'DEBUG' else: @@ -106,14 +121,16 @@ def get_logger_config(debug: bool = False) -> Any: # ---------------------------------------------------------------------------- -# Start application and webserver -# ---------------------------------------------------------------------------- def main(): + ''' + Start application and webserver + ''' + # --- Commandline argument parsing arg = parse_cmdline_arguments() if arg.version: - print(f'{APP_NAME} - {APP_VERSION}\nPython {sys.version}') + print(f'{APP_NAME} {APP_VERSION}\nPython {sys.version}') sys.exit(0) # --- Setup logging @@ -122,8 +139,8 @@ def main(): try: logging.config.dictConfig(logger_config) - except Exception: - print('An error ocurred while setting up the logging system.') + except (ValueError, TypeError, AttributeError, ImportError) as exc: + print('An error ocurred while setting up the logging system: %s', exc) sys.exit(1) logging.info('====================== Start Logging ======================') @@ -139,7 +156,7 @@ def main(): ssl_ctx.load_cert_chain(path.join(certs_dir, 'cert.pem'), path.join(certs_dir, 'privkey.pem')) except FileNotFoundError: - logging.critical(f'SSL certificates missing in {certs_dir}') + logging.critical('SSL certificates missing in %s', certs_dir) print('--------------------------------------------------------------', 'Certificates should be issued by a certificate authority (CA),', 'such as https://letsencrypt.org. ', @@ -178,12 +195,14 @@ def main(): '--------------------------------------------------------------', sep='\n') sys.exit(1) - except LearnException as e: + except LearnException as exc: logging.critical('Failed to start backend') - sys.exit(1) + raise + # sys.exit(1) except Exception: logging.critical('Unknown error') - sys.exit(1) + # sys.exit(1) + raise else: logging.info('LearnApp started') diff --git a/aprendizations/questions.py b/aprendizations/questions.py index 0ae4475..95cd04f 100644 --- a/aprendizations/questions.py +++ b/aprendizations/questions.py @@ -1,26 +1,29 @@ +''' +Classes the implement several types of questions. +''' + # python standard library import asyncio from datetime import datetime +import logging +from os import path import random import re -from os import path -import logging from typing import Any, Dict, NewType import uuid # this project -from .tools import run_script, run_script_async +from aprendizations.tools import run_script, run_script_async # setup logger for this module logger = logging.getLogger(__name__) - QDict = NewType('QDict', Dict[str, Any]) class QuestionException(Exception): - pass + '''Exceptions raised in this module''' # ============================================================================ @@ -33,8 +36,11 @@ class Question(dict): for each student. Instances can shuffle options or automatically generate questions. ''' - def __init__(self, q: QDict) -> None: - super().__init__(q) + + def gen(self) -> None: + ''' + Sets defaults that are valid for any question type + ''' # add required keys if missing self.set_defaults(QDict({ @@ -46,20 +52,23 @@ class Question(dict): })) def set_answer(self, ans) -> None: + '''set answer field and register time''' self['answer'] = ans self['finish_time'] = datetime.now() def correct(self) -> None: + '''default correction (synchronous version)''' self['comments'] = '' self['grade'] = 0.0 async def correct_async(self) -> None: + '''default correction (async version)''' self.correct() - def set_defaults(self, d: QDict) -> None: - 'Add k:v pairs from default dict d for nonexistent keys' - for k, v in d.items(): - self.setdefault(k, v) + def set_defaults(self, qdict: QDict) -> None: + '''Add k:v pairs from default dict d for nonexistent keys''' + for k, val in qdict.items(): + self.setdefault(k, val) # ============================================================================ @@ -75,79 +84,89 @@ class QuestionRadio(Question): choose (int) # only used if shuffle=True ''' - # ------------------------------------------------------------------------ - def __init__(self, q: QDict) -> None: - super().__init__(q) - + def gen(self) -> None: + ''' + Sets defaults, performs checks and generates the actual question + by modifying the options and correct values + ''' + super().gen() try: - n = len(self['options']) - except KeyError: - msg = f'Missing `options` in radio question. See {self["path"]}' - raise QuestionException(msg) - except TypeError: - msg = f'`options` must be a list. See {self["path"]}' - raise QuestionException(msg) + nopts = len(self['options']) + except KeyError as exc: + msg = f'Missing `options`. In question "{self["ref"]}"' + logger.error(msg) + raise QuestionException(msg) from exc + except TypeError as exc: + msg = f'`options` must be a list. In question "{self["ref"]}"' + logger.error(msg) + raise QuestionException(msg) from exc self.set_defaults(QDict({ 'text': '', 'correct': 0, 'shuffle': True, 'discount': True, - 'max_tries': (n + 3) // 4 # 1 try for each 4 options + 'max_tries': (nopts + 3) // 4 # 1 try for each 4 options })) # check correct bounds and convert int to list, # e.g. correct: 2 --> correct: [0,0,1,0,0] if isinstance(self['correct'], int): - if not (0 <= self['correct'] < n): - msg = (f'Correct option not in range 0..{n-1} in ' - f'"{self["ref"]}"') + if not 0 <= self['correct'] < nopts: + msg = (f'`correct` out of range 0..{nopts-1}. ' + f'In question "{self["ref"]}"') + logger.error(msg) raise QuestionException(msg) self['correct'] = [1.0 if x == self['correct'] else 0.0 - for x in range(n)] + for x in range(nopts)] elif isinstance(self['correct'], list): # must match number of options - if len(self['correct']) != n: - msg = (f'Incompatible sizes: {n} options vs ' - f'{len(self["correct"])} correct in "{self["ref"]}"') + if len(self['correct']) != nopts: + msg = (f'{nopts} options vs {len(self["correct"])} correct. ' + f'In question "{self["ref"]}"') + logger.error(msg) raise QuestionException(msg) + # make sure is a list of floats try: self['correct'] = [float(x) for x in self['correct']] - except (ValueError, TypeError): - msg = (f'Correct list must contain numbers [0.0, 1.0] or ' - f'booleans in "{self["ref"]}"') - raise QuestionException(msg) + except (ValueError, TypeError) as exc: + msg = ('`correct` must be list of numbers or booleans.' + f'In "{self["ref"]}"') + logger.error(msg) + raise QuestionException(msg) from exc # check grade boundaries if self['discount'] and not all(0.0 <= x <= 1.0 for x in self['correct']): - msg = (f'Correct values must be in the interval [0.0, 1.0] in ' - f'"{self["ref"]}"') + msg = ('`correct` values must be in the interval [0.0, 1.0]. ' + f'In "{self["ref"]}"') + logger.error(msg) raise QuestionException(msg) # at least one correct option if all(x < 1.0 for x in self['correct']): - msg = (f'At least one correct option is required in ' - f'"{self["ref"]}"') + msg = ('At least one correct option is required. ' + f'In "{self["ref"]}"') + logger.error(msg) raise QuestionException(msg) # If shuffle==false, all options are shown as defined # otherwise, select 1 correct and choose a few wrong ones if self['shuffle']: # lists with indices of right and wrong options - right = [i for i in range(n) if self['correct'][i] >= 1] - wrong = [i for i in range(n) if self['correct'][i] < 1] + right = [i for i in range(nopts) if self['correct'][i] >= 1] + wrong = [i for i in range(nopts) if self['correct'][i] < 1] self.set_defaults(QDict({'choose': 1+len(wrong)})) # try to choose 1 correct option if right: - r = random.choice(right) - options = [self['options'][r]] - correct = [self['correct'][r]] + sel = random.choice(right) + options = [self['options'][sel]] + correct = [self['correct'][sel]] else: options = [] correct = [] @@ -164,20 +183,23 @@ class QuestionRadio(Question): self['correct'] = [correct[i] for i in perm] # ------------------------------------------------------------------------ - # can assign negative grades for wrong answers def correct(self) -> None: + ''' + Correct `answer` and set `grade`. + Can assign negative grades for wrong answers + ''' super().correct() if self['answer'] is not None: - x = self['correct'][int(self['answer'])] # get grade of the answer - n = len(self['options']) - x_aver = sum(self['correct']) / n # expected value of grade + grade = self['correct'][int(self['answer'])] # grade of the answer + nopts = len(self['options']) + grade_aver = sum(self['correct']) / nopts # expected value # note: there are no numerical errors when summing 1.0s so the # x_aver can be exactly 1.0 if all options are right - if self['discount'] and x_aver != 1.0: - x = (x - x_aver) / (1.0 - x_aver) - self['grade'] = float(x) + if self['discount'] and grade_aver != 1.0: + grade = (grade - grade_aver) / (1.0 - grade_aver) + self['grade'] = grade # ============================================================================ @@ -194,83 +216,77 @@ class QuestionCheckbox(Question): ''' # ------------------------------------------------------------------------ - def __init__(self, q: QDict) -> None: - super().__init__(q) + def gen(self) -> None: + super().gen() try: - n = len(self['options']) - except KeyError: - msg = f'Missing `options` in radio question. See {self["path"]}' - raise QuestionException(msg) - except TypeError: - msg = f'`options` must be a list. See {self["path"]}' - raise QuestionException(msg) + nopts = len(self['options']) + except KeyError as exc: + msg = f'Missing `options`. In question "{self["ref"]}"' + logger.error(msg) + raise QuestionException(msg) from exc + except TypeError as exc: + msg = f'`options` must be a list. In question "{self["ref"]}"' + logger.error(msg) + raise QuestionException(msg) from exc # set defaults if missing self.set_defaults(QDict({ 'text': '', - 'correct': [1.0] * n, # Using 0.0 breaks (right, wrong) options + 'correct': [1.0] * nopts, # Using 0.0 breaks (right, wrong) 'shuffle': True, 'discount': True, - 'choose': n, # number of options - 'max_tries': max(1, min(n - 1, 3)) + 'choose': nopts, # number of options + 'max_tries': max(1, min(nopts - 1, 3)) })) # must be a list of numbers if not isinstance(self['correct'], list): msg = 'Correct must be a list of numbers or booleans' + logger.error(msg) raise QuestionException(msg) # must match number of options - if len(self['correct']) != n: - msg = (f'Incompatible sizes: {n} options vs ' - f'{len(self["correct"])} correct in "{self["ref"]}"') + if len(self['correct']) != nopts: + msg = (f'{nopts} options vs {len(self["correct"])} correct. ' + f'In question "{self["ref"]}"') + logger.error(msg) raise QuestionException(msg) # make sure is a list of floats try: self['correct'] = [float(x) for x in self['correct']] - except (ValueError, TypeError): - msg = (f'Correct list must contain numbers or ' - f'booleans in "{self["ref"]}"') - raise QuestionException(msg) + except (ValueError, TypeError) as exc: + msg = ('`correct` must be list of numbers or booleans.' + f'In "{self["ref"]}"') + logger.error(msg) + raise QuestionException(msg) from exc # check grade boundaries if self['discount'] and not all(0.0 <= x <= 1.0 for x in self['correct']): - - msg0 = ('+--------------- BEHAVIOR CHANGE NOTICE ---------------+') - msg1 = ('| Correct values in checkbox questions must be in the |') - msg2 = ('| interval [0.0, 1.0]. I will convert to the new |') - msg3 = ('| behavior, for now, but you should fix it. |') - msg4 = ('+------------------------------------------------------+') - logger.warning(msg0) - logger.warning(msg1) - logger.warning(msg2) - logger.warning(msg3) - logger.warning(msg4) - logger.warning(f'please fix "{self["ref"]}"') - - # normalize to [0,1] - self['correct'] = [(x+1)/2 for x in self['correct']] + msg = ('values in the `correct` field of checkboxes must be in ' + 'the [0.0, 1.0] interval. ' + f'Please fix "{self["ref"]}" in "{self["path"]}"') + logger.error(msg) + raise QuestionException(msg) # if an option is a list of (right, wrong), pick one options = [] correct = [] - for o, c in zip(self['options'], self['correct']): - if isinstance(o, list): - r = random.randint(0, 1) - o = o[r] - if r == 1: - # c = -c - c = 1.0 - c - options.append(str(o)) - correct.append(c) + for option, corr in zip(self['options'], self['correct']): + if isinstance(option, list): + sel = random.randint(0, 1) + option = option[sel] + if sel == 1: + corr = 1.0 - corr + options.append(str(option)) + correct.append(corr) # generate random permutation, e.g. [2,1,4,0,3] # and apply to `options` and `correct` if self['shuffle']: - perm = random.sample(range(n), k=self['choose']) + perm = random.sample(range(nopts), k=self['choose']) self['options'] = [options[i] for i in perm] self['correct'] = [correct[i] for i in perm] else: @@ -283,18 +299,18 @@ class QuestionCheckbox(Question): super().correct() if self['answer'] is not None: - x = 0.0 + grade = 0.0 if self['discount']: sum_abs = sum(abs(2*p-1) for p in self['correct']) - for i, p in enumerate(self['correct']): - x += 2*p-1 if str(i) in self['answer'] else 1-2*p + for i, pts in enumerate(self['correct']): + grade += 2*pts-1 if str(i) in self['answer'] else 1-2*pts else: sum_abs = sum(abs(p) for p in self['correct']) - for i, p in enumerate(self['correct']): - x += p if str(i) in self['answer'] else 0.0 + for i, pts in enumerate(self['correct']): + grade += pts if str(i) in self['answer'] else 0.0 try: - self['grade'] = x / sum_abs + self['grade'] = grade / sum_abs except ZeroDivisionError: self['grade'] = 1.0 # limit p->0 @@ -309,9 +325,8 @@ class QuestionText(Question): ''' # ------------------------------------------------------------------------ - def __init__(self, q: QDict) -> None: - super().__init__(q) - + def gen(self) -> None: + super().gen() self.set_defaults(QDict({ 'text': '', 'correct': [], # no correct answers, always wrong @@ -325,33 +340,36 @@ class QuestionText(Question): # make sure all elements of the list are strings self['correct'] = [str(a) for a in self['correct']] - for f in self['transform']: - if f not in ('remove_space', 'trim', 'normalize_space', 'lower', - 'upper'): - msg = (f'Unknown transform "{f}" in "{self["ref"]}"') + for transform in self['transform']: + if transform not in ('remove_space', 'trim', 'normalize_space', + 'lower', 'upper'): + msg = (f'Unknown transform "{transform}" in "{self["ref"]}"') raise QuestionException(msg) # check if answers are invariant with respect to the transforms if any(c != self.transform(c) for c in self['correct']): - logger.warning(f'in "{self["ref"]}", correct answers are not ' - 'invariant wrt transformations => never correct') + logger.warning('in "%s", correct answers are not invariant wrt ' + 'transformations => never correct', self["ref"]) # ------------------------------------------------------------------------ - # apply optional filters to the answer - def transform(self, ans): - for f in self['transform']: - if f == 'remove_space': # removes all spaces - ans = ans.replace(' ', '') - elif f == 'trim': # removes spaces around + def transform(self, ans: str): + '''apply optional filters to the answer''' + + # apply transformations in sequence + for transform in self['transform']: + if transform == 'remove_space': # removes all spaces + ans = re.sub(r'\s+', '', ans) + elif transform == 'trim': # removes spaces around ans = ans.strip() - elif f == 'normalize_space': # replaces multiple spaces by one + elif transform == 'normalize_space': # replaces multiple spaces by one ans = re.sub(r'\s+', ' ', ans.strip()) - elif f == 'lower': # convert to lowercase + elif transform == 'lower': # convert to lowercase ans = ans.lower() - elif f == 'upper': # convert to uppercase + elif transform == 'upper': # convert to uppercase ans = ans.upper() else: - logger.warning(f'in "{self["ref"]}", unknown transform "{f}"') + logger.warning('in "%s", unknown transform "%s"', + self["ref"], transform) return ans # ------------------------------------------------------------------------ @@ -359,7 +377,7 @@ class QuestionText(Question): super().correct() if self['answer'] is not None: - answer = self.transform(self['answer']) # apply transformations + answer = self.transform(self['answer']) self['grade'] = 1.0 if answer in self['correct'] else 0.0 @@ -376,8 +394,8 @@ class QuestionTextRegex(Question): ''' # ------------------------------------------------------------------------ - def __init__(self, q: QDict) -> None: - super().__init__(q) + def gen(self) -> None: + super().gen() self.set_defaults(QDict({ 'text': '', @@ -388,27 +406,19 @@ class QuestionTextRegex(Question): if not isinstance(self['correct'], list): self['correct'] = [self['correct']] - # converts patterns to compiled versions - try: - self['correct'] = [re.compile(a) for a in self['correct']] - except Exception: - msg = f'Failed to compile regex in "{self["ref"]}"' - raise QuestionException(msg) - # ------------------------------------------------------------------------ def correct(self) -> None: super().correct() if self['answer'] is not None: - self['grade'] = 0.0 - for r in self['correct']: + for regex in self['correct']: try: - if r.match(self['answer']): + if re.fullmatch(regex, self['answer']): self['grade'] = 1.0 return except TypeError: - logger.error(f'While matching regex {r.pattern} with ' - f'answer "{self["answer"]}".') - + logger.error('While matching regex "%s" with answer "%s".', + regex, self['answer']) + self['grade'] = 0.0 # ============================================================================ class QuestionNumericInterval(Question): @@ -421,8 +431,8 @@ class QuestionNumericInterval(Question): ''' # ------------------------------------------------------------------------ - def __init__(self, q: QDict) -> None: - super().__init__(q) + def gen(self) -> None: + super().gen() self.set_defaults(QDict({ 'text': '', @@ -438,19 +448,22 @@ class QuestionNumericInterval(Question): if len(self['correct']) != 2: msg = (f'Numeric interval must be a list with two numbers, in ' f'{self["ref"]}') + logger.error(msg) raise QuestionException(msg) try: self['correct'] = [float(n) for n in self['correct']] - except Exception: + except Exception as exc: msg = (f'Numeric interval must be a list with two numbers, in ' f'{self["ref"]}') - raise QuestionException(msg) + logger.error(msg) + raise QuestionException(msg) from exc # invalid else: msg = (f'Numeric interval must be a list with two numbers, in ' f'{self["ref"]}') + logger.error(msg) raise QuestionException(msg) # ------------------------------------------------------------------------ @@ -479,8 +492,8 @@ class QuestionTextArea(Question): ''' # ------------------------------------------------------------------------ - def __init__(self, q: QDict) -> None: - super().__init__(q) + def gen(self) -> None: + super().gen() self.set_defaults(QDict({ 'text': '', @@ -504,21 +517,22 @@ class QuestionTextArea(Question): ) if out is None: - logger.warning(f'No grade after running "{self["correct"]}".') + logger.warning('No grade after running "%s".', self["correct"]) + self['comments'] = 'O programa de correcção abortou...' self['grade'] = 0.0 elif isinstance(out, dict): self['comments'] = out.get('comments', '') try: self['grade'] = float(out['grade']) except ValueError: - logger.error(f'Output error in "{self["correct"]}".') + logger.error('Output error in "%s".', self["correct"]) except KeyError: - logger.error(f'No grade in "{self["correct"]}".') + logger.error('No grade in "%s".', self["correct"]) else: try: self['grade'] = float(out) except (TypeError, ValueError): - logger.error(f'Invalid grade in "{self["correct"]}".') + logger.error('Invalid grade in "%s".', self["correct"]) # ------------------------------------------------------------------------ async def correct_async(self) -> None: @@ -533,28 +547,34 @@ class QuestionTextArea(Question): ) if out is None: - logger.warning(f'No grade after running "{self["correct"]}".') + logger.warning('No grade after running "%s".', self["correct"]) + self['comments'] = 'O programa de correcção abortou...' self['grade'] = 0.0 elif isinstance(out, dict): self['comments'] = out.get('comments', '') try: self['grade'] = float(out['grade']) except ValueError: - logger.error(f'Output error in "{self["correct"]}".') + logger.error('Output error in "%s".', self["correct"]) except KeyError: - logger.error(f'No grade in "{self["correct"]}".') + logger.error('No grade in "%s".', self["correct"]) else: try: self['grade'] = float(out) except (TypeError, ValueError): - logger.error(f'Invalid grade in "{self["correct"]}".') + logger.error('Invalid grade in "%s".', self["correct"]) # ============================================================================ class QuestionInformation(Question): + ''' + Not really a question, just an information panel. + The correction is always right. + ''' + # ------------------------------------------------------------------------ - def __init__(self, q: QDict) -> None: - super().__init__(q) + def gen(self) -> None: + super().gen() self.set_defaults(QDict({ 'text': '', })) @@ -566,41 +586,11 @@ class QuestionInformation(Question): # ============================================================================ -# -# QFactory is a class that can generate question instances, e.g. by shuffling -# options, running a script to generate the question, etc. -# -# To generate an instance of a question we use the method generate(). -# It returns a question instance of the correct class. -# There is also an asynchronous version called gen_async(). This version is -# synchronous for all question types (radio, checkbox, etc) except for -# generator types which run asynchronously. -# -# Example: -# -# # make a factory for a question -# qfactory = QFactory({ -# 'type': 'radio', -# 'text': 'Choose one', -# 'options': ['a', 'b'] -# }) -# -# # generate synchronously -# question = qfactory.generate() -# -# # generate asynchronously -# question = await qfactory.gen_async() -# -# # answer one question and correct it -# question['answer'] = 42 # set answer -# question.correct() # correct answer -# grade = question['grade'] # get grade -# -# ============================================================================ -class QFactory(object): - # Depending on the type of question, a different question class will be - # instantiated. All these classes derive from the base class `Question`. - _types = { +def question_from(qdict: QDict) -> Question: + ''' + Converts a question specified in a dict into an instance of Question() + ''' + types = { 'radio': QuestionRadio, 'checkbox': QuestionCheckbox, 'text': QuestionText, @@ -614,48 +604,92 @@ class QFactory(object): 'alert': QuestionInformation, } + # Get class for this question type + try: + qclass = types[qdict['type']] + except KeyError: + logger.error('Invalid type "%s" in "%s"', + qdict['type'], qdict['ref']) + raise + + # Create an instance of Question() of appropriate type + try: + qinstance = qclass(QDict(qdict)) + except QuestionException: + logger.error('Error generating "%s" in %s/%s', + qdict['ref'], qdict['path'], qdict['filename']) + raise + + return qinstance + + +# ============================================================================ +class QFactory(): + ''' + QFactory is a class that can generate question instances, e.g. by shuffling + options, running a script to generate the question, etc. + + To generate an instance of a question we use the method generate(). + It returns a question instance of the correct class. + There is also an asynchronous version called gen_async(). This version is + synchronous for all question types (radio, checkbox, etc) except for + generator types which run asynchronously. + + Example: + + # make a factory for a question + qfactory = QFactory({ + 'type': 'radio', + 'text': 'Choose one', + 'options': ['a', 'b'] + }) + + # generate synchronously + question = qfactory.generate() + + # generate asynchronously + question = await qfactory.gen_async() + + # answer one question and correct it + question['answer'] = 42 # set answer + question.correct() # correct answer + grade = question['grade'] # get grade + ''' + def __init__(self, qdict: QDict = QDict({})) -> None: - self.question = qdict + self.qdict = qdict # ------------------------------------------------------------------------ - # generates a question instance of QuestionRadio, QuestionCheckbox, ..., - # which is a descendent of base class Question. - # ------------------------------------------------------------------------ async def gen_async(self) -> Question: - logger.debug(f'generating {self.question["ref"]}...') + ''' + generates a question instance of QuestionRadio, QuestionCheckbox, ..., + which is a descendent of base class Question. + ''' + + logger.debug('generating %s...', self.qdict["ref"]) # Shallow copy so that script generated questions will not replace # the original generators - q = self.question.copy() - q['qid'] = str(uuid.uuid4()) # unique for each generated question + qdict = QDict(self.qdict.copy()) + qdict['qid'] = str(uuid.uuid4()) # unique for each question # If question is of generator type, an external program will be run # which will print a valid question in yaml format to stdout. This # output is then yaml parsed into a dictionary `q`. - if q['type'] == 'generator': - logger.debug(f' \\_ Running "{q["script"]}".') - q.setdefault('args', []) - q.setdefault('stdin', '') - script = path.join(q['path'], q['script']) - out = await run_script_async(script=script, args=q['args'], - stdin=q['stdin']) - q.update(out) - - # Get class for this question type - try: - qclass = self._types[q['type']] - except KeyError: - logger.error(f'Invalid type "{q["type"]}" in "{q["ref"]}"') - raise - - # Finally create an instance of Question() - try: - qinstance = qclass(QDict(q)) - except QuestionException as e: - # logger.error(e) - raise e - - return qinstance + if qdict['type'] == 'generator': + logger.debug(' \\_ Running "%s".', qdict['script']) + qdict.setdefault('args', []) + qdict.setdefault('stdin', '') + script = path.join(qdict['path'], qdict['script']) + out = await run_script_async(script=script, + args=qdict['args'], + stdin=qdict['stdin']) + qdict.update(out) + + question = question_from(qdict) # returns a Question instance + question.gen() + return question # ------------------------------------------------------------------------ def generate(self) -> Question: + '''generate question (synchronous version)''' return asyncio.get_event_loop().run_until_complete(self.gen_async()) diff --git a/aprendizations/serve.py b/aprendizations/serve.py index 181beb1..8b14a27 100644 --- a/aprendizations/serve.py +++ b/aprendizations/serve.py @@ -1,23 +1,30 @@ +''' +Webserver +''' + # python standard library import asyncio import base64 import functools -import logging.config +import logging import mimetypes -from os import path +from os.path import join, dirname, expanduser import signal import sys from typing import List, Optional, Union import uuid # third party libraries +import tornado.httpserver +import tornado.ioloop import tornado.web from tornado.escape import to_unicode # this project -from .tools import md_to_html -from . import APP_NAME +from aprendizations.tools import md_to_html +from aprendizations.learnapp import LearnException +from aprendizations import APP_NAME # setup logger for this module @@ -25,39 +32,39 @@ logger = logging.getLogger(__name__) # ---------------------------------------------------------------------------- -# Decorator used to restrict access to the administrator -# ---------------------------------------------------------------------------- def admin_only(func): + ''' + Decorator used to restrict access to the administrator + ''' @functools.wraps(func) def wrapper(self, *args, **kwargs): if self.current_user != '0': raise tornado.web.HTTPError(403) # forbidden - else: - func(self, *args, **kwargs) + func(self, *args, **kwargs) return wrapper # ============================================================================ -# WebApplication - Tornado Web Server -# ============================================================================ class WebApplication(tornado.web.Application): - + ''' + WebApplication - Tornado Web Server + ''' def __init__(self, learnapp, debug=False): handlers = [ - (r'/login', LoginHandler), - (r'/logout', LogoutHandler), + (r'/login', LoginHandler), + (r'/logout', LogoutHandler), (r'/change_password', ChangePasswordHandler), - (r'/question', QuestionHandler), # render question - (r'/rankings', RankingsHandler), # rankings table - (r'/topic/(.+)', TopicHandler), # start topic - (r'/file/(.+)', FileHandler), # serve file - (r'/courses', CoursesHandler), # show list of courses - (r'/course/(.*)', CourseHandler), # show course topics - (r'/', RootHandler), # redirects + (r'/question', QuestionHandler), # render question + (r'/rankings', RankingsHandler), # rankings table + (r'/topic/(.+)', TopicHandler), # start topic + (r'/file/(.+)', FileHandler), # serve file + (r'/courses', CoursesHandler), # show list of courses + (r'/course/(.*)', CourseHandler), # show course topics + (r'/', RootHandler), # redirects ] settings = { - 'template_path': path.join(path.dirname(__file__), 'templates'), - 'static_path': path.join(path.dirname(__file__), 'static'), + 'template_path': join(dirname(__file__), 'templates'), + 'static_path': join(dirname(__file__), 'static'), 'static_url_prefix': '/static/', 'xsrf_cookies': True, 'cookie_secret': base64.b64encode(uuid.uuid4().bytes), @@ -71,30 +78,40 @@ class WebApplication(tornado.web.Application): # ============================================================================ # Handlers # ============================================================================ - -# ---------------------------------------------------------------------------- -# Base handler common to all handlers. -# ---------------------------------------------------------------------------- +# pylint: disable=abstract-method class BaseHandler(tornado.web.RequestHandler): + ''' + Base handler common to all handlers. + ''' @property def learn(self): + '''easier access to learnapp''' return self.application.learn def get_current_user(self): - cookie = self.get_secure_cookie('user') - if cookie: - uid = cookie.decode('utf-8') - counter = self.get_secure_cookie('counter').decode('utf-8') - if counter == str(self.learn.get_login_counter(uid)): - return uid + '''called on every method decorated with @tornado.web.authenticated''' + user_cookie = self.get_secure_cookie('aprendizations_user') + counter_cookie = self.get_secure_cookie('counter') + if user_cookie is not None: + uid = user_cookie.decode('utf-8') + + if counter_cookie is not None: + counter = counter_cookie.decode('utf-8') + if counter == str(self.learn.get_login_counter(uid)): + return uid + return None -# ---------------------------------------------------------------------------- -# /rankings # ---------------------------------------------------------------------------- class RankingsHandler(BaseHandler): + ''' + Handles rankings page + ''' @tornado.web.authenticated def get(self): + ''' + Renders list of students that have answers in this course. + ''' uid = self.current_user current_course = self.learn.get_current_course_id(uid) course_id = self.get_query_argument('course', default=current_course) @@ -110,23 +127,33 @@ class RankingsHandler(BaseHandler): # ---------------------------------------------------------------------------- -# /auth/login +# # ---------------------------------------------------------------------------- class LoginHandler(BaseHandler): + ''' + Handles /login + ''' def get(self): + ''' + Renders login page + ''' self.render('login.html', appname=APP_NAME, error='') async def post(self): - uid = self.get_body_argument('uid').lstrip('l') - pw = self.get_body_argument('pw') + ''' + Perform authentication and redirects to application if successful + ''' + + userid = (self.get_body_argument('uid') or '').lstrip('l') + passwd = self.get_body_argument('pw') - login_ok = await self.learn.login(uid, pw) + login_ok = await self.learn.login(userid, passwd) if login_ok: - counter = str(self.learn.get_login_counter(uid)) - self.set_secure_cookie('user', uid) + counter = str(self.learn.get_login_counter(userid)) + self.set_secure_cookie('aprendizations_user', userid) self.set_secure_cookie('counter', counter) self.redirect('/') else: @@ -136,11 +163,15 @@ class LoginHandler(BaseHandler): # ---------------------------------------------------------------------------- -# /auth/logout -# ---------------------------------------------------------------------------- class LogoutHandler(BaseHandler): + ''' + Handles /logout + ''' @tornado.web.authenticated def get(self): + ''' + clears cookies and removes user session + ''' self.clear_cookie('user') self.clear_cookie('counter') self.redirect('/') @@ -151,12 +182,18 @@ class LogoutHandler(BaseHandler): # ---------------------------------------------------------------------------- class ChangePasswordHandler(BaseHandler): + ''' + Handles password change + ''' @tornado.web.authenticated async def post(self): - uid = self.current_user - pw = self.get_body_arguments('new_password')[0] + ''' + Tries to perform password change and then replies success/fail status + ''' + userid = self.current_user + passwd = self.get_body_arguments('new_password')[0] - changed_ok = await self.learn.change_password(uid, pw) + changed_ok = await self.learn.change_password(userid, passwd) if changed_ok: notification = self.render_string( 'notification.html', @@ -174,45 +211,56 @@ class ChangePasswordHandler(BaseHandler): # ---------------------------------------------------------------------------- -# / -# redirects to appropriate place -# ---------------------------------------------------------------------------- class RootHandler(BaseHandler): + ''' + Handles root / + ''' @tornado.web.authenticated def get(self): + '''Simply redirects to the main entrypoint''' self.redirect('/courses') # ---------------------------------------------------------------------------- -# /courses -# Shows a list of available courses -# ---------------------------------------------------------------------------- class CoursesHandler(BaseHandler): + ''' + Handles /courses + ''' + def set_default_headers(self, *args, **kwargs): + self.set_header('Cache-Control', 'no-cache') + @tornado.web.authenticated def get(self): + '''Renders list of available courses''' uid = self.current_user self.render('courses.html', appname=APP_NAME, uid=uid, name=self.learn.get_student_name(uid), courses=self.learn.get_courses(), + # courses_progress= ) -# ---------------------------------------------------------------------------- -# /course/... -# Start a given course and show list of topics -# ---------------------------------------------------------------------------- +# ============================================================================ class CourseHandler(BaseHandler): + ''' + Handles a particular course to show the topics table + ''' + @tornado.web.authenticated def get(self, course_id): + ''' + Handles get /course/... + Starts a given course and show list of topics + ''' uid = self.current_user if course_id == '': course_id = self.learn.get_current_course_id(uid) try: self.learn.start_course(uid, course_id) - except KeyError: + except LearnException: self.redirect('/courses') self.render('maintopics-table.html', @@ -225,17 +273,24 @@ class CourseHandler(BaseHandler): ) -# ---------------------------------------------------------------------------- -# /topic/... -# Start a given topic -# ---------------------------------------------------------------------------- +# ============================================================================ class TopicHandler(BaseHandler): + ''' + Handles a topic + ''' + def set_default_headers(self, *args, **kwargs): + self.set_header('Cache-Control', 'no-cache') + @tornado.web.authenticated async def get(self, topic): + ''' + Handles get /topic/... + Starts a given topic + ''' uid = self.current_user try: - await self.learn.start_topic(uid, topic) + await self.learn.start_topic(uid, topic) # FIXME GET should not modify state... except KeyError: self.redirect('/topics') @@ -243,42 +298,43 @@ class TopicHandler(BaseHandler): appname=APP_NAME, uid=uid, name=self.learn.get_student_name(uid), - # course_title=self.learn.get_student_course_title(uid), course_id=self.learn.get_current_course_id(uid), ) -# ---------------------------------------------------------------------------- -# Serves files from the /public subdir of the topics. -# ---------------------------------------------------------------------------- +# ============================================================================ class FileHandler(BaseHandler): + ''' + Serves files from the /public subdir of the topics. + ''' @tornado.web.authenticated async def get(self, filename): + ''' + Serves files from /public subdirectories of a particular topic + ''' uid = self.current_user public_dir = self.learn.get_current_public_dir(uid) - filepath = path.expanduser(path.join(public_dir, filename)) - content_type = mimetypes.guess_type(filename)[0] + filepath = expanduser(join(public_dir, filename)) try: - with open(filepath, 'rb') as f: - data = f.read() - except FileNotFoundError: - logger.error(f'File not found: {filepath}') - except PermissionError: - logger.error(f'No permission: {filepath}') - except Exception: - logger.error(f'Error reading: {filepath}') + with open(filepath, 'rb') as file: + data = file.read() + except OSError: + logger.error('Error reading: %s', filepath) raise - else: + + content_type = mimetypes.guess_type(filename)[0] + if content_type is not None: self.set_header("Content-Type", content_type) - self.write(data) - await self.flush() + self.write(data) + await self.flush() -# ---------------------------------------------------------------------------- -# respond to AJAX to get a JSON question -# ---------------------------------------------------------------------------- +# ============================================================================ class QuestionHandler(BaseHandler): + ''' + Responds to AJAX to get a JSON question + ''' templates = { 'checkbox': 'question-checkbox.html', 'radio': 'question-radio.html', @@ -294,27 +350,27 @@ class QuestionHandler(BaseHandler): } # ------------------------------------------------------------------------ - # GET - # gets question to render. If there are no more questions in the topic - # shows an animated trophy - # ------------------------------------------------------------------------ @tornado.web.authenticated async def get(self): + ''' + Gets question to render. + Shows an animated trophy if there are no more questions in the topic. + ''' logger.debug('[QuestionHandler]') user = self.current_user - q = await self.learn.get_question(user) + question = await self.learn.get_question(user) # show current question - if q is not None: - qhtml = self.render_string(self.templates[q['type']], - question=q, md=md_to_html) + if question is not None: + qhtml = self.render_string(self.templates[question['type']], + question=question, md=md_to_html) response = { 'method': 'new_question', 'params': { - 'type': q['type'], + 'type': question['type'], 'question': to_unicode(qhtml), 'progress': self.learn.get_student_progress(user), - 'tries': q['tries'], + 'tries': question['tries'], } } @@ -331,20 +387,20 @@ class QuestionHandler(BaseHandler): self.write(response) # ------------------------------------------------------------------------ - # POST - # corrects answer and returns status: right, wrong, try_again - # does not move to next question. - # ------------------------------------------------------------------------ @tornado.web.authenticated async def post(self) -> None: + ''' + Corrects answer and returns status: right, wrong, try_again + Does not move to next question. + ''' user = self.current_user answer = self.get_body_arguments('answer') # list qid = self.get_body_arguments('qid')[0] - logger.debug(f'[QuestionHandler] answer={answer}') + # logger.debug('[QuestionHandler] answer=%s', answer) # --- check if browser opened different questions simultaneously if qid != self.learn.get_current_question_id(user): - logger.info(f'User {user} desynchronized questions') + logger.warning('User %s desynchronized questions', user) self.write({ 'method': 'invalid', 'params': { @@ -370,51 +426,55 @@ class QuestionHandler(BaseHandler): ans = answer # --- check answer (nonblocking) and get corrected question and action - q = await self.learn.check_answer(user, ans) + question = await self.learn.check_answer(user, ans) # --- built response to return - response = {'method': q['status'], 'params': {}} + response = {'method': question['status'], 'params': {}} - if q['status'] == 'right': # get next question in the topic - comments_html = self.render_string( - 'comments-right.html', comments=q['comments'], md=md_to_html) + if question['status'] == 'right': # get next question in the topic + comments = self.render_string('comments-right.html', + comments=question['comments'], + md=md_to_html) - solution_html = self.render_string( - 'solution.html', solution=q['solution'], md=md_to_html) + solution = self.render_string('solution.html', + solution=question['solution'], + md=md_to_html) response['params'] = { - 'type': q['type'], + 'type': question['type'], 'progress': self.learn.get_student_progress(user), - 'comments': to_unicode(comments_html), - 'solution': to_unicode(solution_html), - 'tries': q['tries'], + 'comments': to_unicode(comments), + 'solution': to_unicode(solution), + 'tries': question['tries'], } - elif q['status'] == 'try_again': - comments_html = self.render_string( - 'comments.html', comments=q['comments'], md=md_to_html) + elif question['status'] == 'try_again': + comments = self.render_string('comments.html', + comments=question['comments'], + md=md_to_html) response['params'] = { - 'type': q['type'], + 'type': question['type'], 'progress': self.learn.get_student_progress(user), - 'comments': to_unicode(comments_html), - 'tries': q['tries'], + 'comments': to_unicode(comments), + 'tries': question['tries'], } - elif q['status'] == 'wrong': # no more tries - comments_html = self.render_string( - 'comments.html', comments=q['comments'], md=md_to_html) + elif question['status'] == 'wrong': # no more tries + comments = self.render_string('comments.html', + comments=question['comments'], + md=md_to_html) - solution_html = self.render_string( - 'solution.html', solution=q['solution'], md=md_to_html) + solution = self.render_string( + 'solution.html', solution=question['solution'], md=md_to_html) response['params'] = { - 'type': q['type'], + 'type': question['type'], 'progress': self.learn.get_student_progress(user), - 'comments': to_unicode(comments_html), - 'solution': to_unicode(solution_html), - 'tries': q['tries'], + 'comments': to_unicode(comments), + 'solution': to_unicode(solution), + 'tries': question['tries'], } else: - logger.error(f'Unknown question status: {q["status"]}') + logger.error('Unknown question status: %s', question["status"]) self.write(response) @@ -422,29 +482,29 @@ class QuestionHandler(BaseHandler): # ---------------------------------------------------------------------------- # Signal handler to catch Ctrl-C and abort server # ---------------------------------------------------------------------------- -def signal_handler(signal, frame) -> None: - r = input(' --> Stop webserver? (yes/no) ').lower() - if r == 'yes': +def signal_handler(*_) -> None: + ''' + Catches Ctrl-C and stops webserver + ''' + reply = input(' --> Stop webserver? (yes/no) ') + if reply.lower() == 'yes': tornado.ioloop.IOLoop.current().stop() - logger.critical('Webserver stopped.') + logging.critical('Webserver stopped.') sys.exit(0) - else: - logger.info('Abort canceled...') # ---------------------------------------------------------------------------- -def run_webserver(app, - ssl, - port: int = 8443, - debug: bool = False) -> None: +def run_webserver(app, ssl, port: int = 8443, debug: bool = False) -> None: + ''' + Starts and runs webserver until a SIGINT signal (Ctrl-C) is received. + ''' # --- create web application try: webapp = WebApplication(app, debug=debug) except Exception: logger.critical('Failed to start web application.') - raise - # sys.exit(1) + sys.exit(1) else: logger.info('Web application started (tornado.web.Application)') @@ -460,14 +520,12 @@ def run_webserver(app, try: httpserver.listen(port) except OSError: - logger.critical(f'Cannot bind port {port}. Already in use?') + logger.critical('Cannot bind port %d. Already in use?', port) sys.exit(1) - else: - logger.info(f'HTTP server listening on port {port}') # --- run webserver + logger.info('Webserver listening on %d... (Ctrl-C to stop)', port) signal.signal(signal.SIGINT, signal_handler) - logger.info('Webserver running... (Ctrl-C to stop)') try: tornado.ioloop.IOLoop.current().start() # running... diff --git a/aprendizations/static/css/animate.min.css b/aprendizations/static/css/animate.min.css deleted file mode 100644 index 62832ba..0000000 --- a/aprendizations/static/css/animate.min.css +++ /dev/null @@ -1,11 +0,0 @@ -@charset "UTF-8"; - -/*! - * animate.css -http://daneden.me/animate - * Version - 3.6.0 - * Licensed under the MIT license - http://opensource.org/licenses/MIT - * - * Copyright (c) 2018 Daniel Eden - */ - -.animated{-webkit-animation-duration:1s;animation-duration:1s;-webkit-animation-fill-mode:both;animation-fill-mode:both}.animated.infinite{-webkit-animation-iteration-count:infinite;animation-iteration-count:infinite}@-webkit-keyframes bounce{0%,20%,53%,80%,to{-webkit-animation-timing-function:cubic-bezier(.215,.61,.355,1);animation-timing-function:cubic-bezier(.215,.61,.355,1);-webkit-transform:translateZ(0);transform:translateZ(0)}40%,43%{-webkit-animation-timing-function:cubic-bezier(.755,.05,.855,.06);animation-timing-function:cubic-bezier(.755,.05,.855,.06);-webkit-transform:translate3d(0,-30px,0);transform:translate3d(0,-30px,0)}70%{-webkit-animation-timing-function:cubic-bezier(.755,.05,.855,.06);animation-timing-function:cubic-bezier(.755,.05,.855,.06);-webkit-transform:translate3d(0,-15px,0);transform:translate3d(0,-15px,0)}90%{-webkit-transform:translate3d(0,-4px,0);transform:translate3d(0,-4px,0)}}@keyframes bounce{0%,20%,53%,80%,to{-webkit-animation-timing-function:cubic-bezier(.215,.61,.355,1);animation-timing-function:cubic-bezier(.215,.61,.355,1);-webkit-transform:translateZ(0);transform:translateZ(0)}40%,43%{-webkit-animation-timing-function:cubic-bezier(.755,.05,.855,.06);animation-timing-function:cubic-bezier(.755,.05,.855,.06);-webkit-transform:translate3d(0,-30px,0);transform:translate3d(0,-30px,0)}70%{-webkit-animation-timing-function:cubic-bezier(.755,.05,.855,.06);animation-timing-function:cubic-bezier(.755,.05,.855,.06);-webkit-transform:translate3d(0,-15px,0);transform:translate3d(0,-15px,0)}90%{-webkit-transform:translate3d(0,-4px,0);transform:translate3d(0,-4px,0)}}.bounce{-webkit-animation-name:bounce;animation-name:bounce;-webkit-transform-origin:center bottom;transform-origin:center bottom}@-webkit-keyframes flash{0%,50%,to{opacity:1}25%,75%{opacity:0}}@keyframes flash{0%,50%,to{opacity:1}25%,75%{opacity:0}}.flash{-webkit-animation-name:flash;animation-name:flash}@-webkit-keyframes pulse{0%{-webkit-transform:scaleX(1);transform:scaleX(1)}50%{-webkit-transform:scale3d(1.05,1.05,1.05);transform:scale3d(1.05,1.05,1.05)}to{-webkit-transform:scaleX(1);transform:scaleX(1)}}@keyframes pulse{0%{-webkit-transform:scaleX(1);transform:scaleX(1)}50%{-webkit-transform:scale3d(1.05,1.05,1.05);transform:scale3d(1.05,1.05,1.05)}to{-webkit-transform:scaleX(1);transform:scaleX(1)}}.pulse{-webkit-animation-name:pulse;animation-name:pulse}@-webkit-keyframes rubberBand{0%{-webkit-transform:scaleX(1);transform:scaleX(1)}30%{-webkit-transform:scale3d(1.25,.75,1);transform:scale3d(1.25,.75,1)}40%{-webkit-transform:scale3d(.75,1.25,1);transform:scale3d(.75,1.25,1)}50%{-webkit-transform:scale3d(1.15,.85,1);transform:scale3d(1.15,.85,1)}65%{-webkit-transform:scale3d(.95,1.05,1);transform:scale3d(.95,1.05,1)}75%{-webkit-transform:scale3d(1.05,.95,1);transform:scale3d(1.05,.95,1)}to{-webkit-transform:scaleX(1);transform:scaleX(1)}}@keyframes rubberBand{0%{-webkit-transform:scaleX(1);transform:scaleX(1)}30%{-webkit-transform:scale3d(1.25,.75,1);transform:scale3d(1.25,.75,1)}40%{-webkit-transform:scale3d(.75,1.25,1);transform:scale3d(.75,1.25,1)}50%{-webkit-transform:scale3d(1.15,.85,1);transform:scale3d(1.15,.85,1)}65%{-webkit-transform:scale3d(.95,1.05,1);transform:scale3d(.95,1.05,1)}75%{-webkit-transform:scale3d(1.05,.95,1);transform:scale3d(1.05,.95,1)}to{-webkit-transform:scaleX(1);transform:scaleX(1)}}.rubberBand{-webkit-animation-name:rubberBand;animation-name:rubberBand}@-webkit-keyframes shake{0%,to{-webkit-transform:translateZ(0);transform:translateZ(0)}10%,30%,50%,70%,90%{-webkit-transform:translate3d(-10px,0,0);transform:translate3d(-10px,0,0)}20%,40%,60%,80%{-webkit-transform:translate3d(10px,0,0);transform:translate3d(10px,0,0)}}@keyframes shake{0%,to{-webkit-transform:translateZ(0);transform:translateZ(0)}10%,30%,50%,70%,90%{-webkit-transform:translate3d(-10px,0,0);transform:translate3d(-10px,0,0)}20%,40%,60%,80%{-webkit-transform:translate3d(10px,0,0);transform:translate3d(10px,0,0)}}.shake{-webkit-animation-name:shake;animation-name:shake}@-webkit-keyframes headShake{0%{-webkit-transform:translateX(0);transform:translateX(0)}6.5%{-webkit-transform:translateX(-6px) rotateY(-9deg);transform:translateX(-6px) rotateY(-9deg)}18.5%{-webkit-transform:translateX(5px) rotateY(7deg);transform:translateX(5px) rotateY(7deg)}31.5%{-webkit-transform:translateX(-3px) rotateY(-5deg);transform:translateX(-3px) rotateY(-5deg)}43.5%{-webkit-transform:translateX(2px) rotateY(3deg);transform:translateX(2px) rotateY(3deg)}50%{-webkit-transform:translateX(0);transform:translateX(0)}}@keyframes headShake{0%{-webkit-transform:translateX(0);transform:translateX(0)}6.5%{-webkit-transform:translateX(-6px) rotateY(-9deg);transform:translateX(-6px) rotateY(-9deg)}18.5%{-webkit-transform:translateX(5px) rotateY(7deg);transform:translateX(5px) rotateY(7deg)}31.5%{-webkit-transform:translateX(-3px) rotateY(-5deg);transform:translateX(-3px) rotateY(-5deg)}43.5%{-webkit-transform:translateX(2px) rotateY(3deg);transform:translateX(2px) rotateY(3deg)}50%{-webkit-transform:translateX(0);transform:translateX(0)}}.headShake{-webkit-animation-timing-function:ease-in-out;animation-timing-function:ease-in-out;-webkit-animation-name:headShake;animation-name:headShake}@-webkit-keyframes swing{20%{-webkit-transform:rotate(15deg);transform:rotate(15deg)}40%{-webkit-transform:rotate(-10deg);transform:rotate(-10deg)}60%{-webkit-transform:rotate(5deg);transform:rotate(5deg)}80%{-webkit-transform:rotate(-5deg);transform:rotate(-5deg)}to{-webkit-transform:rotate(0deg);transform:rotate(0deg)}}@keyframes swing{20%{-webkit-transform:rotate(15deg);transform:rotate(15deg)}40%{-webkit-transform:rotate(-10deg);transform:rotate(-10deg)}60%{-webkit-transform:rotate(5deg);transform:rotate(5deg)}80%{-webkit-transform:rotate(-5deg);transform:rotate(-5deg)}to{-webkit-transform:rotate(0deg);transform:rotate(0deg)}}.swing{-webkit-transform-origin:top center;transform-origin:top center;-webkit-animation-name:swing;animation-name:swing}@-webkit-keyframes tada{0%{-webkit-transform:scaleX(1);transform:scaleX(1)}10%,20%{-webkit-transform:scale3d(.9,.9,.9) rotate(-3deg);transform:scale3d(.9,.9,.9) rotate(-3deg)}30%,50%,70%,90%{-webkit-transform:scale3d(1.1,1.1,1.1) rotate(3deg);transform:scale3d(1.1,1.1,1.1) rotate(3deg)}40%,60%,80%{-webkit-transform:scale3d(1.1,1.1,1.1) rotate(-3deg);transform:scale3d(1.1,1.1,1.1) rotate(-3deg)}to{-webkit-transform:scaleX(1);transform:scaleX(1)}}@keyframes tada{0%{-webkit-transform:scaleX(1);transform:scaleX(1)}10%,20%{-webkit-transform:scale3d(.9,.9,.9) rotate(-3deg);transform:scale3d(.9,.9,.9) rotate(-3deg)}30%,50%,70%,90%{-webkit-transform:scale3d(1.1,1.1,1.1) rotate(3deg);transform:scale3d(1.1,1.1,1.1) rotate(3deg)}40%,60%,80%{-webkit-transform:scale3d(1.1,1.1,1.1) rotate(-3deg);transform:scale3d(1.1,1.1,1.1) rotate(-3deg)}to{-webkit-transform:scaleX(1);transform:scaleX(1)}}.tada{-webkit-animation-name:tada;animation-name:tada}@-webkit-keyframes wobble{0%{-webkit-transform:translateZ(0);transform:translateZ(0)}15%{-webkit-transform:translate3d(-25%,0,0) rotate(-5deg);transform:translate3d(-25%,0,0) rotate(-5deg)}30%{-webkit-transform:translate3d(20%,0,0) rotate(3deg);transform:translate3d(20%,0,0) rotate(3deg)}45%{-webkit-transform:translate3d(-15%,0,0) rotate(-3deg);transform:translate3d(-15%,0,0) rotate(-3deg)}60%{-webkit-transform:translate3d(10%,0,0) rotate(2deg);transform:translate3d(10%,0,0) rotate(2deg)}75%{-webkit-transform:translate3d(-5%,0,0) rotate(-1deg);transform:translate3d(-5%,0,0) rotate(-1deg)}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes wobble{0%{-webkit-transform:translateZ(0);transform:translateZ(0)}15%{-webkit-transform:translate3d(-25%,0,0) rotate(-5deg);transform:translate3d(-25%,0,0) rotate(-5deg)}30%{-webkit-transform:translate3d(20%,0,0) rotate(3deg);transform:translate3d(20%,0,0) rotate(3deg)}45%{-webkit-transform:translate3d(-15%,0,0) rotate(-3deg);transform:translate3d(-15%,0,0) rotate(-3deg)}60%{-webkit-transform:translate3d(10%,0,0) rotate(2deg);transform:translate3d(10%,0,0) rotate(2deg)}75%{-webkit-transform:translate3d(-5%,0,0) rotate(-1deg);transform:translate3d(-5%,0,0) rotate(-1deg)}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}.wobble{-webkit-animation-name:wobble;animation-name:wobble}@-webkit-keyframes jello{0%,11.1%,to{-webkit-transform:translateZ(0);transform:translateZ(0)}22.2%{-webkit-transform:skewX(-12.5deg) skewY(-12.5deg);transform:skewX(-12.5deg) skewY(-12.5deg)}33.3%{-webkit-transform:skewX(6.25deg) skewY(6.25deg);transform:skewX(6.25deg) skewY(6.25deg)}44.4%{-webkit-transform:skewX(-3.125deg) skewY(-3.125deg);transform:skewX(-3.125deg) skewY(-3.125deg)}55.5%{-webkit-transform:skewX(1.5625deg) skewY(1.5625deg);transform:skewX(1.5625deg) skewY(1.5625deg)}66.6%{-webkit-transform:skewX(-.78125deg) skewY(-.78125deg);transform:skewX(-.78125deg) skewY(-.78125deg)}77.7%{-webkit-transform:skewX(.390625deg) skewY(.390625deg);transform:skewX(.390625deg) skewY(.390625deg)}88.8%{-webkit-transform:skewX(-.1953125deg) skewY(-.1953125deg);transform:skewX(-.1953125deg) skewY(-.1953125deg)}}@keyframes jello{0%,11.1%,to{-webkit-transform:translateZ(0);transform:translateZ(0)}22.2%{-webkit-transform:skewX(-12.5deg) skewY(-12.5deg);transform:skewX(-12.5deg) skewY(-12.5deg)}33.3%{-webkit-transform:skewX(6.25deg) skewY(6.25deg);transform:skewX(6.25deg) skewY(6.25deg)}44.4%{-webkit-transform:skewX(-3.125deg) skewY(-3.125deg);transform:skewX(-3.125deg) skewY(-3.125deg)}55.5%{-webkit-transform:skewX(1.5625deg) skewY(1.5625deg);transform:skewX(1.5625deg) skewY(1.5625deg)}66.6%{-webkit-transform:skewX(-.78125deg) skewY(-.78125deg);transform:skewX(-.78125deg) skewY(-.78125deg)}77.7%{-webkit-transform:skewX(.390625deg) skewY(.390625deg);transform:skewX(.390625deg) skewY(.390625deg)}88.8%{-webkit-transform:skewX(-.1953125deg) skewY(-.1953125deg);transform:skewX(-.1953125deg) skewY(-.1953125deg)}}.jello{-webkit-animation-name:jello;animation-name:jello;-webkit-transform-origin:center;transform-origin:center}@-webkit-keyframes bounceIn{0%,20%,40%,60%,80%,to{-webkit-animation-timing-function:cubic-bezier(.215,.61,.355,1);animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;-webkit-transform:scale3d(.3,.3,.3);transform:scale3d(.3,.3,.3)}20%{-webkit-transform:scale3d(1.1,1.1,1.1);transform:scale3d(1.1,1.1,1.1)}40%{-webkit-transform:scale3d(.9,.9,.9);transform:scale3d(.9,.9,.9)}60%{opacity:1;-webkit-transform:scale3d(1.03,1.03,1.03);transform:scale3d(1.03,1.03,1.03)}80%{-webkit-transform:scale3d(.97,.97,.97);transform:scale3d(.97,.97,.97)}to{opacity:1;-webkit-transform:scaleX(1);transform:scaleX(1)}}@keyframes bounceIn{0%,20%,40%,60%,80%,to{-webkit-animation-timing-function:cubic-bezier(.215,.61,.355,1);animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;-webkit-transform:scale3d(.3,.3,.3);transform:scale3d(.3,.3,.3)}20%{-webkit-transform:scale3d(1.1,1.1,1.1);transform:scale3d(1.1,1.1,1.1)}40%{-webkit-transform:scale3d(.9,.9,.9);transform:scale3d(.9,.9,.9)}60%{opacity:1;-webkit-transform:scale3d(1.03,1.03,1.03);transform:scale3d(1.03,1.03,1.03)}80%{-webkit-transform:scale3d(.97,.97,.97);transform:scale3d(.97,.97,.97)}to{opacity:1;-webkit-transform:scaleX(1);transform:scaleX(1)}}.bounceIn{-webkit-animation-duration:.75s;animation-duration:.75s;-webkit-animation-name:bounceIn;animation-name:bounceIn}@-webkit-keyframes bounceInDown{0%,60%,75%,90%,to{-webkit-animation-timing-function:cubic-bezier(.215,.61,.355,1);animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;-webkit-transform:translate3d(0,-3000px,0);transform:translate3d(0,-3000px,0)}60%{opacity:1;-webkit-transform:translate3d(0,25px,0);transform:translate3d(0,25px,0)}75%{-webkit-transform:translate3d(0,-10px,0);transform:translate3d(0,-10px,0)}90%{-webkit-transform:translate3d(0,5px,0);transform:translate3d(0,5px,0)}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes bounceInDown{0%,60%,75%,90%,to{-webkit-animation-timing-function:cubic-bezier(.215,.61,.355,1);animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;-webkit-transform:translate3d(0,-3000px,0);transform:translate3d(0,-3000px,0)}60%{opacity:1;-webkit-transform:translate3d(0,25px,0);transform:translate3d(0,25px,0)}75%{-webkit-transform:translate3d(0,-10px,0);transform:translate3d(0,-10px,0)}90%{-webkit-transform:translate3d(0,5px,0);transform:translate3d(0,5px,0)}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}.bounceInDown{-webkit-animation-name:bounceInDown;animation-name:bounceInDown}@-webkit-keyframes bounceInLeft{0%,60%,75%,90%,to{-webkit-animation-timing-function:cubic-bezier(.215,.61,.355,1);animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;-webkit-transform:translate3d(-3000px,0,0);transform:translate3d(-3000px,0,0)}60%{opacity:1;-webkit-transform:translate3d(25px,0,0);transform:translate3d(25px,0,0)}75%{-webkit-transform:translate3d(-10px,0,0);transform:translate3d(-10px,0,0)}90%{-webkit-transform:translate3d(5px,0,0);transform:translate3d(5px,0,0)}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes bounceInLeft{0%,60%,75%,90%,to{-webkit-animation-timing-function:cubic-bezier(.215,.61,.355,1);animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;-webkit-transform:translate3d(-3000px,0,0);transform:translate3d(-3000px,0,0)}60%{opacity:1;-webkit-transform:translate3d(25px,0,0);transform:translate3d(25px,0,0)}75%{-webkit-transform:translate3d(-10px,0,0);transform:translate3d(-10px,0,0)}90%{-webkit-transform:translate3d(5px,0,0);transform:translate3d(5px,0,0)}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}.bounceInLeft{-webkit-animation-name:bounceInLeft;animation-name:bounceInLeft}@-webkit-keyframes bounceInRight{0%,60%,75%,90%,to{-webkit-animation-timing-function:cubic-bezier(.215,.61,.355,1);animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;-webkit-transform:translate3d(3000px,0,0);transform:translate3d(3000px,0,0)}60%{opacity:1;-webkit-transform:translate3d(-25px,0,0);transform:translate3d(-25px,0,0)}75%{-webkit-transform:translate3d(10px,0,0);transform:translate3d(10px,0,0)}90%{-webkit-transform:translate3d(-5px,0,0);transform:translate3d(-5px,0,0)}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes bounceInRight{0%,60%,75%,90%,to{-webkit-animation-timing-function:cubic-bezier(.215,.61,.355,1);animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;-webkit-transform:translate3d(3000px,0,0);transform:translate3d(3000px,0,0)}60%{opacity:1;-webkit-transform:translate3d(-25px,0,0);transform:translate3d(-25px,0,0)}75%{-webkit-transform:translate3d(10px,0,0);transform:translate3d(10px,0,0)}90%{-webkit-transform:translate3d(-5px,0,0);transform:translate3d(-5px,0,0)}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}.bounceInRight{-webkit-animation-name:bounceInRight;animation-name:bounceInRight}@-webkit-keyframes bounceInUp{0%,60%,75%,90%,to{-webkit-animation-timing-function:cubic-bezier(.215,.61,.355,1);animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;-webkit-transform:translate3d(0,3000px,0);transform:translate3d(0,3000px,0)}60%{opacity:1;-webkit-transform:translate3d(0,-20px,0);transform:translate3d(0,-20px,0)}75%{-webkit-transform:translate3d(0,10px,0);transform:translate3d(0,10px,0)}90%{-webkit-transform:translate3d(0,-5px,0);transform:translate3d(0,-5px,0)}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes bounceInUp{0%,60%,75%,90%,to{-webkit-animation-timing-function:cubic-bezier(.215,.61,.355,1);animation-timing-function:cubic-bezier(.215,.61,.355,1)}0%{opacity:0;-webkit-transform:translate3d(0,3000px,0);transform:translate3d(0,3000px,0)}60%{opacity:1;-webkit-transform:translate3d(0,-20px,0);transform:translate3d(0,-20px,0)}75%{-webkit-transform:translate3d(0,10px,0);transform:translate3d(0,10px,0)}90%{-webkit-transform:translate3d(0,-5px,0);transform:translate3d(0,-5px,0)}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}.bounceInUp{-webkit-animation-name:bounceInUp;animation-name:bounceInUp}@-webkit-keyframes bounceOut{20%{-webkit-transform:scale3d(.9,.9,.9);transform:scale3d(.9,.9,.9)}50%,55%{opacity:1;-webkit-transform:scale3d(1.1,1.1,1.1);transform:scale3d(1.1,1.1,1.1)}to{opacity:0;-webkit-transform:scale3d(.3,.3,.3);transform:scale3d(.3,.3,.3)}}@keyframes bounceOut{20%{-webkit-transform:scale3d(.9,.9,.9);transform:scale3d(.9,.9,.9)}50%,55%{opacity:1;-webkit-transform:scale3d(1.1,1.1,1.1);transform:scale3d(1.1,1.1,1.1)}to{opacity:0;-webkit-transform:scale3d(.3,.3,.3);transform:scale3d(.3,.3,.3)}}.bounceOut{-webkit-animation-duration:.75s;animation-duration:.75s;-webkit-animation-name:bounceOut;animation-name:bounceOut}@-webkit-keyframes bounceOutDown{20%{-webkit-transform:translate3d(0,10px,0);transform:translate3d(0,10px,0)}40%,45%{opacity:1;-webkit-transform:translate3d(0,-20px,0);transform:translate3d(0,-20px,0)}to{opacity:0;-webkit-transform:translate3d(0,2000px,0);transform:translate3d(0,2000px,0)}}@keyframes bounceOutDown{20%{-webkit-transform:translate3d(0,10px,0);transform:translate3d(0,10px,0)}40%,45%{opacity:1;-webkit-transform:translate3d(0,-20px,0);transform:translate3d(0,-20px,0)}to{opacity:0;-webkit-transform:translate3d(0,2000px,0);transform:translate3d(0,2000px,0)}}.bounceOutDown{-webkit-animation-name:bounceOutDown;animation-name:bounceOutDown}@-webkit-keyframes bounceOutLeft{20%{opacity:1;-webkit-transform:translate3d(20px,0,0);transform:translate3d(20px,0,0)}to{opacity:0;-webkit-transform:translate3d(-2000px,0,0);transform:translate3d(-2000px,0,0)}}@keyframes bounceOutLeft{20%{opacity:1;-webkit-transform:translate3d(20px,0,0);transform:translate3d(20px,0,0)}to{opacity:0;-webkit-transform:translate3d(-2000px,0,0);transform:translate3d(-2000px,0,0)}}.bounceOutLeft{-webkit-animation-name:bounceOutLeft;animation-name:bounceOutLeft}@-webkit-keyframes bounceOutRight{20%{opacity:1;-webkit-transform:translate3d(-20px,0,0);transform:translate3d(-20px,0,0)}to{opacity:0;-webkit-transform:translate3d(2000px,0,0);transform:translate3d(2000px,0,0)}}@keyframes bounceOutRight{20%{opacity:1;-webkit-transform:translate3d(-20px,0,0);transform:translate3d(-20px,0,0)}to{opacity:0;-webkit-transform:translate3d(2000px,0,0);transform:translate3d(2000px,0,0)}}.bounceOutRight{-webkit-animation-name:bounceOutRight;animation-name:bounceOutRight}@-webkit-keyframes bounceOutUp{20%{-webkit-transform:translate3d(0,-10px,0);transform:translate3d(0,-10px,0)}40%,45%{opacity:1;-webkit-transform:translate3d(0,20px,0);transform:translate3d(0,20px,0)}to{opacity:0;-webkit-transform:translate3d(0,-2000px,0);transform:translate3d(0,-2000px,0)}}@keyframes bounceOutUp{20%{-webkit-transform:translate3d(0,-10px,0);transform:translate3d(0,-10px,0)}40%,45%{opacity:1;-webkit-transform:translate3d(0,20px,0);transform:translate3d(0,20px,0)}to{opacity:0;-webkit-transform:translate3d(0,-2000px,0);transform:translate3d(0,-2000px,0)}}.bounceOutUp{-webkit-animation-name:bounceOutUp;animation-name:bounceOutUp}@-webkit-keyframes fadeIn{0%{opacity:0}to{opacity:1}}@keyframes fadeIn{0%{opacity:0}to{opacity:1}}.fadeIn{-webkit-animation-name:fadeIn;animation-name:fadeIn}@-webkit-keyframes fadeInDown{0%{opacity:0;-webkit-transform:translate3d(0,-100%,0);transform:translate3d(0,-100%,0)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes fadeInDown{0%{opacity:0;-webkit-transform:translate3d(0,-100%,0);transform:translate3d(0,-100%,0)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}.fadeInDown{-webkit-animation-name:fadeInDown;animation-name:fadeInDown}@-webkit-keyframes fadeInDownBig{0%{opacity:0;-webkit-transform:translate3d(0,-2000px,0);transform:translate3d(0,-2000px,0)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes fadeInDownBig{0%{opacity:0;-webkit-transform:translate3d(0,-2000px,0);transform:translate3d(0,-2000px,0)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}.fadeInDownBig{-webkit-animation-name:fadeInDownBig;animation-name:fadeInDownBig}@-webkit-keyframes fadeInLeft{0%{opacity:0;-webkit-transform:translate3d(-100%,0,0);transform:translate3d(-100%,0,0)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes fadeInLeft{0%{opacity:0;-webkit-transform:translate3d(-100%,0,0);transform:translate3d(-100%,0,0)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}.fadeInLeft{-webkit-animation-name:fadeInLeft;animation-name:fadeInLeft}@-webkit-keyframes fadeInLeftBig{0%{opacity:0;-webkit-transform:translate3d(-2000px,0,0);transform:translate3d(-2000px,0,0)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes fadeInLeftBig{0%{opacity:0;-webkit-transform:translate3d(-2000px,0,0);transform:translate3d(-2000px,0,0)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}.fadeInLeftBig{-webkit-animation-name:fadeInLeftBig;animation-name:fadeInLeftBig}@-webkit-keyframes fadeInRight{0%{opacity:0;-webkit-transform:translate3d(100%,0,0);transform:translate3d(100%,0,0)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes fadeInRight{0%{opacity:0;-webkit-transform:translate3d(100%,0,0);transform:translate3d(100%,0,0)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}.fadeInRight{-webkit-animation-name:fadeInRight;animation-name:fadeInRight}@-webkit-keyframes fadeInRightBig{0%{opacity:0;-webkit-transform:translate3d(2000px,0,0);transform:translate3d(2000px,0,0)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes fadeInRightBig{0%{opacity:0;-webkit-transform:translate3d(2000px,0,0);transform:translate3d(2000px,0,0)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}.fadeInRightBig{-webkit-animation-name:fadeInRightBig;animation-name:fadeInRightBig}@-webkit-keyframes fadeInUp{0%{opacity:0;-webkit-transform:translate3d(0,100%,0);transform:translate3d(0,100%,0)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes fadeInUp{0%{opacity:0;-webkit-transform:translate3d(0,100%,0);transform:translate3d(0,100%,0)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}.fadeInUp{-webkit-animation-name:fadeInUp;animation-name:fadeInUp}@-webkit-keyframes fadeInUpBig{0%{opacity:0;-webkit-transform:translate3d(0,2000px,0);transform:translate3d(0,2000px,0)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes fadeInUpBig{0%{opacity:0;-webkit-transform:translate3d(0,2000px,0);transform:translate3d(0,2000px,0)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}.fadeInUpBig{-webkit-animation-name:fadeInUpBig;animation-name:fadeInUpBig}@-webkit-keyframes fadeOut{0%{opacity:1}to{opacity:0}}@keyframes fadeOut{0%{opacity:1}to{opacity:0}}.fadeOut{-webkit-animation-name:fadeOut;animation-name:fadeOut}@-webkit-keyframes fadeOutDown{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(0,100%,0);transform:translate3d(0,100%,0)}}@keyframes fadeOutDown{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(0,100%,0);transform:translate3d(0,100%,0)}}.fadeOutDown{-webkit-animation-name:fadeOutDown;animation-name:fadeOutDown}@-webkit-keyframes fadeOutDownBig{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(0,2000px,0);transform:translate3d(0,2000px,0)}}@keyframes fadeOutDownBig{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(0,2000px,0);transform:translate3d(0,2000px,0)}}.fadeOutDownBig{-webkit-animation-name:fadeOutDownBig;animation-name:fadeOutDownBig}@-webkit-keyframes fadeOutLeft{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(-100%,0,0);transform:translate3d(-100%,0,0)}}@keyframes fadeOutLeft{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(-100%,0,0);transform:translate3d(-100%,0,0)}}.fadeOutLeft{-webkit-animation-name:fadeOutLeft;animation-name:fadeOutLeft}@-webkit-keyframes fadeOutLeftBig{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(-2000px,0,0);transform:translate3d(-2000px,0,0)}}@keyframes fadeOutLeftBig{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(-2000px,0,0);transform:translate3d(-2000px,0,0)}}.fadeOutLeftBig{-webkit-animation-name:fadeOutLeftBig;animation-name:fadeOutLeftBig}@-webkit-keyframes fadeOutRight{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(100%,0,0);transform:translate3d(100%,0,0)}}@keyframes fadeOutRight{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(100%,0,0);transform:translate3d(100%,0,0)}}.fadeOutRight{-webkit-animation-name:fadeOutRight;animation-name:fadeOutRight}@-webkit-keyframes fadeOutRightBig{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(2000px,0,0);transform:translate3d(2000px,0,0)}}@keyframes fadeOutRightBig{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(2000px,0,0);transform:translate3d(2000px,0,0)}}.fadeOutRightBig{-webkit-animation-name:fadeOutRightBig;animation-name:fadeOutRightBig}@-webkit-keyframes fadeOutUp{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(0,-100%,0);transform:translate3d(0,-100%,0)}}@keyframes fadeOutUp{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(0,-100%,0);transform:translate3d(0,-100%,0)}}.fadeOutUp{-webkit-animation-name:fadeOutUp;animation-name:fadeOutUp}@-webkit-keyframes fadeOutUpBig{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(0,-2000px,0);transform:translate3d(0,-2000px,0)}}@keyframes fadeOutUpBig{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(0,-2000px,0);transform:translate3d(0,-2000px,0)}}.fadeOutUpBig{-webkit-animation-name:fadeOutUpBig;animation-name:fadeOutUpBig}@-webkit-keyframes flip{0%{-webkit-transform:perspective(400px) rotateY(-1turn);transform:perspective(400px) rotateY(-1turn);-webkit-animation-timing-function:ease-out;animation-timing-function:ease-out}40%{-webkit-transform:perspective(400px) translateZ(150px) rotateY(-190deg);transform:perspective(400px) translateZ(150px) rotateY(-190deg);-webkit-animation-timing-function:ease-out;animation-timing-function:ease-out}50%{-webkit-transform:perspective(400px) translateZ(150px) rotateY(-170deg);transform:perspective(400px) translateZ(150px) rotateY(-170deg);-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in}80%{-webkit-transform:perspective(400px) scale3d(.95,.95,.95);transform:perspective(400px) scale3d(.95,.95,.95);-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in}to{-webkit-transform:perspective(400px);transform:perspective(400px);-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in}}@keyframes flip{0%{-webkit-transform:perspective(400px) rotateY(-1turn);transform:perspective(400px) rotateY(-1turn);-webkit-animation-timing-function:ease-out;animation-timing-function:ease-out}40%{-webkit-transform:perspective(400px) translateZ(150px) rotateY(-190deg);transform:perspective(400px) translateZ(150px) rotateY(-190deg);-webkit-animation-timing-function:ease-out;animation-timing-function:ease-out}50%{-webkit-transform:perspective(400px) translateZ(150px) rotateY(-170deg);transform:perspective(400px) translateZ(150px) rotateY(-170deg);-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in}80%{-webkit-transform:perspective(400px) scale3d(.95,.95,.95);transform:perspective(400px) scale3d(.95,.95,.95);-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in}to{-webkit-transform:perspective(400px);transform:perspective(400px);-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in}}.animated.flip{-webkit-backface-visibility:visible;backface-visibility:visible;-webkit-animation-name:flip;animation-name:flip}@-webkit-keyframes flipInX{0%{-webkit-transform:perspective(400px) rotateX(90deg);transform:perspective(400px) rotateX(90deg);-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in;opacity:0}40%{-webkit-transform:perspective(400px) rotateX(-20deg);transform:perspective(400px) rotateX(-20deg);-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in}60%{-webkit-transform:perspective(400px) rotateX(10deg);transform:perspective(400px) rotateX(10deg);opacity:1}80%{-webkit-transform:perspective(400px) rotateX(-5deg);transform:perspective(400px) rotateX(-5deg)}to{-webkit-transform:perspective(400px);transform:perspective(400px)}}@keyframes flipInX{0%{-webkit-transform:perspective(400px) rotateX(90deg);transform:perspective(400px) rotateX(90deg);-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in;opacity:0}40%{-webkit-transform:perspective(400px) rotateX(-20deg);transform:perspective(400px) rotateX(-20deg);-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in}60%{-webkit-transform:perspective(400px) rotateX(10deg);transform:perspective(400px) rotateX(10deg);opacity:1}80%{-webkit-transform:perspective(400px) rotateX(-5deg);transform:perspective(400px) rotateX(-5deg)}to{-webkit-transform:perspective(400px);transform:perspective(400px)}}.flipInX{-webkit-backface-visibility:visible!important;backface-visibility:visible!important;-webkit-animation-name:flipInX;animation-name:flipInX}@-webkit-keyframes flipInY{0%{-webkit-transform:perspective(400px) rotateY(90deg);transform:perspective(400px) rotateY(90deg);-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in;opacity:0}40%{-webkit-transform:perspective(400px) rotateY(-20deg);transform:perspective(400px) rotateY(-20deg);-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in}60%{-webkit-transform:perspective(400px) rotateY(10deg);transform:perspective(400px) rotateY(10deg);opacity:1}80%{-webkit-transform:perspective(400px) rotateY(-5deg);transform:perspective(400px) rotateY(-5deg)}to{-webkit-transform:perspective(400px);transform:perspective(400px)}}@keyframes flipInY{0%{-webkit-transform:perspective(400px) rotateY(90deg);transform:perspective(400px) rotateY(90deg);-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in;opacity:0}40%{-webkit-transform:perspective(400px) rotateY(-20deg);transform:perspective(400px) rotateY(-20deg);-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in}60%{-webkit-transform:perspective(400px) rotateY(10deg);transform:perspective(400px) rotateY(10deg);opacity:1}80%{-webkit-transform:perspective(400px) rotateY(-5deg);transform:perspective(400px) rotateY(-5deg)}to{-webkit-transform:perspective(400px);transform:perspective(400px)}}.flipInY{-webkit-backface-visibility:visible!important;backface-visibility:visible!important;-webkit-animation-name:flipInY;animation-name:flipInY}@-webkit-keyframes flipOutX{0%{-webkit-transform:perspective(400px);transform:perspective(400px)}30%{-webkit-transform:perspective(400px) rotateX(-20deg);transform:perspective(400px) rotateX(-20deg);opacity:1}to{-webkit-transform:perspective(400px) rotateX(90deg);transform:perspective(400px) rotateX(90deg);opacity:0}}@keyframes flipOutX{0%{-webkit-transform:perspective(400px);transform:perspective(400px)}30%{-webkit-transform:perspective(400px) rotateX(-20deg);transform:perspective(400px) rotateX(-20deg);opacity:1}to{-webkit-transform:perspective(400px) rotateX(90deg);transform:perspective(400px) rotateX(90deg);opacity:0}}.flipOutX{-webkit-animation-duration:.75s;animation-duration:.75s;-webkit-animation-name:flipOutX;animation-name:flipOutX;-webkit-backface-visibility:visible!important;backface-visibility:visible!important}@-webkit-keyframes flipOutY{0%{-webkit-transform:perspective(400px);transform:perspective(400px)}30%{-webkit-transform:perspective(400px) rotateY(-15deg);transform:perspective(400px) rotateY(-15deg);opacity:1}to{-webkit-transform:perspective(400px) rotateY(90deg);transform:perspective(400px) rotateY(90deg);opacity:0}}@keyframes flipOutY{0%{-webkit-transform:perspective(400px);transform:perspective(400px)}30%{-webkit-transform:perspective(400px) rotateY(-15deg);transform:perspective(400px) rotateY(-15deg);opacity:1}to{-webkit-transform:perspective(400px) rotateY(90deg);transform:perspective(400px) rotateY(90deg);opacity:0}}.flipOutY{-webkit-animation-duration:.75s;animation-duration:.75s;-webkit-backface-visibility:visible!important;backface-visibility:visible!important;-webkit-animation-name:flipOutY;animation-name:flipOutY}@-webkit-keyframes lightSpeedIn{0%{-webkit-transform:translate3d(100%,0,0) skewX(-30deg);transform:translate3d(100%,0,0) skewX(-30deg);opacity:0}60%{-webkit-transform:skewX(20deg);transform:skewX(20deg);opacity:1}80%{-webkit-transform:skewX(-5deg);transform:skewX(-5deg);opacity:1}to{-webkit-transform:translateZ(0);transform:translateZ(0);opacity:1}}@keyframes lightSpeedIn{0%{-webkit-transform:translate3d(100%,0,0) skewX(-30deg);transform:translate3d(100%,0,0) skewX(-30deg);opacity:0}60%{-webkit-transform:skewX(20deg);transform:skewX(20deg);opacity:1}80%{-webkit-transform:skewX(-5deg);transform:skewX(-5deg);opacity:1}to{-webkit-transform:translateZ(0);transform:translateZ(0);opacity:1}}.lightSpeedIn{-webkit-animation-name:lightSpeedIn;animation-name:lightSpeedIn;-webkit-animation-timing-function:ease-out;animation-timing-function:ease-out}@-webkit-keyframes lightSpeedOut{0%{opacity:1}to{-webkit-transform:translate3d(100%,0,0) skewX(30deg);transform:translate3d(100%,0,0) skewX(30deg);opacity:0}}@keyframes lightSpeedOut{0%{opacity:1}to{-webkit-transform:translate3d(100%,0,0) skewX(30deg);transform:translate3d(100%,0,0) skewX(30deg);opacity:0}}.lightSpeedOut{-webkit-animation-name:lightSpeedOut;animation-name:lightSpeedOut;-webkit-animation-timing-function:ease-in;animation-timing-function:ease-in}@-webkit-keyframes rotateIn{0%{-webkit-transform-origin:center;transform-origin:center;-webkit-transform:rotate(-200deg);transform:rotate(-200deg);opacity:0}to{-webkit-transform-origin:center;transform-origin:center;-webkit-transform:translateZ(0);transform:translateZ(0);opacity:1}}@keyframes rotateIn{0%{-webkit-transform-origin:center;transform-origin:center;-webkit-transform:rotate(-200deg);transform:rotate(-200deg);opacity:0}to{-webkit-transform-origin:center;transform-origin:center;-webkit-transform:translateZ(0);transform:translateZ(0);opacity:1}}.rotateIn{-webkit-animation-name:rotateIn;animation-name:rotateIn}@-webkit-keyframes rotateInDownLeft{0%{-webkit-transform-origin:left bottom;transform-origin:left bottom;-webkit-transform:rotate(-45deg);transform:rotate(-45deg);opacity:0}to{-webkit-transform-origin:left bottom;transform-origin:left bottom;-webkit-transform:translateZ(0);transform:translateZ(0);opacity:1}}@keyframes rotateInDownLeft{0%{-webkit-transform-origin:left bottom;transform-origin:left bottom;-webkit-transform:rotate(-45deg);transform:rotate(-45deg);opacity:0}to{-webkit-transform-origin:left bottom;transform-origin:left bottom;-webkit-transform:translateZ(0);transform:translateZ(0);opacity:1}}.rotateInDownLeft{-webkit-animation-name:rotateInDownLeft;animation-name:rotateInDownLeft}@-webkit-keyframes rotateInDownRight{0%{-webkit-transform-origin:right bottom;transform-origin:right bottom;-webkit-transform:rotate(45deg);transform:rotate(45deg);opacity:0}to{-webkit-transform-origin:right bottom;transform-origin:right bottom;-webkit-transform:translateZ(0);transform:translateZ(0);opacity:1}}@keyframes rotateInDownRight{0%{-webkit-transform-origin:right bottom;transform-origin:right bottom;-webkit-transform:rotate(45deg);transform:rotate(45deg);opacity:0}to{-webkit-transform-origin:right bottom;transform-origin:right bottom;-webkit-transform:translateZ(0);transform:translateZ(0);opacity:1}}.rotateInDownRight{-webkit-animation-name:rotateInDownRight;animation-name:rotateInDownRight}@-webkit-keyframes rotateInUpLeft{0%{-webkit-transform-origin:left bottom;transform-origin:left bottom;-webkit-transform:rotate(45deg);transform:rotate(45deg);opacity:0}to{-webkit-transform-origin:left bottom;transform-origin:left bottom;-webkit-transform:translateZ(0);transform:translateZ(0);opacity:1}}@keyframes rotateInUpLeft{0%{-webkit-transform-origin:left bottom;transform-origin:left bottom;-webkit-transform:rotate(45deg);transform:rotate(45deg);opacity:0}to{-webkit-transform-origin:left bottom;transform-origin:left bottom;-webkit-transform:translateZ(0);transform:translateZ(0);opacity:1}}.rotateInUpLeft{-webkit-animation-name:rotateInUpLeft;animation-name:rotateInUpLeft}@-webkit-keyframes rotateInUpRight{0%{-webkit-transform-origin:right bottom;transform-origin:right bottom;-webkit-transform:rotate(-90deg);transform:rotate(-90deg);opacity:0}to{-webkit-transform-origin:right bottom;transform-origin:right bottom;-webkit-transform:translateZ(0);transform:translateZ(0);opacity:1}}@keyframes rotateInUpRight{0%{-webkit-transform-origin:right bottom;transform-origin:right bottom;-webkit-transform:rotate(-90deg);transform:rotate(-90deg);opacity:0}to{-webkit-transform-origin:right bottom;transform-origin:right bottom;-webkit-transform:translateZ(0);transform:translateZ(0);opacity:1}}.rotateInUpRight{-webkit-animation-name:rotateInUpRight;animation-name:rotateInUpRight}@-webkit-keyframes rotateOut{0%{-webkit-transform-origin:center;transform-origin:center;opacity:1}to{-webkit-transform-origin:center;transform-origin:center;-webkit-transform:rotate(200deg);transform:rotate(200deg);opacity:0}}@keyframes rotateOut{0%{-webkit-transform-origin:center;transform-origin:center;opacity:1}to{-webkit-transform-origin:center;transform-origin:center;-webkit-transform:rotate(200deg);transform:rotate(200deg);opacity:0}}.rotateOut{-webkit-animation-name:rotateOut;animation-name:rotateOut}@-webkit-keyframes rotateOutDownLeft{0%{-webkit-transform-origin:left bottom;transform-origin:left bottom;opacity:1}to{-webkit-transform-origin:left bottom;transform-origin:left bottom;-webkit-transform:rotate(45deg);transform:rotate(45deg);opacity:0}}@keyframes rotateOutDownLeft{0%{-webkit-transform-origin:left bottom;transform-origin:left bottom;opacity:1}to{-webkit-transform-origin:left bottom;transform-origin:left bottom;-webkit-transform:rotate(45deg);transform:rotate(45deg);opacity:0}}.rotateOutDownLeft{-webkit-animation-name:rotateOutDownLeft;animation-name:rotateOutDownLeft}@-webkit-keyframes rotateOutDownRight{0%{-webkit-transform-origin:right bottom;transform-origin:right bottom;opacity:1}to{-webkit-transform-origin:right bottom;transform-origin:right bottom;-webkit-transform:rotate(-45deg);transform:rotate(-45deg);opacity:0}}@keyframes rotateOutDownRight{0%{-webkit-transform-origin:right bottom;transform-origin:right bottom;opacity:1}to{-webkit-transform-origin:right bottom;transform-origin:right bottom;-webkit-transform:rotate(-45deg);transform:rotate(-45deg);opacity:0}}.rotateOutDownRight{-webkit-animation-name:rotateOutDownRight;animation-name:rotateOutDownRight}@-webkit-keyframes rotateOutUpLeft{0%{-webkit-transform-origin:left bottom;transform-origin:left bottom;opacity:1}to{-webkit-transform-origin:left bottom;transform-origin:left bottom;-webkit-transform:rotate(-45deg);transform:rotate(-45deg);opacity:0}}@keyframes rotateOutUpLeft{0%{-webkit-transform-origin:left bottom;transform-origin:left bottom;opacity:1}to{-webkit-transform-origin:left bottom;transform-origin:left bottom;-webkit-transform:rotate(-45deg);transform:rotate(-45deg);opacity:0}}.rotateOutUpLeft{-webkit-animation-name:rotateOutUpLeft;animation-name:rotateOutUpLeft}@-webkit-keyframes rotateOutUpRight{0%{-webkit-transform-origin:right bottom;transform-origin:right bottom;opacity:1}to{-webkit-transform-origin:right bottom;transform-origin:right bottom;-webkit-transform:rotate(90deg);transform:rotate(90deg);opacity:0}}@keyframes rotateOutUpRight{0%{-webkit-transform-origin:right bottom;transform-origin:right bottom;opacity:1}to{-webkit-transform-origin:right bottom;transform-origin:right bottom;-webkit-transform:rotate(90deg);transform:rotate(90deg);opacity:0}}.rotateOutUpRight{-webkit-animation-name:rotateOutUpRight;animation-name:rotateOutUpRight}@-webkit-keyframes hinge{0%{-webkit-transform-origin:top left;transform-origin:top left;-webkit-animation-timing-function:ease-in-out;animation-timing-function:ease-in-out}20%,60%{-webkit-transform:rotate(80deg);transform:rotate(80deg);-webkit-transform-origin:top left;transform-origin:top left;-webkit-animation-timing-function:ease-in-out;animation-timing-function:ease-in-out}40%,80%{-webkit-transform:rotate(60deg);transform:rotate(60deg);-webkit-transform-origin:top left;transform-origin:top left;-webkit-animation-timing-function:ease-in-out;animation-timing-function:ease-in-out;opacity:1}to{-webkit-transform:translate3d(0,700px,0);transform:translate3d(0,700px,0);opacity:0}}@keyframes hinge{0%{-webkit-transform-origin:top left;transform-origin:top left;-webkit-animation-timing-function:ease-in-out;animation-timing-function:ease-in-out}20%,60%{-webkit-transform:rotate(80deg);transform:rotate(80deg);-webkit-transform-origin:top left;transform-origin:top left;-webkit-animation-timing-function:ease-in-out;animation-timing-function:ease-in-out}40%,80%{-webkit-transform:rotate(60deg);transform:rotate(60deg);-webkit-transform-origin:top left;transform-origin:top left;-webkit-animation-timing-function:ease-in-out;animation-timing-function:ease-in-out;opacity:1}to{-webkit-transform:translate3d(0,700px,0);transform:translate3d(0,700px,0);opacity:0}}.hinge{-webkit-animation-duration:2s;animation-duration:2s;-webkit-animation-name:hinge;animation-name:hinge}@-webkit-keyframes jackInTheBox{0%{opacity:0;-webkit-transform:scale(.1) rotate(30deg);transform:scale(.1) rotate(30deg);-webkit-transform-origin:center bottom;transform-origin:center bottom}50%{-webkit-transform:rotate(-10deg);transform:rotate(-10deg)}70%{-webkit-transform:rotate(3deg);transform:rotate(3deg)}to{opacity:1;-webkit-transform:scale(1);transform:scale(1)}}@keyframes jackInTheBox{0%{opacity:0;-webkit-transform:scale(.1) rotate(30deg);transform:scale(.1) rotate(30deg);-webkit-transform-origin:center bottom;transform-origin:center bottom}50%{-webkit-transform:rotate(-10deg);transform:rotate(-10deg)}70%{-webkit-transform:rotate(3deg);transform:rotate(3deg)}to{opacity:1;-webkit-transform:scale(1);transform:scale(1)}}.jackInTheBox{-webkit-animation-name:jackInTheBox;animation-name:jackInTheBox}@-webkit-keyframes rollIn{0%{opacity:0;-webkit-transform:translate3d(-100%,0,0) rotate(-120deg);transform:translate3d(-100%,0,0) rotate(-120deg)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes rollIn{0%{opacity:0;-webkit-transform:translate3d(-100%,0,0) rotate(-120deg);transform:translate3d(-100%,0,0) rotate(-120deg)}to{opacity:1;-webkit-transform:translateZ(0);transform:translateZ(0)}}.rollIn{-webkit-animation-name:rollIn;animation-name:rollIn}@-webkit-keyframes rollOut{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(100%,0,0) rotate(120deg);transform:translate3d(100%,0,0) rotate(120deg)}}@keyframes rollOut{0%{opacity:1}to{opacity:0;-webkit-transform:translate3d(100%,0,0) rotate(120deg);transform:translate3d(100%,0,0) rotate(120deg)}}.rollOut{-webkit-animation-name:rollOut;animation-name:rollOut}@-webkit-keyframes zoomIn{0%{opacity:0;-webkit-transform:scale3d(.3,.3,.3);transform:scale3d(.3,.3,.3)}50%{opacity:1}}@keyframes zoomIn{0%{opacity:0;-webkit-transform:scale3d(.3,.3,.3);transform:scale3d(.3,.3,.3)}50%{opacity:1}}.zoomIn{-webkit-animation-name:zoomIn;animation-name:zoomIn}@-webkit-keyframes zoomInDown{0%{opacity:0;-webkit-transform:scale3d(.1,.1,.1) translate3d(0,-1000px,0);transform:scale3d(.1,.1,.1) translate3d(0,-1000px,0);-webkit-animation-timing-function:cubic-bezier(.55,.055,.675,.19);animation-timing-function:cubic-bezier(.55,.055,.675,.19)}60%{opacity:1;-webkit-transform:scale3d(.475,.475,.475) translate3d(0,60px,0);transform:scale3d(.475,.475,.475) translate3d(0,60px,0);-webkit-animation-timing-function:cubic-bezier(.175,.885,.32,1);animation-timing-function:cubic-bezier(.175,.885,.32,1)}}@keyframes zoomInDown{0%{opacity:0;-webkit-transform:scale3d(.1,.1,.1) translate3d(0,-1000px,0);transform:scale3d(.1,.1,.1) translate3d(0,-1000px,0);-webkit-animation-timing-function:cubic-bezier(.55,.055,.675,.19);animation-timing-function:cubic-bezier(.55,.055,.675,.19)}60%{opacity:1;-webkit-transform:scale3d(.475,.475,.475) translate3d(0,60px,0);transform:scale3d(.475,.475,.475) translate3d(0,60px,0);-webkit-animation-timing-function:cubic-bezier(.175,.885,.32,1);animation-timing-function:cubic-bezier(.175,.885,.32,1)}}.zoomInDown{-webkit-animation-name:zoomInDown;animation-name:zoomInDown}@-webkit-keyframes zoomInLeft{0%{opacity:0;-webkit-transform:scale3d(.1,.1,.1) translate3d(-1000px,0,0);transform:scale3d(.1,.1,.1) translate3d(-1000px,0,0);-webkit-animation-timing-function:cubic-bezier(.55,.055,.675,.19);animation-timing-function:cubic-bezier(.55,.055,.675,.19)}60%{opacity:1;-webkit-transform:scale3d(.475,.475,.475) translate3d(10px,0,0);transform:scale3d(.475,.475,.475) translate3d(10px,0,0);-webkit-animation-timing-function:cubic-bezier(.175,.885,.32,1);animation-timing-function:cubic-bezier(.175,.885,.32,1)}}@keyframes zoomInLeft{0%{opacity:0;-webkit-transform:scale3d(.1,.1,.1) translate3d(-1000px,0,0);transform:scale3d(.1,.1,.1) translate3d(-1000px,0,0);-webkit-animation-timing-function:cubic-bezier(.55,.055,.675,.19);animation-timing-function:cubic-bezier(.55,.055,.675,.19)}60%{opacity:1;-webkit-transform:scale3d(.475,.475,.475) translate3d(10px,0,0);transform:scale3d(.475,.475,.475) translate3d(10px,0,0);-webkit-animation-timing-function:cubic-bezier(.175,.885,.32,1);animation-timing-function:cubic-bezier(.175,.885,.32,1)}}.zoomInLeft{-webkit-animation-name:zoomInLeft;animation-name:zoomInLeft}@-webkit-keyframes zoomInRight{0%{opacity:0;-webkit-transform:scale3d(.1,.1,.1) translate3d(1000px,0,0);transform:scale3d(.1,.1,.1) translate3d(1000px,0,0);-webkit-animation-timing-function:cubic-bezier(.55,.055,.675,.19);animation-timing-function:cubic-bezier(.55,.055,.675,.19)}60%{opacity:1;-webkit-transform:scale3d(.475,.475,.475) translate3d(-10px,0,0);transform:scale3d(.475,.475,.475) translate3d(-10px,0,0);-webkit-animation-timing-function:cubic-bezier(.175,.885,.32,1);animation-timing-function:cubic-bezier(.175,.885,.32,1)}}@keyframes zoomInRight{0%{opacity:0;-webkit-transform:scale3d(.1,.1,.1) translate3d(1000px,0,0);transform:scale3d(.1,.1,.1) translate3d(1000px,0,0);-webkit-animation-timing-function:cubic-bezier(.55,.055,.675,.19);animation-timing-function:cubic-bezier(.55,.055,.675,.19)}60%{opacity:1;-webkit-transform:scale3d(.475,.475,.475) translate3d(-10px,0,0);transform:scale3d(.475,.475,.475) translate3d(-10px,0,0);-webkit-animation-timing-function:cubic-bezier(.175,.885,.32,1);animation-timing-function:cubic-bezier(.175,.885,.32,1)}}.zoomInRight{-webkit-animation-name:zoomInRight;animation-name:zoomInRight}@-webkit-keyframes zoomInUp{0%{opacity:0;-webkit-transform:scale3d(.1,.1,.1) translate3d(0,1000px,0);transform:scale3d(.1,.1,.1) translate3d(0,1000px,0);-webkit-animation-timing-function:cubic-bezier(.55,.055,.675,.19);animation-timing-function:cubic-bezier(.55,.055,.675,.19)}60%{opacity:1;-webkit-transform:scale3d(.475,.475,.475) translate3d(0,-60px,0);transform:scale3d(.475,.475,.475) translate3d(0,-60px,0);-webkit-animation-timing-function:cubic-bezier(.175,.885,.32,1);animation-timing-function:cubic-bezier(.175,.885,.32,1)}}@keyframes zoomInUp{0%{opacity:0;-webkit-transform:scale3d(.1,.1,.1) translate3d(0,1000px,0);transform:scale3d(.1,.1,.1) translate3d(0,1000px,0);-webkit-animation-timing-function:cubic-bezier(.55,.055,.675,.19);animation-timing-function:cubic-bezier(.55,.055,.675,.19)}60%{opacity:1;-webkit-transform:scale3d(.475,.475,.475) translate3d(0,-60px,0);transform:scale3d(.475,.475,.475) translate3d(0,-60px,0);-webkit-animation-timing-function:cubic-bezier(.175,.885,.32,1);animation-timing-function:cubic-bezier(.175,.885,.32,1)}}.zoomInUp{-webkit-animation-name:zoomInUp;animation-name:zoomInUp}@-webkit-keyframes zoomOut{0%{opacity:1}50%{opacity:0;-webkit-transform:scale3d(.3,.3,.3);transform:scale3d(.3,.3,.3)}to{opacity:0}}@keyframes zoomOut{0%{opacity:1}50%{opacity:0;-webkit-transform:scale3d(.3,.3,.3);transform:scale3d(.3,.3,.3)}to{opacity:0}}.zoomOut{-webkit-animation-name:zoomOut;animation-name:zoomOut}@-webkit-keyframes zoomOutDown{40%{opacity:1;-webkit-transform:scale3d(.475,.475,.475) translate3d(0,-60px,0);transform:scale3d(.475,.475,.475) translate3d(0,-60px,0);-webkit-animation-timing-function:cubic-bezier(.55,.055,.675,.19);animation-timing-function:cubic-bezier(.55,.055,.675,.19)}to{opacity:0;-webkit-transform:scale3d(.1,.1,.1) translate3d(0,2000px,0);transform:scale3d(.1,.1,.1) translate3d(0,2000px,0);-webkit-transform-origin:center bottom;transform-origin:center bottom;-webkit-animation-timing-function:cubic-bezier(.175,.885,.32,1);animation-timing-function:cubic-bezier(.175,.885,.32,1)}}@keyframes zoomOutDown{40%{opacity:1;-webkit-transform:scale3d(.475,.475,.475) translate3d(0,-60px,0);transform:scale3d(.475,.475,.475) translate3d(0,-60px,0);-webkit-animation-timing-function:cubic-bezier(.55,.055,.675,.19);animation-timing-function:cubic-bezier(.55,.055,.675,.19)}to{opacity:0;-webkit-transform:scale3d(.1,.1,.1) translate3d(0,2000px,0);transform:scale3d(.1,.1,.1) translate3d(0,2000px,0);-webkit-transform-origin:center bottom;transform-origin:center bottom;-webkit-animation-timing-function:cubic-bezier(.175,.885,.32,1);animation-timing-function:cubic-bezier(.175,.885,.32,1)}}.zoomOutDown{-webkit-animation-name:zoomOutDown;animation-name:zoomOutDown}@-webkit-keyframes zoomOutLeft{40%{opacity:1;-webkit-transform:scale3d(.475,.475,.475) translate3d(42px,0,0);transform:scale3d(.475,.475,.475) translate3d(42px,0,0)}to{opacity:0;-webkit-transform:scale(.1) translate3d(-2000px,0,0);transform:scale(.1) translate3d(-2000px,0,0);-webkit-transform-origin:left center;transform-origin:left center}}@keyframes zoomOutLeft{40%{opacity:1;-webkit-transform:scale3d(.475,.475,.475) translate3d(42px,0,0);transform:scale3d(.475,.475,.475) translate3d(42px,0,0)}to{opacity:0;-webkit-transform:scale(.1) translate3d(-2000px,0,0);transform:scale(.1) translate3d(-2000px,0,0);-webkit-transform-origin:left center;transform-origin:left center}}.zoomOutLeft{-webkit-animation-name:zoomOutLeft;animation-name:zoomOutLeft}@-webkit-keyframes zoomOutRight{40%{opacity:1;-webkit-transform:scale3d(.475,.475,.475) translate3d(-42px,0,0);transform:scale3d(.475,.475,.475) translate3d(-42px,0,0)}to{opacity:0;-webkit-transform:scale(.1) translate3d(2000px,0,0);transform:scale(.1) translate3d(2000px,0,0);-webkit-transform-origin:right center;transform-origin:right center}}@keyframes zoomOutRight{40%{opacity:1;-webkit-transform:scale3d(.475,.475,.475) translate3d(-42px,0,0);transform:scale3d(.475,.475,.475) translate3d(-42px,0,0)}to{opacity:0;-webkit-transform:scale(.1) translate3d(2000px,0,0);transform:scale(.1) translate3d(2000px,0,0);-webkit-transform-origin:right center;transform-origin:right center}}.zoomOutRight{-webkit-animation-name:zoomOutRight;animation-name:zoomOutRight}@-webkit-keyframes zoomOutUp{40%{opacity:1;-webkit-transform:scale3d(.475,.475,.475) translate3d(0,60px,0);transform:scale3d(.475,.475,.475) translate3d(0,60px,0);-webkit-animation-timing-function:cubic-bezier(.55,.055,.675,.19);animation-timing-function:cubic-bezier(.55,.055,.675,.19)}to{opacity:0;-webkit-transform:scale3d(.1,.1,.1) translate3d(0,-2000px,0);transform:scale3d(.1,.1,.1) translate3d(0,-2000px,0);-webkit-transform-origin:center bottom;transform-origin:center bottom;-webkit-animation-timing-function:cubic-bezier(.175,.885,.32,1);animation-timing-function:cubic-bezier(.175,.885,.32,1)}}@keyframes zoomOutUp{40%{opacity:1;-webkit-transform:scale3d(.475,.475,.475) translate3d(0,60px,0);transform:scale3d(.475,.475,.475) translate3d(0,60px,0);-webkit-animation-timing-function:cubic-bezier(.55,.055,.675,.19);animation-timing-function:cubic-bezier(.55,.055,.675,.19)}to{opacity:0;-webkit-transform:scale3d(.1,.1,.1) translate3d(0,-2000px,0);transform:scale3d(.1,.1,.1) translate3d(0,-2000px,0);-webkit-transform-origin:center bottom;transform-origin:center bottom;-webkit-animation-timing-function:cubic-bezier(.175,.885,.32,1);animation-timing-function:cubic-bezier(.175,.885,.32,1)}}.zoomOutUp{-webkit-animation-name:zoomOutUp;animation-name:zoomOutUp}@-webkit-keyframes slideInDown{0%{-webkit-transform:translate3d(0,-100%,0);transform:translate3d(0,-100%,0);visibility:visible}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes slideInDown{0%{-webkit-transform:translate3d(0,-100%,0);transform:translate3d(0,-100%,0);visibility:visible}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}.slideInDown{-webkit-animation-name:slideInDown;animation-name:slideInDown}@-webkit-keyframes slideInLeft{0%{-webkit-transform:translate3d(-100%,0,0);transform:translate3d(-100%,0,0);visibility:visible}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes slideInLeft{0%{-webkit-transform:translate3d(-100%,0,0);transform:translate3d(-100%,0,0);visibility:visible}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}.slideInLeft{-webkit-animation-name:slideInLeft;animation-name:slideInLeft}@-webkit-keyframes slideInRight{0%{-webkit-transform:translate3d(100%,0,0);transform:translate3d(100%,0,0);visibility:visible}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes slideInRight{0%{-webkit-transform:translate3d(100%,0,0);transform:translate3d(100%,0,0);visibility:visible}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}.slideInRight{-webkit-animation-name:slideInRight;animation-name:slideInRight}@-webkit-keyframes slideInUp{0%{-webkit-transform:translate3d(0,100%,0);transform:translate3d(0,100%,0);visibility:visible}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}@keyframes slideInUp{0%{-webkit-transform:translate3d(0,100%,0);transform:translate3d(0,100%,0);visibility:visible}to{-webkit-transform:translateZ(0);transform:translateZ(0)}}.slideInUp{-webkit-animation-name:slideInUp;animation-name:slideInUp}@-webkit-keyframes slideOutDown{0%{-webkit-transform:translateZ(0);transform:translateZ(0)}to{visibility:hidden;-webkit-transform:translate3d(0,100%,0);transform:translate3d(0,100%,0)}}@keyframes slideOutDown{0%{-webkit-transform:translateZ(0);transform:translateZ(0)}to{visibility:hidden;-webkit-transform:translate3d(0,100%,0);transform:translate3d(0,100%,0)}}.slideOutDown{-webkit-animation-name:slideOutDown;animation-name:slideOutDown}@-webkit-keyframes slideOutLeft{0%{-webkit-transform:translateZ(0);transform:translateZ(0)}to{visibility:hidden;-webkit-transform:translate3d(-100%,0,0);transform:translate3d(-100%,0,0)}}@keyframes slideOutLeft{0%{-webkit-transform:translateZ(0);transform:translateZ(0)}to{visibility:hidden;-webkit-transform:translate3d(-100%,0,0);transform:translate3d(-100%,0,0)}}.slideOutLeft{-webkit-animation-name:slideOutLeft;animation-name:slideOutLeft}@-webkit-keyframes slideOutRight{0%{-webkit-transform:translateZ(0);transform:translateZ(0)}to{visibility:hidden;-webkit-transform:translate3d(100%,0,0);transform:translate3d(100%,0,0)}}@keyframes slideOutRight{0%{-webkit-transform:translateZ(0);transform:translateZ(0)}to{visibility:hidden;-webkit-transform:translate3d(100%,0,0);transform:translate3d(100%,0,0)}}.slideOutRight{-webkit-animation-name:slideOutRight;animation-name:slideOutRight}@-webkit-keyframes slideOutUp{0%{-webkit-transform:translateZ(0);transform:translateZ(0)}to{visibility:hidden;-webkit-transform:translate3d(0,-100%,0);transform:translate3d(0,-100%,0)}}@keyframes slideOutUp{0%{-webkit-transform:translateZ(0);transform:translateZ(0)}to{visibility:hidden;-webkit-transform:translate3d(0,-100%,0);transform:translate3d(0,-100%,0)}}.slideOutUp{-webkit-animation-name:slideOutUp;animation-name:slideOutUp} \ No newline at end of file diff --git a/aprendizations/static/css/topic.css b/aprendizations/static/css/topic.css index 954d256..107fb5f 100644 --- a/aprendizations/static/css/topic.css +++ b/aprendizations/static/css/topic.css @@ -1,12 +1,4 @@ -.progress { - /*position: fixed;*/ - top: 0; - height: 70px; - border-radius: 0px; -} body { - margin: 0; - padding-top: 0px; margin-bottom: 120px; /* Margin bottom by footer height */ } @@ -19,10 +11,6 @@ body { /*background-color: #f5f5f5;*/ } -html { - position: relative; - min-height: 100%; -} .CodeMirror { border: 1px solid #eee; height: auto; diff --git a/aprendizations/student.py b/aprendizations/student.py index e5e99fd..0b78720 100644 --- a/aprendizations/student.py +++ b/aprendizations/student.py @@ -1,42 +1,49 @@ +''' +Implementation of the StudentState class. +Each object of this class will contain the state of a student while logged in. +Manages things like current course, topic, question, etc, and defines the +logic of the application in what it applies to a single student. +''' + # python standard library from datetime import datetime import logging import random -from typing import List, Optional, Tuple +from typing import List, Optional # third party libraries import networkx as nx # this project -from .questions import Question +from aprendizations.questions import Question # setup logger for this module logger = logging.getLogger(__name__) -# ---------------------------------------------------------------------------- -# kowledge state of a student: -# uid - string with userid, e.g. '12345' -# state - dict of unlocked topics and their levels -# {'topic1': {'level': 0.5, 'date': datetime}, ...} -# topic_sequence - recommended topic sequence ['topic1', 'topic2', ...] -# questions - [Question, ...] for the current topic -# current_course - string or None -# current_topic - string or None -# current_question - Question or None -# -# -# also has access to shared data between students: -# courses - dictionary {course: [topic1, ...]} -# deps - dependency graph as a networkx digraph -# factory - dictionary {ref: QFactory} -# ---------------------------------------------------------------------------- -class StudentState(object): - # ======================================================================= +# ============================================================================ +class StudentState(): + ''' + kowledge state of a student: + uid - string with userid, e.g. '12345' + state - dict of unlocked topics and their levels + {'topic1': {'level': 0.5, 'date': datetime}, ...} + topic_sequence - recommended topic sequence ['topic1', 'topic2', ...] + questions - [Question, ...] for the current topic + current_course - string or None + current_topic - string or None + current_question - Question or None + also has access to shared data between students: + courses - dictionary {course: [topic1, ...]} + deps - dependency graph as a networkx digraph + factory - dictionary {ref: QFactory} + ''' + + # ======================================================================== # methods that update state - # ======================================================================= + # ======================================================================== def __init__(self, uid, state, courses, deps, factory) -> None: # shared application data between all students self.deps = deps # dependency graph @@ -54,6 +61,10 @@ class StudentState(object): # ------------------------------------------------------------------------ def start_course(self, course: Optional[str]) -> None: + ''' + Tries to start a course. + Finds the recommended sequence of topics for the student. + ''' if course is None: logger.debug('no active course') self.current_course: Optional[str] = None @@ -63,125 +74,136 @@ class StudentState(object): try: topics = self.courses[course]['goals'] except KeyError: - logger.debug(f'course "{course}" does not exist') + logger.debug('course "%s" does not exist', course) raise - logger.debug(f'starting course "{course}"') + logger.debug('starting course "%s"', course) self.current_course = course - self.topic_sequence = self.recommend_sequence(topics) + self.topic_sequence = self._recommend_sequence(topics) # ------------------------------------------------------------------------ - # Start a new topic. - # questions: list of generated questions to do in the given topic - # current_question: the current question to be presented - # ------------------------------------------------------------------------ - async def start_topic(self, topic: str) -> None: - logger.debug(f'start topic "{topic}"') + async def start_topic(self, topic_ref: str) -> None: + ''' + Start a new topic. + questions: list of generated questions to do in the given topic + current_question: the current question to be presented + ''' + + logger.debug('start topic "%s"', topic_ref) # avoid regenerating questions in the middle of the current topic - if self.current_topic == topic and self.uid != '0': + if self.current_topic == topic_ref and self.uid != '0': logger.info('Restarting current topic is not allowed.') return # do not allow locked topics - if self.is_locked(topic) and self.uid != '0': - logger.debug(f'is locked "{topic}"') + if self.is_locked(topic_ref) and self.uid != '0': + logger.debug('is locked "%s"', topic_ref) return self.previous_topic: Optional[str] = None # choose k questions - self.current_topic = topic + self.current_topic = topic_ref self.correct_answers = 0 self.wrong_answers = 0 - t = self.deps.nodes[topic] - k = t['choose'] - if t['shuffle_questions']: - questions = random.sample(t['questions'], k=k) + topic = self.deps.nodes[topic_ref] + k = topic['choose'] + if topic['shuffle_questions']: + questions = random.sample(topic['questions'], k=k) else: - questions = t['questions'][:k] - logger.debug(f'selected questions: {", ".join(questions)}') + questions = topic['questions'][:k] + logger.debug('selected questions: %s', ', '.join(questions)) self.questions: List[Question] = [await self.factory[ref].gen_async() for ref in questions] - logger.debug(f'generated {len(self.questions)} questions') + logger.debug('generated %s questions', len(self.questions)) # get first question self.next_question() # ------------------------------------------------------------------------ - # corrects current question - # updates keys: answer, grade, finish_time, status, tries - # ------------------------------------------------------------------------ async def check_answer(self, answer) -> None: - q = self.current_question - if q is None: + ''' + Corrects current question. + Updates keys: `answer`, `grade`, `finish_time`, `status`, `tries` + ''' + + question = self.current_question + if question is None: logger.error('check_answer called but current_question is None!') return None - q.set_answer(answer) - await q.correct_async() # updates q['grade'] + question.set_answer(answer) + await question.correct_async() # updates q['grade'] - if q['grade'] > 0.999: + if question['grade'] > 0.999: self.correct_answers += 1 - q['status'] = 'right' + question['status'] = 'right' else: self.wrong_answers += 1 - q['tries'] -= 1 - if q['tries'] > 0: - q['status'] = 'try_again' + question['tries'] -= 1 + if question['tries'] > 0: + question['status'] = 'try_again' else: - q['status'] = 'wrong' + question['status'] = 'wrong' - logger.debug(f'ref = {q["ref"]}, status = {q["status"]}') + logger.debug('ref = %s, status = %s', + question["ref"], question["status"]) # ------------------------------------------------------------------------ - # gets next question to show if the status is 'right' or 'wrong', - # otherwise just returns the current question - # ------------------------------------------------------------------------ async def get_question(self) -> Optional[Question]: - q = self.current_question - if q is None: + ''' + Gets next question to show if the status is 'right' or 'wrong', + otherwise just returns the current question. + ''' + + question = self.current_question + if question is None: logger.error('get_question called but current_question is None!') return None - logger.debug(f'{q["ref"]} status = {q["status"]}') + logger.debug('%s status = %s', question["ref"], question["status"]) - if q['status'] == 'right': + if question['status'] == 'right': self.next_question() - elif q['status'] == 'wrong': - if q['append_wrong']: + elif question['status'] == 'wrong': + if question['append_wrong']: logger.debug(' wrong answer => append new question') - new_question = await self.factory[q['ref']].gen_async() + new_question = await self.factory[question['ref']].gen_async() self.questions.append(new_question) self.next_question() return self.current_question # ------------------------------------------------------------------------ - # moves to next question - # ------------------------------------------------------------------------ def next_question(self) -> None: + ''' + Moves to next question + ''' + try: - q = self.questions.pop(0) + question = self.questions.pop(0) except IndexError: self.finish_topic() return - t = self.deps.nodes[self.current_topic] - q['start_time'] = datetime.now() - q['tries'] = q.get('max_tries', t['max_tries']) - q['status'] = 'new' - self.current_question: Optional[Question] = q + topic = self.deps.nodes[self.current_topic] + question['start_time'] = datetime.now() + question['tries'] = question.get('max_tries', topic['max_tries']) + question['status'] = 'new' + self.current_question: Optional[Question] = question # ------------------------------------------------------------------------ - # The topic has finished and there are no more questions. - # The topic level is updated in state and unlocks are performed. - # The current topic is unchanged. - # ------------------------------------------------------------------------ def finish_topic(self) -> None: - logger.debug(f'finished {self.current_topic} in {self.current_course}') + ''' + The topic has finished and there are no more questions. + The topic level is updated in state and unlocks are performed. + The current topic is unchanged. + ''' + + logger.debug('finished %s in %s', self.current_topic, self.current_course) self.state[self.current_topic] = { 'date': datetime.now(), @@ -194,22 +216,25 @@ class StudentState(object): self.unlock_topics() # ------------------------------------------------------------------------ - # Update proficiency level of the topics using a forgetting factor - # ------------------------------------------------------------------------ def update_topic_levels(self) -> None: + ''' + Update proficiency level of the topics using a forgetting factor + ''' + now = datetime.now() - for tref, s in self.state.items(): - dt = now - s['date'] + for tref, state in self.state.items(): + elapsed = now - state['date'] try: forgetting_factor = self.deps.nodes[tref]['forgetting_factor'] - s['level'] *= forgetting_factor ** dt.days # forgetting factor + state['level'] *= forgetting_factor ** elapsed.days except KeyError: - logger.warning(f'Update topic levels: {tref} not in the graph') + logger.warning('Update topic levels: %s not in the graph', tref) # ------------------------------------------------------------------------ - # Unlock topics whose dependencies are satisfied (> min_level) - # ------------------------------------------------------------------------ def unlock_topics(self) -> None: + ''' + Unlock topics whose dependencies are satisfied (> min_level) + ''' for topic in self.deps.nodes(): if topic not in self.state: # if locked pred = self.deps.predecessors(topic) @@ -221,7 +246,7 @@ class StudentState(object): 'level': 0.0, # unlock 'date': datetime.now() } - logger.debug(f'unlocked "{topic}"') + logger.debug('unlocked "%s"', topic) # else: # lock this topic if deps do not satisfy min_level # del self.state[topic] @@ -230,64 +255,78 @@ class StudentState(object): # ======================================================================== def topic_has_finished(self) -> bool: + ''' + Checks if the all the questions in the current topic have been + answered. + ''' return self.current_topic is None and self.previous_topic is not None # ------------------------------------------------------------------------ - # compute recommended sequence of topics ['a', 'b', ...] - # ------------------------------------------------------------------------ - def recommend_sequence(self, goals: List[str] = []) -> List[str]: - G = self.deps - ts = set(goals) - for t in goals: - ts.update(nx.ancestors(G, t)) # include dependencies not in goals + def _recommend_sequence(self, goals: List[str]) -> List[str]: + ''' + compute recommended sequence of topics ['a', 'b', ...] + ''' + + topics = set(goals) + # include dependencies not in goals + for topic in goals: + topics.update(nx.ancestors(self.deps, topic)) todo = [] - for t in ts: - level = self.state[t]['level'] if t in self.state else 0.0 - min_level = G.nodes[t]['min_level'] - if t in goals or level < min_level: - todo.append(t) + for topic in topics: + level = self.state[topic]['level'] if topic in self.state else 0.0 + min_level = self.deps.nodes[topic]['min_level'] + if topic in goals or level < min_level: + todo.append(topic) - logger.debug(f' {len(ts)} total topics, {len(todo)} listed ') + logger.debug(' %s total topics, %s listed ', len(topics), len(todo)) # FIXME topological sort is a poor way to sort topics - tl = list(nx.topological_sort(G.subgraph(todo))) + topic_seq = list(nx.topological_sort(self.deps.subgraph(todo))) # sort with unlocked first - unlocked = [t for t in tl if t in self.state] - locked = [t for t in tl if t not in unlocked] + unlocked = [t for t in topic_seq if t in self.state] + locked = [t for t in topic_seq if t not in unlocked] return unlocked + locked # ------------------------------------------------------------------------ def get_current_question(self) -> Optional[Question]: + '''gets current question''' return self.current_question # ------------------------------------------------------------------------ def get_current_topic(self) -> Optional[str]: + '''gets current topic''' return self.current_topic # ------------------------------------------------------------------------ def get_previous_topic(self) -> Optional[str]: + '''gets previous topic''' return self.previous_topic # ------------------------------------------------------------------------ def get_current_course_title(self) -> str: + '''gets current course title''' return str(self.courses[self.current_course]['title']) # ------------------------------------------------------------------------ def get_current_course_id(self) -> Optional[str]: + '''gets current course id''' return self.current_course # ------------------------------------------------------------------------ def is_locked(self, topic: str) -> bool: + '''checks if a given topic is locked''' return topic not in self.state # ------------------------------------------------------------------------ - # Return list of {ref: 'xpto', name: 'long name', leve: 0.5} - # Levels are in the interval [0, 1] if unlocked or None if locked. - # Topics unlocked but not yet done have level 0.0. - # ------------------------------------------------------------------------ def get_knowledge_state(self): + ''' + Return list of {ref: 'xpto', name: 'long name', leve: 0.5} + Levels are in the interval [0, 1] if unlocked or None if locked. + Topics unlocked but not yet done have level 0.0. + ''' + return [{ 'ref': ref, 'type': self.deps.nodes[ref]['type'], @@ -297,19 +336,16 @@ class StudentState(object): # ------------------------------------------------------------------------ def get_topic_progress(self) -> float: + '''computes progress of the current topic''' return self.correct_answers / (1 + self.correct_answers + len(self.questions)) # ------------------------------------------------------------------------ def get_topic_level(self, topic: str) -> float: + '''gets level of a given topic''' return float(self.state[topic]['level']) # ------------------------------------------------------------------------ def get_topic_date(self, topic: str): + '''gets date of a given topic''' return self.state[topic]['date'] - - # ------------------------------------------------------------------------ - # Recommends a topic to practice/learn from the state. - # ------------------------------------------------------------------------ - # def get_recommended_topic(self): # FIXME untested - # return min(self.state.items(), key=lambda x: x[1]['level'])[0] diff --git a/aprendizations/templates/courses.html b/aprendizations/templates/courses.html index bbe903e..2a8508e 100644 --- a/aprendizations/templates/courses.html +++ b/aprendizations/templates/courses.html @@ -4,28 +4,28 @@ {{appname}} - + - - - - + + + + - - - - - - + + + + + + -
-
-
- -
+
@@ -101,5 +100,4 @@
- - \ No newline at end of file + diff --git a/aprendizations/tools.py b/aprendizations/tools.py index 0073f51..169d0b1 100644 --- a/aprendizations/tools.py +++ b/aprendizations/tools.py @@ -228,7 +228,7 @@ async def run_script_async(script: str, ) try: - stdout, stderr = await asyncio.wait_for( + stdout, _ = await asyncio.wait_for( p.communicate(input=stdin.encode('utf-8')), timeout=timeout ) diff --git a/package-lock.json b/package-lock.json index 0ddf4af..002933d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,21 +1,50 @@ { + "name": "aprendizations", + "lockfileVersion": 2, "requires": true, - "lockfileVersion": 1, + "packages": { + "": { + "dependencies": { + "@fortawesome/fontawesome-free": "^5.15.2", + "codemirror": "^5.59.1", + "mdbootstrap": "^4.19.2" + } + }, + "node_modules/@fortawesome/fontawesome-free": { + "version": "5.15.3", + "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-free/-/fontawesome-free-5.15.3.tgz", + "integrity": "sha512-rFnSUN/QOtnOAgqFRooTA3H57JLDm0QEG/jPdk+tLQNL/eWd+Aok8g3qCI+Q1xuDPWpGW/i9JySpJVsq8Q0s9w==", + "hasInstallScript": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/codemirror": { + "version": "5.61.1", + "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.61.1.tgz", + "integrity": "sha512-+D1NZjAucuzE93vJGbAaXzvoBHwp9nJZWWWF9utjv25+5AZUiah6CIlfb4ikG4MoDsFsCG8niiJH5++OO2LgIQ==" + }, + "node_modules/mdbootstrap": { + "version": "4.19.2", + "resolved": "https://registry.npmjs.org/mdbootstrap/-/mdbootstrap-4.19.2.tgz", + "integrity": "sha512-a+LwPflYRYwlmYKTvftW0X7SfOMrRZ02qZjrssNko1lPU/HR5JRFc1uwa3Dmmw+6TwsYH760waqdghBFrucpOw==" + } + }, "dependencies": { "@fortawesome/fontawesome-free": { - "version": "5.12.0", - "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-free/-/fontawesome-free-5.12.0.tgz", - "integrity": "sha512-vKDJUuE2GAdBERaQWmmtsciAMzjwNrROXA5KTGSZvayAsmuTGjam5z6QNqNPCwDfVljLWuov1nEC3mEQf/n6fQ==" + "version": "5.15.3", + "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-free/-/fontawesome-free-5.15.3.tgz", + "integrity": "sha512-rFnSUN/QOtnOAgqFRooTA3H57JLDm0QEG/jPdk+tLQNL/eWd+Aok8g3qCI+Q1xuDPWpGW/i9JySpJVsq8Q0s9w==" }, "codemirror": { - "version": "5.51.0", - "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.51.0.tgz", - "integrity": "sha512-vyuYYRv3eXL0SCuZA4spRFlKNzQAewHcipRQCOKgRy7VNAvZxTKzbItdbCl4S5AgPZ5g3WkHp+ibWQwv9TLG7Q==" + "version": "5.61.1", + "resolved": "https://registry.npmjs.org/codemirror/-/codemirror-5.61.1.tgz", + "integrity": "sha512-+D1NZjAucuzE93vJGbAaXzvoBHwp9nJZWWWF9utjv25+5AZUiah6CIlfb4ikG4MoDsFsCG8niiJH5++OO2LgIQ==" }, "mdbootstrap": { - "version": "4.12.0", - "resolved": "https://registry.npmjs.org/mdbootstrap/-/mdbootstrap-4.12.0.tgz", - "integrity": "sha512-+X4x63tE96zpVOcRlVUGdcR65M9Ud+/l1TvdmcwUjEGo3ktn9TO3e6S3DBLTvchO9U5eKuJh/MIWIGac7+569g==" + "version": "4.19.2", + "resolved": "https://registry.npmjs.org/mdbootstrap/-/mdbootstrap-4.19.2.tgz", + "integrity": "sha512-a+LwPflYRYwlmYKTvftW0X7SfOMrRZ02qZjrssNko1lPU/HR5JRFc1uwa3Dmmw+6TwsYH760waqdghBFrucpOw==" } } } diff --git a/package.json b/package.json index 00e3fd9..584dc59 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,9 @@ "description": "Javascript libraries required to run the server", "email": "mjsb@uevora.pt", "dependencies": { - "@fortawesome/fontawesome-free": "^5.12.0", - "codemirror": "^5.51.0", - "mdbootstrap": "^4.12.0" + "@fortawesome/fontawesome-free": "^5.15.2", + "codemirror": "^5.59.1", + "mdbootstrap": "^4.19.2" }, "private": true } diff --git a/setup.py b/setup.py index ab66535..109dd11 100644 --- a/setup.py +++ b/setup.py @@ -18,13 +18,13 @@ setup( url="https://git.xdi.uevora.pt/mjsb/aprendizations.git", packages=find_packages(), include_package_data=True, # install files from MANIFEST.in - python_requires='>=3.7.*', + python_requires='>=3.8.*', install_requires=[ 'tornado>=6.0', 'mistune', 'pyyaml>=5.1', 'pygments', - 'sqlalchemy', + 'sqlalchemy<1.4', 'bcrypt>=3.1', 'networkx>=2.4' ], -- libgit2 0.21.2