Exemple #1
0
def generate_head_column_html(field,
                              is_login_user,
                              record,
                              head_column_link_maker=None,
                              edit_link_maker=None):
    # 标题增加链接
    # 可转债: https://quote.eastmoney.com/bond/sz128051.html
    # 正股: https://quote.eastmoney.com/sz002741.html
    prefix = ''
    prefix_append = ''
    suffix = ''
    if head_column_link_maker is not None and head_column_link_maker(
            record, field) is not None:
        return "<a href='" + head_column_link_maker(record,
                                                    field) + "'>", "</a>", ""
    elif field == '名称':
        bond_code = record.get('bond_code')
        if bond_code is None:
            return None, None, None
        new_bond_code = rebuild_bond_code(bond_code)
        nid = record['nid']
        stock_code = record['stock_code']
        market = 'sz'
        if bond_code.startswith('11'):
            market = 'sh'
        prefix = "<a href = 'javascript:void(0)' onclick=\"popWin.showWin('1200','600', '" + new_bond_code + "');return false\"" + ">"

        prefix_append += "</a>&nbsp;<a target='_blank' href='http://www.ninwin.cn/index.php?m=cb&c=detail&a=detail&id=" + str(
            nid
        ) + "'><img src='/static/img/nw.png' alt='宁稳网' title='宁稳网查看转债信息' width='14' height='14' class='site-link'/></a>"

        prefix_append += "&nbsp;<a target = '_blank' href = 'https://xueqiu.com/S/" + market + bond_code + "'><img src='/static/img/xueqiu.png' alt='雪球' title='雪球查看转债讨论' width='14' height='14' class='site-link'/></a>"

        # https://xueqiu.com/S/SH600998
        suffix = "<br/>"
        if stock_code is not None:
            suffix += "<a target='_blank' href='https://quote.eastmoney.com/" + market + stock_code + ".html'><img src='/static/img/eastmoney.png' alt='东方财富' title='东方财富查看正股信息' width='14' height='14' class='next-site-link'/></a> "
            suffix += "<a target='_blank' href='http://doctor.10jqka.com.cn/" + stock_code + "/'><img src='/static/img/ths.png' alt='同花顺' title='同花顺正股诊断' width='14' height='14' class='next-site-link'/></a>"

        # http://www.ninwin.cn/index.php?m=cb&c=graph_k&a=graph_k&id=157
        suffix += "&nbsp;<a target='_blank' href='http://www.ninwin.cn/index.php?m=cb&c=graph_k&a=graph_k&id=" + str(
            nid
        ) + "'><img src='/static/img/trend.png' alt='走势图' title='宁稳网查看转债&正股走势(非会员20次/天)' width='14' height='14' class='next-site-link'/></a>"

        if is_login_user:
            hold_id = record.get('hold_id', None)
            id = record.get('id', None)
            if edit_link_maker is None:
                edit_link_maker = default_edit_link_maker

            suffix += edit_link_maker(id, hold_id, bond_code)
            suffix += "&nbsp;<a href='/view_my_trade_history.html/" + bond_code + "/'><img src='/static/img/detail.png' alt='交易明细' title='交易明细' width='14' height='14' class='next-site-link'/></a>"
    return prefix, prefix_append, suffix
