Beispiel #1
0
def test_config_alterations_kwargs():
    class LineConfig(Config):
        show_legend = False
        fill = True
        pretty_print = True
        x_labels = ["a", "b", "c"]

    config = LineConfig()

    line1 = Line(config)
    line1.add("_", [1, 2, 3])
    l1 = line1.render()

    line1.stroke = False
    l1bis = line1.render()
    assert l1 != l1bis

    line2 = Line(config)
    line2.add("_", [1, 2, 3])
    l2 = line2.render()
    assert l1 == l2
    assert l1bis != l2

    line3 = Line(config, title="Title")
    line3.add("_", [1, 2, 3])
    l3 = line3.render()
    assert l3 != l2

    l2bis = line2.render()
    assert l2 == l2bis
Beispiel #2
0
def test_config_behaviours():
    line1 = Line()
    line1.show_legend = False
    line1.fill = True
    line1.pretty_print = True
    line1.x_labels = ['a', 'b', 'c']
    line1.add('_', [1, 2, 3])
    l1 = line1.render()

    line2 = Line(
        show_legend=False,
        fill=True,
        pretty_print=True,
        x_labels=['a', 'b', 'c'])
    line2.add('_', [1, 2, 3])
    l2 = line2.render()
    assert l1 == l2

    class LineConfig(Config):
        show_legend = False
        fill = True
        pretty_print = True
        x_labels = ['a', 'b', 'c']

    line3 = Line(LineConfig)
    line3.add('_', [1, 2, 3])
    l3 = line3.render()
    assert l1 == l3

    line4 = Line(LineConfig())
    line4.add('_', [1, 2, 3])
    l4 = line4.render()
    assert l1 == l4
def test_config_behaviours():
    line1 = Line()
    line1.show_legend = False
    line1.fill = True
    line1.pretty_print = True
    line1.x_labels = ['a', 'b', 'c']
    line1.add('_', [1, 2, 3])
    l1 = line1.render()

    line2 = Line(
        show_legend=False,
        fill=True,
        pretty_print=True,
        x_labels=['a', 'b', 'c'])
    line2.add('_', [1, 2, 3])
    l2 = line2.render()
    assert l1 == l2

    class LineConfig(Config):
        show_legend = False
        fill = True
        pretty_print = True
        x_labels = ['a', 'b', 'c']

    line3 = Line(LineConfig)
    line3.add('_', [1, 2, 3])
    l3 = line3.render()
    assert l1 == l3

    line4 = Line(LineConfig())
    line4.add('_', [1, 2, 3])
    l4 = line4.render()
    assert l1 == l4
Beispiel #4
0
def test_config_alterations_kwargs():
    class LineConfig(Config):
        no_prefix = True
        show_legend = False
        fill = True
        pretty_print = True
        x_labels = ['a', 'b', 'c']

    config = LineConfig()

    line1 = Line(config)
    line1.add('_', [1, 2, 3])
    l1 = line1.render()

    line1.stroke = False
    l1bis = line1.render()
    assert l1 != l1bis

    line2 = Line(config)
    line2.add('_', [1, 2, 3])
    l2 = line2.render()
    assert l1 == l2
    assert l1bis != l2

    line3 = Line(config, title='Title')
    line3.add('_', [1, 2, 3])
    l3 = line3.render()
    assert l3 != l2

    l2bis = line2.render()
    assert l2 == l2bis
Beispiel #5
0
def test_config_alterations_kwargs():
    """Assert a config can be changed with keyword args"""

    class LineConfig(Config):
        no_prefix = True
        show_legend = False
        fill = True
        pretty_print = True
        x_labels = ['a', 'b', 'c']

    config = LineConfig()

    line1 = Line(config)
    line1.add('_', [1, 2, 3])
    l1 = line1.render()

    line1.stroke = False
    l1bis = line1.render()
    assert l1 != l1bis

    line2 = Line(config)
    line2.add('_', [1, 2, 3])
    l2 = line2.render()
    assert l1 == l2
    assert l1bis != l2

    line3 = Line(config, title='Title')
    line3.add('_', [1, 2, 3])
    l3 = line3.render()
    assert l3 != l2

    l2bis = line2.render()
    assert l2 == l2bis
