当前位置: 首页>>代码示例>>Python>>正文


Python SimpleLineChart.fill_solid方法代码示例

本文整理汇总了Python中pygooglechart.SimpleLineChart.fill_solid方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleLineChart.fill_solid方法的具体用法?Python SimpleLineChart.fill_solid怎么用?Python SimpleLineChart.fill_solid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygooglechart.SimpleLineChart的用法示例。


在下文中一共展示了SimpleLineChart.fill_solid方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _partyline

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import fill_solid [as 别名]
    def _partyline(self, party_results):
        if self.request.GET.get('percentages') == 'true':
            key = 'percentage'
        else:
            key = 'count'

        maxcount = 0
        allcounts = []
        granularity = self.request.GET.get('granularity')
        months = []

        for party, results in party_results.iteritems():
            counts = [x.get(key) for x in results['results']]
            allcounts.append(counts)
            if max(counts) > maxcount:
                maxcount = max(counts)

            if granularity == 'month':
                months = [x['month'] for x in results['results']]
                januaries = [x for x in months if x.endswith('01')]
                january_indexes = [months.index(x) for x in januaries]
                january_percentages = [int((x / float(len(months))) * 100) for x in january_indexes]

            #times = [x.get(granularity) for x in results['results']]

        width = int(self.request.GET.get('width', 575))
        height = int(self.request.GET.get('height', 318))
        chart = SimpleLineChart(width, height, y_range=(0, max(counts)))

        chart.fill_solid('bg', '00000000')  # Make the background transparent
        chart.set_grid(0, 50, 2, 5)  # Set gridlines

        if granularity == 'month':
            index = chart.set_axis_labels(Axis.BOTTOM, [x[:4] for x in januaries[::2]])
            chart.set_axis_positions(index, [x for x in january_percentages[::2]])

        if key == 'percentage':
            label = '%.4f' % maxcount
        else:
            label = int(maxcount)
        index = chart.set_axis_labels(Axis.LEFT, [label, ])
        chart.set_axis_positions(index, [100, ])

        for n, counts in enumerate(allcounts):
            chart.add_data(counts)
            chart.set_line_style(n, thickness=2)  # Set line thickness

        colors = {'R': 'bb3110', 'D': '295e72', }
        chart_colors = []
        chart_legend = []
        for k in party_results.keys():
            chart_colors.append(colors.get(k, '000000'))
            chart_legend.append(k)
            chart.legend_position = 'b'

        chart.set_colours(chart_colors)

        if self.request.GET.get('legend', 'true') != 'false':
            chart.set_legend(chart_legend)
        return chart.get_url()
开发者ID:notthatbreezy,项目名称:Capitol-Words,代码行数:62,代码来源:views.py

示例2: show

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import fill_solid [as 别名]
def show(request, isa_id):
    isa = get_object_or_404(ISA, pk=isa_id)
    isafunds = isa.isafund_set.all()
    start_date = isa.created
    end_date = date.today()
    current_date = start_date
    data = []
    while current_date <= end_date:
        value = 0
        for isafund in isafunds:
            try:
                fundprice = isafund.fund.fundprice_set.get(date=current_date)
                value += fundprice.price * isafund.quantity
            except FundPrice.DoesNotExist:
                pass
        data.append(value)
        current_date += timedelta(1)
    chart = SimpleLineChart(500, 200, y_range=[min(data), max(data)])
    chart.add_data(data)
    chart.add_data([data[0], data[0]])
    chart.set_colours(['0000FF', 'AAAAAA'])
    chart.fill_solid('bg', 'DDDDFF')
    chart.set_axis_labels(Axis.LEFT, [int(min(data)), int(max(data))])
    chart.set_axis_labels(Axis.BOTTOM, [start_date, end_date])
    url = chart.get_url()
    return render_to_response('isas/show.html', {'isa': isa, 'chart_url': url})
开发者ID:adamgreig,项目名称:isatracker,代码行数:28,代码来源:views.py

