def bar_test(item_id) -> Bar: category = 68 # 创建Session 数据库相关操作 engine = create_engine('sqlite:///96345.db', echo=True) Session = sessionmaker(bind=engine) session = Session() # 取得所有当前类目数据库数据 元祖类型 降序 result = db.query_date_feedback_info(session, item_id, tools.get_today()) res = tools.change_2_pyechart_format(result) t = (Bar(init_opts=opts.InitOpts(theme=ThemeType.WHITE)).add_xaxis( res.get('name')).add_yaxis( "批评", res.get('cri'), stack="stack1", itemstyle_opts=opts.ItemStyleOpts(color='red')).add_yaxis( "满意", res.get('sat'), stack="stack1", itemstyle_opts=opts.ItemStyleOpts(color='#29b394')).add_yaxis( "表扬", res.get('pri'), stack="stack1", itemstyle_opts=opts.ItemStyleOpts( color='#fed861')).set_series_opts( label_opts=opts.LabelOpts( is_show=False), ).set_global_opts( title_opts=opts.TitleOpts(title="当前概况"), xaxis_opts=opts.AxisOpts( axislabel_opts=opts.LabelOpts( rotate=-15)), datazoom_opts=opts.DataZoomOpts())) return t
def increase_bar(day, item_id) -> Bar: logger.debug("显示增量表") # 创建Session 数据库相关操作 # engine = create_engine('sqlite:///96345.db', echo=True) # Session = sessionmaker(bind=engine) # session = Session() session = db.get_db_session(db_path) # 取得所有当前类目数据库数据 元祖类型 降序 result = tools.get_item_merchants_timelaspes_increase( session, item_id, tools.get_today(), tools.get_assign_year_date(day)) c = (Bar(init_opts=opts.InitOpts(theme=ThemeType.ROMANTIC)).add_xaxis( result.get('name')).add_yaxis( "新增单数", result.get('increment')).reversal_axis().set_global_opts( datazoom_opts=[ opts.DataZoomOpts(range_start=60, range_end=100, orient="vertical"), opts.DataZoomOpts(type_="inside", orient="vertical") ], tooltip_opts=[ opts.TooltipOpts(trigger='axis', axis_pointer_type='shadow') ]).set_series_opts( label_opts=opts.LabelOpts(is_show=True), markpoint_opts=opts.MarkPointOpts(data=[ opts.MarkPointItem(type_="max", name="最大值"), ]), )) session.close() return c
def every_day_update_feedback2(param, base_url, header, session, flag): all_merchant_info = spider.get_all_pages_service_info( base_url, header, param, '1') all_merchant_info_detail = spider.get_personal_service_data( all_merchant_info) if flag == 0: db.insert_feedback(session, all_merchant_info_detail) elif flag == 1: db.update_feedback(session, all_merchant_info_detail, tools.get_today())
def item_bar(item_id) -> Bar: logger.debug("显示总表") # 创建Session 数据库相关操作 # engine = create_engine('sqlite:///96345.db', echo=True) # Session = sessionmaker(bind=engine) # session = Session() session = db.get_db_session(db_path) # 取得所有当前类目数据库数据 元祖类型 降序 result = db.query_date_feedback_info(session, item_id, tools.get_today()) res = tools.change_2_pyechart_format(result) t = ( Bar(init_opts=opts.InitOpts(theme=ThemeType.WHITE)).add_xaxis( res.get('name')).add_yaxis( "批评", res.get('cri'), stack="stack1", itemstyle_opts=opts.ItemStyleOpts(color='red')).add_yaxis( "满意", res.get('sat'), stack="stack1", itemstyle_opts=opts.ItemStyleOpts( color='#29b394')).add_yaxis( "表扬", res.get('pri'), stack="stack1", itemstyle_opts=opts.ItemStyleOpts( color='#fed861')).set_series_opts( label_opts=opts.LabelOpts( is_show=False), ).set_global_opts( title_opts=opts.TitleOpts( title="当前概况"), xaxis_opts=opts.AxisOpts( axislabel_opts=opts.LabelOpts( rotate=-15)), datazoom_opts=[ opts.DataZoomOpts( range_start=0, range_end=50), # 设置起始结束范围 opts.DataZoomOpts( type_="inside") ] # 增加内缩放 )) session.close() return t
def bar_test_three(day): category = 68 # 创建Session 数据库相关操作 engine = create_engine('sqlite:///96345.db', echo=True) Session = sessionmaker(bind=engine) session = Session() # 取得所有当前类目数据库数据 元祖类型 降序 result = tools.get_item_merchants_timelaspes_increase( session, category, tools.get_today(), tools.get_assign_year_date(day)) c = (Bar().add_xaxis(result.get('name')).add_yaxis( "新增单数", result.get('increment')).set_global_opts().set_series_opts( label_opts=opts.LabelOpts(is_show=True), markpoint_opts=opts.MarkPointOpts(data=[ opts.MarkPointItem(type_="max", name="最大值"), ]), )) return c
def insert_feedback(session, all_info): log.debug("------------------更新反馈启动------------------\n") try: feedback_list = [] for i in all_info: feedback = Feedback(merchantId=i['id'], itemId=i['item'], satisfaction=i['satisfaction'], praise=i['praise'], criticism=i['criticism'], amount=i['amount'], createTime=tools.get_today()) log.debug(feedback.__repr__()) feedback_list.append(feedback) session.bulk_save_objects(feedback_list) # session.add_all(feedback_list) session.commit() log.info("每日首次插入feedback数据成功!!") log.debug("------------------更新反馈结束------------------\n") except exc.SQLAlchemyError as e: log.error("每日首次插入feedback数据失败!!")
def every_day_update_feedback(param, base_url, header, session, flag): item = db.query_all_item(session) for i in item: item_id = i.id item_merchant_amount = i.serviceAmount all_merchant_info = spider.get_all_pages_service_info( base_url, header, param, str(item_id)) all_merchant_info_detail = spider.get_personal_service_data( all_merchant_info) if flag == 0: # 每天插入第一次数据时进行商户完整性检查 是否有更新/删除 check_merchants(session, item_id, all_merchant_info, item_merchant_amount) # 当天第一次更新反馈信息 插入新row db.insert_feedback(session, all_merchant_info_detail) elif flag == 1: db.update_feedback(session, all_merchant_info_detail, tools.get_today()) # 插入最近更新时间 db.update_updateTime(session, item_id)
def get_item_table(item_id): session = db.get_db_session(db_path) result = db.query_date_feedback_info(session, item_id, tools.get_today()) formatted_result = tools.change_2_layui_table_formatted(result) return json.dumps(formatted_result)