Beispiel #6
0
def test_config_behaviours():
    """Test that all different way to set config produce same results"""
    line1 = Line()
    line1.show_legend = False
    line1.fill = True
    line1.pretty_print = True
    line1.no_prefix = True
    line1.x_labels = ['a', 'b', 'c']
    line1.add('_', [1, 2, 3])
    l1 = line1.render()

    q = line1.render_pyquery()
    assert len(q(".axis.x")) == 1
    assert len(q(".axis.y")) == 1
    assert len(q(".plot .series path")) == 1
    assert len(q(".legend")) == 0
    assert len(q(".x.axis .guides")) == 3
    assert len(q(".y.axis .guides")) == 11
    assert len(q(".dots")) == 3
    assert q(".axis.x text").map(texts) == ['a', 'b', 'c']

    line2 = Line(
        show_legend=False,
        fill=True,
        pretty_print=True,
        no_prefix=True,
        x_labels=['a', 'b', 'c'])
    line2.add('_', [1, 2, 3])
    l2 = line2.render()
    assert l1 == l2

    class LineConfig(Config):
        show_legend = False
        fill = True
        pretty_print = True
        no_prefix = True
        x_labels = ['a', 'b', 'c']

    line3 = Line(LineConfig)
    line3.add('_', [1, 2, 3])
    l3 = line3.render()
    assert l1 == l3

    line4 = Line(LineConfig())
    line4.add('_', [1, 2, 3])
    l4 = line4.render()
    assert l1 == l4

    line_config = Config()
    line_config.show_legend = False
    line_config.fill = True
    line_config.pretty_print = True
    line_config.no_prefix = True
    line_config.x_labels = ['a', 'b', 'c']

    line5 = Line(line_config)
    line5.add('_', [1, 2, 3])
    l5 = line5.render()
    assert l1 == l5
Beispiel #7
0
def test_config_behaviours():
    """Test that all different way to set config produce same results"""
    line1 = Line()
    line1.show_legend = False
    line1.fill = True
    line1.pretty_print = True
    line1.no_prefix = True
    line1.x_labels = ['a', 'b', 'c']
    line1.add('_', [1, 2, 3])
    l1 = line1.render()

    q = line1.render_pyquery()
    assert len(q(".axis.x")) == 1
    assert len(q(".axis.y")) == 1
    assert len(q(".plot .series path")) == 1
    assert len(q(".legend")) == 0
    assert len(q(".x.axis .guides")) == 3
    assert len(q(".y.axis .guides")) == 11
    assert len(q(".dots")) == 3
    assert q(".axis.x text").map(texts) == ['a', 'b', 'c']

    line2 = Line(
        show_legend=False,
        fill=True,
        pretty_print=True,
        no_prefix=True,
        x_labels=['a', 'b', 'c'])
    line2.add('_', [1, 2, 3])
    l2 = line2.render()
    assert l1 == l2

    class LineConfig(Config):
        show_legend = False
        fill = True
        pretty_print = True
        no_prefix = True
        x_labels = ['a', 'b', 'c']

    line3 = Line(LineConfig)
    line3.add('_', [1, 2, 3])
    l3 = line3.render()
    assert l1 == l3

    line4 = Line(LineConfig())
    line4.add('_', [1, 2, 3])
    l4 = line4.render()
    assert l1 == l4

    line_config = Config()
    line_config.show_legend = False
    line_config.fill = True
    line_config.pretty_print = True
    line_config.no_prefix = True
    line_config.x_labels = ['a', 'b', 'c']

    line5 = Line(line_config)
    line5.add('_', [1, 2, 3])
    l5 = line5.render()
    assert l1 == l5
