예제 #1
0
파일: views.py 프로젝트: qfjj/sim_yq
def bigdata():
    taskname = (Settingtask.query.get(int(session["user_id"]))).taskname
    keyname = (Settingtask.query.get(int(session["user_id"]))).keyname
    username = session["user"]
    news = Data.query.filter(db.cast(datetime.now(), db.DATE) - db.cast(Data.created_at, db.DATE) < 200).filter(
        Data.content.like("%" + keyname + "%")).all()

    news_mg = Data.query.filter(db.cast(datetime.now(), db.DATE) - db.cast(Data.created_at, db.DATE) < 200).filter(Data.mg == '敏感').filter(
        Data.content.like("%" + keyname + "%")).all()


    return render_template("user/bigdata-2.html", taskname=taskname, username=username,news=news, news_mg=news_mg)
예제 #2
0
def index():
    page = request.args.get('page', type=int, default=1)
    pagination = Blog.query.order_by(Blog.id.desc()).paginate(page, 5, False)
    blogs = pagination.items
    b = Blog.query.all()
    t = date.today()
    d = Blog.query.filter(
        db.cast(Blog.time, db.DATE) == db.cast(t, db.DATE)).all()
    return render_template('main/index.html',
                           pagination=pagination,
                           blogs=blogs,
                           b=len(b),
                           d=len(d))
예제 #3
0
def GetLogListJson():
    page = request.args.get("pageIndex", type=int)
    per_page = request.args.get("pageSize", type=int)
    userName = request.args.get("UserName")
    ipAddress = request.args.get("IpAddress")
    startTime = request.args.get("StartTime")
    endTime = request.args.get("EndTime")
    sort = request.args.get("sort")
    sortType = request.args.get("sortType")

    data = {'Tag': 0, "Message": "", "Data": "", "Total": 0}
    data["Tag"] = 1
    data["Message"] = "操作成功"
    logs = SysLog.query.join(User,
                             SysLog.CreateUserid == User.Id).with_entities(
                                 SysLog.Id.label('Id'), User.UserName,
                                 SysLog.IpAddress, SysLog.IpLocation,
                                 SysLog.Browser, SysLog.OS, SysLog.LogType,
                                 SysLog.ExecuteUrl, SysLog.ExecuteResult,
                                 SysLog.ExecuteParam, SysLog.Status,
                                 SysLog.CreateTime, SysLog.Remark)
    if len(userName) > 0:
        logs = logs.filter(User.UserName.contains(userName))
    if len(ipAddress) > 0:
        logs = logs.filter(SysLog.IpAddress.contains(ipAddress))
    if len(startTime) > 0:
        logs = logs.filter(
            db.cast(SysLog.CreateTime, db.DATE) >= db.cast(startTime, db.DATE))
    if len(endTime) > 0:
        logs = logs.filter(
            db.cast(SysLog.CreateTime, db.DATE) <= db.cast(endTime, db.DATE))
    if len(sort) > 0:
        if sortType == "asc":
            logs = logs.order_by(asc(str(sort)))
        else:
            logs = logs.order_by(desc(str(sort)))
    logs_length = logs.count()
    logs = logs.paginate(page=page, per_page=per_page)
    data["Total"] = logs_length
    data["Data"] = logs.items
    return jsonify(data)
예제 #4
0
def GetRoleListJson():
    page = request.args.get("pageIndex", type=int)
    per_page = request.args.get("pageSize", type=int)
    roleName = request.args.get("RoleName")
    roleStatus = request.args.get("RoleStatus")
    startTime = request.args.get("StartTime")
    endTime = request.args.get("EndTime")
    sort = request.args.get("sort")
    sortType = request.args.get("sortType")
    data={'Tag': 0,"Message":"","Data":"","Total":0}
    data["Tag"]=1
    data["Message"]="操作成功"
    roles=Role.query.with_entities(Role.Id.label('Id'),
        Role.Name.label('RoleName'),
        Role.Sort.label('RoleSort'),
        Role.Status.label('RoleStatus'),
        Role.ModifyTime.label('BaseModifyTime'),
        )
    if len(roleName)>0:
        roles=roles.filter(Role.Name.contains(roleName))
    if len(roleStatus)>0 and roleStatus!="-1":
        print("roleStatus:",roleStatus)
        roles=roles.filter(Role.Status==int(roleStatus))
    if len(startTime)>0:
        roles=roles.filter(db.cast(Role.CreateTime, db.DATE)>=db.cast(startTime, db.DATE))
    if len(endTime)>0:
        roles=roles.filter(db.cast(Role.CreateTime, db.DATE)<=db.cast(endTime, db.DATE))
    if len(sort)>0:
        if sortType.lower()=="asc":
            roles=roles.order_by(asc(str(sort)))
        else:
            roles=roles.order_by(desc(str(sort)))

    roles_length=roles.count()
    roles=roles.paginate(page=page,per_page=per_page)
    data["Total"]=roles_length
    data["Data"]=roles.items
    return jsonify(data)
