コード例 #1
0
ファイル: hadokey.py プロジェクト: Kozea/hadokey
def graph(graph, type, year, month):
    """Create graphs with the parameters passed."""
    db = get_db()
    now = datetime.now()
    timestamp = now.timestamp()
    time_first_day = datetime(year, month, 1).timestamp()
    first_day = datetime(year, month, 1)
    cal = calendar.monthrange(year, month)
    time_last_day = datetime(year, month, cal[1], 23, 59, 59).timestamp()
    last_day = datetime(year, month, cal[1])
    
    if graph in ['ligne', 'histogramme']:
        line_chart = Line(interpolate='cubic') if graph == 'ligne' else Bar()
        if type == 'hour':
            line_chart.title = (
                'Somme des hoquets par heure en %s' % 
                calendar.month_name[month])
            requete = db.execute(
                'select CAST(strftime(\'%H\', datetime(moment, \'unixepoch\','
                ' \'localtime\')) as integer) as hour, count(*) from ok '
                'where moment between (?) and (?) group by hour', 
                [time_first_day, time_last_day])
            hoquet = dict(requete)
            line_chart.x_labels = [
               str(hour) for hour, val in sorted(hoquet.items())]
            line_chart.add('Annabelle', [
                val for hour, val in sorted(hoquet.items())])
        else:
            hoquet = []
            x_labels = []
            x_labels_major = []
            line_chart.title = (
                'Nombre de hoquets par jour en %s' % 
                calendar.month_name[month])
            for i,day in enumerate(range (int(time_first_day),
            int(time_last_day), 86400)):                 
                if is_in_weekend(day):
                    requete = None
                else:
                    requete = db.execute(
                        'select count(*) from ok where moment >= (?) '
                        'and moment <= (?)', [day, day+86400]).fetchone()[0]
                    x_labels_major.append(i+1)
                    
                x_labels.append(i+1)                   
                hoquet.append(requete)
            line_chart.x_labels = map(str, x_labels)
            line_chart.x_labels_major = list(map(str, x_labels_major))
            line_chart.add('Annabelle', hoquet)
        return line_chart.render_response()
            
        return gauge_chart.render_response()
コード例 #2
0
ファイル: test_line.py プロジェクト: young-0/pygal
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
コード例 #3
0
ファイル: test_style.py プロジェクト: ConnorMooreLUC/pygal
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()
コード例 #4
0
ファイル: test_line.py プロジェクト: aroraumang/pygal
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
コード例 #5
0
ファイル: test_line.py プロジェクト: aroraumang/pygal
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']
コード例 #6
0
ファイル: test_line.py プロジェクト: sattel/pygal
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
コード例 #7
0
ファイル: svg_createline.py プロジェクト: riverzhou/hp_pp
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()
コード例 #8
0
ファイル: svg_createline.py プロジェクト: riverzhou/hp_pp
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()
コード例 #9
0
ファイル: svg_createline.py プロジェクト: riverzhou/hp_pp
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()
コード例 #10
0
ファイル: test_line.py プロジェクト: sattel/pygal
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']
コード例 #11
0
ファイル: test_line.py プロジェクト: AlanRun/UiAutoTest
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
コード例 #12
0
ファイル: tests.py プロジェクト: Kozea/pygal
    def test_stroke_config():
        line = Line(stroke_style={'width': .5})
        line.add('test_no_line', range(12), stroke=False)
        line.add('test', reversed(range(12)), stroke_style={'width': 3})
        line.add(
            'test_no_dots', [5] * 12,
            show_dots=False,
            stroke_style={
                'width': 2,
                'dasharray': '12, 31'
            }
        )
        line.add(
            'test_big_dots', [randint(1, 12) for _ in range(12)], dots_size=5
        )
        line.add(
            'test_fill', [randint(1, 3) for _ in range(12)],
            fill=True,
            stroke_style={
                'width': 5,
                'dasharray': '4, 12, 7, 20'
            }
        )

        line.x_labels = [
            'lol', 'lol1', 'lol2', 'lol3', 'lol4', 'lol5', 'lol6', 'lol7',
            'lol8', 'lol9', 'lol10', 'lol11'
        ]
        return line.render_response()
コード例 #13
0
ファイル: test_line.py プロジェクト: AlanRun/UiAutoTest
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
コード例 #14
0
ファイル: tests.py プロジェクト: rnjdeltaYoda/pygal
    def test_stroke_config():
        line = Line(stroke_style={"width": 0.5})
        line.add("test_no_line", range(12), stroke=False)
        line.add("test", reversed(range(12)), stroke_style={"width": 3})
        line.add("test_no_dots", [5] * 12, show_dots=False, stroke_style={"width": 2, "dasharray": "12, 31"})
        line.add("test_big_dots", [randint(1, 12) for _ in range(12)], dots_size=5)
        line.add(
            "test_fill",
            [randint(1, 3) for _ in range(12)],
            fill=True,
            stroke_style={"width": 5, "dasharray": "4, 12, 7, 20"},
        )

        line.x_labels = [
            "lol",
            "lol1",
            "lol2",
            "lol3",
            "lol4",
            "lol5",
            "lol6",
            "lol7",
            "lol8",
            "lol9",
            "lol10",
            "lol11",
        ]
        return line.render_response()
