Esempio n. 1
0
def HomeService(args):

    response = {}
    house_object = {}
    houses_array = []

    # database query
    sql = '''SELECT house_id, title, description, rent, images FROM house ORDER BY house_id DESC'''
    rows = Db().select(sql)
    if rows:
        for row in rows:
            house_object['house_id'] = row['house_id']
            house_object['title'] = row['title']
            house_object['description'] = row['description']
            house_object['rent'] = row['rent']
            house_object['images'] = json.loads(row['images'])

            # storing house data in array of objects
            houses_array.append(house_object)
            house_object = {}

        response['status'] = "Success"
        response['data'] = houses_array
        return response
    else:
        response['status'] = "Failure"
        response['error'] = "Could not find data of houses"
        return response
Esempio n. 2
0
def main():
    parser = argparse.ArgumentParser(
        description=
        "Graph the simulation results, using IPC to access the simulation's in-memory database."
    )
    parser.add_argument('--use_db',
                        type=str,
                        default='false',
                        help='set to "true to use database instead of IPC')
    args = parser.parse_args()

    use_db = args.use_db.lower() == "true"

    if use_db:
        conn = Db(DB_PATH)
        run = Run(db=conn)
    else:
        conn = Ipc()
        run = Run(ipc=conn)

    run_name = "run{}".format(run.run_id)
    run_dir = "{}/{}".format(IMG_DIR, run_name)
    if os.path.exists(run_dir):
        shutil.rmtree(run_dir)
    os.makedirs(run_dir)

    if use_db:
        graph_gen = GraphGen(run, db=conn, run_dir=run_dir)
    else:
        graph_gen = GraphGen(run, ipc=conn, run_dir=run_dir)

    graph_gen.plot_cumulative_best_fitness()
    graph_gen.plot_avg_fitness()

    conn.close()
Esempio n. 3
0
def RegisterService(args):

    request = dict(args)
    response = {}

    # parameter checks
    if not 'email' in request:
        return Failure("email")

    if not 'password' in request:
        return Failure("passord")

    if not 'name' in request:
        return Failure("name")

    if not 'mobile' in request:
        return Failure("mobile")

    # database query
    sql = '''INSERT INTO user (`name`,`email`,`mobile`,`password`) VALUES (%s, %s, %s, %s);'''
    val = (request['name'], request['email'], request['mobile'],
           request['password'])

    user_id = Db().insert(sql, val)
    if isinstance(user_id, int):
        response['status'] = "Success"
        return response
    else:
        response['status'] = "Failure"
        response['error'] = user_id
        return response
Esempio n. 4
0
def HouseService(args):

    request = dict(args)
    response = {}

    # parameter checks
    if not 'house_id' in request:
        return Failure("house_id")

    # database query
    sql = '''SELECT * from house INNER JOIN user on house.user_id = user.user_id WHERE house_id = %s''' % (
        request['house_id'])
    rows = Db().select(sql)
    if rows:
        for row in rows:
            response['house_id'] = row['house_id']
            response['title'] = row['title']
            response['description'] = row['description']
            response['rent'] = row['rent']
            response['address'] = row['address']
            response['images'] = json.loads(row['images'])
            response['name'] = row['name']
            response['email'] = row['email']
            response['mobile'] = row['mobile']

            response['status'] = "Success"
            return response

    else:
        return Failure("correct house_id")
Esempio n. 5
0
def LoginService(args):

    request = dict(args)
    response = {}

    # parameter checks
    if not 'email' in request:
        return Failure("email")

    if not 'password' in request:
        return Failure("password")

    # database query
    sql = '''SELECT * FROM user WHERE email="%s" AND password="******"''' % (
        request['email'], request['password'])

    rows = Db().select(sql)
    if rows:
        for row in rows:
            response['user_id'] = row['user_id']
            response['name'] = row['name']
            response['email'] = row['email']
            response['mobile'] = row['mobile']
            response['password'] = row['password']

        response['status'] = "Success"
        return response
    else:
        return Failure("correct email and password")
Esempio n. 6
0
    def __init__(self):
        super().__init__()

        self.db = Db()
        self.session = self.db.get_session()

        products = self.session.query(Product).all()
        self.products = {
            ProductService.build_url(product): product
            for product in products
        }

        if not self.products:
            return

        self.start_urls = self.products.keys()

        brands = self.session.query(Brand).filter(
            Brand.id.in_([product.brand_id for product in products])).all()
        self.brands = {brand.title: brand for brand in brands}

        category_ids = self.session.query(func.unnest(Product.category_ids)) \
            .filter(Product.id.in_([product.id for product in products])).distinct()
        categories = self.session.query(Category) \
            .filter(Category.id.in_(category_ids)).all()

        self.categories = {
            catalog_category.title: catalog_category
            for catalog_category in categories
        }
Esempio n. 7
0
    def __init__(self, url=''):
        super().__init__()

        self.db = Db()
        self.session = self.db.get_session()

        if url != '':
            self.start_urls.append(url)
Esempio n. 8
0
def AddService(args):

    request = dict(args)
    response = {}

    # parameter checks
    if not 'user_id' in request:
        return Failure("user_id")

    if not 'title' in request:
        return Failure("title")

    if not 'description' in request:
        return Failure("description")

    if not 'rent' in request:
        return Failure("rent")

    if not 'address' in request:
        return Failure("address")

    if not 'images' in request:
        return Failure("images")

    # database query
    sql = '''INSERT INTO house (`user_id`,`title`,`description`,`rent`,`address`,`images`) VALUES (%s, %s, %s, %s, %s, %s);'''
    val = (request['user_id'], request['title'], request['description'],
           request['rent'], request['address'], json.dumps(request['images']))

    house_id = Db().insert(sql, val)
    if isinstance(house_id, int):
        response['status'] = "Success"
        return response
    else:
        response['status'] = "Failure"
        response['error'] = house_id
        return response
Esempio n. 9
0
    def __init__(self, db_path):
        Gtk.Window.__init__(self, title='Viewer')
        self.set_default_size(ViewWindow.WIDTH, ViewWindow.HEIGHT)
        self.maximize()

        self.db = Db(db_path)
        self.run = Run(self.db)
        self.tree_gen = TreeGen(self.db)
        self.graph_gen = GraphGen(self.run, db=self.db)

        #we'll simulate an MRU (most recently used) cache using an OrderedDict
        #it's not the most efficient, but it's good enough for this application
        self.tree_cache = OrderedDict()
        self.grn_cache = OrderedDict()

        vbox = Gtk.VBox()
        paned = Gtk.Paned()
        left_scroll = Gtk.ScrolledWindow()
        self.tree_img = Gtk.Image()
        left_scroll.add_with_viewport(self.tree_img)
        paned.add1(left_scroll)

        right_scroll = Gtk.ScrolledWindow()
        self.grn_img = Gtk.Image()
        right_scroll.add_with_viewport(self.grn_img)
        paned.add2(right_scroll)
        paned.set_position(ViewWindow.WIDTH // 2)

        vbox.pack_start(paned, True, True, 0)
        vbox.pack_end(self._build_bottom_panel(), False, False, 0)

        self.add(vbox)

        self.show_all()

        self.update_views()