Beispiel #8
0
def test_config_behaviours():
    line1 = Line()
    line1.show_legend = False
    line1.fill = True
    line1.pretty_print = True
    line1.no_prefix = True
    line1.x_labels = ["a", "b", "c"]
    line1.add("_", [1, 2, 3])
    l1 = line1.render()

    q = line1.render_pyquery()
    assert len(q(".axis.x")) == 1
    assert len(q(".axis.y")) == 1
    assert len(q(".plot .series path")) == 1
    assert len(q(".legend")) == 0
    assert len(q(".x.axis .guides")) == 3
    assert len(q(".y.axis .guides")) == 21
    assert len(q(".dots")) == 3
    assert q(".axis.x text").map(texts) == ["a", "b", "c"]

    line2 = Line(show_legend=False, fill=True, pretty_print=True, no_prefix=True, x_labels=["a", "b", "c"])
    line2.add("_", [1, 2, 3])
    l2 = line2.render()
    assert l1 == l2

    class LineConfig(Config):
        show_legend = False
        fill = True
        pretty_print = True
        no_prefix = True
        x_labels = ["a", "b", "c"]

    line3 = Line(LineConfig)
    line3.add("_", [1, 2, 3])
    l3 = line3.render()
    assert l1 == l3

    line4 = Line(LineConfig())
    line4.add("_", [1, 2, 3])
    l4 = line4.render()
    assert l1 == l4

    line_config = Config()
    line_config.show_legend = False
    line_config.fill = True
    line_config.pretty_print = True
    line_config.no_prefix = True
    line_config.x_labels = ["a", "b", "c"]

    line5 = Line(line_config)
    line5.add("_", [1, 2, 3])
    l5 = line5.render()
    assert l1 == l5
Beispiel #9
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 #10
0
def draw_price_line(name, list_x, list_y):
        line = Line()
        line.disable_xml_declaration = True
        line.js = []

        line.x_label_rotation = 45
        line.y_labels_major_every = 3
        line.show_legend = False
        line.print_values = False
        line.width  = 1280
        line.height = 720
        line.value_formatter = lambda x:str(int(x))
        #line.major_label_font_size = 20
        #line.print_zeroes = True
        #line.show_minor_x_labels = True
        #line.show_minor_y_labels = True

        line.title = name 
        digital_y = list(filter(lambda x:x != None, list_y))
        if digital_y == [] : digital_y = [0]
        line.range = (min(digital_y)-100, max(digital_y)+300)
        line.x_labels = list_x
        line.y_labels = map(lambda x:x*100, range(int((min(digital_y)/100)-1), int((max(digital_y)/100+4))))
        line.add(name, list_y)
        return line.render()
Beispiel #11
0
def draw_multi_price_line(name, dict_data):
        line = Line()
        line.disable_xml_declaration = True
        line.js = []

        line.x_label_rotation = 45
        line.y_labels_major_every = 3
        #line.show_legend = False
        line.legend_at_bottom = True
        line.print_values = False
        line.width  = 1280
        line.height = 720
        line.value_formatter = lambda x:str(int(x))
        #line.major_label_font_size = 20
        #line.print_zeroes = True
        #line.show_minor_x_labels = True
        #line.show_minor_y_labels = True

        line.title = name
        min_y = None
        max_y = None
        for name in dict_data:
                #print(name)
                list_x, list_y = dict_data[name]
                line.add(name, list_y)
                min_list_y = min(list_y)
                max_list_y = max(list_y)
                if min_y == None or min_list_y < min_y : min_y = min_list_y
                if max_y == None or max_list_y > max_y : max_y = max_list_y
        if min_y == None : min_y = 0
        if max_y == None : max_y = 0 
        line.range = (min_y-100, max_y+300)
        line.x_labels = map(str, list_x)
        line.y_labels = map(lambda x:x*100, range(int((min_y/100)-1), int((max_y/100+4))))
        return line.render()
Beispiel #12
0
def draw_number_line(name, list_x, list_y, max_y = 0):
        line = Line()
        line.disable_xml_declaration = True
        line.js = []

        line.x_label_rotation = 45
        line.x_labels_major_count = 31
        #line.y_labels_major_every = 3
        line.show_legend = False
        line.print_values = False
        line.print_zeroes = False
        line.width  = 1280
        line.height = 720
        line.value_formatter = lambda x:str(int(x))
        #line.major_label_font_size = 20
        #line.print_zeroes = True
        line.show_minor_x_labels = False
        #line.show_minor_y_labels = True
        line.show_dots = False
        #line.interpolate = 'hermite'

        line.title = name
        list_int_y = [0]
        for y in list_y:
                if y != None:
                        list_int_y.append(y)
        line.range = (0, max(int(max(list_int_y)*1.1), max_y))
        line.x_labels = list_x
        #line.y_labels = map(lambda x:x*100, range(int((min(list_y)/100)-1), int((max(list_y)/100+4))))
        line.add(name, list_y)
        return line.render()