コード例 #15
0
ファイル: test_line.py プロジェクト: young-0/pygal
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
コード例 #16
0
ファイル: test_config.py プロジェクト: rayleyva/pygal
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
コード例 #17
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
コード例 #18
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
コード例 #19
0
ファイル: test_style.py プロジェクト: yzhen-hit/pygal
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()
コード例 #20
0
ファイル: test_config.py プロジェクト: Frankie-666/pygal
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
コード例 #21
0
ファイル: test_config.py プロジェクト: sjourdois/pygal
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
コード例 #22
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()
コード例 #23
0
ファイル: tests.py プロジェクト: fredtantini/pygal
 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()
コード例 #24
0
ファイル: web.py プロジェクト: mortbauer/limitsofgrowth
def simulation():
    x = w.x_odeint(w.initial)
    line = Line(show_dots=False,show_minor_x_labels=False)
    for c in x:
        line.add(c,x[c])
    line.x_labels = map(str,x.index.values)
    line.x_labels_major = map(str,range(x.index[0],x.index[-1]+50,50))
    return line.render_response()
コード例 #25
0
ファイル: test_line.py プロジェクト: rayleyva/pygal
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
コード例 #26
0
ファイル: test_line.py プロジェクト: andreasnuesslein/pygal
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
コード例 #27
0
ファイル: test_line.py プロジェクト: AlanRun/UiAutoTest
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']
コード例 #28
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']
コード例 #29
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
コード例 #30
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()
コード例 #31
0
ファイル: test_style.py プロジェクト: yzhen-hit/pygal
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
コード例 #32
0
ファイル: test_style.py プロジェクト: Kozea/pygal
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
コード例 #33
0
def get_users_time_graph(users):
    tvec = get_time_vector(UserPost, GRAPH_LEN)

    graph = Line(x_label_rotation=90)
    graph.x_labels = time_vector_2_string(tvec)

    for user in users:
        user_y = get_user_time_serie(user, tvec)
        graph.add(user, user_y)
    return graph
コード例 #34
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 + "'"
コード例 #35
0
def get_teams_time_graph(teams=None):
    tvec = get_time_vector(TeamPost, GRAPH_LEN)
    if teams is None:
        teams = get_teams_list()
    graph = Line(x_label_rotation=90)
    graph.x_labels = time_vector_2_string(tvec)

    for team in teams:
        team_y = get_team_time_serie(team, tvec)
        graph.add(team, team_y)
    return graph
コード例 #36
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 + "'"
コード例 #37
0
ファイル: test_line.py プロジェクト: aroraumang/pygal
def test_int_x_labels():
    """Test x_labels"""
    line = Line()
    line.add('test1', range(100))
    line.truncate_label = -1
    line.x_labels = list(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']
コード例 #38
0
def test_int_x_labels():
    """Test x_labels"""
    line = Line()
    line.add('test1', range(100))
    line.truncate_label = -1
    line.x_labels = list(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']
コード例 #39
0
ファイル: test_config.py プロジェクト: Cortana-/pygal
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
コード例 #40
0
ファイル: tests.py プロジェクト: ChaliZhg/pygal
    def test_stroke_config():
        line = Line()
        line.add('test_no_line', range(12), stroke=False)
        line.add('test', reversed(range(12)))
        line.add('test_no_dots', [5] * 12, show_dots=False)
        line.add('test_big_dots', [
            randint(1, 12) for _ in range(12)], dots_size=5)
        line.add('test_fill', [
            randint(1, 3) for _ in range(12)], fill=True)

        line.x_labels = [
            'lol', 'lol1', 'lol2', 'lol3', 'lol4', 'lol5',
            'lol6', 'lol7', 'lol8', 'lol9', 'lol10', 'lol11']
        return line.render_response()
コード例 #41
0
ファイル: tests.py プロジェクト: wuzesheng/pygal
    def test_stroke_config():
        line = Line()
        line.add('test_no_line', range(12), stroke=False)
        line.add('test', reversed(range(12)))
        line.add('test_no_dots', [5] * 12, show_dots=False)
        line.add('test_big_dots', [randint(1, 12) for _ in range(12)],
                 dots_size=5)
        line.add('test_fill', [randint(1, 3) for _ in range(12)], fill=True)

        line.x_labels = [
            'lol', 'lol1', 'lol2', 'lol3', 'lol4', 'lol5', 'lol6', 'lol7',
            'lol8', 'lol9', 'lol10', 'lol11'
        ]
        return line.render_response()
コード例 #42
0
    def test_stroke_config():
        line = Line(stroke_style={'width': .5})
        line.add('test_no_line', range(12), stroke=False)
        line.add('test', reversed(range(12)), stroke_style={'width': 3})
        line.add('test_no_dots', [5] * 12, show_dots=False,
                 stroke_style={'width': 2, 'dasharray': '12, 31'})
        line.add('test_big_dots', [
            randint(1, 12) for _ in range(12)], dots_size=5)
        line.add('test_fill', [
            randint(1, 3) for _ in range(12)], fill=True,
                 stroke_style={'width': 5, 'dasharray': '4, 12, 7, 20'})

        line.x_labels = [
            'lol', 'lol1', 'lol2', 'lol3', 'lol4', 'lol5',
            'lol6', 'lol7', 'lol8', 'lol9', 'lol10', 'lol11']
        return line.render_response()
コード例 #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
コード例 #44
0
ファイル: tests.py プロジェクト: rnjdeltaYoda/pygal
 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()
コード例 #45
0
ファイル: gui.py プロジェクト: macwojs/Terratest
    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))