示例3: group

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import fill_solid [as 别名]
def group(request, group_id):
    group = get_object_or_404(GroupedMessage, pk=group_id)

    message_list = group.message_set.all()
    
    obj = message_list.order_by('-id')[0]
    if '__sentry__' in obj.data:
        module, args, frames = obj.data['__sentry__']['exc']
        obj.class_name = str(obj.class_name)
        # We fake the exception class due to many issues with imports/builtins/etc
        exc_type = type(obj.class_name, (Exception,), {})
        exc_value = exc_type(obj.message)

        exc_value.args = args
    
        reporter = ImprovedExceptionReporter(obj.request, exc_type, exc_value, frames, obj.data['__sentry__'].get('template'))
        traceback = mark_safe(reporter.get_traceback_html())
    elif group.traceback:
        traceback = mark_safe('<pre>%s</pre>' % (group.traceback,))
    
    unique_urls = message_list.filter(url__isnull=False).values_list('url', 'logger', 'view', 'checksum').annotate(times_seen=Count('url')).values('url', 'times_seen').order_by('-times_seen')
    
    unique_servers = message_list.filter(server_name__isnull=False).values_list('server_name', 'logger', 'view', 'checksum').annotate(times_seen=Count('server_name')).values('server_name', 'times_seen').order_by('-times_seen')

    def iter_data(obj):
        for k, v in obj.data.iteritems():
            if k.startswith('_') or k in ['url']:
                continue
            yield k, v
    
    json_data = iter_data(obj)
    
    # TODO: this should be a template tag
    engine = get_db_engine()
    if SimpleLineChart and not engine.startswith('sqlite'):
        today = datetime.datetime.now()

        chart_qs = message_list\
                          .filter(datetime__gte=today - datetime.timedelta(hours=24))\
                          .extra(select={'hour': 'extract(hour from datetime)'}).values('hour')\
                          .annotate(num=Count('id')).values_list('hour', 'num')

        rows = dict(chart_qs)
        if rows:
            max_y = max(rows.values())
        else:
            max_y = 1

        chart = SimpleLineChart(300, 80, y_range=[0, max_y])
        chart.add_data([max_y]*30)
        chart.add_data([rows.get((today-datetime.timedelta(hours=d)).hour, 0) for d in range(0, 24)][::-1])
        chart.add_data([0]*30)
        chart.fill_solid(chart.BACKGROUND, 'eeeeee')
        chart.add_fill_range('eeeeee', 0, 1)
        chart.add_fill_range('e0ebff', 1, 2)
        chart.set_colours(['eeeeee', '999999', 'eeeeee'])
        chart.set_line_style(1, 1)
        chart_url = chart.get_url()
    
    return render_to_response('sentry/group/details.html', locals())
开发者ID:texastribune,项目名称:django-sentry,代码行数:62,代码来源:views.py

示例4: _line

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import fill_solid [as 别名]
    def _line(self, results):
        key = 'count'
        if self.request.GET.get('percentages') == 'true':
            key = 'percentage'
        counts = [x.get(key) for x in results]
        maxcount = max(counts)

        granularity = self.request.GET.get('granularity')
        times = [x.get(granularity) for x in results]

        width = int(self.request.GET.get('width', 575))
        height = int(self.request.GET.get('height', 300))
        chart = SimpleLineChart(width, height, y_range=(0, max(counts)))
        chart.add_data(counts)
        chart.set_line_style(0, thickness=2)  # Set line thickness
        chart.set_colours(['E0B300', ])
        chart.fill_solid('bg', '00000000')  # Make the background transparent
        chart.set_grid(0, 50, 2, 5)  # Set gridlines

        if self.request.GET.get('granularity') == 'month':
            months = [x['month'] for x in results]
            januaries = [x for x in months if x.endswith('01')]
            january_indexes = [months.index(x) for x in januaries]
            january_percentages = [int((x / float(len(months))) * 100) for x in january_indexes]
            index = chart.set_axis_labels(Axis.BOTTOM, [x[:4] for x in januaries[::2]])
            chart.set_axis_positions(index, [x for x in january_percentages[::2]])

        if key == 'percentage':
            label = '%.4f' % maxcount
            label += '%'
        else:
            label = int(maxcount)
        index = chart.set_axis_labels(Axis.LEFT, [label, ])
        chart.set_axis_positions(index, [100, ])

        if self.request.GET.get('legend', 'true') != 'false':
            chart.set_legend([self.request.GET.get('phrase'), ])

        return chart.get_url()
