Пример #1
0
    def read_installations(self, path):
        """
        Reads a JSON file which contains data for the installations

        >>> reader = ReadJSON()
        >>> installations = reader.read_installations("data/test_installations.json")
        >>> (installations[0].number, installations[0].name, installations[0].address, installations[0].zip_code, installations[0].city, installations[0].latitude, installations[0].longitude)
        ('440010002', 'Terrain de Sports', 'Le Bois Vert', '44170', 'Abbaretz', 47.552265, -1.532627)
        """
        file = open(path)
        data = json.load(file)
        result = []

        pbar = ProgressBar(
            widgets=['Reading installations JSON: ',
                     Percentage(), ' ',
                     ETA()])
        for line in pbar(data["data"]):
            if str(line["InsNoVoie"]) == "None":
                result.append(
                    Installation(line["InsNumeroInstall"], line["geo"]["name"],
                                 str(line["InsLibelleVoie"]),
                                 line["InsCodePostal"], line["ComLib"],
                                 line["Latitude"], line["Longitude"]))
            else:
                result.append(
                    Installation(
                        line["InsNumeroInstall"], line["geo"]["name"],
                        str(line["InsNoVoie"]) + " " +
                        str(line["InsLibelleVoie"]), line["InsCodePostal"],
                        line["ComLib"], line["Latitude"], line["Longitude"]))

        return result
Пример #2
0
    def test_b(self):
        room = Room(100, 50)
        tile = Tile(60, 20)
        border = 0
        init = {}

        installation = Installation(room, tile, border, init)
        plan = installation.process()
        installation.print()
        self.sanity_checks(init, plan, room, border)
Пример #3
0
    def test_a(self):
        room = Room(3330, 2700)
        tile = Tile(1286, 194)
        border = 8
        init = {
            0: 1286,
            12: 1286
        }

        installation = Installation(room, tile, border, init)
        plan = installation.process()
        installation.print()
        self.sanity_checks(init, plan, room, border)
Пример #4
0
def main():
    room = Room(3330, 2700)
    tile = Tile(1286, 194)
    border = 8
    init = {
        5: 1286,
        10: 1286
    }

    installation = Installation(room, tile, border, init)

    plan = installation.process()
    installation.print()
    Printer.print(plan)
Пример #5
0
    def readInstallation(self):
        """
		Read one installation and insert it in the database
		"""
        data = json.load(self.path)

        for row in data["data"]:
            self.result.append(
                Installation(
                    row["InsNumeroInstall"], row["geo"]["name"],
                    str(row["InsNoVoie"]) + " " + str(row["InsLibelleVoie"]),
                    row["InsCodePostal"], row["ComLib"], row["Latitude"],
                    row["Longitude"]))
    def read_Installations(self):
        """
		Reading of the entire installation table
		"""
        c = self.conn.cursor()
        c.execute('SELECT * FROM installation')
        result = c.fetchall()
        installations = []

        for i in result:
            installations.append(
                Installation(i[0], i[1], i[2], i[3], i[4], i[5], i[6]))

        return installations
Пример #7
0
    def read_installations(self):
        """
        Reads all the installations from the 'installations' table
        """
        c = self.conn.cursor()
        c.execute('SELECT * FROM installations')
        rows = c.fetchall()
        installations = []

        for row in rows:
            installations.append(
                Installation(row[0], row[1], row[2], row[3], row[4], row[5],
                             row[6]))

        return installations
    def read_One_Installation(self, number):
        """
		Read the entry of the given number
		"""
        c = self.conn.cursor()
        c.execute('SELECT * FROM installation WHERE number = :givenNumber',
                  {'givenNumber': number})
        result = c.fetchone()

        try:
            installation = Installation(result[0], result[1], result[2],
                                        result[3], result[4], result[5],
                                        result[6])
        except:
            return "Il n'y a pas d'installation qui possède ce numéro"
        return installation
Пример #9
0
    def read_installation(self, number):
        """
        Reads the installation which has the given number from the 'installations' table
        """
        c = self.conn.cursor()
        c.execute('SELECT * FROM installations WHERE numero = :numero',
                  {'numero': number})
        row = c.fetchone()

        try:
            installation = Installation(row[0], row[1], row[2], row[3], row[4],
                                        row[5], row[6])
        except TypeError:
            return '<h2>Aucune installation ne correspond à ce numéro</h2>'

        return installation
Пример #10
0
    def read_Informations(self, activity, city):
        """      
		Read information about a sport in a city
		"""
        c = self.conn.cursor()
        #c.execute("""SELECT i.number, i.name, e.number, e.name, a.number, a.name FROM installation i JOIN equipement e ON i.number = e.installationNumber JOIN equipement_activite ea ON e.number = ea.number_equipment JOIN activite a ON ea.number_activity = a.number WHERE i.city = ' + city + '  AND a.name LIKE '% + activity + %'""")
        c.execute(
            "SELECT DISTINCT i.number, i.name, e.number, e.name, a.number, a.name FROM installation i, equipement e, equipement_activite ea, activite a WHERE i.number = e.installationNumber AND e.number = ea.number_equipment AND ea.number_activity = a.number AND i.city = ' + city + '  AND a.name LIKE '% + activity + %'"
            "")
        result = c.fetchall()
        query = []

        for r in result:
            query.append(Installation(r[0], r[1]), Equipment(r[0], r[1]),
                         Activity(r[0], r[1]))

        print(query)
        return query
Пример #11
0
    def get_infos(self, activity_name, city):
        """
        Gives all the installations, equipments and activities which match the given activity and city
        """
        c = self.conn.cursor()
        c.execute("""SELECT i.numero, i.nom, e.numero, e.nom, a.numero, a.nom
        FROM installations i
        JOIN equipements e ON i.numero = e.numero_installation
        JOIN equipements_activites ea ON e.numero = ea.numero_equipement
        JOIN activites a ON ea.numero_activite = a.numero
        WHERE LOWER(i.ville) = LOWER('""" + city + """') AND a.nom LIKE '%""" +
                  activity_name + """%'""")
        rows = c.fetchall()
        results = []

        for row in rows:
            results.append(
                (Installation(row[0],
                              row[1]), Equipment(row[2], row[3], row[0]),
                 Activity(row[4], row[5], row[2])))

        return results