예제 #5
0
def search():
    try:
        form = SearchForm()
        query = form.search.data
        logs = []

        if form.validate_on_submit():
            logs = db.session.query(Log) \
                .filter(db.text("logfts MATCH '{}'".format(build_query(query.replace("'", "''").replace('"', '""'))))) \
                .order_by(db.desc(db.cast(Log.uts, db.Float))).limit(100).all()

            logs = [
                format_line(line.to_dict(), True) for line in logs
                if line.action not in ['PING', 'NOTICE']
            ]

        return render_template('search.html',
                               form=form,
                               logs=logs,
                               query=query)
    except Exception as ex:
        abort(400, ex)
예제 #6
0
파일: views.py 프로젝트: qfjj/sim_yq
def user():
    username = session["user"]
    taskname = (Settingtask.query.get(int(session["user_id"]))).taskname
    keyname = (Settingtask.query.get(int(session["user_id"]))).keyname
    time = request.args.get("time", '')
    order = request.args.get("order", '')
    type = request.args.get("type", '')

    PER_PAGE = 10
    total = Data.query.filter(db.cast(datetime.now(), db.DATE) - db.cast(Data.created_at, db.DATE) < 1000).filter(
        Data.content.like("%" + keyname + "%")).count()
    page = request.args.get(get_page_parameter(), type=int, default=1)
    start = (page - 1) * PER_PAGE
    end = start + PER_PAGE
    pagination = Pagination(bs_version=4, page=page, total=total)

    news = Data.query.filter(db.cast(datetime.now(), db.DATE) - db.cast(Data.created_at, db.DATE) <= 1000).filter(
        Data.content.like("%" + keyname + "%")).order_by(Data.created_at.desc()).slice(start, end)

    # if not time and not order or order == 'desc' and not type or type == 'all':
    #     news = Data.query.filter(db.cast(datetime.now(), db.DATE) - db.cast(Data.created_at, db.DATE) <= 30).filter(
    #     Data.content.like("%" + keyname + "%")).order_by(Data.created_at.desc()).slice(start, end)
    # elif not order and not type:
    #     news = Data.query.filter(db.cast(datetime.now(), db.DATE) - db.cast(Data.created_at, db.DATE) <= time).filter(
    #     Data.content.like("%" + keyname + "%")).order_by(Data.created_at.desc()).slice(start, end)
    # elif order == 'asc' and not time and not type:
    #     news = Data.query.filter(db.cast(datetime.now(), db.DATE) - db.cast(Data.created_at, db.DATE) <= 7).filter(
    #     Data.content.like("%" + keyname + "%")).order_by(Data.created_at.asc()).slice(start, end)
    # elif order == 'desc' or not order and not type or type == 'all':
    #     news = Data.query.filter(db.cast(datetime.now(), db.DATE) - db.cast(Data.created_at, db.DATE) <= time).filter(
    #     Data.content.like("%" + keyname + "%")).order_by(Data.created_at.asc()).slice(start, end)
    # elif order == 'asc' and not type or type == 'all':
    #     news = Data.query.filter(db.cast(datetime.now(), db.DATE) - db.cast(Data.created_at, db.DATE) <= time).filter(
    #     Data.content.like("%" + keyname + "%")).order_by(Data.created_at.asc()).slice(start, end)
    # elif order == 'asc' and type == 'mg':
    #     news = Data.query.filter(db.cast(datetime.now(), db.DATE) - db.cast(Data.created_at, db.DATE) <= time).filter(
    #     Data.content.like("%" + keyname + "%")).filter(Data.mg == '敏感').order_by(Data.created_at.asc()).slice(start, end)
    # elif order == 'asc' and type == 'nomg':
    #     news = Data.query.filter(db.cast(datetime.now(), db.DATE) - db.cast(Data.created_at, db.DATE) <= time).filter(
    #     Data.content.like("%" + keyname + "%")).filter(Data.mg == None).order_by(Data.created_at.asc()).slice(start, end)
    # elif not order or order == 'desc' and type == 'mg':
    #     news = Data.query.filter(db.cast(datetime.now(), db.DATE) - db.cast(Data.created_at, db.DATE) <= time).filter(
    #     Data.content.like("%" + keyname + "%")).filter(Data.mg == '敏感').order_by(Data.created_at.desc()).slice(start, end)
    # elif not time and not order or order == 'desc' and type == 'mg':
    #     news = Data.query.filter(db.cast(datetime.now(), db.DATE) - db.cast(Data.created_at, db.DATE) <= 7).filter(
    #     Data.content.like("%" + keyname + "%")).filter(Data.mg == '敏感').order_by(Data.created_at.desc()).slice(start, end)
    # elif not time and not order or order == 'desc' and type == 'nomg':
    #     news = Data.query.filter(db.cast(datetime.now(), db.DATE) - db.cast(Data.created_at, db.DATE) <= 7).filter(
    #     Data.content.like("%" + keyname + "%")).filter(Data.mg == None).order_by(Data.created_at.desc()).slice(start, end)
    # elif not order or order == 'desc' and type == 'nomg':
    #     news = Data.query.filter(db.cast(datetime.now(), db.DATE) - db.cast(Data.created_at, db.DATE) <= time).filter(
    #     Data.content.like("%" + keyname + "%")).filter(Data.mg == None).order_by(Data.created_at.desc()).slice(start, end)
    # else:
    #     news = Data.query.filter(db.cast(datetime.now(), db.DATE) - db.cast(Data.created_at, db.DATE) <= 30).filter(
    #     Data.content.like("%" + keyname + "%")).order_by(Data.created_at.desc()).slice(start, end)

    p = dict(
        time = time,
        order = order,
        type = type
    )

    context = {
        'pagination': pagination,
        'news': news
    }

    return render_template("user/home.html", username=username, taskname=taskname, keyname=keyname, p=p, **context)