开发者ID:notthatbreezy,项目名称:Capitol-Words,代码行数:41,代码来源:views.py

示例5: group_message_list

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import fill_solid [as 别名]
def group_message_list(request, group_id):
    group = get_object_or_404(GroupedMessage, pk=group_id)

    message_list = group.message_set.all().order_by('-datetime')
    
    unique_urls = message_list.filter(url__isnull=False).values_list('url', 'logger', 'view', 'checksum').annotate(times_seen=Count('url')).values('url', 'times_seen').order_by('-times_seen')
    
    unique_servers = message_list.filter(server_name__isnull=False).values_list('server_name', 'logger', 'view', 'checksum').annotate(times_seen=Count('server_name')).values('server_name', 'times_seen').order_by('-times_seen')
    
    engine = get_db_engine()
    if SimpleLineChart and not engine.startswith('sqlite'):
        today = datetime.datetime.now()

        chart_qs = message_list\
                          .filter(datetime__gte=today - datetime.timedelta(hours=24))\
                          .extra(select={'hour': 'extract(hour from datetime)'}).values('hour')\
                          .annotate(num=Count('id')).values_list('hour', 'num')

        rows = dict(chart_qs)
        if rows:
            max_y = max(rows.values())
        else:
            max_y = 1

        chart = SimpleLineChart(300, 80, y_range=[0, max_y])
        chart.add_data([max_y]*30)
        chart.add_data([rows.get((today-datetime.timedelta(hours=d)).hour, 0) for d in range(0, 24)][::-1])
        chart.add_data([0]*30)
        chart.fill_solid(chart.BACKGROUND, 'eeeeee')
        chart.add_fill_range('eeeeee', 0, 1)
        chart.add_fill_range('e0ebff', 1, 2)
        chart.set_colours(['eeeeee', '999999', 'eeeeee'])
        chart.set_line_style(1, 1)
        chart_url = chart.get_url()
    
    page = 'messages'
    
    return render_to_response('sentry/group/message_list.html', locals())
开发者ID:texastribune,项目名称:django-sentry,代码行数:40,代码来源:views.py

示例6: chart_url

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import fill_solid [as 别名]
def chart_url(group):
    today = datetime.datetime.now()

    chart_qs = group.message_set.all()\
                      .filter(datetime__gte=today - datetime.timedelta(hours=24))\
                      .extra(select={'hour': 'extract(hour from datetime)'}).values('hour')\
                      .annotate(num=Count('id')).values_list('hour', 'num')

    rows = dict(chart_qs)
    if rows:
        max_y = max(rows.values())
    else:
        max_y = 1

    chart = SimpleLineChart(300, 80, y_range=[0, max_y])
    chart.add_data([max_y]*30)
    chart.add_data([rows.get((today-datetime.timedelta(hours=d)).hour, 0) for d in range(0, 24)][::-1])
    chart.add_data([0]*30)
    chart.fill_solid(chart.BACKGROUND, 'eeeeee')
    chart.add_fill_range('eeeeee', 0, 1)
    chart.add_fill_range('e0ebff', 1, 2)
    chart.set_colours(['eeeeee', '999999', 'eeeeee'])
    chart.set_line_style(1, 1)
    return chart.get_url()
开发者ID:indro,项目名称:django-sentry,代码行数:26,代码来源:sentry_helpers.py

