Exemplo n.º 1
0
def make_image(data, filepath, title, labels, major_labels):
    custom_style = Style(background='#fff',
                         plot_background='transparent',
                         title_font_size=14,
                         guide_stroke_dasharray='1,0',
                         major_guide_stroke_dasharray='1,0',
                         foreground='rgba(0, 0, 0, .87)',
                         foreground_strong='rgba(0, 0, 0, .87)',
                         foreground_subtle='rgba(0, 0, 0, .87)',
                         stroke_opacity='1',
                         stroke_opacity_hover='1',
                         stroke_width=10,
                         stroke_width_hover=10,
                         opacity='1',
                         opacity_hover='1',
                         colors=('#C5D4B5BB', '#3D7930'))
    print(custom_style.to_dict())

    r = get_range(data)

    config = Config()
    config.interpolate = 'cubic'
    config.style = custom_style
    config.width = 400
    config.height = 225
    config.explicit_size = True
    config.margin_left = 0
    config.margin_right = 0
    config.margin_top = 10
    config.margin_bottom = 30
    config.show_minor_x_labels = False
    config.truncate_label = -1
    config.show_legend = False
    config.include_x_axis = True
    config.range = r
    config.show_dots = False

    chart = pygal.Line(config)
    chart.title = ("Throughput (%s, Mb/s)" % (title))
    chart.x_labels = labels
    chart.x_labels_major = major_labels
    chart.y_labels = [
        x for x in range(0, r[1] + 1, 100 if (r[1] > 550) else 50)
    ]
    chart.add(None, data, fill=True)
    chart.add(None, data)
    #with open(filepath, 'w') as output:
    #  output.write(chart.render())
    chart.render_to_png(filepath)
Exemplo n.º 2
0
def draw_line(valxy):
    import pygal
    from pygal import Config
    from pygal.style import Style
    config = Config()
    custom_style = Style(background='white',
                         foreground='#000',
                         foreground_strong='#000',
                         foreground_subtle='#000',
                         opacity='.9',
                         opacity_hover='.6',
                         plot_background='#fff',
                         transition='100ms',
                         label_font_size=12,
                         major_label_font_size=12,
                         value_font_family='Arial',
                         font_family='Arial',
                         major_label_font_family='Sans',
                         colors=('#3333CC', '#3333CC', '#3333CC', '#3333CC'),
                         guide_stroke_dasharray='2,7',
                         major_guide_stroke_dasharray='2,7')
    config.margin_left = 0
    config.margin_bottom = 0
    config.width = 350
    config.height = 350
    config.x_title = "Angle, degrees"
    config.y_title = "Overlaps, %"
    config.explicit_size = True
    config.show_x_guides = False
    config.show_y_guides = True
    xy_chart = pygal.XY(config,
                        show_legend=False,
                        dots_size=3,
                        style=custom_style)  #interpolate='quadratic',
    #xy_chart.title = "Overlaps in oscillation range"
    xy_chart.add('', valxy)
    #xy_chart.y_labels = [int(phibg), int(phend)]
    # col=20
    # stp=1
    # for val in range(int(phibg), int(phend), stp):
    #     xy_chart.add("", [{'value': val, 'color': 'rgb(%s, 0, 0)' % (col)}],
    #                   stroke_style={'width': 1, 'linejoin': 'round', 'linecap': 'round', 'linejoin': 'round'})
    #     col=col+stp

    return xy_chart.render(is_unicode=True)
