예제 #1
0
def graph_data(list_of_plots, output_directory, resource_path,
               output_filename):
    date_plot = pygal.DateY(x_label_rotation=20,
                            height=500,
                            width=1200,
                            legend_at_bottom=True,
                            style=pygal.style.BlueStyle)
    for plot in list_of_plots:
        plot_data = []
        with open(plot.input_csv, 'r') as csv_data:
            for line in csv_data:
                line_data = line.strip('\n').split(',')
                if '.' in line_data[0]:
                    plot_data.append(
                        (datetime.datetime.strptime(line_data[0],
                                                    '%Y-%m-%d %H:%M:%S.%f'),
                         float(line_data[1])))
                else:
                    plot_data.append(
                        (datetime.datetime.strptime(line_data[0],
                                                    '%Y-%m-%d %H:%M:%S'),
                         float(line_data[1])))
        date_plot.add(plot.graph_title, plot_data)
        date_plot.render_to_file(
            os.path.join(output_directory, output_filename + '.svg'))
        with open(os.path.join(output_directory, output_filename + '.div'),
                  'w') as div_file:
            div_file.write('<figure><embed type="image/svg+xml" src="' +
                           resource_path + '/' + output_filename + '.svg' +
                           '"/></figure>')
        return True, os.path.join(output_directory, output_filename + '.div')
예제 #2
0
    def generate(self, data_sorted, multiplier, calc_netsize):

        _netsize_graph = pygal.DateY(show_dots=False, x_label_rotation=20)
        _requests_graph = pygal.DateY(show_dots=False, x_label_rotation=20)

        _netsize_graph.title = 'Est. Network Size (multiplier: %d)' % multiplier
        _requests_graph.title = 'Requests Per Hour'

        netsize_s, req_s = list(), list()
        for hour, netsize, reqs in self.collect(data_sorted, multiplier,
                                                calc_netsize):
            netsize_s.append((hour, netsize))
            req_s.append((hour, reqs))

        _netsize_graph.add('Routers', netsize_s)
        _requests_graph.add('news.xml Requests', req_s)
        return _netsize_graph, _requests_graph
예제 #3
0
def generate_chart(calendar, filename):
    imps = {}
    for improvement in calendar:
        imp_date = datetime.fromtimestamp(int(improvement['datetime'] / 1000))
        print imp_date
        day = imps.get(str(imp_date.date()), {})
        if not day:
            imps[str(imp_date.date())] = {}
        points_of_day = day.get('points', 0)
        points_of_day += int(improvement['improvement'])
        imps[str(imp_date.date())]['points'] = points_of_day
        imps[str(imp_date.date())]['date'] = imp_date.date()

    datey = pygal.DateY(range=(0), x_label_rotation=20)

    datey.add(
        "Points",
        sorted([(imps[key]['date'], imps[key]['points']) for key in imps],
               key=lambda variable: variable[0]))

    datey.render_to_file(filename, include_x_axis=True)
예제 #4
0
# -*- coding: utf-8 -*-
import pygal
from datetime import datetime

Date_Y = pygal.DateY(x_label_rotation=25)
Date_Y.title = "Flights and amount of passengers arriving from St. Louis."
Date_Y.add("Arrival",
           [(datetime(2014, 1, 5), 42), (datetime(2014, 1, 14), 123),
            (datetime(2014, 2, 2), 97), (datetime(2014, 3, 22), 164)])
Date_Y.render_to_file('datey_chart.svg')
예제 #5
0
# -*- coding: utf-8 -*-
import pygal
from datetime import datetime

Date_Y = pygal.DateY()
Date_Y.title = "Flights and amount of passengers arriving from St. Louis."
Date_Y.add("Arrival", [
    (datetime(2014, 1, 5), 42), 
    (datetime(2014, 1, 14), 123),
    (datetime(2014, 2, 2), 97),
    (datetime(2014, 3, 22), 164)
])
Date_Y.render_to_file('datey_chart.svg')
예제 #6
0
              (datetime(2016, 2, 9, 8, 11, 29), 1),
              (datetime(2016, 2, 9, 8, 11, 59), 10),
              (datetime(2016, 2, 9, 8, 12, 29), 1),
              (datetime(2016, 2, 9, 8, 12, 59), 3)]

    gstyle = Style(
        # http://www.pygal.org/en/latest/documentation/custom_styles.html
        background='white',
        plot_background='rgba(0, 0, 255, 0.03)',
        foreground='rgba(0, 0, 0, 0.8)',
        foreground_light='rgba(0, 0, 0, 0.9)',
        foreground_dark='rgba(0, 0, 0, 0.7)',
        colors=('#5DA5DA', '#FAA43A', '#60BD68', '#F17CB0', '#4D4D4D',
                '#B2912F', '#B276B2', '#DECF3F', '#F15854'))
    # human_readable is what introduce the strange Y data labels.
    graph = pygal.DateY(x_label_rotation=20,
                        title="Test",
                        x_title="Time",
                        y_title="Water Volume",
                        legend_at_bottom=True,
                        human_readable=False,
                        style=gstyle,
                        x_labels_major_every=5)
    # include_x_axis=True)
    graph.x_label_format = "%Y-%m-%d %I:%M:%S"
    #graph.add("graph1",list(zip(x,y))+[None,None])
    graph.add("graph1", tuples + [None, None])
    graph.render_to_file("/redhat/html/misc/pygal/datey-time.svg")

    sys.exit()
예제 #7
0
    cur.execute(
        'SELECT timeutc, scal FROM rinn_thal__temp1 WHERE scal != \'0\' ORDER BY timeutc ASC LIMIT 10000'
    )
    t1 = cur.fetchall()
    #cur.execute('SELECT timeutc, scal FROM rinn_thal__temp1 WHERE scal != \'0\' ORDER BY timeutc ASC')
    #t2 = cur.fetchall()
    cur.execute(
        'SELECT timeutc, scal FROM rinn_thal__hum1 WHERE scal != \'0\' ORDER BY timeutc ASC LIMIT 10000'
    )
    h1 = cur.fetchall()

    dark_lighten_style = LightenStyle('#336676',
                                      base_style=LightColorizedStyle)

    datey = pygal.DateY(x_label_rotation=20,
                        dots_size=1,
                        order_min=-1,
                        style=dark_lighten_style)
    datey.add("Temp1", t1)
    #datey.add("Temp2", t2)
    datey.add("Hum1", h1, secondary=True)

    datey.x_label_format = "%Y-%m-%d"
    datey.render_to_file('demo_pygal_2.svg')

except psycopg2.DatabaseError, e:
    print 'Error %s' % e
    sys.exit(1)

finally:
    if con:
        con.close()