示例7: index

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import fill_solid [as 别名]
def index(request):
    logger_names = SortedDict((l, l) for l in GroupedMessage.objects.values_list("logger", flat=True).distinct())
    server_names = SortedDict((l, l) for l in Message.objects.values_list("server_name", flat=True).distinct())
    level_names = SortedDict((str(k), v) for k, v in LOG_LEVELS)

    logger = request.GET.get("logger")
    server_name = request.GET.get("server_name") or ""
    level = request.GET.get("level") or ""

    try:
        page = int(request.GET.get("p", 1))
    except (TypeError, ValueError):
        page = 1

    realtime = page == 1

    if logger not in logger_names:
        logger = ""

    if server_name not in server_names:
        server_name = ""

    if level not in level_names:
        level = ""

    # this only works in postgres
    message_list = (
        GroupedMessage.objects.filter(status=0)
        .extra(
            select={"score": "times_seen / (pow((floor(extract(epoch from now() - last_seen) / 3600) + 2), 1.25) + 1)"}
        )
        .order_by("-score", "-last_seen")
    )

    today = datetime.datetime.now()

    chart_qs = (
        Message.objects.filter(datetime__gte=today - datetime.timedelta(hours=24))
        .extra(select={"hour": "extract(hour from datetime)"})
        .values("hour")
        .annotate(num=Count("id"))
        .values_list("hour", "num")
    )

    if logger:
        message_list = message_list.filter(logger=logger)
        chart_qs = chart_qs.filter(logger=logger)

    if level:
        message_list = message_list.filter(level=level)
        chart_qs = chart_qs.filter(level=level)

    if server_name:
        message_list = message_list.filter(message_set__server_name=server_name).distinct()
        chart_qs = chart_qs.filter(server_name=server_name)

    rows = dict(chart_qs)
    if rows:
        max_y = max(rows.values())
    else:
        max_y = 1

    if SimpleLineChart:
        chart = SimpleLineChart(384, 80, y_range=[0, max_y])
        chart.add_data([max_y] * 30)
        chart.add_data([rows.get((today - datetime.timedelta(hours=d)).hour, 0) for d in range(0, 24)][::-1])
        chart.add_data([0] * 30)
        chart.fill_solid(chart.BACKGROUND, "eeeeee")
        chart.add_fill_range("eeeeee", 0, 1)
        chart.add_fill_range("e0ebff", 1, 2)
        chart.set_colours(["eeeeee", "999999", "eeeeee"])
        chart.set_line_style(1, 1)
        chart_url = chart.get_url()

    return render_to_response("sentry/index.html", locals())
开发者ID:justquick,项目名称:django-sentry,代码行数:77,代码来源:views.py

示例8: group

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import fill_solid [as 别名]
def group(request, group_id):
    group = GroupedMessage.objects.get(pk=group_id)

    message_list = group.message_set.all()

    obj = message_list[0]
    if "__sentry__" in obj.data:
        module, args, frames = obj.data["__sentry__"]["exc"]
        obj.class_name = str(obj.class_name)
        # We fake the exception class due to many issues with imports/builtins/etc
        exc_type = type(obj.class_name, (Exception,), {})
        exc_value = exc_type(obj.message)

        exc_value.args = args

        fake_request = FakeRequest()
        fake_request.META = obj.data.get("META", {})
        fake_request.GET = obj.data.get("GET", {})
        fake_request.POST = obj.data.get("POST", {})
        fake_request.FILES = obj.data.get("FILES", {})
        fake_request.COOKIES = obj.data.get("COOKIES", {})
        fake_request.url = obj.url
        if obj.url:
            fake_request.path_info = "/" + obj.url.split("/", 3)[-1]
        else:
            fake_request.path_info = ""

        reporter = ImprovedExceptionReporter(
            fake_request, exc_type, exc_value, frames, obj.data["__sentry__"].get("template")
        )
        traceback = mark_safe(reporter.get_traceback_html())
    else:
        traceback = mark_safe("<pre>%s</pre>" % (group.traceback,))

    unique_urls = (
        message_list.filter(url__isnull=False)
        .values_list("url", "logger", "view", "checksum")
        .annotate(times_seen=Count("url"))
        .values("url", "times_seen")
        .order_by("-times_seen")
    )

    unique_servers = (
        message_list.filter(server_name__isnull=False)
        .values_list("server_name", "logger", "view", "checksum")
        .annotate(times_seen=Count("server_name"))
        .values("server_name", "times_seen")
        .order_by("-times_seen")
    )

    today = datetime.datetime.now()

    chart_qs = (
        message_list.filter(datetime__gte=today - datetime.timedelta(hours=24))
        .extra(select={"hour": "extract(hour from datetime)"})
        .values("hour")
        .annotate(num=Count("id"))
        .values_list("hour", "num")
    )

    rows = dict(chart_qs)
    if rows:
        max_y = max(rows.values())
    else:
        max_y = 1

    if SimpleLineChart:
        chart = SimpleLineChart(384, 80, y_range=[0, max_y])
        chart.add_data([max_y] * 30)
        chart.add_data([rows.get((today - datetime.timedelta(hours=d)).hour, 0) for d in range(0, 24)][::-1])
        chart.add_data([0] * 30)
        chart.fill_solid(chart.BACKGROUND, "eeeeee")
        chart.add_fill_range("eeeeee", 0, 1)
        chart.add_fill_range("e0ebff", 1, 2)
        chart.set_colours(["eeeeee", "999999", "eeeeee"])
        chart.set_line_style(1, 1)
        chart_url = chart.get_url()

    return render_to_response("sentry/group.html", locals())
