Example #1
0
    def get_data(self, model, filter_by=[], value=[], ids_list=[]):
        """
        Get the data from a specific model
        Then we show the different option to choose and the information with it

        :param model:
        :param filter_by:
        :param value:
        :param ids_list:
        :return: ids_list
        """
        for i, key in enumerate(filter_by):
            test = getattr(model, key)
            test.value = value[i]

        if type(model) in {Category, Favorite}:
            data = get_all(model, self.my_cursor)
        else:
            data = get_all(model, self.my_cursor)[:5]
        for new_model in data:
            if type(model) == Favorite:
                product = new_model.product_id.models
                sub = new_model.substitute_id.models
                info = "Produit : %s note %s, Substitue : %s note %s" % (
                    product.name.value, product.nutrition_grade.value,
                    sub.name.value, sub.nutrition_grade.value)
            else:
                info = "Id : %s, Name : %s" % (new_model.id,
                                               new_model.name.value)
                if type(model) == Product:
                    info += ", Note : %s" % new_model.nutrition_grade.value
            print(info)
            ids_list.append(new_model.id)
        return ids_list
Example #2
0
def burndown():
    """
    Helper method for parsing the plot points and
    returning them as appropriate.
    """
    total_jobs = [int(x.total_jobs) for x in get_all()]
    finished_jobs = [int(x.finished_jobs) for x in get_all()]
    captured_dates = [x.captured_date for x in get_all()]
    return total_jobs, finished_jobs, captured_dates
Example #3
0
 def get(self):
     return [{
         'id': x.id,
         'name': x.name,
         'status': x.status,
         'limit': x.limit
     } for x in get_all()]
Example #4
0
def index(page):
    """
    Handle http request to root
    """
    notices = get_all(page)
    notices = JSONEncoder().encode(notices)
    return jsonify(json.loads(notices))
Example #5
0
def content_list():
    ret = []
    if request.args.get("rg") == "large":
        records = models.get_all("Content")
        for t in records:
            ret.append(t.format())
    else:
        records = models.get_keys("Content")
        for t in records:
            ret.append(t.id())
    return common.json_response(ret)
Example #6
0
def tag_list():
    ret = []
    if request.args.get('rg') == 'large':
        records = models.get_all('Tag')
        for t in records:
            ret.append(t.format())
    else:
        records = models.get_keys('Content')
        for t in records:
            ret.append(t.id())
    return common.json_response(ret)
Example #7
0
def tag_list():
    ret = []
    if request.args.get('rg') == 'large':
        records = models.get_all('Tag')
        for t in records:
            ret.append(t.format())
    else:
        records = models.get_keys('Content')
        for t in records:
            ret.append(t.id())
    return common.json_response(ret)
Example #8
0
def index(request):
    global process
    global ad
    
    print user_ip(request)
    
    links = get_all()
    if process == None:
        process = DownloadProcess()
    if ad == None:
        ad = AutoDownload()
#    print links
    #c = {}
    #c.update(csrf(request))
    # 
    r = render_to_response('index.html', {'links': links}, context_instance=RequestContext(request))
    return r
Example #9
0
finished_jobs = query_es_rna_seq(es, 'burn_idx', myQuery, "repoDataBundleId")
# Create the plot point
plot = Burndown(total_jobs=total_jobs, finished_jobs=finished_jobs)
# Enter the plot point in the table
bd_user = os.getenv('BD_POSTGRES_USER')
bd_password = os.getenv('BD_POSTGRES_PASSWORD')
bd_table = os.getenv('BD_POSTGRES_DB')
db_url = 'postgresql://{}:{}@bdchart-db/{}'.format(bd_user, bd_password,
                                                   bd_table)
engine = create_engine(db_url)
session = sessionmaker()
session.configure(bind=engine)
s = session()
s.add(plot)
# Delete old entries
old_entries = datetime.today().replace(second=0,
                                       microsecond=0) - timedelta(days=1)