コード例 #46
0
ファイル: tests.py プロジェクト: Cortana-/pygal
    def test_stroke_config():
        line = Line()
        line.add("test_no_line", range(12), stroke=False)
        line.add("test", reversed(range(12)))
        line.add("test_no_dots", [5] * 12, show_dots=False)
        line.add("test_big_dots", [randint(1, 12) for _ in range(12)], dots_size=5)
        line.add("test_fill", [randint(1, 3) for _ in range(12)], fill=True)

        line.x_labels = [
            "lol",
            "lol1",
            "lol2",
            "lol3",
            "lol4",
            "lol5",
            "lol6",
            "lol7",
            "lol8",
            "lol9",
            "lol10",
            "lol11",
        ]
        return line.render_response()
コード例 #47
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
コード例 #48
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
コード例 #49
0
ファイル: tests.py プロジェクト: fredtantini/pygal
 def test_labels():
     line = Line()
     line.add('test1', range(100))
     line.x_labels = map(str, range(11))
     return line.render_response()
コード例 #50
0
ファイル: tests.py プロジェクト: Cortana-/pygal
 def test_ylabels():
     chart = Line()
     chart.x_labels = "Red", "Blue", "Green"
     chart.y_labels = 0.0001, 0.0003, 0.0004, 0.00045, 0.0005
     chart.add("line", [0.0002, 0.0005, 0.00035])
     return chart.render_response()
コード例 #51
0
ファイル: tests.py プロジェクト: ChaliZhg/pygal
 def test_ylabels():
     chart = Line()
     chart.x_labels = 'Red', 'Blue', 'Green'
     chart.y_labels = .0001, .0003, .0004, .00045, .0005
     chart.add('line', [.0002, .0005, .00035])
     return chart.render_response()
コード例 #52
0
ファイル: tests.py プロジェクト: wuzesheng/pygal
 def test_labels():
     line = Line()
     line.add('test1', range(100))
     line.x_labels = map(str, range(11))
     return line.render_response()
コード例 #53
0
ファイル: tests.py プロジェクト: wuzesheng/pygal
 def test_ylabels():
     chart = Line()
     chart.x_labels = 'Red', 'Blue', 'Green'
     chart.y_labels = .0001, .0003, .0004, .00045, .0005
     chart.add('line', [.0002, .0005, .00035])
     return chart.render_response()
コード例 #54
0
ファイル: namd-plot.py プロジェクト: mermoldy/namd-tools
# -*- coding: utf-8 -*-
import os
from pygal.style import Style
from pygal       import Line

X_AXIS = [ 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]
Y_AXIS = [ 3.909, 6.833, 9.520, 12.26, 14.89, 17.58, 20.20, 22.81, 25.96, 28.11, 31.20, 33.46, 36.32, 38.54, 41.58, 44.32, 46.80, 49.74, 52.17, 54.85]

LightStyle = Style ( 
   					    background       ='white',
    					plot_background  ='white',
    					foreground       ='black',
    					foreground_light ='black',
    					foreground_dark  ='black',
    					colors           =('#0100FF', '#9f6767')
   					)

plot = Line(style=LightStyle, x_label_rotation=90)
plot.x_labels = map(str, X_AXIS)
plot.add('Wall time, sec', Y_AXIS) 
plot.render_to_file('namd-plot.svg')
os.system("inkscape -z -e namd-plot.png -w 1024 -h 1024 namd-plot.svg")
os.system("rm namd-plot.svg")