Beispiel #1
0
def test_no_data():
    line = Line()
    q = line.render_pyquery()
    assert q(".text-overlay text").text() == "No data"
    line.no_data_text = u("þæ®þ怀&ij¿’€")
    q = line.render_pyquery()
    assert q(".text-overlay text").text() == u("þæ®þ怀&ij¿’€")
Beispiel #2
0
def test_value_formatter():
    line = Line(value_formatter=lambda x: str(x) + u('‰'))
    line.add('_', [10 ** 4, 10 ** 5, 23 * 10 ** 4])
    q = line.render_pyquery()
    assert len(q(".y.axis .guides")) == 11
    assert q(".axis.y text").map(texts) == list(map(
        lambda x: str(x) + u('‰'), map(float, range(20000, 240000, 20000))))
Beispiel #3
0
def test_only_major_dots_every():
    """Test major dots"""
    line = Line(show_only_major_dots=True, x_labels_major_every=3)
    line.add('test', range(12))
    line.x_labels = map(str, range(12))
    q = line.render_pyquery()
    assert len(q(".dots")) == 4
Beispiel #4
0
def test_parametric_styles_with_parameters():
    """Test a parametric style with parameters"""
    line = Line(style=RotateStyle(
        '#de3804', step=12, max_=180, base_style=LightStyle))
    line.add('_', [1, 2, 3])
    line.x_labels = 'abc'
    assert line.render()
Beispiel #5
0
def test_one_dot():
    line = Line()
    line.add('one dot', [12])
    line.x_labels = ['one']
    q = line.render_pyquery()
    assert len(q(".axis.x")) == 1
    assert len(q(".axis.y")) == 1
    assert len(q(".y.axis .guides")) == 1
Beispiel #6
0
 def test_major_dots():
     line = Line(x_labels_major_count=2, show_only_major_dots=True)
     line.add('test', range(12))
     line.x_labels = [
         'lol', 'lol1', 'lol2', 'lol3', 'lol4', 'lol5',
         'lol6', 'lol7', 'lol8', 'lol9', 'lol10', 'lol11']
     # line.x_labels_major = ['lol3']
     return line.render_response()
Beispiel #7
0
def test_human_readable():
    line = Line()
    line.add("_", [10 ** 4, 10 ** 5, 23 * 10 ** 4])
    # q = line.render_pyquery()
    # assert q(".axis.y text").map(texts) == map(
    # str, range(20000, 240000, 20000))
    line.human_readable = True
    q = line.render_pyquery()
    assert q(".axis.y text").map(texts) == map(lambda x: "%dk" % x, range(20, 240, 20))
Beispiel #8
0
def test_not_equal_x_labels():
    line = Line()
    line.add('test1', range(100))
    line.x_labels = map(str, range(11))
    q = line.render_pyquery()
    assert len(q(".dots")) == 100
    assert len(q(".axis.x")) == 1
    assert q(".axis.x text").map(texts) == ['0', '1', '2', '3', '4', '5', '6',
                                            '7', '8', '9', '10']
def test_logarithmic_bad_interpolation():
    try:
        import scipy
    except ImportError:
        return
    line = Line(logarithmic=True, interpolate='cubic')
    line.add('_', [.001, .00000001, 1])
    q = line.render_pyquery()
    assert len(q(".y.axis .guides")) == 40
Beispiel #10
0
def test_no_serie_config():
    """Test per serie no configuration"""
    chart = Line()
    chart.add('1', s1)
    chart.add('2', s2)
    q = chart.render_pyquery()
    assert len(q('.serie-0 .line')) == 1
    assert len(q('.serie-1 .line')) == 1
    assert len(q('.serie-0 .dot')) == 5
    assert len(q('.serie-1 .dot')) == 6
Beispiel #11
0
def test_global_config():
    """Test global configuration"""
    chart = Line(stroke=False)
    chart.add('1', s1)
    chart.add('2', s2)
    q = chart.render_pyquery()
    assert len(q('.serie-0 .line')) == 0
    assert len(q('.serie-1 .line')) == 0
    assert len(q('.serie-0 .dot')) == 5
    assert len(q('.serie-1 .dot')) == 6