开发者ID:justquick,项目名称:django-sentry,代码行数:81,代码来源:views.py

示例9: read

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import fill_solid [as 别名]
    def read(self, request, *args, **kwargs):
        self.request = request
        if kwargs.get('chart_type') == 'timeline':
            handler = PhraseOverTimeHandler()
            if request.GET.get('split_by_party') == 'true':
                resultsets = {}
                for party in ['R', 'D', ]:
                    kwargs['party'] = party
                    resultsets[party] = handler.read(request, *args, **kwargs)
                return {'results': {'url': self._partyline(resultsets), }, }

            elif request.GET.get('compare') == 'true':
                phrases = request.GET.get('phrases', '').split(',')[:5]  # Max of 5 phrases
                parties = request.GET.get('parties', '').split(',')
                states = request.GET.get('states', '').split(',')
                #chambers = request.GET.get('chambers', '').split(',')

                colors = ['8E2844', 'A85B08', 'AF9703', ]

                metadata = []
                legend_items = []
                months = None

                key = 'count'
                if self.request.GET.get('percentages') == 'true':
                    key = 'percentage'

                granularity = self.request.GET.get('granularity')

                width = int(request.GET.get('width', 575))
                height = int(request.GET.get('height', 300))
                chart = SimpleLineChart(width, height)
                chart.set_grid(0, 50, 2, 5)  # Set gridlines
                chart.fill_solid('bg', '00000000')  # Make the background transparent
                chart.set_colours(colors)
                maxcount = 0

                # Use phrases as a baseline; that is, assume that
                # there's a corresponding value for the other filters.
                # If a filter doesn't have as many values as the number
                # of phrases, the corresponding phrase will not be
                # filtered.
                # (However, if a value is set for 'party' or 'state'
                # in the querystring, that will override any values
                # set in 'phrases' or 'parties.')
                for n, phrase in enumerate(phrases):
                    chart.set_line_style(n, thickness=2)  # Set line thickness

                    if not phrase.strip():
                        continue
                    kwargs['phrase'] = phrase
                    legend = phrase
                    try:
                        kwargs['party'] = parties[n]
                    except IndexError:
                        pass

                    try:
                        kwargs['state'] = states[n]
                    except IndexError:
                        pass

                    if kwargs.get('party') and kwargs.get('state'):
                        legend += ' (%(party)s, %(state)s)' % kwargs
                    elif kwargs.get('party'):
                        legend += ' (%(party)s)' % kwargs
                    elif kwargs.get('state'):
                        legend += ' (%(state)s)' % kwargs

                    legend_items.append(legend)

                    data = handler.read(request, *args, **kwargs)
                    results = data['results']
                    counts = [x.get(key) for x in results]
                    if max(counts) > maxcount:
                        maxcount = max(counts)

                    chart.add_data(counts)
                    metadata.append(kwargs)

                # Duplicated code; should move into separate function.
                if self.request.GET.get('granularity') == 'month':
                    if not months:
                        months = [x['month'] for x in results]
                        januaries = [x for x in months if x.endswith('01')]
                        january_indexes = [months.index(x) for x in januaries]
                        january_percentages = [int((x / float(len(months))) * 100) for x in january_indexes]
                        index = chart.set_axis_labels(Axis.BOTTOM, [x[:4] for x in januaries[::2]])
                        chart.set_axis_positions(index, [x for x in january_percentages[::2]])

                chart.y_range = (0, maxcount)

                if key == 'percentage':
                    label = '%.4f' % maxcount
                    label += '%'
                else:
                    label = int(maxcount)

                index = chart.set_axis_labels(Axis.LEFT, [label, ])
                chart.set_axis_positions(index, [100, ])
