Exemplo n.º 1
0
    def set_state_from_object(self, mycard: RFIDCard):
        """
		Function gets card as object and sets the state as requested
		If the card doesn't exist - Adding new card and setting the newState as requested
		"""
        cardID = mycard.get_uid()
        newState = mycard.get_active()
        self.set_state(cardID, newState)
Exemplo n.º 2
0
 def get_card_byID(self, cardID: str):
     query_str = ["SELECT * FROM cards", "WHERE card_id = '{}';"]
     self.c.execute(str.join(" ", query_str).format(cardID))
     # ~ self.c.execute('SELECT * FROM cards WHERE card_id = ?', (cardID,))
     cardData = self.c.fetchall()
     if len(cardData) <= 0:
         return None
     # print(cardData)
     card = RFIDCard(cardData[0][0], cardData[0][2], cardData[0][1] == 1)
     return card
Exemplo n.º 3
0
    def get_all_cards(self):
        """
		Returns a tuple of all cards as RFIDCard objects
		"""
        query_str = ["SELECT * FROM cards;"]
        self.c.execute(str.join(" ", query_str))
        cardsData = self.c.fetchall()
        cards = []
        for row in cardsData:
            card = RFIDCard(str(row[0]), row[2], row[1] == 1)
            cards.append(card)
        return tuple(cards)
Exemplo n.º 4
0
    def get_not_active_cards(self):
        """
		Returns a tuple of all non-active cards  as RFIDCard objects
		"""
        query_str = [
            "SELECT * FROM cards", "WHERE cards.synced = '0'",
            "OR cards.synced = 'False';"
        ]
        self.c.execute(str.join(" ", query_str))
        cardsData = self.c.fetchall()
        cards = []
        for row in cardsData:
            card = RFIDCard(str(row[0]), row[2], row[1] == 1)
            cards.append(card)
        return tuple(cards)
Exemplo n.º 5
0
    def get_all_feeding_logs(self):
        """
		Returns a tuple of all feeding logs , the cards are objects inside the tuple
		"""
        query_str = [
            "SELECT * FROM feeding_logs JOIN cards",
            "ON feeding_logs.card_id=cards.card_id;"
        ]
        self.c.execute(str.join(" ", query_str))
        logData = self.c.fetchall()
        logs = []
        for row in logData:
            thisCard = RFIDCard(row[7], row[9], row[8] == 1)
            log = FeedingLog(thisCard,
                             open_time=row[2],
                             close_time=row[3],
                             start_weight=row[4],
                             end_weight=row[5],
                             feeding_id=row[0],
                             synced=(row[6] == 1))
            logs.append(log)
        return tuple(logs)