Example #1
0
 def __init__(self, category, term_list):
     self.category_quiz_is_on = Category(category, term_list)
     self.number_of_terms_in_set = self.category_quiz_is_on.get_number_of_terms_in_category()
     self.current_term = self.category_quiz_is_on.get_random_term_in_category()
     self.number_of_terms_right = 0
     self.number_of_terms_through = 1
     self.percentage_correct = 0
Example #2
0
class Quiz:

    def __init__(self, category, term_list):
        self.category_quiz_is_on = Category(category, term_list)
        self.number_of_terms_in_set = self.category_quiz_is_on.get_number_of_terms_in_category()
        self.current_term = self.category_quiz_is_on.get_random_term_in_category()
        self.number_of_terms_right = 0
        self.number_of_terms_through = 1
        self.percentage_correct = 0

    # checks if the user's input is correct
    def is_user_input_correct(self, user_input):
        is_correct = False
        if self.current_term.get_term_name() == user_input:
            is_correct = True
        return is_correct

    # returns the number of terms correct so far
    def get_number_of_terms_right(self):
        return self.number_of_terms_right

    # gets the number of terms through so far
    def get_number_of_terms_through(self):
        return self.number_of_terms_through

    # gets the total number of terms in set
    def get_number_of_terms_in_set(self):
        return self.number_of_terms_in_set

    # increments the number terms through
    def increment_number_of_terms_through(self):
        self.number_of_terms_through += 1

    # increments the number of terms right
    def increment_number_of_terms_right(self):
        self.number_of_terms_right += 1

    # gets the current term
    def get_term(self):
        return self.current_term

    # updates the percentage correct
    def update_percentage_correct(self):
        self.percentage_correct = (self.number_of_terms_right /
                                   self.number_of_terms_in_set) * 100

    # returns the percentage correct so far
    def get_percentage_correct(self):
        return self.percentage_correct

    # sets the new term for the quiz
    def set_new_term_from_category(self):
        self.current_term = self.category_quiz_is_on.get_random_term_in_category()

    # returns whether or not the game is finished
    def is_game_finished(self):
        if self.number_of_terms_through == self.number_of_terms_in_set:
            return True
        else:
            return False
Example #3
0
 def GET(self, code = None):
     """Lista as categorias cadastradas no sistema."""        
     #Se nenhum código de categoria foi informado        
     if code == None:            
         #Capturo a lista de categorias e faço um dump dos dicionários da lista
         return json.dumps([c.__dict__ for c in Category().selectAllCategories()])                
     else:
         #Se um código de categoria foi informado, capturo o objeto e faço um dump de seu dicionario
         return json.dumps(Category().selectCategory(code).__dict__)
Example #4
0
 def DELETE(self, code = None):
     """Apaga uma categoria do sistema."""   
             
     #Se o código informado não for nulo,
     if code != None:
         
         #Testo selecionar a categoria
         category = Category().selectCategory(code)
         
         #Se ela realmente existir
         if category != None:                
             #Deleto-a
             category.deleteCategory()
Example #5
0
    def selectAllProducts(self):
        """Recupera todos os produtos cadastrados no sistema"""

        #Instancio a classe banco
        database = Database()

        try:
            #Crio um cursor para acessar o banco de dados
            cursor = database.conn.cursor()

            #Executo o select
            cursor.execute("SELECT code, name, category FROM Product")

            #Crio uma lista para armazenar os resultados
            products = []

            #Preencho os dados do objeto com as informações retornadas
            for product in cursor:
                prod = Product(product[0], product[1],
                               Category().selectCategory(product[2]))
                products.append(prod)

            #Fecho o cursor
            cursor.close()

            #Retorno a lista de objetos
            return products
        except:
            #Capturo a mensagem de erro
            error = traceback.format_exc()
            print(error)
            return False