#.........这里部分代码省略.........
开发者ID:notthatbreezy,项目名称:Capitol-Words,代码行数:103,代码来源:views.py

示例10: get_chart_url

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import fill_solid [as 别名]
def get_chart_url():
    cache_key = 'phonedb-chart-url-%s' % settings.LANGUAGE_CODE
    url = cache.get(cache_key)
    if url is not None:
        return url
    enddate = datetime.datetime.now()
    # This works badly, we will rather render only chart for month after
    # it has finished
    #+ datetime.timedelta(days=30)
    endyear = enddate.year
    endmonthlast = enddate.month
    endmonth = 12

    dates = []
    unsupported = []
    supported = []
    totals = []
    alls = []
    years = []

    for year in xrange(2006, endyear + 1):
        if year == endyear:
            endmonth = endmonthlast
        for month in xrange(1, endmonth + 1):
            if month == 1:
                years.append('%d' % year)
            else:
                years.append('')

            time_range = (datetime.date(1900, 1, 1), datetime.date(year, month, 1))

            supported_val = Phone.objects.exclude(state = 'deleted').filter(connection__isnull = False).filter(created__range = time_range).count()
            unsupported_val = Phone.objects.exclude(state = 'deleted').filter(connection__isnull = True).filter(created__range = time_range).count()
            all_val = Phone.objects.filter(created__lt = datetime.date(year, month, 1)).count()

            supported.append(supported_val)
            unsupported.append(unsupported_val)
            totals.append(unsupported_val + supported_val)
            alls.append(all_val)
            dates.append('%d-%02d' % (year, month))

#print dates
#print unsupported
#print supported
#print totals
#print alls

    max_y = ((max(alls) / 100) + 1) * 100

    chart = SimpleLineChart(800, 300, y_range=[0, max_y])


    chart.fill_solid(chart.BACKGROUND, 'ffd480')
    chart.fill_solid(chart.CHART, 'ffd480')
# Chart data
    chart.add_data(supported)
    chart.add_data(totals)
    chart.add_data(alls)
# Lowest value
    chart.add_data([0] * 2)

# Set the line colour to blue
    chart.set_colours(['00FF00', 'FF0000', '0000FF', '00000000'])

#chart.add_fill_range('76A4FB', 2, 3)
# Set the vertical stripes
    month_stripes = 3.0
    chart.fill_linear_stripes(Chart.CHART, 0, 'ffe4a0', month_stripes / len(alls), 'ffd480', month_stripes / len(alls))

# Set the horizontal dotted lines
    chart.set_grid(0, 10, 5, 5)

    chart.set_legend([
        _('Supported phones').encode('utf-8'),
        _('Approved records').encode('utf-8'),
        _('Total records').encode('utf-8')])

    left_axis = map(lambda x: '%d' % x, xrange(0, max_y + 1, max_y / 10))
    left_axis[0] = ''
    chart.set_axis_labels(Axis.LEFT, left_axis)

    chart.set_axis_labels(Axis.BOTTOM, years)

    url = chart.get_url()
    cache.set(cache_key, url, 3600)
    return url
开发者ID:juanjosezg,项目名称:website,代码行数:88,代码来源:views.py