s.query(Burndown).filter(Burndown.captured_date <= old_entries).delete()
# Commit Changes to the DB
s.commit()
print [(str(x.total_jobs),
        str(x.finished_jobs),
        x.captured_date,
        "{}:{}".format(x.captured_date.hour,
                       x.captured_date.minute)) for x in get_all()]
print "Total Jobs: {} Finished Jobs: {}".format(total_jobs, finished_jobs)

session.close_all()
engine.dispose()

Example #10
0
def main():
    my_db, my_cursor = connect_to_database()

    # Creating our tables

    print("Create Table if not existing")
    Category().save(my_cursor)
    Product().save(my_cursor)
    Substitute().save(my_cursor)
    Favorite().save(my_cursor)

    # Load the categories stock in a json file,

    headers = {"user-agent": "python-app/0.0.1"}
    current_path = os.path.dirname(os.path.abspath(__file__))
    json_path = os.path.join(current_path, "categories.json")

    with open(json_path, 'r') as file:
        data = json.load(file)

    categories_url = "https://fr.openfoodfacts.org/categorie/"
    print("Loading category")
    for category in data['tags']:
        # Get the data wanted from json file
        new_category = Category()
        new_category.name.value = category['name']
        new_category.tags.value = category['id']
        category_url = categories_url + new_category.tags.value + ".json"
        # Get the number of product available in this category ( can change )
        r = requests.get(category_url, headers=headers)
        new_category.products.value = r.json()["count"]

        new_category.insert_data(my_cursor)
        my_db.commit()

    categories = get_all(Category(), my_cursor)

    search_url = "https://fr.openfoodfacts.org/cgi/search.pl?"

    for category in categories:
        # Load all the product of the category and put in database

        print("Start loading product from category %s" % category.name.value)

        payload = {
            "action": "process",
            "tagtype_0": "categories",
            "tag_contains_0": "contains",
            "tag_0": category.tags.value,
            "page_size": 50,
            "sort_by": "unique_scans_n",
            "json": 1
        }
        for i in range(int(category.products.value / payload["page_size"])):
            # Get all the data wanted from the request we made
            # Get through every page of the category's product
            payload['page'] = i
            print("Loading page %d from category %s" %
                  (i, category.name.value))
            r = requests.get(search_url, headers=headers, params=payload)
            data = r.json()
            for product in data["products"]:
                new_product = Product()
                new_product.name.value = check_error(product, 'product_name',
                                                     '')
                new_product.ingredients.value = check_error(
                    product, 'ingredients_text_fr', '')
                new_product.url.value = product['url']
                new_product.code.value = str(product['code'])

                new_product.store.value = check_error(product, 'stores', '')
                new_product.category.value = category.id

                new_product.nutrition_grade.value = check_error(
                    product, 'nutrition_grades', '')

                new_product.salt_100.value = check_error(
                    product, 'nutriments', 'salt_100g')
                new_product.salt_lvl.value = check_error(
                    product, 'nutrient_levels', 'salt')

                new_product.sugar_100.value = check_error(
                    product, 'nutriments', 'sugars_100g')
                new_product.sugar_lvl.value = check_error(
                    product, 'nutrient_levels', 'sugars')

                new_product.fat_100.value = check_error(
                    product, 'nutriments', 'fat_100g')
                new_product.fat_lvl.value = check_error(
                    product, 'nutrient_levels', 'fat')

                new_product.saturated_fat_100.value = check_error(
                    product, 'nutriments', 'saturated-fat_100g')
                new_product.saturated_fat_lvl.value = check_error(
                    product, 'nutrient_levels', 'saturated-fat')

                new_product.insert_data(my_cursor)

                my_db.commit()

    print("\n Database is ready to be used")
Example #11
0
 def GET(self):
     sites = models.get_all()
     return render.index(sites, True) #admin())
Example #12
0
def tag_num_list():
    tags = models.get_all('Tag')
    ret = []
    for t in tags:
        ret.append(t.num)
    return common.json_response(ret)
