packages = ["matplotlib", "pandas"]
from js import createObject
from pyodide.ffi import create_proxy
import random
createObject(create_proxy(globals()), "pyodideGlobals")
import pandas as pd
import os
from pyodide.http import open_url
url = (
"https://raw.githubusercontent.com/ghidinelli/fred-jehle-spanish-verbs/master/jehle_verb_database.csv"
)
df = pd.read_csv(open_url(url))
def formToSubject(form):
if (form=='form_1s'):
return 'yo'
elif (form=='form_2s'):
return 'tu'
elif (form=='form_3s'):
return 'el/ella/usted'
elif (form=='form_1p'):
return 'nosotros'
elif (form=='form_3p'):
return 'ellos/ellas/ustedes'
else:
return 'error'
def submitConjugated(word):
global showInfinitive
showInfinitive = True
global currentSubject
global currentConjugatedWord
global currentWord
conjugationForm = random.randint(1,5)
if (conjugationForm==1):
currentSubject = 'form_1s'
elif (conjugationForm==2):
currentSubject = 'form_2s'
elif (conjugationForm==3):
currentSubject = 'form_3s'
elif (conjugationForm==4):
currentSubject = 'form_1p'
elif (conjugationForm==5):
currentSubject = 'form_3p'
word = word.lower();
if (word != currentConjugatedWord):
Element('correctOrNot').write('Incorrect! The correct conjugation was: ' + currentConjugatedWord)
else:
Element('correctOrNot').write('Correct!')
currentIndex = random.randint(1,possibleWords.infinitive.size-1)
currentWord = possibleWords.loc[currentIndex].at['infinitive']
currentConjugatedWord = possibleWords.loc[currentIndex].at[currentSubject]
global currentDefinition
currentDefinition = possibleWords.loc[currentIndex].at['infinitive']
currentDefinition = currentDefinition + " - " + possibleWords.loc[currentIndex].at['infinitive_english'].replace(';',',').split(',')[0]
Element('wordPromptSpan').write(currentWord)
Element('subjectPrompt').write(formToSubject(currentSubject))
def selectConjugation(tense):
global showInfinitive
showInfinitive=True
global possibleWords
if (int(tense)==1):
possibleWords = df.loc[df['mood_english'] == 'Indicative'].loc[df['tense'] =='Presente'].dropna().reset_index()
currentTense = 'Presente'
if (int(tense)==2):
possibleWords = df.loc[df['mood_english'] == 'Indicative'].loc[df['tense'] =='Pretérito'].dropna().reset_index()
currentTense = 'Pretérito'
if (int(tense)==3):
possibleWords = df.loc[df['mood_english'] == 'Indicative'].loc[df['tense'] =='Futuro'].dropna().reset_index()
currentTense = 'Futuro'
if (int(tense)==4):
possibleWords = df.loc[df['mood_english'] == 'Subjunctive'].loc[df['tense'] =='Presente'].dropna().reset_index()
currentTense = 'Futuro'
if (int(tense)==5):
possibleWords = df.loc[df['mood_english'] == 'Subjunctive'].loc[df['tense'] =='Futuro'].dropna().reset_index()
currentTense = 'Futuro'
submitConjugated('')
def toggleInfinitiveDefinition():
global showInfinitive
showInfinitive = not showInfinitive
if (showInfinitive):
Element('wordPromptSpan').write(currentWord)
else:
Element('wordPromptSpan').write(currentDefinition)
currentSubject = 'form_1s'
currentTense = 'Presente'
#possibleWords = df.loc[df['mood_english'] == 'Indicative'].dropna().reset_index()
#possibleWords = possibleWords.loc[df['tense'] == 'Presente'].dropna().reset_index()
possibleWords = df.loc[df['mood_english'] == 'Indicative'].loc[df['tense'] =='Presente'].dropna().reset_index()
currentIndex = random.randint(1,possibleWords.infinitive.size-1)
currentWord = possibleWords.loc[currentIndex].at['infinitive']
currentDefinition = possibleWords.loc[currentIndex].at['infinitive']
currentDefinition = currentDefinition + " - " + possibleWords.loc[currentIndex].at['infinitive_english'].replace(';',',').split(',')[0]
showInfinitive = True
currentConjugatedWord = possibleWords.loc[currentIndex].at[currentSubject]
if (showInfinitive):
Element('wordPromptSpan').write(currentWord) #currentConjugatedWord for cheating
else:
Element('wordPromptSpan').write(currentDefinition)
Element('subjectPrompt').write(formToSubject(currentSubject))
class Circle():
def __init__(self, radius):
self.radius = radius
@property
def area(self):
return symbols['pi'] * self.radius**2