Exemple #2
0
def generate_bar_html(rows, title):
    xx1 = []
    xx2 = []
    yy1 = []
    yy2 = []

    count = 0
    for row in rows:
        count += 1
        bond_code = row[0]
        bond_code = trade_utils.rebuild_bond_code(bond_code)
        if count <= 20:
            xx1.append(row[1].replace('转债', ''))
            yy1.append({'value': row[2], 'bond_code': bond_code, 'price': row[3], 'premium': row[4], 'name': row[1]})
        else:
            xx2.append(row[1].replace('转债', ''))
            yy2.append({'value': row[2], 'bond_code': bond_code, 'price': row[3], 'premium': row[4], 'name': row[1]})
    max_value = 0
    size = len(yy1)

    for i in range(size):
        if yy1[i]['value'] + abs(yy2[i]['value']) > max_value:
            max_value = yy1[i]['value'] + abs(yy2[i]['value'])

    max_value = round(max_value * 1.1, 2) + 1

    chart_id = str(abs(hash(title)))
    bar = Bar(init_opts=opts.InitOpts(height='700px', width='1424px', theme=ThemeType.SHINE, chart_id=chart_id))
    view_utils.add_popwin_js_code(bar, chart_id)
    # 底部x轴
    bar.add_xaxis(xx1)
    # 顶部x轴
    bar.extend_axis(
        xaxis_data=xx2,
        xaxis=opts.AxisOpts(
            type_="category",
            position='top',
            axislabel_opts=opts.LabelOpts(
                rotate=-60,
            )
        ),
    )
    # 右侧y轴
    bar.extend_axis(
        yaxis=opts.AxisOpts(
            type_="value",
            position="right",
            name='跌幅(%)',
            name_gap=45,
            name_location='middle',
            min_=-max_value,
            axisline_opts=opts.AxisLineOpts(
                linestyle_opts=opts.LineStyleOpts(
                    is_show=True,

                )
            ),
            axislabel_opts=opts.LabelOpts(formatter="{value}%"),
        )
    )
    # 添加涨的柱状图
    bar.add_yaxis("涨", yy1,
                  bar_width=25,
                  category_gap='1%',
                  gap='1%',
                  label_opts=opts.LabelOpts(
                      position="top",
                      formatter=JsCode(
                          "function(x){return x.data['value'] +'%';}"
                      )
                  ),
                  )
    # 添加跌的柱状图
    bar.add_yaxis("跌",
                  yy2,
                  bar_width=25,
                  yaxis_index=1,
                  label_opts=opts.LabelOpts(
                      position="bottom",
                      formatter=JsCode(
                          "function(x){return x.data['value'] +'%';}"
                      )
                  ),
                  )
    # bar.reversal_axis()
    bar.set_series_opts(
        itemstyle_opts=opts.ItemStyleOpts(
            color=JsCode(
                "function(x){return x.data['value']>0?'#c23531':'#1d953f'}"
            )
        )
    )
    bar.set_global_opts(
        title_opts=opts.TitleOpts(
            title="=========" + title + "=========",
            pos_left='center',
            pos_top='-1px',
        ),
        tooltip_opts=opts.TooltipOpts(
            is_show=True,
            formatter=JsCode("function (params){return '名&nbsp;&nbsp;&nbsp;称: ' + params.data['name'] + '<br/>' + '价&nbsp;&nbsp;&nbsp;格: ' + params.data['price'] + '元<br/>' + '溢价率: ' + params.data['premium']}")
        ),
        legend_opts=opts.LegendOpts(is_show=False),
        xaxis_opts=opts.AxisOpts(
            # data=None,
            # type_='category',
            # name_gap=0,
            # name_rotate=90,
            axislabel_opts=opts.LabelOpts(
                rotate=-60,
            ),
            is_scale=True,
            name_location='middle',
            splitline_opts=opts.SplitLineOpts(is_show=False),
            axisline_opts=opts.AxisLineOpts(
                is_on_zero=True,
                # symbol=['none', 'arrow']
            )
        ),
        yaxis_opts=opts.AxisOpts(
            type_='value',
            name='涨幅(%)',
            # name_rotate=90,
            name_gap=35,
            name_location='middle',
            # min_=0,
            max_=max_value,
            is_scale=True,
            axislabel_opts=opts.LabelOpts(formatter='{value}%'),
            splitline_opts=opts.SplitLineOpts(is_show=False),
            axisline_opts=opts.AxisLineOpts(
                is_on_zero=False,
                # symbol=['none', 'arrow']
            )
        ),
    )

    bar_html = bar.render_embed('template.html', html_utils.env)
    return bar_html