예제 #7
0
파일: task.py 프로젝트: yst8493182/UAT
def getHomeData():
    caseCount = CaseInfo.query.filter(db.and_(CaseInfo.type == 1)).count()
    projectCount = Project.query.filter(db.and_(Project.status == 1)).count()
    immTaskCount = Task.query.filter(db.and_(Task.task_type == 2)).count()
    timTaskCount = Task.query.filter(db.and_(Task.task_type == 3)).count()
    today = date.today()
    nearOneMonthData = []
    monthFailCount = 0
    monthTotalCount = 0
    # 往前30天每天的数据
    for d in range(0, 30):
        dayDate = today - timedelta(days=d)
        dailyResult = HomeDayExcuteCount.query.filter(
            db.cast(HomeDayExcuteCount.add_time, db.DATE) == dayDate).all()
        dayFailCount = 0
        dayTotalCount = 0
        if len(dailyResult) > 0:
            for dayResult in dailyResult:
                dayFailCount += dayResult.fail_count
                dayTotalCount += dayResult.total_count
        monthFailCount += dayFailCount
        monthTotalCount += dayTotalCount
        dayDateStr = dayDate.strftime("%Y-%m-%d %H:%M:%S")
        stamptime = time.mktime(time.strptime(dayDateStr, "%Y-%m-%d %H:%M:%S"))
        nearOneMonthData.append({
            'runTime': round(stamptime * 1000),
            'day': dayDate.strftime("%Y-%m-%d"),
            'runTaskCount': len(dailyResult),
            'failCount': dayFailCount,
            'totalCount': dayTotalCount,
        })
    caseMountAddData = []
    thisMonth = 0
    year = datetime.now().year
    month = datetime.now().month
    for m in range(1, 13):
        monthCaseCount = CaseInfo.query.filter(
            db.and_(
                extract('year', CaseInfo.update_time) == year,
                extract('month', CaseInfo.update_time) == m,
                CaseInfo.type == 1,
            )).count()
        if m == month:
            thisMonth = monthCaseCount
        caseMountAddData.append({
            'x':
            '{year}-{month}'.format(year=year, month=m),
            'y':
            monthCaseCount,
        })
    monthSucessCount = monthTotalCount - monthFailCount
    monthExecutePre = 0
    if monthTotalCount > 0:
        monthExecutePre = round((monthSucessCount / monthTotalCount) * 10, 1)
    content = {
        'caseCount': caseCount,
        'projectCount': projectCount,
        'immTaskCount': immTaskCount,
        'timTaskCount': timTaskCount,
        'nearOneMonthData': nearOneMonthData,
        'caseMountAddData': caseMountAddData,
        'thisMonth': thisMonth,
        'monthExecutePre': monthExecutePre,
    }

    return make_response(
        jsonify({
            'code': 0,
            'content': content,
            'msg': u'操作成功!'
        }))