Beispiel #12
0
def test_parametric_styles():
    """Test that no parametric produce the same result"""
    chart = None
    for style in STYLES:
        line = Line(style=style('#f4e83a'))
        line.add('_', [1, 2, 3])
        line.x_labels = 'abc'
        new_chart = line.render()
        assert chart != new_chart
        chart = new_chart
Beispiel #13
0
def test_line():
    line = Line()
    rng = [8, 12, 23, 73, 39, 57]
    line.add('Single serie', rng)
    line.title = "One serie"
    q = line.render_pyquery()
    assert len(q(".axis.x")) == 0
    assert len(q(".axis.y")) == 1
    assert len(q(".plot .series path")) == 1
    assert len(q(".x.axis .guides")) == 0
    assert len(q(".y.axis .guides")) == 7
Beispiel #14
0
def test_negative_and_float_and_no_data_sparktext():
    chart = Line()
    chart.add('_', [0.1, 0.2, 0.9, -0.5])
    assert chart.render_sparktext() == u('▁▂█▁')

    chart2 = Line()
    chart2.add('_', [])
    assert chart2.render_sparktext() == u('')

    chart3 = Line()
    assert chart3.render_sparktext() == u('')
Beispiel #15
0
def test_logarithmic():
    line = Line(logarithmic=True)
    line.add('_', [1, 10 ** 10, 1])
    q = line.render_pyquery()
    assert len(q(".axis.x")) == 0
    assert len(q(".axis.y")) == 1
    assert len(q(".plot .series path")) == 1
    assert len(q(".legend")) == 1
    assert len(q(".x.axis .guides")) == 0
    assert len(q(".y.axis .guides")) == 51
    assert len(q(".dots")) == 3
def monthly_total_precip_line(monthlies, append_title=""):
    """
    Given `monthlies` data as returned by `aggregate_monthly_data()`,
    returns a Pygal line graph of precipitation totals for each month.
    """

    graph = Line(title="Precipitation" + append_title,
                 x_labels=MONTH_NAMES, x_label_rotation=90)

    graph.add("Precip(mm)", [monthly['precipitation_total'] / 10.
                             for monthly in monthlies])

    return graph
Beispiel #17
0
def test_simple_line():
    """Simple line test"""
    line = Line()
    rng = range(-30, 31, 5)
    line.add('test1', [cos(x / 10) for x in rng])
    line.add('test2', [sin(x / 10) for x in rng])
    line.add('test3', [cos(x / 10) - sin(x / 10) for x in rng])
    line.x_labels = map(str, rng)
    line.title = "cos sin and cos - sin"
    q = line.render_pyquery()
    assert len(q(".axis.x")) == 1
    assert len(q(".axis.y")) == 1
    assert len(q(".plot .series path")) == 3
    assert len(q(".legend")) == 3
    assert len(q(".x.axis .guides")) == 13
    assert len(q(".y.axis .guides")) == 13
    assert len(q(".dots")) == 3 * 13
    assert q(".axis.x text").map(texts) == [
        '-30', '-25', '-20', '-15', '-10', '-5',
        '0', '5', '10', '15', '20', '25', '30']
    assert q(".axis.y text").map(texts) == [
        '-1.2', '-1', '-0.8', '-0.6', '-0.4', '-0.2',
        '0', '0.2', '0.4', '0.6', '0.8', '1', '1.2']
    assert q(".title").text() == 'cos sin and cos - sin'
    assert q(".legend text").map(texts) == ['test1', 'test2', 'test3']
Beispiel #18
0
 def test_interpolate_secondary():
     chart = Line(title=u"Some different points", interpolate="cubic")
     chart.add("line", [1000, 2000, 7000])
     chart.add("other line", [100, 500, 500], secondary=True)
     chart.range = 0, 10000
     chart.secondary_range = 0, 1000
     return chart.render_response()
Beispiel #19
0
 def test_interpolate_secondary():
     chart = Line(title=u'Some different points', interpolate='cubic')
     chart.add('line', [1000, 2000, 7000])
     chart.add('other line', [100, 500, 500], secondary=True)
     chart.range = 0, 10000
     chart.secondary_range = 0, 1000
     return chart.render_response()