Exemple #3
0
def generate_scatter_html_with_multi_tables(tables,
                                            title="可转债分布情况",
                                            subtitle=None,
                                            select=None,
                                            use_personal_features=True,
                                            price_field_name='转债价格'):
    chart_id = str(abs(hash(title)))
    scatter = Scatter(
        opts.InitOpts(height='700px',
                      width='1424px',
                      theme=ThemeType.LIGHT,
                      chart_id=chart_id))
    scatter.add_js_funcs('chart_' + chart_id +
                         """.on('click', function(params){
            // alert(params)
            popWin.showWin("1200","600", params['data']['value'][3]);
        })
    """)

    for label, table in tables.items():
        if select is not None and label not in select:
            continue

        x = []
        y = []

        point_items = []
        rows = table._rows
        for row in rows:
            record = get_record(table, row)
            if record['溢价率'] is None:
                continue

            x1 = record[price_field_name]
            x.append(x1)
            y1 = record['溢价率'].replace('%', '') * 1
            amount = record.get("持有数量", 0)
            bond_name = record['名称'].replace('转债', '')
            bond_code = record['bond_code']
            bond_code = trade_utils.rebuild_bond_code(bond_code)
            y.append([y1])

            # todo symbol 轮出:triangle 轮入:diamond
            if use_personal_features and record.get(
                    'hold_id') is not None and amount > 0:
                point_items.append(
                    opts.MarkPointItem(
                        coord=[x1, y1],
                        symbol_size=amount,
                        itemstyle_opts=opts.ItemStyleOpts(
                            opacity=0.5,
                            border_color='#000',
                            border_width=1,
                        ),
                        value=[bond_name, x1, y1, bond_code, amount]))
            else:
                point_items.append(
                    opts.MarkPointItem(
                        coord=[x1, y1],
                        # symbol_size=symbol_size,
                        itemstyle_opts=opts.ItemStyleOpts(
                            # color='#fff',
                            # border_color='#000'
                        ),
                        value=[bond_name, x1, y1, bond_code]))

        scatter.add_xaxis(x)

        scatter.add_yaxis(
            label,
            y,
            label_opts=opts.LabelOpts(is_show=False),
            markpoint_opts=opts.MarkPointOpts(
                symbol='circle',
                symbol_size=10,
                data=point_items,
                label_opts=opts.LabelOpts(
                    position='bottom',
                    formatter=JsCode(
                        'function(params){return params.value[0]}'))),
            markline_opts=opts.MarkLineOpts(
                linestyle_opts=opts.LineStyleOpts(type_='dashed'),
                is_silent=True,
                label_opts=opts.LabelOpts(
                    position='end',
                    formatter=JsCode(
                        "function(params){return params.data['name'];}")),
                data=[
                    opts.MarkLineItem(x=utils.trade_utils.MID_X,
                                      name='中位数(' +
                                      str(utils.trade_utils.MID_X) + '元)'),
                    opts.MarkLineItem(y=utils.trade_utils.MID_Y,
                                      name='中位数(' +
                                      str(utils.trade_utils.MID_Y) + '%)'),
                ]))

    # scatter.add_xaxis(x)

    scatter.set_global_opts(
        title_opts=opts.TitleOpts(title=title,
                                  subtitle=subtitle,
                                  pos_left='center'),
        tooltip_opts=opts.TooltipOpts(formatter=get_hover_js_code()),
        legend_opts=opts.LegendOpts(pos_bottom=-5,
                                    # selected_mode='single'
                                    ),
        toolbox_opts=opts.ToolboxOpts(feature={
            'dataZoom': {},
        }),
        # visualmap_opts=opts.VisualMapOpts(
        #     type_="color", max_=150, min_=20, dimension=1
        # ),
        xaxis_opts=opts.AxisOpts(
            # data=None,
            type_='value',
            name='转债价格(元)',
            name_gap=30,
            is_scale=True,
            name_location='middle',
            splitline_opts=opts.SplitLineOpts(is_show=False),
            axislabel_opts=opts.LabelOpts(formatter='{value}元'),
            axisline_opts=opts.AxisLineOpts(is_on_zero=False,
                                            symbol=['none', 'arrow'])),
        yaxis_opts=opts.AxisOpts(
            type_='value',
            name='转股溢价率(%)',
            name_rotate=90,
            name_gap=35,
            name_location='middle',
            is_scale=True,
            axislabel_opts=opts.LabelOpts(formatter='{value}%'),
            splitline_opts=opts.SplitLineOpts(is_show=False),
            axisline_opts=opts.AxisLineOpts(is_on_zero=False,
                                            symbol=['none', 'arrow'])))
    scatter_html = scatter.render_embed('template.html', env)
    return scatter_html
Exemple #4
0
def generate_scatter_html_with_one_table(
    table,
    title=None,
    sub_title='',
    draw_figure=True,
    field_name='溢价率',
    get_label=default_get_label,
    label_y='转股溢价率(%)',
    use_personal_features=False,
    hover_maker=None,
    click_maker=None,
    hover_content_field=None,
):
    x = []
    y = []
    point_items = []
    for row in table._rows:
        record = db_utils.get_record(table, row)

        x1 = record['转债价格']
        bond_code = record['bond_code']
        bond_code = trade_utils.rebuild_bond_code(bond_code)
        x.append(x1)
        field_value = record[field_name]
        y1 = float(field_value.replace('%', ''))
        y.append(y1)

        hover_content = None
        if hover_content_field is not None:
            hover_content = record[hover_content_field]

        if use_personal_features and record.get('hold_id') is not None:
            amount = record.get("持有数量", 0)
            point_items.append(
                opts.MarkPointItem(coord=[x1, y1],
                                   symbol_size=amount,
                                   itemstyle_opts=opts.ItemStyleOpts(
                                       opacity=0.5,
                                       border_color='#000',
                                       border_width=1,
                                   ),
                                   value=[
                                       get_label(record), x1, y1, bond_code,
                                       amount, hover_content
                                   ]))
        else:
            point_items.append(
                opts.MarkPointItem(
                    coord=[x1, y1],
                    itemstyle_opts=opts.ItemStyleOpts(border_color='#000'),
                    value=[
                        get_label(record), x1, y1, bond_code, None,
                        hover_content
                    ]))

    if draw_figure is False:
        return ''

    return create_scatter(title,
                          sub_title,
                          field_name,
                          label_y,
                          point_items,
                          x,
                          y,
                          hover_maker=hover_maker,
                          click_maker=click_maker)