예제 #8
0
def getfoudListByPaged():
    request_args_dicts = request.args.to_dict()
    pageindex = None
    pagesize = None
    # navDate = None
    keyword = None
    codes = None
    category = None
    subCategory = None
    orgcode = None  # 机构code
    '''
    基金列表接口调整 
    1.返回近3个月的有基金净值(unitNav)的基金数据(包括按大小类查询)
    2.基金如果没有净值返回null给到前端,前端会根据null处理,不能返回0
    不再根据日期查询了
    '''
    for d in request_args_dicts:  # 忽略大小写
        if 'pageindex'.lower() == d.lower():
            pageindex = request_args_dicts.get(d)
        if 'pagesize'.lower() == d.lower():
            pagesize = request_args_dicts.get(d)
        if 'keyword'.lower() == d.lower():
            keyword = request_args_dicts.get(d)
        if 'codes'.lower() == d.lower():
            codes = request_args_dicts.get(d)
        # if 'time'.lower() == d.lower():
        #     navDate = request_args_dicts.get(d)
        if 'category'.lower() == d.lower():
            category = request_args_dicts.get(d)
        if 'subCategory'.lower() == d.lower():
            subCategory = request_args_dicts.get(d)
        if 'orgcode'.lower() == d.lower():
            orgcode = request_args_dicts.get(d)

    data = None
    if pageindex is None:
        pageindex = 1
    else:
        pageindex = int(pageindex)
    if pagesize is None:
        pagesize = 10
    else:
        pagesize = int(pagesize)

    # 拼接查询条件参数数组
    params = []
    # 默认查询3个月内有基金净值的数据
    limitDate = datetime.datetime.today().date() + relativedelta(months=-3)

    if keyword or codes:
        if keyword:
            keyword_title = '%' + keyword + '%'
            keyword_code = keyword.zfill(6)
            # title模糊匹配,code不满6位自动向前补全0
            params.append(
                db.or_(Fund.title.like(keyword_title),
                       Fund.code == keyword_code))
        if codes:
            params.append(Fund.code.in_(codes.split(',')))
    else:
        params.append(db.cast(FundNetValue.navDate, db.Date) >= limitDate)

    if category:
        params.append(Fund.category == category)

    if subCategory:
        params.append(Fund.subCategory == subCategory)

    if orgcode:
        params.append(Fund.mechanismCode == orgcode)

    # if navDate:  # 比较日期格式,不匹配时分秒格式
    #     params.append(db.cast(FundNetValue.navDate, db.Date) == db.cast(navDate, db.Date))

    # max_navDate = db.session.query(db.func.max(FundNetValue.navDate)).filter(Fund.id == FundNetValue.fundId).filter(
    #     *params).first()
    # if max_navDate[0]:
    #     params.append(FundNetValue.navDate == max_navDate[0])

    Fund2 = orm.aliased(Fund)  # 定义表别名,用于子查询
    # 根据title和code分组后获取最新的净值日期对应的基金数据  单个查询code 2018年之前不用显示了?
    data = db.session.query(Fund, FundNetValue).join(FundNetValue) \
        .filter(FundNetValue.navDate == db.session.query(db.func.max(FundNetValue.navDate)).join(Fund2).filter(*params)
                .filter(db.and_(Fund2.code == Fund.code)) \
                .group_by(Fund2.code)  # code分组,旧的不要了
                ).order_by(Fund.code)

    totalCount = data.count()
    dataPaged = data.paginate(page=pageindex,
                              per_page=pagesize,
                              error_out=False).items
    items = []

    for f, fnv in dataPaged:
        dataDic = {}
        dataDic['id'] = f.id
        dataDic['code'] = f.code
        dataDic['title'] = f.title
        dataDic['category'] = f.category
        dataDic['subCategory'] = f.subCategory
        dataDic['mechanismCode'] = f.mechanismCode
        dataDic['annualizedRate'] = fnv.annualizedRate
        if not fnv.unitNav:
            dataDic['unitNav'] = 0
        else:
            dataDic['unitNav'] = fnv.unitNav
        dataDic['navDate'] = fnv.navDate
        dataDic['createTime'] = fnv.createTime
        items.append(dataDic)

    # app.logger.info(dataPaged)
    r = ResultDtos.PagedResultDto(totalCount=totalCount,
                                  items=items,
                                  isEntity=False)
    return r.data