Beispiel #13
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 #14
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 #15
0
def test_config_alterations_class():
    class LineConfig(Config):
        show_legend = False
        fill = True
        pretty_print = True
        x_labels = ['a', 'b', 'c']

    line1 = Line(LineConfig)
    line1.add('_', [1, 2, 3])
    l1 = line1.render()

    LineConfig.stroke = False
    line2 = Line(LineConfig)
    line2.add('_', [1, 2, 3])
    l2 = line2.render()
    assert l1 != l2

    l1bis = line1.render()
    assert l1 == l1bis
Beispiel #16
0
def test_config_alterations_class():
    class LineConfig(Config):
        show_legend = False
        fill = True
        pretty_print = True
        x_labels = ['a', 'b', 'c']

    line1 = Line(LineConfig)
    line1.add('_', [1, 2, 3])
    l1 = line1.render()

    LineConfig.stroke = False
    line2 = Line(LineConfig)
    line2.add('_', [1, 2, 3])
    l2 = line2.render()
    assert l1 != l2

    l1bis = line1.render()
    assert l1 == l1bis
Beispiel #17
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 #18
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 #19
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 #20
0
    def plot_disp(self):

        s1, s2, s3, x = self.badanie.plotdata()

        chart = Line()
        chart.x_title = 'Czas'
        chart.y_title = 'Ugięcie'
        # chart.title = 'Wykres ugięcia gruntu przy badaniu'
        chart.x_labels = map(str, x)
        chart.x_labels_major_count = 20
        chart.show_minor_x_labels = False
        chart.x_label_rotation = 60
        chart.add('Zrzut 1', s1)
        chart.add('Zrzut 2', s2)
        chart.add('Zrzut 3', s3)
        chart.render(is_unicode=True)
        plotpath = 'plots/plot.svg'
        chart.render_to_file(plotpath)
        ploturl = "file:///home/macwojs/PycharmProjects/Terratest/" + plotpath
        self.main_screen.plotview.load(QUrl(ploturl))
Beispiel #21
0
def test_config_alterations_instance():
    class LineConfig(Config):
        show_legend = False
        fill = True
        pretty_print = True
        x_labels = ["a", "b", "c"]

    config = LineConfig()
    line1 = Line(config)
    line1.add("_", [1, 2, 3])
    l1 = line1.render()

    config.stroke = False
    line2 = Line(config)
    line2.add("_", [1, 2, 3])
    l2 = line2.render()
    assert l1 != l2

    l1bis = line1.render()
    assert l1 == l1bis
Beispiel #22
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 #23
0
def test_config_alterations_instance():
    """Assert a config can be changed on instance"""
    class LineConfig(Config):
        no_prefix = True
        show_legend = False
        fill = True
        pretty_print = True
        x_labels = ['a', 'b', 'c']

    config = LineConfig()
    line1 = Line(config)
    line1.add('_', [1, 2, 3])
    l1 = line1.render()

    config.stroke = False
    line2 = Line(config)
    line2.add('_', [1, 2, 3])
    l2 = line2.render()
    assert l1 != l2

    l1bis = line1.render()
    assert l1 == l1bis
Beispiel #24
0
def test_config_alterations_instance():
    """Assert a config can be changed on instance"""
    class LineConfig(Config):
        no_prefix = True
        show_legend = False
        fill = True
        pretty_print = True
        x_labels = ['a', 'b', 'c']

    config = LineConfig()
    line1 = Line(config)
    line1.add('_', [1, 2, 3])
    l1 = line1.render()

    config.stroke = False
    line2 = Line(config)
    line2.add('_', [1, 2, 3])
    l2 = line2.render()
    assert l1 != l2

    l1bis = line1.render()
    assert l1 == l1bis
Beispiel #25
0
 def log(self, name, y):
     """记录一个y"""
     self.count += 1
     if name in self.plt_dict:
         lst = self.plt_dict[name]
     else:
         lst = []
         self.plt_dict[name] = lst
     lst.append(y)
     #折线图
     tl = Line()
     #画出x轴表示记录次数 最大画20格
     # tl.x_labels=range(0,self.count,max(1,self.count//20))
     #绘图
     for k in self.plt_dict:
         tl.add(k, self.plt_dict[k])
     str = tl.render(is_unicode=True) + f"\n{end_chars}\n"
     self.server.stdin.write(str.encode())