Пример #1
0
 def process(self, key, value, conn, processStatistic):
     if key == 'Composer':
         self.storeOldScoreAuthor(conn)
         self.composers = []
         for c in value.split(';'):
             p = Person(conn, c.strip())
             processStatistic.processData(p)
             pId = p.store()
             self.composers.append(pId)
     if key == 'Title':
         s = Score(conn, value)
         s.store()
         self.lastTitle = s.name
     if key in ['Genre', 'Key', 'Composition Year', 'Incipit']:
         if not self.lastTitle is None:
             res = Score.fetch_item(conn, self.lastTitle)
             if not res is None:
                 score = Score(conn, res[1])
                 score.id = res[0]
                 score.genre = (value if key == 'Genre' else res[2])
                 score.key = (value if key == 'Key' else res[3])
                 score.incipit = (value if key == 'Incipit' else res[4])
                 score.year = (value
                               if key == 'Composition Year' else res[5])
                 score.store()
 def generatePopulation(self, size, infertilePersonAmount):
     population = []
     for x in range(size):
         if (infertilePersonAmount > 0):
             population.append(Person(int(x), 0, True, False))
             infertilePersonAmount = infertilePersonAmount - 1
         else:
             population.append(Person(int(x), 0, False, False))
     return population
Пример #3
0
 def update_item(self, target, person_id, name, address, contact_email,
                 contact_tel_num):
     i = []
     tar = person_id if (target == 'person_id') \
         else name if (target == 'name') \
         else address if (target == 'address') \
         else contact_email if (target == 'contact_email') \
         else contact_tel_num if (target == 'contact_tel_num') \
         else None
     if tar is not None:
         j = 0
         for row in self.items:
             if len(row) != 0:
                 if row[target] == tar:
                     i.append(j)
             j += 1
         if i:
             for idx in i:
                 self.items[idx] = Person().\
                     generator(list([person_id, name, address, contact_email, contact_tel_num]))
                 self.db.update_table(
                     self.table_name,
                     f"person_id={self.items[idx]['person_id']}, "
                     f"name='{self.items[idx]['name']}', "
                     f"address='{self.items[idx]['address']}', "
                     f"contact_email='{self.items[idx]['contact_email']}', "
                     f"contact_tel_num='{self.items[idx]['contact_tel_num']}', ",
                     target + "=" + str(tar))
             # print(self.items)
         else:
             raise mvc_exc.ItemNotStored(
                 'Can\'t update "{}" because it\'s not stored'.format(tar))
Пример #4
0
    def findAll(self):
        persons = []

        with open(self.file, 'rb') as csvfile:
            reader = csv.reader(csvfile, delimiter=',', quotechar='"')
            next(reader)
            for row in reader:
                persons += [Person(row[0], row[1])]

        return persons
    def breed(self, population):
        if len(list(filter(lambda p: p.isBreed == False, population))) > 2:
            firstPerson = self.retrieveFirstPerson(population)
            secondPerson = self.retrieveSecondPerson(population,
                                                     firstPerson.id)

            if (not (firstPerson.isInfertile or secondPerson.isInfertile)
                    and (firstPerson.age == secondPerson.age)):
                child = Person(len(population), 0, False, True)
                #child = Person(len(population), 0, bool(random.getrandbits(1)), False)
                population.append(child)
                firstPerson.isBreed = True
                secondPerson.isBreed = True
            return True
        else:
            return False
Пример #6
0
 def set_listTable_by_db(self, name_table_db):
     print(f"\nTABLE \"{name_table_db}\":")
     self.__cur.execute("SELECT * " "FROM \"" + name_table_db + "\";")
     row = self.__cur.fetchone()
     if name_table_db.upper() == 'DEPARTAMENT':
         entity = Departament()
     elif name_table_db.upper() == 'ORDER':
         entity = Order()
     elif name_table_db.upper() == 'PERSON':
         entity = Person()
     elif name_table_db.upper() == 'THING':
         entity = Thing()
     elif name_table_db.upper() == 'TYPE':
         entity = Type()
     self.__listTable.append(entity.generator(row))
     while row is not None:
         row = self.__cur.fetchone()
         self.__listTable.append(entity.generator(row))
Пример #7
0
 def create_item(self, person_id, name, address, contact_email,
                 contact_tel_num):
     results = []
     for row in self.items:
         if len(row) != 0:
             if row['person_id'] == person_id:
                 results.append(row['person_id'])
     if results:
         raise mvc_exc.ItemAlreadyStored(
             '"{}" already stored!'.format(person_id))
     else:
         results = Person().generator(
             list(
                 [person_id, name, address, contact_email,
                  contact_tel_num]))
         self.items.append(results)
         self.db.execute_query(
             f"INSERT INTO {self.table_name} "
             f"    (person_id, name, address, contact_email, contact_tel_num) "
             f"VALUES ({results['person_id']}, '{results['name']}', "
             f"'{(results['address'])}', '{results['contact_email']}',"
             f"'{results['contact_tel_num']}');")
Пример #8
0
 def add_person(self, person_id, name, address, email, tel_num):
     self.session.add(Person(person_id, name, address, email, tel_num))
     self.session.commit()