示例11: group

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import fill_solid [as 别名]
def group(request, group_id):
    group = GroupedMessage.objects.get(pk=group_id)

    message_list = group.message_set.all()
    
    obj = message_list[0]
    if '__sentry__' in obj.data:
        module, args, frames = obj.data['__sentry__']['exc']
        obj.class_name = str(obj.class_name)
        # We fake the exception class due to many issues with imports/builtins/etc
        exc_type = type(obj.class_name, (Exception,), {})
        exc_value = exc_type(obj.message)

        exc_value.args = args
    
        fake_request = FakeRequest()
        fake_request.META = obj.data.get('META', {})
        fake_request.GET = obj.data.get('GET', {})
        fake_request.POST = obj.data.get('POST', {})
        fake_request.FILES = obj.data.get('FILES', {})
        fake_request.COOKIES = obj.data.get('COOKIES', {})
        fake_request.url = obj.url
        if obj.url:
            fake_request.path_info = '/' + obj.url.split('/', 3)[-1]
        else:
            fake_request.path_info = ''

        reporter = ImprovedExceptionReporter(fake_request, exc_type, exc_value, frames, obj.data['__sentry__'].get('template'))
        traceback = mark_safe(reporter.get_traceback_html())
    elif group.traceback:
        traceback = mark_safe('<pre>%s</pre>' % (group.traceback,))
    
    unique_urls = message_list.filter(url__isnull=False).values_list('url', 'logger', 'view', 'checksum').annotate(times_seen=Count('url')).values('url', 'times_seen').order_by('-times_seen')
    
    unique_servers = message_list.filter(server_name__isnull=False).values_list('server_name', 'logger', 'view', 'checksum').annotate(times_seen=Count('server_name')).values('server_name', 'times_seen').order_by('-times_seen')
    
    if SimpleLineChart:
        today = datetime.datetime.now()

        chart_qs = message_list\
                          .filter(datetime__gte=today - datetime.timedelta(hours=24))\
                          .extra(select={'hour': 'extract(hour from datetime)'}).values('hour')\
                          .annotate(num=Count('id')).values_list('hour', 'num')

        rows = dict(chart_qs)
        if rows:
            max_y = max(rows.values())
        else:
            max_y = 1

        chart = SimpleLineChart(300, 80, y_range=[0, max_y])
        chart.add_data([max_y]*30)
        chart.add_data([rows.get((today-datetime.timedelta(hours=d)).hour, 0) for d in range(0, 24)][::-1])
        chart.add_data([0]*30)
        chart.fill_solid(chart.BACKGROUND, 'eeeeee')
        chart.add_fill_range('eeeeee', 0, 1)
        chart.add_fill_range('e0ebff', 1, 2)
        chart.set_colours(['eeeeee', '999999', 'eeeeee'])
        chart.set_line_style(1, 1)
        chart_url = chart.get_url()
    
    return render_to_response('sentry/group.html', locals())
开发者ID:bryanchow,项目名称:django-sentry,代码行数:64,代码来源:views.py

示例12: render

# 需要导入模块: from pygooglechart import SimpleLineChart [as 别名]
# 或者: from pygooglechart.SimpleLineChart import fill_solid [as 别名]