Beispiel #20
0
def test_same_max_and_relative_values_sparktext():
    chart = Line()
    chart.add('_', [0, 0, 0, 0, 0])
    assert chart.render_sparktext() == u('▁▁▁▁▁')

    chart2 = Line()
    chart2.add('_', [1, 1, 1, 1, 1])
    assert chart2.render_sparktext(relative_to=1) == u('▁▁▁▁▁')
    def create_graph(self, data, args):
        """
        Creates the graph based on rendering data
        """
        line_chart_arguments = {
            'style': RedBlueStyle,
        }
        for arg in self.allowed_chart_url_args.keys():
            if arg in args:
                line_chart_arguments.update({arg: args[arg]})

        line_chart = Line(**line_chart_arguments)
        values = []
        if 'results' in data and len(data['results']) > 0:
            values = [price['value'] for price in data['results']]
            line_chart.add(data['results'][0]['currency'], values)
        return line_chart
Beispiel #22
0
def test_show_dots():
    line = Line()
    line.add('_', [1, 2, 3])
    q = line.render_pyquery()
    assert len(q(".dots")) == 3
    line.show_dots = False
    q = line.render_pyquery()
    assert len(q(".dots")) == 0
Beispiel #23
0
 def test_interruptions():
     chart = Line(allow_interruptions=True)
     chart.add('interrupt', [22, 34, 43, 12, None, 12, 55, None, 56],
               allow_interruptions=False)
     chart.add('not interrupt', [
         -a if a else None for a in (22, 34, 43, 12, None, 12, 55, None, 56)
     ])
     return chart.render_response()
Beispiel #24
0
def test_another_sparktext():
    chart = Line()
    chart.add('_', [0, 30, 55, 80, 33, 150])
    assert chart.render_sparktext() == u('▁▂▃▄▂█')
    assert chart.render_sparktext() == chart.render_sparktext()
    chart2 = Bar()
    chart2.add('_', [0, 30, 55, 80, 33, 150])
    assert chart2.render_sparktext() == chart.render_sparktext()
Beispiel #25
0
def test_only_major_dots_count():
    """Test major dots with a major label count"""
    line = Line(show_only_major_dots=True)
    line.add('test', range(12))
    line.x_labels = map(str, range(12))
    line.x_labels_major_count = 2
    q = line.render_pyquery()
    assert len(q(".dots")) == 2
Beispiel #26
0
def test_only_major_dots():
    """Test major dots with specified major labels"""
    line = Line(show_only_major_dots=True, )
    line.add('test', range(12))
    line.x_labels = map(str, range(12))
    line.x_labels_major = ['1', '5', '11']
    q = line.render_pyquery()
    assert len(q(".dots")) == 3
Beispiel #27
0
def test_show_legend():
    line = Line()
    line.add('_', [1, 2, 3])
    q = line.render_pyquery()
    assert len(q(".legend")) == 1
    line.show_legend = False
    q = line.render_pyquery()
    assert len(q(".legend")) == 0
Beispiel #28
0
def test_line_secondary():
    line = Line()
    rng = [8, 12, 23, 73, 39, 57]
    line.add('First serie', rng)
    line.add('Secondary serie', map(lambda x: x * 2, rng), secondary=True)
    line.title = "One serie"
    q = line.render_pyquery()
    assert len(q(".axis.x")) == 0
    assert len(q(".axis.y")) == 1
    assert len(q(".plot .series path")) == 2
    assert len(q(".x.axis .guides")) == 0
    assert len(q(".y.axis .guides")) == 7
def monthly_avg_min_max_temp_line(monthlies, append_title=""):
    """
    Given `monthlies` data as returned by `aggregate_monthly_data()`,
    returns a Pygal line graph of average minimum and average maximum
    temperatures for each month.
    """

    graph = Line(title="Average High-Low Temperature" + append_title,
                 x_labels=MONTH_NAMES, x_label_rotation=90)

    graph.add("Avg High(C)", [monthly['max_temperature_total'] / 10. /
                              monthly['days_of_data']
                              for monthly in monthlies])

    graph.add("Avg Low(C)", [monthly['min_temperature_total'] / 10. /
                             monthly['days_of_data']
                             for monthly in monthlies])

    return graph