Exemplo n.º 3
0
    def get(self):
        self._context.error = ''
        step = self.get_argument("step", 0)
        self._context.next = self.get_next_url()
        #获取用户uid
        user_info = None
        uid = self.get_secure_cookie('uid', None)
        if (step == '1' or step == '2' or step == '3'
                or step == 'end') and (not uid):
            self.redirect('/reg/?step=0')
            return
        else:
            #获取用户信息
            user_info = self.user.getItem(uid)
        if urlparse.urlparse(self._context.next).path == '/reg':
            self._context.next = '/index'
        if step == '0':
            self.assignDirection()
            if uid:
                self._context.user_info = user_info
                self._context.area = ','.join(
                    self.d.getDistrictParents(user_info['area_id'], res=[]))
            else:
                self._context.user_info = None
            self._handler_template = 'user/reg.html'
        elif step == '1':
            #判断用户是否保存到cookie中
            if not uid:
                self.redirect('/reg/?step=0')
            #获取用户信息
            user_info = self.user.getItem(uid)
            self._context.user_info = user_info
            self._context.user_email = user_info['user_email']
            #判断是否给用户发送了邮件
            self._context.is_send = True
            uv = UserVerify()
            uv_info = uv.getVerifyInfo(uid)
            if uv_info:
                #不需要发送邮件
                self._context.is_send = False
                #验证url没有过期
                now = int(time.mktime(datetime.datetime.now().timetuple()))
                if user_info[
                        'is_verify'] != 1 and utiles.formateDateToTimestamp(
                            uv_info['verify_expire_time']) > now:
                    self._context.error = ErrorMessage.error_message['016']
                elif user_info[
                        'is_verify'] != 1 and utiles.formateDateToTimestamp(
                            uv_info['verify_expire_time']) <= now:
                    self._context.is_send = True
            self._handler_template = 'user/reg_step_1.html'

        elif step == '2':
            #判断是否给用户发送了邮件
            ret = self.checkTokenUrl(uid)
            self._context.is_send = True if ret['code'] == 'success' else False
            if ret['code'] == 'error':
                self._context.error = ret['msg']
                self._handler_template = 'user/reg_step_1.html'
            else:
                list = self.getChaList()
                self._context.list = list
                self._context.ids = ','.join(
                    [str(item['id']) for item in list])
                self._handler_template = 'user/reg_step_2.html'

        elif step == '3':
            ut = UserBfiTest()
            ut_info = ut.queryOne(filterString=[('uid', uid)],
                                  fields=ut._table_columns)
            if ut_info:
                #获取性格测试平均值
                sysconfig = SysConfig()
                bfi_vals = sysconfig.getConfig('bfi_total')
                bfi_user_total = int(
                    sysconfig.getConfig('bfi_user_total')['val'])

                #建立雷达图
                config = Config()
                config.explicit_size = True
                config.width = 500
                config.height = 450
                config.label_font_size = 14
                config.x_label_rotation = 1
                radar_chart = pygal.Radar(config)
                radar_chart.title = u'人格初测结果'
                radar_chart.x_labels = [
                    u'开放性O', u'神经质N', u'宜人性A', u'外向型E', u'尽职性C'
                ]
                radar_chart.add(user_info['user_name'], [
                    int(ut_info['O_val']),
                    int(ut_info['N_val']),
                    int(ut_info['A_val']),
                    int(ut_info['E_val']),
                    int(ut_info['C_val'])
                ])
                radar_chart.add(u'平均值', [
                    bfi_vals['O'] / bfi_user_total, bfi_vals['N'] /
                    bfi_user_total, bfi_vals['A'] / bfi_user_total,
                    bfi_vals['E'] / bfi_user_total,
                    bfi_vals['C'] / bfi_user_total
                ])
                self._context.radar = radar_chart.render()
                #评价
                self._context.N_msg = BfiCharacterTest.transform(
                    'N', int(ut_info['N_val']))[0]
                self._context.O_msg = BfiCharacterTest.transform(
                    'O', int(ut_info['O_val']))[0]
                self._context.A_msg = BfiCharacterTest.transform(
                    'A', int(ut_info['A_val']))[0]
                self._context.E_msg = BfiCharacterTest.transform(
                    'E', int(ut_info['E_val']))[0]
                self._context.C_msg = BfiCharacterTest.transform(
                    'C', int(ut_info['C_val']))[0]
                #从人格特点推荐好友

                #活动推荐

            else:
                self._context.radar = None

            self._handler_template = 'user/reg_step_3.html'

        #跳转到活动列表页
        elif step == 'end':
            self.redirect('/activity')

        self.render(self._handler_template)
        return