Example #6
0
    def selectProduct(self, code):
        """Retorna informações de um produto"""

        #Instancio a classe banco
        database = Database()

        try:
            #Crio um cursor para acessar o banco de dados
            cursor = database.conn.cursor()

            #Executo a seleção
            cursor.execute(
                "SELECT code, name, category FROM Product WHERE code = " +
                str(code) + " ")

            #Preencho os dados do objeto com as informações retornadas
            for product in cursor:
                self.code = product[0]
                self.name = product[1]
                self.category = Category().selectCategory(product[2])

            #Fecho o cursor
            cursor.close()

            #Retorno o objeto
            return self
        except:
            #Capturo a mensagem de erro
            error = traceback.format_exc()
            print(error)
            return False
Example #7
0
 def PUT(self, strJson):
     """Inclui ou atualiza """
     if strJson != None:
         category = Category()
         category.__dict__ = json.loads(strJson)
         
         #Se é um novo registro, adiciono. Caso contrário, atualizo.            
         if category.isNew():
             category.insertCategory()
         else:
             category.updateCategory()                
Example #8
0
    def load_categories(self):
        db = sqlite3.connect(self.dataFile)
        c = db.cursor()
        c.execute('SELECT category_id, name from categories')
        categories_raw = c.fetchall()
        c.close()
        categories_new = []

        for s in categories_raw:
            categories_new.append(Category(s[0], s[1]))

        self.categories = categories_new
Example #9
0
class Controller:
    category = None

    # creates the tables in the database that are needed for this application
    def create_tables(self):
        database = DatabaseAccess()
        database.connect()
        database.create_tables()
        database.commit()
        database.close_connection()


    # gettings all terms in new category from database
    def get_all_terms_in_category(self, category):
        database = DatabaseAccess()
        database.connect()
        results = database.get_all_terms_in_category(category)
        database.close_connection()
        terms = []
        for result in results:
            term = Term(result[0], result[1], result[2])
            terms.append(term)

        return terms

    # setting a new category selection
    def set_category(self, category_name):
        term_list = self.get_all_terms_in_category(category_name)
        self.category = Category(category_name, term_list)

    # get term names and ids in the currently selected category
    def get_term_names_in_category_and_ids(self):
        terms_and_ids = self.category.get_all_term_names_and_ids()
        if terms_and_ids == ():
            term_table_model = TermTableModel(("",))
        else:
            term_table_model = TermTableModel(terms_and_ids)
        return term_table_model

    def get_empty_term_table_view_model(self):
        return TermTableModel(("", ))

    # get all categories currently stored in database
    def get_all_categories(self):
        database = DatabaseAccess()
        database.connect()
        results = database.get_all_categories()
        database.close_connection()
        return results

    # open the quiz dialog
    def begin_quiz(self, category):
        terms_in_category = self.get_all_terms_in_category(category)
        test_view = TestView(category, terms_in_category)
        test_view.exec_()

    # gets the currently selected category
    def get_current_category(self):
        if self.category is not None:
            return self.category.get_category_name()

    # def get_all_of_a_terms_categories(self, term_id):
    #     database = DatabaseAccess()
    #     results = database.get_all_of_a_terms_categories(term_id)
    #     database.close_connection()
    #     return results

    # gets the number of terms in currently selected category
    def get_number_of_terms_in_category(self):
        return self.category.get_number_of_terms_in_category()
Example #10
0
 def set_category(self, category_name):
     term_list = self.get_all_terms_in_category(category_name)
     self.category = Category(category_name, term_list)
Example #11
0
from controllers.Id_generator import IdGenerator

app = Flask(__name__)

login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = "login"

users = []

idGen = IdGenerator()

u1 = User(idGen.get_new_user_id(), "pam", "pam", "123", "123")
users.append(u1)

c1 = Category(1, "Дети")
c2 = Category(2, "Животные")
с3 = Category(3, "Пожилые жители")
с4 = Category(4, "Благоустройство")
с5 = Category(5, "Разное")

c_l = [c1, c2, с3, с4, с5]


def get_category_by_id(id):
    for c in c_l:
        if c.id == id:
            return c


t1 = Task(