Beispiel #30
0
 def test_major_dots():
     line = Line(x_labels_major_count=2, show_only_major_dots=True)
     line.add("test", range(12))
     line.x_labels = [
         "lol",
         "lol1",
         "lol2",
         "lol3",
         "lol4",
         "lol5",
         "lol6",
         "lol7",
         "lol8",
         "lol9",
         "lol10",
         "lol11",
     ]
     # line.x_labels_major = ['lol3']
     return line.render_response()
Beispiel #31
0
 def test_major_dots():
     line = Line(x_labels_major_every=3, show_only_major_dots=True)
     line.add('test', range(12))
     line.x_labels = [
         'lol', 'lol1', 'lol2', 'lol3', 'lol4', 'lol5', 'lol6', 'lol7',
         'lol8', 'lol9', 'lol10', 'lol11'
     ]
     line.x_labels_major = ['lol3']
     return line.render_response()
Beispiel #32
0
def graphing(budget_list):
    the_graph = Line()
    the_graph.title = 'Maximum profits based on given prices'
    the_graph.x_labels = sorted(budget_list)
    the_graph.add('Profits', all_profits_from_prices(budget_list))

    # option to save to local dir
    # the_graph.render_to_file('profits.svg')
    return the_graph.render_data_uri()
Beispiel #33
0
def test_another_sparktext():
    """Test that same data produces same sparktext"""
    chart = Line()
    chart.add('_', [0, 30, 55, 80, 33, 150])
    assert chart.render_sparktext() == u('▁▂▃▄▂█')
    assert chart.render_sparktext() == chart.render_sparktext()
    chart2 = Bar()
    chart2.add('_', [0, 30, 55, 80, 33, 150])
    assert chart2.render_sparktext() == chart.render_sparktext()
Beispiel #34
0
    def test_erfinv():
        from scipy import stats as sstats
        chart = Line(show_dots=False)
        chart.add('scipy', [sstats.norm.ppf(x / 1000) for x in range(1, 999)])
        chart.add('approx', [stats.ppf(x / 1000) for x in range(1, 999)])

        # chart.add('approx', [
        #    special.erfinv(x/1000) - erfinv(x/1000)
        #    for x in range(-999, 1000)])
        return chart.render_response()
Beispiel #35
0
def test_human_readable():
    line = Line()
    line.add('_', [10**4, 10**5, 23 * 10**4])
    q = line.render_pyquery()
    assert q(".axis.y text").map(texts) == list(
        map(str, map(float, range(20000, 240000, 20000))))
    line.human_readable = True
    q = line.render_pyquery()
    assert q(".axis.y text").map(texts) == list(
        map(lambda x: '%dk' % x, range(20, 240, 20)))
Beispiel #36
0
def test_serie_config():
    """Test per serie configuration"""
    chart = Line()
    chart.add('1', s1, stroke=False)
    chart.add('2', s2)
    q = chart.render_pyquery()
    assert len(q('.serie-0 .line')) == 0
    assert len(q('.serie-1 .line')) == 1
    assert len(q('.serie-0 .dot')) == 5
    assert len(q('.serie-1 .dot')) == 6
Beispiel #37
0
def test_serie_precedence_over_global_config():
    """Test that per serie configuration overide global configuration"""
    chart = Line(stroke=False)
    chart.add('1', s1, stroke=True)
    chart.add('2', s2)
    q = chart.render_pyquery()
    assert len(q('.serie-0 .line')) == 1
    assert len(q('.serie-1 .line')) == 0
    assert len(q('.serie-0 .dot')) == 5
    assert len(q('.serie-1 .dot')) == 6
Beispiel #38
0
def test_only_major_dots_count():
    line = Line(show_only_major_dots=True)
    line.add('test', range(12))
    line.x_labels = map(str, range(12))
    line.x_labels_major_count = 2
    q = line.render_pyquery()
    assert len(q(".dots")) == 2