Example #13
0
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///myspa.db'
app.register_blueprint(api_bp)


@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def index(path):
    return render_template('index.html')


def gen(camera):
    while True:
        frame = camera.get_frame()
        yield b'--frame\r\n' + b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n'
        sleep(0.33)


@app.route('/video')
def video():
    camera = LifeGameCamera()
    return Response(gen(camera),
                    mimetype='multipart/x-mixed-replace; boundary=frame')


if __name__ == '__main__':
    with app.app_context():
        init_db(app)
        if not get_all():
            insert('foo', 'This is foo.')
            insert('bar', 'This is bar.')
    app.run()
Example #14
0
def tag_num_list():
    tags = models.get_all('Tag')
    ret = []
    for t in tags:
        ret.append(t.num)
    return common.json_response(ret)
Example #15
0
    def get_new_product_favorite(self):
        # Find a product to substitute
        # And add the product and his substitute to Favorite

        ###############################
        #        SHOW CATEGORY        #
        ###############################

        print("Voici toute les categories disponibles : ")
        category_id = self.get_data(Category())

        chosen_category = self.check_int(
            input("Veuillez entrée le chiffre de la "
                  "catégorie dont vous désirez voir les produits : \n"),
            category_id)

        ##############################
        #        SHOW PRODUCT        #
        ##############################

        product_id = self.get_data(Product(), ["category"], [chosen_category])

        chosen_product = self.check_int(
            input(
                "Veuillez entrée le chiffre du produit que vous voulez choisir : "
            ), product_id)

        #################################
        #        SHOW Substitute        #
        #################################

        nutrition_grades = ["a", "b", "c", "d", "e"]
        substitutes_id = []
        for grade in nutrition_grades:
            substitutes_id = self.get_data(Product(),
                                           ["category", "nutrition_grade"],
                                           [chosen_category, grade],
                                           substitutes_id)
            if len(substitutes_id) >= 5:
                break

        chosen_substitute = self.check_int(
            input("Veuillez entrée le chiffre du substitute "
                  "que vous voulez choisir : \n"), substitutes_id)

        #################################
        #        Save Substitute        #
        #################################

        substitute = Product()
        substitute.id = chosen_substitute
        new_substitute = Substitute()
        result = get_all(substitute, self.my_cursor)
        for key in result[0].__dict__:
            if key != "id":
                value = getattr(result[0], key).value
                getattr(new_substitute, key).value = value
        sub_id = new_substitute.insert_data(self.my_cursor)

        ###############################
        #        Save Favorite        #
        ###############################

        favorite = Favorite()
        favorite.product_id.value = chosen_product
        favorite.substitute_id.value = sub_id
        favorite.insert_data(self.my_cursor)
        self.my_db.commit()

        print("Produit sauvegardé dans les Favories")
        self.choosing_option()
Example #16
0
 def get(self):
     return [{
         'id': x.pk,
         'name': x.name,
         'note': x.note
     } for x in get_all()]
Example #17
0
    parser.add_argument('--model-names', dest='model_names')
    parser.add_argument('--processes', dest='processes', default=1, type=int)
    parser.add_argument('--epochs', dest='epochs',
                        default=DEFAULT_EPOCHS, type=int)
    parser.add_argument('--repetitions', dest='repetitions',
                        default=DEFAULT_REPETITIONS, type=int)
    return parser


parser = get_args_parser()
args = parser.parse_args()

params['repetitions'] = args.repetitions
params['epochs'] = args.epochs

networks = network.get_combinations(args, models.get_all())

datasets, params = dataset.load(params, args.test_datasets)

manager = multiprocessing.Manager()
model_scores = manager.dict()

nxt = 0
while nxt < len(networks):

    # Just references, no duplicated in memory.
    processes = []
    for i in range(nxt, nxt + args.processes):

        if i >= len(networks):
            # No more networks to process.