#.........这里部分代码省略.........
                    chart.add_marker(index, last_index, 't'+str(last_data), _valid_color(last_config.text), last_config.size)
                    chart.add_marker(index, last_index, last_config.style, _valid_color(last_config.color), last_config.thickness)

            if serie_config.area:
                fill_config = ChartConfig()
                fill_config.__dict__.update(serie_config.__dict__)
                fill_config.__dict__.update(serie_config.area)
                to = ordered_keys.index(fill_config.to)
                chart.add_fill_range(_valid_color(fill_config.color), index, to)

            if serie_config.dash:
                chart.set_line_style(index, serie_config.thickness, serie_config.dash, serie_config.dash)
            else:
                chart.set_line_style(index, serie_config.thickness)

            if serie_config.legend:
                legend.append(serie_config.legend)
                legend_set = True
            else:
                legend.append('')

            if serie_config.marks:
                mark_config = ChartConfig()
                mark_config.__dict__.update(serie_config.__dict__)
                mark_config.__dict__.update(serie_config.marks)
                mark_data = copy.copy(data[mark_config.serie.split('.')[0]]['series'][mark_config.serie.split('.')[1]])
                mark_data = compress_to(mark_data, config.nval, min_index, max_index)[0]
                for i, m in enumerate(mark_data):
                    if not m:
                        mark_data[i] = " "
                density = max(1.0, 1.0 * mark_config.space * len("".join(mark_data))*mark_config.size  / config.width)

                for i, v in enumerate(mark_data):
                    if (i +1) % round(density) == 0:
                        if serie_data[i] != 0:
                            text = str(mark_data[i])
                        else:
                            text = " "
                        chart.add_marker(index, i, 't'+text, _valid_color(mark_config.color), mark_config.size)

            index = index + 1

        # Compute vertical range

        if config.axes:
            range_min_ref_units = 0
            if not chart_min == sys.maxint and not chart_max == -sys.maxint:
                range_min = chart_min-config.ymargin[0]
                range_max = chart_max+config.ymargin[1]
                range_min_target_units = math.floor(converter.convert(measure, range_min))
                range_max_target_units = math.ceil(converter.convert(measure, range_max))
                range_min_ref_units = converter.convert_back(measure, range_min_target_units)
                range_max_ref_units = converter.convert_back(measure, range_max_target_units)
                self.logger.debug("Y range: "+str(range_min_target_units) +" "+str(range_max_target_units))
                chart.set_axis_range(Axis.LEFT, range_min_target_units, range_max_target_units+1)
                chart.add_data([range_min_ref_units, range_max_ref_units])
                colors.append("00000000")
            else:
                chart.set_axis_range(Axis.LEFT, 0, 100)
            chart.set_axis_style(0, _valid_color(config.text), config.size, 0, Axis.BOTH if config.ticks else Axis.AXIS_LINES)
        else:
            chart.set_axis_labels(Axis.LEFT, [])
            chart.set_axis_style(0, _valid_color(config.text), config.size, 0, Axis.TICK_MARKS, _valid_color(config.bgcolor))

        if config.zero and config.axes and range_min_ref_units < 0 and range_max_ref_units > 0:
            zero_config = ChartConfig()
            zero_config.__dict__.update(config.__dict__)
            zero_config.__dict__.update(config.zero)
            chart.add_data([0]*2)
            colors.append(_valid_color(zero_config.color))
            chart.set_line_style(index, zero_config.thickness)

        chart.set_colours(colors)
        chart.fill_solid(Chart.BACKGROUND, _valid_color(config.bgcolor))

        if legend_set:
            chart.set_legend(legend)
            chart.set_legend_position(config.legend_pos)

        if self.labels:
            labels_data = copy.copy(data[self.labels.split('.')[0]]['series'][self.labels.split('.')[1]])
            labels_data = compress_to(labels_data, config.nval, None, None)[0]
            if config.axes:
                density = 1.0 * len("".join(labels_data))*config.size  / config.width

                if density > LABEL_DENSITY_THRESHOLD:
                    for i, v in enumerate(labels_data):
                        if i % round(density) != 0:
                            labels_data[i] = ' '
                chart.set_axis_labels(Axis.BOTTOM, labels_data)
                chart.set_axis_style(1, _valid_color(config.text), config.size, 0, Axis.BOTH if config.ticks else Axis.AXIS_LINES)
            else:
                chart.set_axis_labels(Axis.BOTTOM, [])
                chart.set_axis_style(1, _valid_color(config.text), config.size, 0, Axis.TICK_MARKS, _valid_color(config.color))

        try:
            return chart.get_url()+"&chma=10,10,10,10" # add a margin
        except:
            self.logger.exception("Could not render chart")
            return "http://chart.apis.google.com/chart?cht=lc&chs="+str(config.width)+"x"+str(config.height)
开发者ID:gmassei,项目名称:wfrog,代码行数:104,代码来源:chart.py


注:本文中的pygooglechart.SimpleLineChart.fill_solid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。