Beispiel #39
0
def test_parametric_styles_with_parameters():
    """Test a parametric style with parameters"""
    line = Line(
        style=RotateStyle('#de3804', step=12, max_=180, base_style=LightStyle))
    line.add('_', [1, 2, 3])
    line.x_labels = 'abc'
    assert line.render()
Beispiel #40
0
    def _generate_time_chart(self, datas):
        """
        After generate a time chart,save to file and return the chart path

        Keyword arguments:
        datas -- Dict object of parsed information for a time chart
        """
        if not datas:
            return ""

        line_chart = Line(x_label_rotation=30, sstyle=LightStyle, human_readable=True)

        indices = sorted(datas.keys())
        time_format = self.options["time_format"]
        line_chart.x_labels = map(lambda x: dateutil.parser.parse(x).strftime(time_format), indices)

        chart_data = {}
        for index in indices:
            for data in datas[index]:
                if chart_data.get(data[0]):
                    chart_data.get(data[0]).append(data[1])
                else:
                    chart_data[data[0]] = [data[1]]

        for key in chart_data:
            line_chart.add(key, chart_data[key])

        path = os.path.join(tempfile.gettempdir(), "time{}.svg".format(str(int(time.time()))))
        line_chart.render_to_file(path)
        logging.info("Time chart was created successfully.")

        return path
Beispiel #41
0
def test_only_major_dots():
    line = Line(show_only_major_dots=True,)
    line.add('test', range(12))
    line.x_labels = map(str, range(12))
    line.x_labels_major = ['1', '5', '11']
    q = line.render_pyquery()
    assert len(q(".dots")) == 3
Beispiel #42
0
def test_only_major_dots_every():
    """Test major dots"""
    line = Line(show_only_major_dots=True, x_labels_major_every=3)
    line.add('test', range(12))
    line.x_labels = map(str, range(12))
    q = line.render_pyquery()
    assert len(q(".dots")) == 4
Beispiel #43
0
def generate_chart(data: pd.DataFrame) -> Line:
    line_chart = Line(
        js=(),  # The tooltips are really nice, but I don't want any JS.
        style=GruvboxStyle,
        x_label_rotation=30)

    # Water those datetimes down so they don't overlap and we can read them!
    datetimes = data['Datetime']
    dilution_factor = datetimes.shape[0] // 10
    datetimes = dilute_datetimes(datetimes, factor=dilution_factor)

    line_chart.title = 'HTTP GET by IP vs. HTTP GET by Hostname'
    line_chart.y_title = 'Seconds'
    line_chart.x_labels = datetimes
    line_chart.add(title='By IP', values=data['Seconds for HTTP GET by IP'])
    line_chart.add(title='By Hostname',
                   values=data['Seconds for HTTP GET by Hostname'])
    return line_chart
Beispiel #44
0
    def build_line(self, data, col_2):
        COL_1_INDEX, COL_2_INDEX = 2, 3

        range_1_from, range_1_to = \
            BaseDataLoggerHandler.create_range(data, COL_1_INDEX)

        if col_2:
            range_2_from, range_2_to = \
                BaseDataLoggerHandler.create_range(data, COL_2_INDEX)

        chart = Line(
            show_dots=False, fill=True if col_2 else True,
            show_x_guides=False, show_y_guides=True,
            range=(range_1_from, range_1_to),
            secondary_range=(range_2_from, range_2_to) if col_2 else None,
            x_label_rotation=70, title='Inverter Stats',
            style=BaseDataLoggerHandler.custom_style(col_2)
        )
        chart.y_labels = self.resolve_y_labels(
            range(range_1_from, range_1_to + 1)
        )
        return chart
