コード例 #1
0
def addmonitoritem(user_id):
    form = AddMonitorItemForm()
    item = Monitor()
    if form.validate_on_submit():
        item_id = request.form.get("item_id")
        if not len(strip(item_id)):
            flash("商品ID为必填项")
            return redirect(url_for("addmonitoritem", user_id=user_id))
        user_price = request.form.get("user_price")
        if not len(strip(user_price)):
            flash("The content is necessray!")
            return redirect(url_for("addmonitoritem", user_id=user_id))
        mall_id = request.form.get("mall_id")
        if not len(strip(item_id)):
            flash("The content is necessray!")
            return redirect(url_for("addmonitoritem", user_id=user_id))
        item.item_id = item_id
        item.user_price = user_price
        item.mall_id = mall_id
        item.add_date = datetime.datetime.now()
        item.user_id = user_id
        item.status = True
        try:
            item_exist = Monitor.query.filter(
                Monitor.item_id == item_id).first()
            # print(item_exist)
            if item_exist is not None:
                flash("该商品已经在监控列表中")
                return redirect(url_for("users", user_id=user_id))
        except:
            flash("数据库查询商品错误,请重试")
            return redirect(url_for("addmonitoritem", user_id=user_id))

        item_name, item_price = additemcrawl.additemcrawl(
            item_id, user_id, mall_id)
        print(type(item_name), type(item_price), item_name)
        if type(item_name) == str:
            flash("该商品不存在,请输入正确的商品ID")
            return redirect(url_for("addmonitoritem", user_id=user_id))

        item.item_name = item_name
        item.item_price = item_price

        try:
            db.session.add(item)
            db.session.commit()
        except:
            flash("写入数据库错误")
            return redirect(url_for("addmonitoritem", user_id=user_id))
        flash("添加商品成功")
        return redirect(url_for("users", user_id=user_id))

    return render_template("addmonitoritem.html", form=form)
コード例 #2
0
def init_add_monitors():
    global session, SERVER_MODE, engine
    # Lets assign them all
    accounts = session.query(Account).all()
    channels = session.query(Channel).all()
    account_index = 0
    channel_count = 0

    for channel in channels:
        if account_index in accounts:
            account = accounts[account_index]
            logging.info(
                '{}: Adding monitoring to channel {} with account_id {} to the database'
                .format(sys._getframe().f_code.co_name, channel.channel_name,
                        account.account_id))
            session.add(
                Monitor(channel_id=channel.id,
                        account_id=account.account_id,
                        monitor_tcreate=datetime.now(),
                        monitor_tmodified=datetime.now()))
            channel_count += 1
            if channel_count > 500:
                account_index += 1
                channel_count = 0
    session.commit()
コード例 #3
0
def index():
    if request.method == 'GET':
        monitors = Monitor.query.order_by(desc(Monitor.id)).limit(50)
        return render_template("admin/monitor.html", monitors=monitors)
    elif request.method == 'POST':
        ipv4 = request.form['ipv4']
        monitor = Monitor(ipv4)
        db_session.add(monitor)
        db_session.commit()
        return "OK"
コード例 #4
0
ファイル: views.py プロジェクト: zhangfeifei02/python
def monitor_collect(request):
    req = request
    if req.POST:
        ip = req.POST.get('ip')
        time = req.POST.get('time')
        game = req.POST.get('game')
        app = req.POST.get('app')
        pid = req.POST.get('pid')
        useage = req.POST.get('useage')
        monitor = Monitor()
        monitor.ip = ip
        monitor.time = time
        monitor.game = game
        monitor.app = app
        monitor.pid = pid
        monitor.useage = useage
        monitor.save()
        return HttpResponse('OK')
    else:
        return HttpResponse('no post data')
コード例 #5
0
ファイル: views.py プロジェクト: Product/python
def monitor_collect(request):
    req = request
    if req.POST:
        ip = req.POST.get('ip')
        time = req.POST.get('time')
        game = req.POST.get('game')
        app = req.POST.get('app')
        pid = req.POST.get('pid')
        useage = req.POST.get('useage')
        monitor = Monitor()
        monitor.ip = ip
        monitor.time = time
        monitor.game = game
        monitor.app = app
        monitor.pid = pid
        monitor.useage = useage
        monitor.save()
        return HttpResponse('OK')
    else:
        return HttpResponse('no post data')
コード例 #6
0
            # Compile model
            # model.compile(loss=crossentropy_mask,
            #               metrics=["accuracy", f1_mean], optimizer=optimizer)
            model.compile(optimizer=optimizer,
                          loss=losses,
                          loss_weights=lossWeights,
                          metrics=custom_metrics)

            # Train model on dataset
            history = model.fit_generator(
                generator=training_generator,
                validation_data=validation_generator,
                epochs=params.num_epochs,
                callbacks=[
                    Monitor(validation=validation_generator,
                            patience=15,
                            model_dir=model_k,
                            classes=params.classes)
                ])
            model.save(file_output)

            # save training history
            filename = os.path.join(model_k, 'history_plot_acc.png')
            Results(history.history['cl_output_f_acc'],
                    history.history['val_cl_output_f_acc'],
                    history.history['cl_output_loss'],
                    history.history['val_cl_output_loss'],
                    filename).show_result()

            filename = os.path.join(model_k, 'history_plot_f1batch.png')
            Results(history.history['mean_f1'],
                    history.history['val_cl_output_f_acc'],