Beispiel #45
0
def word_count(text_sample_directory):

    print "Opening '" + text_sample_directory + "'"

    # Dictionary of each word that gets encountered
    words = {}

    for text_file in os.listdir(text_sample_directory):
        with open(text_sample_directory + text_file) as f:
            sys.stdout.write(".")
            sys.stdout.flush()

            for line in f:

                line = line.lower()
                line = clean(line)

                replace_characters = '0123456789~-+=!?@#$%^&*:;<>(){}[]|\/\'`"_,.'
                for character in replace_characters:
                    line = line.replace(character, "")

                word_list = line.split(" ")
                for word in word_list:

                    if word and word in words:
                        words[word] += 1
                    else:
                        words[word] = 1

    output_name = text_sample_directory.strip("/")

    writer = csv.writer(open(output_name + ".csv", "wb"))
    sorted_dict = sorted(words.items(), key=lambda x: x[1], reverse=True)

    # Get the count of occurance for the word that occurs the most
    max_value = int(sorted_dict[0][1])
    keys = []
    values = []

    for key, value in sorted_dict:
        keys.append(key)
        values.append(value)
        writer.writerow([key, value])

    line_chart = Line()
    line_chart.title = "Word Occurance Graph"
    line_chart.x_labels = keys
    line_chart.add(output_name, values)

    svg_data = line_chart.render()
    graphfile = open(output_name + ".svg", "w")
    graphfile.write(svg_data)

    print "\nWriting '" + output_name + "'"
Beispiel #46
0
def test_not_equal_x_labels():
    """Test x_labels"""
    line = Line()
    line.add('test1', range(100))
    line.truncate_label = -1
    line.x_labels = map(str, range(11))
    q = line.render_pyquery()
    assert len(q(".dots")) == 100
    assert len(q(".axis.x")) == 1
    assert q(".axis.x text").map(texts) == [
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
Beispiel #47
0
def test_no_data_sparktext():
    """Test no data sparktext"""
    chart2 = Line()
    chart2.add('_', [])
    assert chart2.render_sparktext() == u('')

    chart3 = Line()
    assert chart3.render_sparktext() == u('')
Beispiel #48
0
def test_one_dot():
    line = Line()
    line.add('one dot', [12])
    line.x_labels = ['one']
    q = line.render_pyquery()
    assert len(q(".axis.x")) == 1
    assert len(q(".axis.y")) == 1
    assert len(q(".y.axis .guides")) == 1
Beispiel #49
0
def test_show_dots():
    line = Line()
    line.add('_', [1, 2, 3])
    q = line.render_pyquery()
    assert len(q(".dots")) == 3
    line.show_dots = False
    q = line.render_pyquery()
    assert len(q(".dots")) == 0
Beispiel #50
0
def test_show_legend():
    line = Line()
    line.add('_', [1, 2, 3])
    q = line.render_pyquery()
    assert len(q(".legend")) == 1
    line.show_legend = False
    q = line.render_pyquery()
    assert len(q(".legend")) == 0
Beispiel #51
0
def test_parametric_styles():
    chart = None
    for style in STYLES:
        line = Line(style=style('#f4e83a'))
        line.add('_', [1, 2, 3])
        line.x_labels = 'abc'
        new_chart = line.render()
        assert chart != new_chart
        chart = new_chart
Beispiel #52
0
def test_human_readable():
    """Test human readable option"""
    line = Line()
    line.add('_', [10 ** 4, 10 ** 5, 23 * 10 ** 4])
    q = line.render_pyquery()
    assert q(".axis.y text").map(texts) == list(map(
        str, range(20000, 240000, 20000)))

    line.value_formatter = formatters.human_readable

    q = line.render_pyquery()
    assert q(".axis.y text").map(texts) == list(map(
        lambda x: '%dk' % x, range(20, 240, 20)))
Beispiel #53
0
def test_parametric_styles():
    """Test that no parametric produce the same result"""
    chart = None
    for style in STYLES:
        line = Line(style=style('#f4e83a'))
        line.add('_', [1, 2, 3])
        line.x_labels = 'abc'
        new_chart = line.render()
        assert chart != new_chart
        chart = new_chart
Beispiel #54
0
def test_line():
    line = Line()
    rng = [8, 12, 23, 73, 39, 57]
    line.add('Single serie', rng)
    line.title = "One serie"
    q = line.render_pyquery()
    assert len(q(".axis.x")) == 0
    assert len(q(".axis.y")) == 1
    assert len(q(".plot .series path")) == 1
    assert len(q(".x.axis .guides")) == 0
    assert len(q(".y.axis .guides")) == 7
Beispiel #55
0
def test_simple_line():
    line = Line()
    rng = range(-30, 31, 5)
    line.add('test1', [cos(x / 10) for x in rng])
    line.add('test2', [sin(x / 10) for x in rng])
    line.add('test3', [cos(x / 10) - sin(x / 10) for x in rng])
    line.x_labels = map(str, rng)
    line.title = "cos sin and cos - sin"
    q = line.render_pyquery()
    assert len(q(".axis.x")) == 1
    assert len(q(".axis.y")) == 1
    assert len(q(".plot .series path")) == 3
    assert len(q(".legend")) == 3
    assert len(q(".x.axis .guides")) == 13
    assert len(q(".y.axis .guides")) == 13
    assert len(q(".dots")) == 3 * 13
    assert q(".axis.x text").map(texts) == [
        '-30', '-25', '-20', '-15', '-10', '-5',
        '0', '5', '10', '15', '20', '25', '30']
    assert q(".axis.y text").map(texts) == [
        '-1.2', '-1.0', '-0.8', '-0.6', '-0.4', '-0.2',
        '0.0', '0.2', '0.4', '0.6', '0.8', '1.0', '1.2']
    assert q(".title").text() == 'cos sin and cos - sin'
    assert q(".legend text").map(texts) == ['test1', 'test2', 'test3']
Beispiel #56
0
    def _generate_time_chart(self, datas):
        """
        After generate a time chart,save to file and return the chart path

        Keyword arguments:
        datas -- Dict object of parsed information for a time chart
        """
        if not datas:
            return ""

        line_chart = Line(x_label_rotation=30,
                          sstyle=LightStyle,
                          human_readable=True)

        indices = sorted(datas.keys())
        time_format = self.options['time_format']
        line_chart.x_labels = map(
            lambda x: dateutil.parser.parse(x).strftime(time_format), indices)

        chart_data = {}
        for index in indices:
            for data in datas[index]:
                if chart_data.get(data[0]):
                    chart_data.get(data[0]).append(data[1])
                else:
                    chart_data[data[0]] = [data[1]]

        for key in chart_data:
            line_chart.add(key, chart_data[key])

        path = os.path.join(tempfile.gettempdir(),
                            "time{}.svg".format(str(int(time.time()))))
        line_chart.render_to_file(path)
        logging.info("Time chart was created successfully.")

        return path
Beispiel #57
0
def monthly_avg_min_max_temp_line(monthlies, append_title=""):
    """
    Given `monthlies` data as returned by `aggregate_monthly_data()`,
    returns a Pygal line graph of average minimum and average maximum
    temperatures for each month.
    """

    graph = Line(title="Average High-Low Temperature" + append_title,
                 x_labels=MONTH_NAMES,
                 x_label_rotation=90)

    graph.add("Avg High(C)", [
        monthly['max_temperature_total'] / 10. / monthly['days_of_data']
        for monthly in monthlies
    ])

    graph.add("Avg Low(C)", [
        monthly['min_temperature_total'] / 10. / monthly['days_of_data']
        for monthly in monthlies
    ])

    return graph
Beispiel #58
0
    def get_line_chart(self, title, lines):
        """Make chart of type line and return it.

        title: Title of chart (string)
        step: x label step and poll interval (integer)
        start: x label start value (integer)
        stop: x label end value and end of polling (integer)
        lines: tuple or list of tuples or lists (line_name, data_points)
            line_name (string)
            data_points (list of ints)

        returns line_chart (pygal.Line())
        """

        chart = Line()
        chart.title = title
        chart.x_labels = self.points
        if type(lines[0]) == type(str()):
            lines = list(lines)
        for line in lines:
            label = line[0]
            data = line[1]
            chart.add(label, data)
        return chart
Beispiel #59
0
def test_no_dot_at_all():
    """Line test with no value"""
    q = Line().render_pyquery()
    assert q(".text-overlay text").text() == 'No data'