def RenderGoogleChart(data, filename):    
    """
    create a GoogleChart from decoded data under filename (.png)
    """
    print "Rendering GoogleChart [%s]" % filename
    # Retrieve chart data
    elements=[]
    max_y = 0
    min_y = 9999
    for i in range(len(data["time"])):
        if data["cps"][i] > max_y: max_y = data["cps"][i]
        if data["cps"][i] < min_y: min_y = data["cps"][i]
        elements.append(data["cps"][i])

    # Chart size of 600x375 pixels and specifying the range for the Y axis
    chart = SimpleLineChart(600, 375, y_range=[min_y-0.1, max_y+0.1])
    
    # Add the chart data
    chart.add_data(elements)
    
    # Set the line colour to blue
    chart.set_colours(['0000FF'])

    # Set the vertical stripes
    chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)

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

    # Define the Y axis labels
    left_axis = [x * 0.1 for x in range(0, int(max_y/0.1))]
    left_axis[0] = 'CPS'
    chart.set_axis_labels(Axis.LEFT, left_axis)

    chart.download(filename)
Exemplo n.º 2
0
def enterprises_graph(num_days=14):
	chart_name="enterprises.png"
	# its a beautiful day
	today = datetime.today().date()

	# step for x axis
	step = timedelta(days=1)

	# empties to fill up with data
	counts = []
	dates = []

	# only get last two weeks of entries 
	day_range = timedelta(days=num_days)
	entries = Enterprise.objects.filter(
			created_at__gt=(today	- day_range))
	
	# count entries per day
	for day in range(num_days):
		count = 0
		d = today - (step * day)
		for e in entries:
			if e.created_at.day == d.day:
				count += 1
		dates.append(d.day)
		counts.append(count)
    
    	line = SimpleLineChart(440, 100, y_range=(0, 100))
	line.add_data(counts)
	line.set_axis_labels(Axis.BOTTOM, dates)
	line.set_axis_labels(Axis.BOTTOM, ['','Date', ''])
	line.set_axis_labels(Axis.LEFT, ['', 5, 10])
	line.set_colours(['0091C7'])
	line.download('apps/shabaa/static/graphs/' + chart_name)
	return chart_name
Exemplo n.º 3
0
def graph_entries(num_days=14):
	# its a beautiful day
	today = datetime.today().date()

	# step for x axis
	step = timedelta(days=1)

	# empties to fill up with data
	counts = []
	dates = []

	# only get last two weeks of entries 
	day_range = timedelta(days=num_days)
	entries = Entry.objects.filter(
			time__gt=(today	- day_range))
	
	# count entries per day
	for day in range(num_days):
		count = 0
		d = today - (step * day)
		for e in entries:
			if e.time.day == d.day:
				count += 1
		dates.append(d.day)
		counts.append(count)
    
    	line = SimpleLineChart(440, 100, y_range=(0, 100))
	line.add_data(counts)
	line.set_axis_labels(Axis.BOTTOM, dates)
	line.set_axis_labels(Axis.BOTTOM, ['','Date', ''])
	line.set_axis_labels(Axis.LEFT, ['', 50, 100])
	line.set_colours(['0091C7'])
	line.download('webui/graphs/entries.png')
	
	return 'saved entries.png' 
Exemplo n.º 4
0
    def create_graph(self, particle_data, time_data):
        # Set the vertical range from 0 to 2
        max_y = 2

        # Chart size of 500x500 pixels and specifying the range for the Y axis
        chart = SimpleLineChart(500, 500, y_range=[0, max_y])

        # Add the chart data
        data = particle_data

        chart.add_data(data)

        # Set the line color blue
        chart.set_colours(['0000FF'])

        # Set the vertical stripes
        chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)

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

        # The Y axis labels
        left_axis = ['0.25', '0.5', '0.75', '1']
        left_axis[0] = ''
        chart.set_axis_labels(Axis.LEFT, left_axis)
        left_axis2 = "Proton Flux"[::-1]
        chart.set_axis_labels(Axis.LEFT, left_axis2)

        # X axis labels
        chart.set_axis_labels(Axis.BOTTOM, time_data[0:3][::-1])
        chart.set_axis_labels(Axis.BOTTOM, "Time")

        chart.download('chart.png')
        return True
Exemplo n.º 5
0
class DiceChart:
    chart = None

    def __init__(self, data, iter=0, width=300, height=300):
        self.chart = SimpleLineChart(width, height, y_range=(0, 10))
        legend = []
        colors = ["cc0000", "00cc00", "0000cc", "990000", "009900", "000099", "0099ff", "FF9900", "9900ff", "ff0099"]
        title = "die rolls per objective"
        if iter > 0:
            title = title + " (%s samples)" % iter
        for i in data.keys():
            self.chart.add_data(data[i])
            legend.append(str(i))

        logging.debug(legend)
        logging.debug(colors)
        self.chart.set_colours(colors)
        self.chart.set_legend(legend)

        grid_x_amount = 100 / (len(data[i]) - 1)
        self.chart.set_grid(grid_x_amount, 10, 5, 5)

        left_axis = range(0, 11, 1)
        left_axis[0] = ""
        self.chart.set_axis_labels(Axis.LEFT, left_axis)

        bottom_len = len(data[i]) + 2
        bottom_axis = range(2, bottom_len, 1)
        self.chart.set_axis_labels(Axis.BOTTOM, bottom_axis)

        self.chart.set_title(title)

    def download(self, name="dicechart.png"):
        self.chart.download(name)
Exemplo n.º 6
0
def getRollingAverageGraph(cursor, colName, rollingWindowDays, title=""):
    sqlCMD = "SELECT pDate, %s from %s" %(colName, N.JOBS_SUMMARY_TABLENAME)
    cursor.execute(sqlCMD)
    results = cursor.fetchall()
    
    beginWindowIndex = 0
    endWindowIndex = 0
    xData = []
    yData = []
    while endWindowIndex < len(results):
        while endWindowIndex < len(results) and (results[endWindowIndex][0] - results[beginWindowIndex][0]).days <= rollingWindowDays:
            endWindowIndex += 1
        yData.append( sum(results[i][1] for i in xrange(beginWindowIndex, endWindowIndex, 1)) / float(endWindowIndex - beginWindowIndex))
        xData.append(results[endWindowIndex-1][0])
        beginWindowIndex = endWindowIndex
    chart = SimpleLineChart(680, 400, y_range = (min(yData)-1, max(yData)+1))
    chart.add_data(yData)
    
    yLabels = range(0, int(max(yData)+1), 5)
    yLabels[0] = ''
    xLabels = [str(xData[-i]) for i in xrange(1, len(xData)-1, int(0.2*len(xData)))]
    xLabels.reverse()
    chart.set_axis_labels(Axis.LEFT, yLabels)
    chart.set_axis_labels(Axis.BOTTOM, xLabels)
    chart.set_title("Rolling %i-Day Average %s" % (rollingWindowDays, title))
    chart.download(N.TEMPIMAGE + 'temp.png')
    f = open(N.TEMPIMAGE + 'temp.png','r')
    toReturn = cStringIO.StringIO(f.read())
    f.close()
    toReturn.seek(0)
    return chart.get_url(), toReturn
    def get_chart_image(self, data, **kw):
        """Return a image file path

        Arguments::

            data -- a list containing the X,Y data representation
        """
        from pygooglechart import SimpleLineChart, Axis

        # Set the vertical range from 0 to 100
        try:
            max_y = max(data['y'])
            min_y = min(data['y'])
        except:
            min_y = 0
            max_y = 100
        width = int(kw.get('width', 600))
        height = int(kw.get('height', 250))
        # Chart size of widthxheight pixels and specifying the range for the Y axis
        chart = SimpleLineChart(width, height, y_range=[0, max_y])

        # Add the chart data
        chart.add_data(data['y'])

        # Set the line colour to blue
        chart.set_colours(['0000FF'])

        try:
            step_x = int(100/(len(data['x'])-1))
        except:
            step_x = 0
        chart.set_grid(step_x, 10, 5, 5)

        # The Y axis labels contains min_y to max_y spling it into 10 equal parts,
        #but remove the first number because it's obvious and gets in the way
        #of the first X label.
        left_axis = [utils.intcomma(x) for x in range(0, max_y + 1, (max_y)/10)]
        left_axis[0] = ''
        chart.set_axis_labels(Axis.LEFT, left_axis)

        # X axis labels
        chart.set_axis_labels(Axis.BOTTOM, data['x'])

        #Generate an hash from arguments
        kw_hash = hash(tuple(sorted(kw.items())))
        data_hash = hash(tuple(sorted([(k, tuple(v))
            for k, v in data.iteritems()])))
        args_hash = str(kw_hash) + str(data_hash)

        image_path = os.path.join(TARGET_DIR, "%s.png" % args_hash)

        if bool(kw.get('refresh', False)) or args_hash not in self.charts:
            #Get image from google chart api
            chart.download(image_path)
            if args_hash not in self.charts:
                self.charts.append(args_hash)
            self._p_changed = True

        return image_path
Exemplo n.º 8
0
def simple_random():
    chart = SimpleLineChart(300, 100, y_range=(0, 100))
    max_y = 100
    list_data = [10, 90, 80, 10, 10, 20, 30, 20, 15, 45, 56, 42, 92]
    chart.add_data(list_data)
    chart.add_data(reversed(list_data))
    chart.set_axis_labels(Axis.LEFT, ['', max_y / 2, max_y])
    chart.set_axis_labels(Axis.BOTTOM, ['Sep', 'Oct', 'Nov', 'Dec'])
    chart.download('line-simple-random.png')
Exemplo n.º 9
0
def simple_line():
    chart = SimpleLineChart(settings.width, settings.height,
                                      x_range=(0, 35))
    chart.set_colours(['00ff00', 'ff0000','ACff0C','B0ffE0','C0ffFF'])
    chart.add_data([1,2,3,4,5])
    chart.add_data([1,4,9,16,25])
    chart.set_title('This is title')
    chart.set_axis_labels('r', 'str')
    chart.set_legend( ['a','b','c','d','e'])
    chart.download('simple-line.png')
Exemplo n.º 10
0
def lineGraphFeed(feed):
    name = feed.getAttribute("name")
    observations = feed.getElementsByTagName("observation")
    print "  Feed %s has %d observations" % (name,len(observations))
    data = []
    for obs in observations:
        value = int(obs.getAttribute("value"))
        #print "   val:%s (%s)" % (value, type(value))
        data.insert(0,value/10)

    #data.reverse  # remeber the feed is reversed
    print "Max Data: %s" % max(data)

    max_y = int(math.ceil(max(data)/100.0))*100
    print "Max_y : %s" % max_y
    chart = SimpleLineChart(180, 120, y_range=[0, max_y])
    chart.add_data(data)

    lftAxisMax = max_y/100;
    print "lftAxisMax %s"%lftAxisMax
    #left_axis = range(0, lftAxisMax,(lftAxisMax/4.0))
    left_axis = []
    right_axis = []
    for i in range(0,4+1):
        kw = (i*lftAxisMax/4.0)
        left_axis.append(kw)
        right_axis.append(kw*24)

    left_axis[0] = 'kW' # remove the first label
    right_axis[0] = 'kWh/d' # remove the first label
    chart.set_axis_labels(Axis.LEFT, left_axis)
    #chart.set_axis_labels(Axis.RIGHT, right_axis)

    chart.set_title(name)

    # facebook colors
    chart.set_title_style('7f93bc',16)
    #chart.set_colours(['7f93bc'])
    chart.set_colours(['3b5998']) #darker blue

    #Colors
    colors=False
    if (colors):
        # Set the line colour to ...
        chart.set_colours(['FFFFFF'])
        # 0 here is the axis index ? 0 works for now
        chart.set_title_style('FFFFFF',16)
        chart.set_axis_style(0,'FFFFFF')
        chart.set_axis_style(1,'FFFFFF')
        chart.fill_linear_gradient(Chart.BACKGROUND,90,'000000',0.9,'007700',0.1)


    print chart.get_url()
    chart.download('%s-line.png'%name)
Exemplo n.º 11
0
def many_labels():
    chart = SimpleLineChart(settings.width, settings.height)

    for a in xrange(3):
        for axis_type in (Axis.LEFT, Axis.RIGHT, Axis.BOTTOM):
            index = chart.set_axis_range(axis_type, 0, random.random() * 100)
            chart.set_axis_style(index, colour=helper.random_colour(), \
                font_size=random.random() * 10 + 5)

    chart.add_data(helper.random_data())
    chart.download('label-many.png')
Exemplo n.º 12
0
def many_labels():
    chart = SimpleLineChart(settings.width, settings.height)

    for a in range(3):
        for axis_type in (Axis.LEFT, Axis.RIGHT, Axis.BOTTOM):
            index = chart.set_axis_range(axis_type, 0, random.random() * 100)
            chart.set_axis_style(index, colour=helper.random_colour(), \
                font_size=random.random() * 10 + 5)

    chart.add_data(helper.random_data())
    chart.download('label-many.png')
Exemplo n.º 13
0
def plotter(fund):
    
    (dates, values) = dataparser("data/%s" % fund)
    left_axis = [int(min(values)), int(max(values) + 1)]
    
    chart = SimpleLineChart(600, 375, y_range=[min(values), max(values) + 1])
    chart.add_data(values)
    chart.add_data([0] * 2)
    chart.set_colours(['76A4FB'] * 5)
    chart.add_fill_range('76A4FB', 0, 1)
    chart.set_grid(0, 5, 1, 25)
    chart.set_axis_labels(Axis.LEFT, left_axis)
    chart.set_axis_labels(Axis.BOTTOM, dates)

    chart.download("charts/%s.png" % fund)
def makechart(aaseq, regions):
    hdph = dict()
    hdph['d'] = -3.5
    hdph['e'] = -3.5
    hdph['k'] = -3.9
    hdph['r'] = -4.5
    hdph['h'] = -3.2
    hdph['y'] = -1.3
    hdph['w'] = -0.9
    hdph['f'] = 2.8
    hdph['c'] = 2.5
    hdph['m'] = 1.9
    hdph['s'] = -0.8
    hdph['t'] = -0.7
    hdph['n'] = -3.5
    hdph['q'] = -3.5
    hdph['g'] = -0.4
    hdph['a'] = 1.8
    hdph['v'] = 4.2
    hdph['l'] = 3.8
    hdph['i'] = 4.5
    hdph['p'] = -1.6
    hdphseq = []
    for i in range(len(aaseq)):
        hdphseq.append(hdph[aaseq[i]])
    
    regionseq = parseregion(regions)
    
    #print regionseq

    min_y = -5
    max_y = 5
    chart = SimpleLineChart(800, 300, y_range=[min_y, max_y])
    
    #chart.add_data([max_y]*2)
    chart.add_data(hdphseq)   
    chart.add_data(regionseq)
    chart.add_data([min_y]*2)
    chart.set_colours(['76A4FB', 'ADFF2F', '000000'])
    chart.add_fill_range('ADFF2F', 1, 2)
    chart.set_axis_labels(Axis.LEFT, [min_y, '', max_y])
    chart.set_axis_labels(Axis.BOTTOM, aaseq)
    
    chart.download('test.png')
    
    #print hdphseq
    return hdphseq
Exemplo n.º 15
0
def stripes():

    # Set the vertical range from 0 to 100
    max_y = 100

    # Chart size of 200x125 pixels and specifying the range for the Y axis
    chart = SimpleLineChart(600, 500, y_range=[0, max_y])

    # Add the chart data
    # data = [
    #     32, 34, 34, 32, 34, 34, 32, 32, 32, 34, 34, 32, 29, 29, 34, 34, 34, 37,
    #     37, 39, 42, 47, 50, 54, 57, 60, 60, 60, 60, 60, 60, 60, 62, 62, 60, 55,
    #     55, 52, 47, 44, 44, 40, 40, 37, 34, 34, 32, 32, 32, 31, 32
    # ]
    # data2 = [
    #     55, 52, 47, 44, 44, 40, 40, 37, 34, 34, 32, 32, 32, 31, 32, 62, 60, 55,
    #     32, 34, 34, 32, 34, 34, 32, 32, 32, 34, 34, 32, 29, 29, 34, 34, 34, 37,
    #     37, 39, 42, 47, 50, 54, 57, 60, 60, 60, 60, 60, 60, 60, 62
    # ]
    data = xrange(0, 100, 20)
    data2 = [0, 20, 20, 40, 40, 80, 80, 100, 100]
    chart.add_data(data)
    chart.add_data(data2)

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

    # Set the vertical stripes
    chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)

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

    # The Y axis labels contains 0 to 100 skipping every 25, but remove the
    # first number because it's obvious and gets in the way of the first X
    # label.
    left_axis = range(0, max_y + 1, 25)
    left_axis[0] = ''
    chart.set_axis_labels(Axis.LEFT, left_axis)

    # X axis labels
    chart.set_axis_labels(Axis.BOTTOM, \
        ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'])

    chart.download('line-stripes.png')
Exemplo n.º 16
0
def stripes():
    
    # Set the vertical range from 0 to 100
    max_y = 100

    # Chart size of 200x125 pixels and specifying the range for the Y axis
    chart = SimpleLineChart(600, 500, y_range=[0, max_y])

    # Add the chart data
    # data = [
    #     32, 34, 34, 32, 34, 34, 32, 32, 32, 34, 34, 32, 29, 29, 34, 34, 34, 37,
    #     37, 39, 42, 47, 50, 54, 57, 60, 60, 60, 60, 60, 60, 60, 62, 62, 60, 55,
    #     55, 52, 47, 44, 44, 40, 40, 37, 34, 34, 32, 32, 32, 31, 32
    # ]
    # data2 = [
    #     55, 52, 47, 44, 44, 40, 40, 37, 34, 34, 32, 32, 32, 31, 32, 62, 60, 55,
    #     32, 34, 34, 32, 34, 34, 32, 32, 32, 34, 34, 32, 29, 29, 34, 34, 34, 37,        
    #     37, 39, 42, 47, 50, 54, 57, 60, 60, 60, 60, 60, 60, 60, 62
    # ] 
    data = xrange(0, 100, 20)
    data2 = [0, 20, 20, 40, 40, 80, 80, 100, 100]
    chart.add_data(data)
    chart.add_data(data2)
    
    # Set the line colour to blue
    chart.set_colours(['0000FF','00CC00'])

    # Set the vertical stripes
    chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)

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

    # The Y axis labels contains 0 to 100 skipping every 25, but remove the
    # first number because it's obvious and gets in the way of the first X
    # label.
    left_axis = range(0, max_y + 1, 25)
    left_axis[0] = ''
    chart.set_axis_labels(Axis.LEFT, left_axis)

    # X axis labels
    chart.set_axis_labels(Axis.BOTTOM, \
        ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'])

    chart.download('line-stripes.png')
Exemplo n.º 17
0
    def printGoogleCharts(X, Y, title, min_y, max_y, output):

        # Create a chart object of 750x400 pixels
        chart = SimpleLineChart(750, 400)

        # Add some data
        chart.add_data(Y)

        # Assign the labels to the pie data
#        chart.set_axis_labels(Axis.BOTTOM, X)
        chart.set_axis_labels(Axis.LEFT, range(int(min_y)-1, int(max_y)+1, 5))
        chart.set_title(title)

        # Print the chart URL
        print chart.get_url()

        # Download the chart
        chart.download(output+".png")
Exemplo n.º 18
0
class PlotObject(object):
    def __init__(self):

        # Set the vertical range from 0 to 100
        factor = 8 - 1
        max_y = 20 * factor
        max_x = 250
        # Chart size of 200x125 pixels and specifying the range for the Y axis
        self.chart = SimpleLineChart(
            width=50 * factor,
            height=25 * factor,
            title='ping ftp.sunet.se',
            #                                     legend=True,
            x_range=[0, max_x],
            y_range=[0, max_y])

        # Set the line colour to blue
        self.chart.set_colours(colours=['0000FF'])

        # Set the vertical stripes:arguments area, angle etc.
        #self.chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)

        # Set the horizontal dotted lines
        #self.chart.set_grid(x_step=0, y_step=5*factor, line_segment=factor, blank_segment=factor)

        # The Y axis labels contains 0 to 100 skipping every 25, but remove the
        # first number because it's obvious and gets in the way of the first X
        # label.
        left_axis = range(0, max_y + 1, 25)
        left_axis[0] = ''
        self.chart.set_axis_labels(axis_type=Axis.LEFT, values=left_axis)

        # X axis labels
        self.chart.set_axis_labels(axis_type=Axis.BOTTOM, \
#        ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'])

        values= [ ' ', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'])

    def plot(self, data):

        self.chart.add_data(data=data)

        self.chart.download(file_name='misse.png')
Exemplo n.º 19
0
def linechart(name, dataset, size=(400,400)):
    max_y = maxy(dataset)
    chart = SimpleLineChart(size[0], size[1], y_range=[0, max_y])
    legend = []
    for series_name, s in dataset:
        chart.add_data([y for x, y in s])
        legend.append(series_name)
    
    chart.set_colours(['057D9F', '8106A9', 'E9FB00', 'FF8100'])
    chart.set_legend(legend)
    chart.set_grid(0, 25, 5, 5)
    
    left_axis = range(0, int(max_y + 1), 25)
    left_axis[0] = ''
    chart.set_axis_labels(Axis.LEFT, left_axis)
    
    bottom_axis = [x for x, y in dataset[0][1]]
    chart.set_axis_labels(Axis.BOTTOM, bottom_axis)
    chart.download(name)
Exemplo n.º 20
0
def generateGraph(fMesureGlobalPerCent, nbComparison, resPath):
    max_y = 100#Fmesure à 100%
    chart = SimpleLineChart(500, 500, y_range=[0, max_y])
    chart.add_data(fMesureGlobalPerCent)
    chart.set_colours(['0000FF'])
    chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)
    chart.set_grid(0, 25, 5, 5)
   
    left_axis = range(0, max_y + 1, 25)
    left_axis[0] = ''
    chart.set_axis_labels(Axis.LEFT, left_axis)


    y_axis = []
    for x in range(nbComparison):
        if x%5 == 0:
            y_axis.append(x)
    chart.set_axis_labels(Axis.BOTTOM, y_axis)
    chart.download(resPath)
Exemplo n.º 21
0
    def linegraph(self, days, bars, output, title=""):
        data = []
        min_count = 0
        max_count = 0
        date = lambda i: datetime.date.today() + datetime.timedelta(-days + i)

        for i in range(0, days + 1):
            count = bars[date(i)]
            max_count = max(count, max_count)
            min_count = min(count, min_count)
            data.append(count)
        chart = SimpleLineChart(800, 350, y_range=[min_count, 60000])
        chart.add_data(data)
        # Set the line colour to blue
        chart.set_colours(['0000FF'])

        # Set the vertical stripes
        d = max(1 / float(days), round(7 / float(days), 2))
        chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', d, 'FFFFFF', d)

        fmt = "%d/%m"
        chart.set_axis_labels(Axis.BOTTOM, \
                              [date(i).strftime(fmt) for i in range(0,days,7)])

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

        # The Y axis labels contains 0 to 100 skipping every 25, but remove the
        # first number because it's obvious and gets in the way of the first X
        # label.
        delta = float(max_count - min_count) / 100
        skip = int(delta) / 5 * 100
        left_axis = range(0, 60000 + 1, skip)
        left_axis[0] = ''
        chart.set_axis_labels(Axis.LEFT, left_axis)

        if len(title) > 0:
            chart.set_title(title % days)

        chart.download(output)
Exemplo n.º 22
0
        def linegraph(self,days,bars,output,title = ""):
                data = []
                min_count = 0
                max_count = 0
                date = lambda i:datetime.date.today() + datetime.timedelta(-days + i)

                for i in range(0,days+1):
                        count = bars[date(i)]
                        max_count = max(count,max_count)
                        min_count = min(count,min_count)
                        data.append(count)
                chart = SimpleLineChart(800,350,y_range=[min_count, 60000])
                chart.add_data(data)
                # Set the line colour to blue
                chart.set_colours(['0000FF'])

                # Set the vertical stripes
                d = max(1/float(days),round(7/float(days),2))
                chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', d, 'FFFFFF', d)

                fmt="%d/%m"
                chart.set_axis_labels(Axis.BOTTOM, \
                                      [date(i).strftime(fmt) for i in range(0,days,7)])

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

                # The Y axis labels contains 0 to 100 skipping every 25, but remove the
                # first number because it's obvious and gets in the way of the first X
                # label.
                delta = float(max_count-min_count) / 100
                skip = int(delta) / 5 * 100
                left_axis = range(0, 60000 + 1, skip)
                left_axis[0] = ''
                chart.set_axis_labels(Axis.LEFT, left_axis)

                if len(title) > 0:
                        chart.set_title(title % days)

                chart.download(output)
def makechart(aaseq, regions):
    hdph = dict()
    hdph['d'] = -3.5
    hdph['e'] = -3.5
    hdph['k'] = -3.9
    hdph['r'] = -4.5
    hdph['h'] = -3.2
    hdph['y'] = -1.3
    hdph['w'] = -0.9
    hdph['f'] = 2.8
    hdph['c'] = 2.5
    hdph['m'] = 1.9
    hdph['s'] = -0.8
    hdph['t'] = -0.7
    hdph['n'] = -3.5
    hdph['q'] = -3.5
    hdph['g'] = -0.4
    hdph['a'] = 1.8
    hdph['v'] = 4.2
    hdph['l'] = 3.8
    hdph['i'] = 4.5
    hdph['p'] = -1.6
    hdphseq = []
    for i in range(len(aaseq)):
        hdphseq.append(hdph[aaseq[i]])
    
    min_y = -5
    max_y = 5
    chart = SimpleLineChart(2, 2, y_range=[min_y, max_y])
    
    #chart.add_data([max_y]*2)
    chart.add_data(hdphseq)   
    #chart.add_data([min_y]*2)
    chart.set_axis_labels(Axis.BOTTOM, aaseq)
    
    chart.download('test.png')
    
    #print hdphseq
    return hdphseq
Exemplo n.º 24
0
def cat_proximity():
    """Cat proximity graph from http://xkcd.com/231/"""
    chart = SimpleLineChart(int(settings.width * 1.5), settings.height)
    chart.set_legend(['INTELLIGENCE', 'INSANITY OF STATEMENTS'])

    # intelligence
    data_index = chart.add_data([100. / y for y in xrange(1, 15)])

    # insanity of statements
    chart.add_data([100. - 100 / y for y in xrange(1, 15)])

    # line colours
    chart.set_colours(['208020', '202080'])

    # "Near" and "Far" labels, they are placed automatically at either ends.
    near_far_axis_index = chart.set_axis_labels(Axis.BOTTOM, ['FAR', 'NEAR'])

    # "Human Proximity to cat" label. Aligned to the center.
    index = chart.set_axis_labels(Axis.BOTTOM, ['HUMAN PROXIMITY TO CAT'])
    chart.set_axis_style(index, '202020', font_size=10, alignment=0)
    chart.set_axis_positions(index, [50])

    chart.download('label-cat-proximity.png')
Exemplo n.º 25
0
def cat_proximity():
    """Cat proximity graph from http://xkcd.com/231/"""
    chart = SimpleLineChart(int(settings.width * 1.5), settings.height)
    chart.set_legend(['INTELLIGENCE', 'INSANITY OF STATEMENTS'])

    # intelligence
    data_index = chart.add_data([100. / y for y in xrange(1, 15)])

    # insanity of statements
    chart.add_data([100. - 100 / y for y in xrange(1, 15)])

    # line colours
    chart.set_colours(['208020', '202080'])

    # "Near" and "Far" labels, they are placed automatically at either ends.
    near_far_axis_index = chart.set_axis_labels(Axis.BOTTOM, ['FAR', 'NEAR'])

    # "Human Proximity to cat" label. Aligned to the center.
    index = chart.set_axis_labels(Axis.BOTTOM, ['HUMAN PROXIMITY TO CAT'])
    chart.set_axis_style(index, '202020', font_size=10, alignment=0)
    chart.set_axis_positions(index, [50])

    chart.download('label-cat-proximity.png')
Exemplo n.º 26
0
def fill():

    # Set the vertical range from 0 to 50
    max_y = 50
    chart = SimpleLineChart(200, 125, y_range=[0, max_y])

    # First value is the highest Y value. Two of them are needed to be
    # plottable.
    chart.add_data([max_y] * 2)

    # 3 sets of real data
    chart.add_data([28, 30, 31, 33, 35, 36, 42, 48, 43, 37, 32, 24, 28])
    chart.add_data([16, 18, 18, 21, 23, 23, 29, 36, 31, 25, 20, 12, 17])
    chart.add_data([7, 9, 9, 12, 14, 14, 20, 27, 21, 15, 10, 3, 7])

    # Last value is the lowest in the Y axis.
    chart.add_data([0] * 2)

    # Black lines
    chart.set_colours(['000000'] * 5)

    # Filled colours
    # from the top to the first real data
    chart.add_fill_range('76A4FB', 0, 1)

    # Between the 3 data values
    chart.add_fill_range('224499', 1, 2)
    chart.add_fill_range('FF0000', 2, 3)

    # from the last real data to the
    chart.add_fill_range('80C65A', 3, 4)

    # Some axis data
    chart.set_axis_labels(Axis.LEFT, ['', max_y / 2, max_y])
    chart.set_axis_labels(Axis.BOTTOM, ['Sep', 'Oct', 'Nov', 'Dec'])

    chart.download('line-fill.png')
Exemplo n.º 27
0
def fill():

    # Set the vertical range from 0 to 50
    max_y = 50
    chart = SimpleLineChart(200, 125, y_range=[0, max_y])

    # First value is the highest Y value. Two of them are needed to be
    # plottable.
    chart.add_data([max_y] * 2)

    # 3 sets of real data
    chart.add_data([28, 30, 31, 33, 35, 36, 42, 48, 43, 37, 32, 24, 28])
    chart.add_data([16, 18, 18, 21, 23, 23, 29, 36, 31, 25, 20, 12, 17])
    chart.add_data([7, 9, 9, 12, 14, 14, 20, 27, 21, 15, 10, 3, 7])

    # Last value is the lowest in the Y axis.
    chart.add_data([0] * 2)

    # Black lines
    chart.set_colours(['000000'] * 5)

    # Filled colours
    # from the top to the first real data
    chart.add_fill_range('76A4FB', 0, 1)

    # Between the 3 data values
    chart.add_fill_range('224499', 1, 2)
    chart.add_fill_range('FF0000', 2, 3)

    # from the last real data to the
    chart.add_fill_range('80C65A', 3, 4)

    # Some axis data
    chart.set_axis_labels(Axis.LEFT, ['', max_y / 2, max_y])
    chart.set_axis_labels(Axis.BOTTOM, ['Sep', 'Oct', 'Nov', 'Dec'])

    chart.download('line-fill.png')
Exemplo n.º 28
0
def fill():

    # Set the vertical range from 0 to 50
    max_y = 50
    chart = SimpleLineChart(200, 125, y_range=[0, max_y])

    # First value is the highest Y value. Two of them are needed to be
    # plottable.
    #chart.add_data([max_y] * 2)

    # 3 sets of real data
    chart.add_data([0, 28, None,None])
    chart.add_data([None, 28, 18,None])
    chart.add_data([None, None, 18,30])

    # Last value is the lowest in the Y axis.
    #chart.add_data([0] * 2)

    # Black lines
    chart.set_colours(["ffc900","d60000","8fb800","d60000","8fb800"])

    # Filled colours
    # from the top to the first real data
    #chart.add_fill_range('76A4FB', 0, 1)

    # Between the 3 data values
    #chart.add_fill_range('224499', 1, 2)
    #chart.add_fill_range('FF0000', 2, 3)

    # from the last real data to the
    #chart.add_fill_range('80C65A', 3, 4)

    # Some axis data
    chart.set_axis_labels(Axis.LEFT, ['', max_y / 2, max_y])
    chart.set_axis_labels(Axis.BOTTOM, ['Sep', 'Oct', 'Nov', 'Dec'])

    chart.download('line-fill.png')
Exemplo n.º 29
0
def draw_plot(data, generation):
    # Set the vertical range from 0 to 100
    max_y = data[0]

    # Chart size of 200x125 pixels and specifying the range for the Y axis
    chart = SimpleLineChart(600, 325, y_range=[0, max_y])

    # Add the chart data
    """
	data = [
	    32, 34, 34, 32, 34, 34, 32, 32, 32, 34, 34, 32, 29, 29, 34, 34, 34, 37,
	    37, 39, 42, 47, 50, 54, 57, 60, 60, 60, 60, 60, 60, 60, 62, 62, 60, 55,
	    55, 52, 47, 44, 44, 40, 40, 37, 0,0,0,0,0,0,0
	]
	"""
    chart.add_data(data)

    # Set the line colour to blue
    chart.set_colours(['0000FF'])

    # Set the vertical stripes
    chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)

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

    # The Y axis labels contains 0 to 100 skipping every 25, but remove the
    # first number because it's obvious and gets in the way of the first X
    # label.
    left_axis = range(0, max_y + 1, 25)
    left_axis[0] = ''
    chart.set_axis_labels(Axis.LEFT, left_axis)

    # X axis labels
    chart.set_axis_labels(Axis.BOTTOM,
                          [str(x) for x in xrange(1, generation + 1)][::14])
    chart.download('plot.png')
Exemplo n.º 30
0
def stripes():
    
    # Set the vertical range from 0 to 100
    max_y = 2

    # Chart size of 200x125 pixels and specifying the range for the Y axis
    chart = SimpleLineChart(500, 500, y_range=[0, max_y])

    # Add the chart data
    data = [ 0.2121649980545044, 0.1335739940404892, 0.1369339972734451, 0.1327839940786362, 0.3375900089740753 ]
    chart.add_data(data)
    
    # Set the line colour to blue
    chart.set_colours(['0000FF'])

    # Set the vertical stripes
    chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)

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

    # The Y axis labels contains 0 to 100 skipping every 25, but remove the
    # first number because it's obvious and gets in the way of the first X
    # label.
    left_axis = list(range(0, max_y + 1, 1))
    left_axis[0] = ''
    chart.set_axis_labels(Axis.LEFT, left_axis)
    left_axis2 = "Proton Flux"[::-1]
    chart.set_axis_labels(Axis.LEFT, left_axis2)

    # X axis labels
    chart.set_axis_labels(Axis.BOTTOM, \
        ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'])
    chart.set_axis_labels(Axis.BOTTOM, "Time")

    chart.download('chart.png')
Exemplo n.º 31
0
def draw_plot(data, generation):
	# Set the vertical range from 0 to 100
	max_y = data[0]

	# Chart size of 200x125 pixels and specifying the range for the Y axis
	chart = SimpleLineChart(600, 325, y_range=[0, max_y])

	# Add the chart data
	"""
	data = [
	    32, 34, 34, 32, 34, 34, 32, 32, 32, 34, 34, 32, 29, 29, 34, 34, 34, 37,
	    37, 39, 42, 47, 50, 54, 57, 60, 60, 60, 60, 60, 60, 60, 62, 62, 60, 55,
	    55, 52, 47, 44, 44, 40, 40, 37, 0,0,0,0,0,0,0
	]
	"""	
	chart.add_data(data)

	# Set the line colour to blue
	chart.set_colours(['0000FF'])

	# Set the vertical stripes
	chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)

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

	# The Y axis labels contains 0 to 100 skipping every 25, but remove the
	# first number because it's obvious and gets in the way of the first X
	# label.
	left_axis = range(0, max_y + 1, 25)
	left_axis[0] = ''
	chart.set_axis_labels(Axis.LEFT, left_axis)

	# X axis labels
	chart.set_axis_labels(Axis.BOTTOM, [str(x) for x in xrange(1, generation+1)][::14])
	chart.download('plot.png')
Exemplo n.º 32
0
def getRollingAverageGraph(cursor, colName, rollingWindowDays, title=""):
    sqlCMD = "SELECT pDate, %s from %s" % (colName, N.JOBS_SUMMARY_TABLENAME)
    cursor.execute(sqlCMD)
    results = cursor.fetchall()
    beginWindowIndex = 0
    endWindowIndex = 0
    xData = []
    yData = []
    while endWindowIndex < len(results):
        while endWindowIndex < len(results) and (
                results[endWindowIndex][0] -
                results[beginWindowIndex][0]).days <= rollingWindowDays:
            endWindowIndex += 1
        yData.append(
            sum(results[i][1]
                for i in xrange(beginWindowIndex, endWindowIndex, 1)) /
            float(endWindowIndex - beginWindowIndex))
        xData.append(results[endWindowIndex - 1][0])
        beginWindowIndex = endWindowIndex
    chart = SimpleLineChart(680, 400, y_range=(min(yData) - 1, max(yData) + 1))
    chart.add_data(yData)

    yLabels = range(0, int(max(yData) + 1), 5)
    yLabels[0] = ''
    xLabels = [
        str(xData[-i]) for i in xrange(1,
                                       len(xData) - 1, int(0.2 * len(xData)))
    ]
    xLabels.reverse()
    chart.set_axis_labels(Axis.LEFT, yLabels)
    chart.set_axis_labels(Axis.BOTTOM, xLabels)
    chart.set_title("Rolling %i-Day Average %s" % (rollingWindowDays, title))
    imgbin = chart.download()
    toReturn = cStringIO.StringIO(imgbin)
    toReturn.seek(0)
    return chart.get_url(), toReturn
Exemplo n.º 33
0
# Chart size of 200x125 pixels and specifying the range for the Y axis
chart = SimpleLineChart(500, 250, y_range=[0, max_y])
# grep khash ~/.bitcoin/debug.log

if platform.system() == 'Linux':
    home = os.path.expanduser('~') 
    log = os.path.join(home, '.bitcoin', 'debug.log')
elif platform.system() == 'Darwin':
    home = os.path.expanduser('~') 
    log = os.path.join(home, 'Library', 'Application Support', 'Bitcoin', 'debug.log')
elif platform.system() == 'Windows':
    log = os.path.join(os.environ['appdata'], 'Bitcoin', 'debug.log')
else:
    home = os.path.expanduser('~') 
    log = os.path.join(home, '.bitcoin', 'debug.log')

debug = open(log)
data = []
for line in debug:
    if 'khash' not in line:
        continue
    #print line.split()
    data.append(int(line.split()[-2]))
    #07/19/2010 13:05 hashmeter      3 CPUs   1466 khash/s
    # Date time hashmeter #cpus hash/s
left_axis = range(0, max_y + 1, 500)
left_axis[0] = ''
chart.set_axis_labels(Axis.LEFT, left_axis)
chart.add_data(data)
chart.download('khash.png')
Exemplo n.º 34
0
print "CSV dates = " + str(csvDates)
print "CSV count = " + str(csvCount)
print str(startYear) + '-' + str(startMonth).zfill(2) + '-01'
print str(endYear) + '-' + str(endMonth).zfill(2) + '-01'

#Generate graph
max_y = 300

chart = SimpleLineChart(500, 500, y_range=[0, max_y])

chart.add_data(count)

# Set the line colour to blue
chart.set_colours(['0000FF'])

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

# The Y axis labels contains 0 to the max skipping every 25, but remove the
# first number because it's obvious and gets in the way of the first X
# label.
left_axis = list(range(0, max_y + 1, 25))
left_axis[0] = ''
chart.set_axis_labels(Axis.LEFT, left_axis)

# X axis labels
chart.set_axis_labels(Axis.BOTTOM, numbers)

chart.download('chart-output.png')
Exemplo n.º 35
0
    def get_chart_image(self, data, **kw):
        """Return a image file path

        Arguments::

            data -- a list containing the X,Y data representation
        """
        from pygooglechart import SimpleLineChart, Axis

        # Set the vertical range from 0 to 100
        try:
            max_y = max(data['y'])
            min_y = min(data['y'])
        except:
            min_y = 0
            max_y = 100
        width = int(kw.get('width', 600))
        height = int(kw.get('height', 250))
        # Chart size of widthxheight pixels and specifying the range for the Y axis
        chart = SimpleLineChart(width, height, y_range=[0, max_y])

        # Add the chart data
        chart.add_data(data['y'])

        # Set the line colour to blue
        chart.set_colours(['0000FF'])

        try:
            step_x = int(100 / (len(data['x']) - 1))
        except:
            step_x = 0
        chart.set_grid(step_x, 10, 5, 5)

        # The Y axis labels contains min_y to max_y spling it into 10 equal parts,
        #but remove the first number because it's obvious and gets in the way
        #of the first X label.
        left_axis = [
            utils.intcomma(x) for x in range(0, max_y + 1, (max_y) / 10)
        ]
        left_axis[0] = ''
        chart.set_axis_labels(Axis.LEFT, left_axis)

        # X axis labels
        chart.set_axis_labels(Axis.BOTTOM, data['x'])

        #Generate an hash from arguments
        kw_hash = hash(tuple(sorted(kw.items())))
        data_hash = hash(
            tuple(sorted([(k, tuple(v)) for k, v in data.iteritems()])))
        args_hash = str(kw_hash) + str(data_hash)

        image_path = os.path.join(TARGET_DIR, "%s.png" % args_hash)

        if bool(kw.get('refresh', False)) or args_hash not in self.charts:
            #Get image from google chart api
            chart.download(image_path)
            if args_hash not in self.charts:
                self.charts.append(args_hash)
            self._p_changed = True

        return image_path
Exemplo n.º 36
0
def simple_random():
    chart = SimpleLineChart(width, height, y_range=(0, 100))
    chart.add_data(random_data())
    chart.download('line-simple-random.png')
Exemplo n.º 37
0
def simple_random():
    chart = SimpleLineChart(settings.width, settings.height, y_range=(0, 100))
    chart.add_data(helper.random_data())
    chart.download('line-simple-random.png')
Exemplo n.º 38
0
from pygooglechart import SimpleLineChart, Axis
chart = SimpleLineChart(200, 125)
data = [ 1, 5, 30, 10, 25 ]
chart.add_data(data)
chart.set_axis_range(Axis.LEFT, 0, 10)
chart.download("hello.png")
print chart.get_url()
Exemplo n.º 39
0
def main():
    size_limit = 3000 * 100
    x_size = 1000
    y_size = 300
    y_max = 100

    parser = OptionParser()
    parser.add_option("-f", "--file", dest="filename", help="input data file")
    parser.add_option("-o",
                      "--output",
                      dest="chartname",
                      help="output chart file")
    parser.add_option("-s",
                      "--size",
                      dest="size",
                      help="'xsize,ysize' length of the chart x*y<=%d" %
                      size_limit)
    parser.add_option("-y", "--y-max", dest="y_max", help="y max limit")
    (options, args) = parser.parse_args(sys.argv[1:])
    if (options.filename == None or options.chartname == None):
        parser.print_help()
        sys.exit(1)
    # init x,y size
    if (options.size):
        size = options.size
        xy_pair = size.split(",")
        if len(xy_pair) == 2:
            x_size = string.atoi(xy_pair[0])
            y_size = string.atoi(xy_pair[1])
        else:
            parser.print_help()
            sys.exit(1)
    if (x_size * y_size > size_limit):
        print("ERROR: x*y > %s" % size_limit)
        sys.exit(1)

    # init y range
    if (options.y_max):
        y_max = string.atoi(options.y_max)

    # input file section
    ifile = open(options.filename)
    while True:
        l = ifile.readline()
        if len(l) == 0:
            break
        # print("get line: %s" % l[:-1])
    data = [
        32, 34, 34, 32, 34, 34, 32, 32, 32, 34, 34, 32, 29, 29, 34, 34, 34, 37,
        37, 39, 42, 47, 50, 54, 57, 60, 60, 60, 60, 60, 60, 60, 62, 62, 60, 55,
        55, 52, 47, 44, 44, 40, 40, 37, 34, 34, 32, 32, 32, 31, 32
    ]
    data2 = [
        55, 52, 47, 44, 44, 40, 40, 37, 34, 34, 32, 32, 32, 31, 32, 62, 60, 55,
        32, 34, 34, 32, 34, 34, 32, 32, 32, 34, 34, 32, 29, 29, 34, 34, 34, 37,
        37, 39, 42, 47, 50, 54, 57, 60, 60, 60, 60, 60, 60, 60, 62
    ]
    data_list = [data, data2]
    # output file section
    chart = SimpleLineChart(x_size, y_size, y_range=[0, y_max])
    # set data
    for d in data_list:
        chart.add_data(d)
    # init color
    RR = 16
    GG = 16
    BB = 16
    color_list = []
    for i in range(len(data_list)):
        RR += 10
        GG += 15
        BB += 65
        color_list.append("%s%s%s" % (str(hex(RR % 255))[2:], str(hex(
            GG % 255))[2:], str(hex(BB % 255))[2:]))
    # print(color_list)
    chart.set_colours(color_list)
    chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)
    chart.set_grid(0, 25, 5, 5)
    # left_axis = range(0, y_max+1, 25)
    # left_axis[0] = ""
    chart.set_axis_labels(Axis.LEFT, ["", "25%", "50%", "75%", "100%"])
    chart.set_axis_labels(Axis.BOTTOM, [
        "0:00", "3:00", "6:00", "9:00", "12:00", "15:00", "18:00", "21:00",
        "24:00"
    ])

    chart.download(options.chartname)
miles = []
for m, i in measurements:
    pos = ((i*1.0)/len(elvs)) * 100
    positions.append(pos)
    miles.append(m)

# Position the mile marker labels along teh x axis
miles_label = chart.set_axis_labels(Axis.BOTTOM, miles)
chart.set_axis_positions(miles_label, positions)

# Label the x axis as "Miles"
miles_text = chart.set_axis_labels(Axis.BOTTOM, ["MILES", ])
chart.set_axis_positions(miles_text, [50, ])

# Save the chart
chart.download('{}_profile.png'.format(elv_img))

log.info("Creating weather summary")

# Get the bounding box centroid for georeferencing weather data
centx = minx + ((maxx-minx)/2)
centy = miny + ((maxy-miny)/2)

# WeatherUnderground API key
# You must register for free at wunderground.com
# to get a key to insert here.
api_key = "18a1726f53fa6efb"

# Get the location id of the route using the bounding box
# centroid and the geolookup api
geolookup_req = "http://api.wunderground.com/api/{}".format(api_key)
def generateGraphs():
	version()
        
        conndio = sqlite3.connect(dbfiledionaea)
	c = conndio.cursor()

        connglas = sqlite3.connect(dbfileglastopf)
        x = connglas.cursor()
        
        #
        #
        # Dionaea Queries starting here!
        #
        #

        #Most attacked ports - Dionaea
        querySQL = 'SELECT COUNT(local_port) AS hitcount,local_port AS port FROM connections WHERE connection_type = "accept" GROUP BY local_port HAVING COUNT(local_port) > 10'
        print querySQL
        c.execute(querySQL)
        
        #Count attacks on port 80 - Glastopf
        querySQL = "SELECT COUNT(request_url) AS hitcount,'80 - http' AS port FROM events"
        print querySQL
        x.execute(querySQL)
        
        chart = PieChart2D(pieChartWidth, pieChartHeight, colours=pieColours)
        
        flist = []
        seclist = []
        
	for row in c:
		print(row)
                flist.append(row[0])
                seclist.append(str(row[1]))

        for row in x:
                print(row)
                flist.append(row[0])
                seclist.append(str(row[1]))      
                  
        seclist = [port.replace('21','21 - ftp') for port in seclist]
        seclist = [port.replace('42','42 - wins') for port in seclist]
        seclist = [port.replace('135','135 - msrpc') for port in seclist]
        seclist = [port.replace('445','445 - smb') for port in seclist]
        seclist = [port.replace('1433','1433 - ms-sql') for port in seclist]
        seclist = [port.replace('3306','3306 - mysql') for port in seclist]
        seclist = [port.replace('5060','5060 - sip') for port in seclist]

        chart.add_data(flist)
        chart.set_legend(seclist)

        chart.download('attacked_ports.png')

        #Top10 Malware
        querySQL = 'SELECT COUNT(download_md5_hash), download_md5_hash FROM downloads GROUP BY download_md5_hash ORDER BY COUNT(download_md5_hash) DESC LIMIT 10'
        print querySQL
        c.execute(querySQL)
			
        chart = PieChart2D(pieChartWidth, pieChartHeight, colours=pieColours)
        
        flist = []
        seclist = []
        
	for row in c:
		print(row)
                flist.append(row[0])
                seclist.append(str(row[1]))
                
        chart.add_data(flist)
        chart.set_legend(seclist)

        chart.download('popular_malware.png')
        
        #Connections per Day Dionaea and Glastopf - 7 Days - Dionaea
        querySQL = "SELECT strftime('%Y', connection_timestamp,'unixepoch') as 'year', strftime('%m', connection_timestamp,'unixepoch') as 'month', strftime('%d', connection_timestamp,'unixepoch') as 'day', count(strftime('%m', connection_timestamp,'unixepoch')) as 'num' FROM connections GROUP BY strftime('%Y', connection_timestamp,'unixepoch'), strftime('%m', connection_timestamp,'unixepoch'), strftime('%d', connection_timestamp,'unixepoch') ORDER BY strftime('%Y', connection_timestamp,'unixepoch') DESC, strftime('%m', connection_timestamp,'unixepoch') DESC, strftime('%d', connection_timestamp,'unixepoch') DESC LIMIT 7"
        print querySQL
        c.execute(querySQL)
        
        #Connections per Day Dionaea and Glastopf - 7 Days - Glastopf
        querySQL = "SELECT COUNT(time), SUBSTR(time,-20,12) AS stripped FROM events GROUP BY stripped ORDER BY stripped DESC LIMIT 7"
        print querySQL
        x.execute(querySQL)
        
        chart = SimpleLineChart(pieChartWidth, pieChartHeight, y_range=[0, 5000])
        
        flist = []
        seclist = []
        
	for (row,rowx) in zip(c,x):
                 print(row)
                 print(rowx)
                 l = list(row)
                 l[3]=row[3]+rowx[0]
                 flist.append(l[3])
                 date = '%s-%s-%s' % (str(row[0]),str(row[1]),str(row[2]))
                 seclist.append(date)
                
        flist.reverse()
        seclist.reverse()
                
        chart.add_data(flist)
        chart.set_axis_labels(Axis.BOTTOM,seclist)
        
        chart.set_colours(['0000FF'])
        chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)
        chart.set_grid(0, 20, 5, 5)
        
        left_axis = range(0, 5001, 1000)
        left_axis[0] = ''
        chart.set_axis_labels(Axis.LEFT, left_axis)
         
        chart.download('connections_per_day.png')
        
        #
        #
        # Glastopf Queries starting here!
        #
        #
        
        #Top15 intext requests
        querySQL = 'SELECT count, content FROM intext ORDER BY count DESC LIMIT 15'
        print querySQL
        x.execute(querySQL)
        
        chart = PieChart2D(pieChartWidth, pieChartHeight, colours=pieColours)
        
        flist = []
        seclist = []
        
        for row in x:
		print(row)
                flist.append(row[0])
                seclist.append(str(row[1]))
                
        chart.add_data(flist)
        chart.set_legend(seclist)

        chart.download('popular_intext.png')
        
        #Top15 intitle requests
        querySQL = 'SELECT count, content FROM intitle ORDER BY count DESC LIMIT 15'
        print querySQL
        x.execute(querySQL)
        
        chart = PieChart2D(pieChartWidth, pieChartHeight, colours=pieColours)
        
        flist = []
        seclist = []
        
        for row in x:
		print(row)
                flist.append(row[0])
                seclist.append(str(row[1]))
                
        chart.add_data(flist)
        chart.set_legend(seclist)

        chart.download('popular_intitle.png')
        
        #Top10 inurl requests
        querySQL = 'SELECT count, SUBSTR(content,0,40) FROM inurl ORDER BY count DESC LIMIT 10'
        print querySQL
        x.execute(querySQL)
        
        chart = PieChart2D(pieChartWidth, pieChartHeight, colours=pieColours)
        
        flist = []
        seclist = []
        
        for row in x:
		print(row)
                flist.append(row[0])
                seclist.append(str(row[1]))
                
        chart.add_data(flist)
        chart.set_legend(seclist)

        chart.download('popular_inurl.png')
Exemplo n.º 42
0
def main():
     size_limit = 3000 * 100;
     x_size = 1000
     y_size = 300
     y_max = 100
     
     parser = OptionParser()
     parser.add_option("-f", "--file", dest="filename",
                       help="input data file")
     parser.add_option("-o", "--output", dest="chartname",
                       help="output chart file")
     parser.add_option("-s", "--size", dest="size",
                       help="'xsize,ysize' length of the chart x*y<=%d" % size_limit)
     parser.add_option("-y", "--y-max", dest="y_max",
                       help="y max limit")
     (options, args) = parser.parse_args(sys.argv[1:])          
     if (options.filename == None or options.chartname == None):
          parser.print_help()
          sys.exit(1)
     # init x,y size
     if (options.size):
          size = options.size
          xy_pair = size.split(",")
          if len(xy_pair) == 2:
               x_size = string.atoi(xy_pair[0])
               y_size = string.atoi(xy_pair[1])
          else :
               parser.print_help()
               sys.exit(1)
     if (x_size * y_size > size_limit):
          print("ERROR: x*y > %s" % size_limit)
          sys.exit(1)

     # init y range
     if (options.y_max):
          y_max = string.atoi(options.y_max)
               
     # input file section
     ifile = open(options.filename)
     while True:
          l = ifile.readline()
          if len(l) == 0:
               break
          # print("get line: %s" % l[:-1])
     data = [
          32, 34, 34, 32, 34, 34, 32, 32, 32, 34, 34, 32, 29, 29, 34, 34, 34, 37,
          37, 39, 42, 47, 50, 54, 57, 60, 60, 60, 60, 60, 60, 60, 62, 62, 60, 55,
          55, 52, 47, 44, 44, 40, 40, 37, 34, 34, 32, 32, 32, 31, 32
          ]
     data2 = [
          55, 52, 47, 44, 44, 40, 40, 37, 34, 34, 32, 32, 32, 31, 32, 62, 60, 55,
          32, 34, 34, 32, 34, 34, 32, 32, 32, 34, 34, 32, 29, 29, 34, 34, 34, 37,        
          37, 39, 42, 47, 50, 54, 57, 60, 60, 60, 60, 60, 60, 60, 62
          ]
     data_list = [data, data2]
     # output file section
     chart = SimpleLineChart(x_size, y_size, y_range=[0, y_max])
     # set data
     for d in data_list:
          chart.add_data(d)
        # init color
     RR=16; GG=16; BB=16
     color_list = []
     for i in range(len(data_list)):
          RR+=10;GG+=15;BB+=65
          color_list.append("%s%s%s" %
                            (str(hex(RR%255))[2:],
                             str(hex(GG%255))[2:],
                             str(hex(BB%255))[2:]) )
     # print(color_list)
     chart.set_colours(color_list)
     chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)
     chart.set_grid(0, 25, 5, 5)
     # left_axis = range(0, y_max+1, 25)
     # left_axis[0] = ""
     chart.set_axis_labels(Axis.LEFT, ["","25%","50%","75%","100%"])
     chart.set_axis_labels(Axis.BOTTOM, ["0:00", "3:00", "6:00", "9:00", "12:00", "15:00", "18:00", "21:00", "24:00"])
    
     chart.download(options.chartname)
Exemplo n.º 43
0
def simple_random():
    chart = SimpleLineChart(400, 400, y_range=(0, 100))
    chart.add_data([20, 0.2121649980545044])
    chart.download('line-simple-random.png')
Exemplo n.º 44
0
 def generate_chart(self):
     """creation du linechart sous forme d image png grace aux donnees historiques"""
     if self.is_valid and len(self.histo_data) > 10:
         
         from pygooglechart import Chart
         from pygooglechart import SimpleLineChart
         from pygooglechart import Axis
         
         price_max = -sys.maxint
         price_min = sys.maxint
         
         vec_price = []
         vec_date = []
         
         for i in range(1, len(self.histo_data)):
             
             if (i < len(self.histo_data)-1) and float(self.histo_data[i][0][5:7]) != float(self.histo_data[i+1][0][5:7]): #end of month ?
                 vec_date.append(self.histo_data[i][0][5:7])
             else:
                 vec_date.append('')
             
             
             if utility.is_number(self.histo_data[i][6]):
                 
                 vec_price.append(self.histo_data[i][6])
                 
                 if self.histo_data[i][6] < price_min:
                     price_min = self.histo_data[i][6]
                 
                 if self.histo_data[i][6] > price_max:
                     price_max = self.histo_data[i][6]
         
         
         y_scale_up = int(price_max)
         y_scale_down = int(price_min)
         
         if y_scale_up-y_scale_down > 500:
             base = 100
         elif y_scale_up-y_scale_down > 200:
             base = 50
         else:
             base = 25
         
         for i in range(1,base+1):
             if ((y_scale_up + i) % base) == 0:
                 y_scale_up = y_scale_up+i
                 break
         
         for i in range(1,base+1):
             if ((y_scale_down - i) % base) == 0:
                 y_scale_down -= i
                 break
         
         
         chart = SimpleLineChart(200, 125, y_range=[y_scale_down, y_scale_up])
         chart.add_data(vec_price)
         chart.set_colours(['0000FF'])
         left_axis = range(y_scale_down, y_scale_up + 1, base)
         chart.set_axis_labels(Axis.LEFT, left_axis)
         chart.set_axis_labels(Axis.BOTTOM, vec_date)
         
         
         utility.create_missing_folder(utility.FOLDER_CHART)
         
         chart.download(utility.FOLDER_CHART + '/' + self.symbol + '.png')
         self.path_chart_1yr = utility.FOLDER_CHART + '/' + self.symbol + '.png'
Exemplo n.º 45
0
    miles.append(m)

## Position the mile marker labels along the x axis
miles_label = chart.set_axis_labels(Axis.BOTTOM, miles)
chart.set_axis_positions(miles_label, positions)

## Label the x axis as 'Miles'
miles_text = chart.set_axis_labels(Axis.BOTTOM, [
    'MILES',
])
chart.set_axis_positions(miles_text, [
    50,
])

## Save the chart
chart.download('{}_profile.png'.format(elv_img))

log.info('Creating weather summary')
## Get the bounding box centroid for georeferencing weather data
centx = minx + ((maxx - minx) / 2)
centy = miny + ((maxy - miny) / 2)

## WeatherUnderground API key
api_key = '0cc5fdfd4599eddf'
## Get the location id of the route using the bounding box centroid
## and the geolookup API
geolookup_reg = 'http://api.wunderground.com/api/{}'.format(api_key)
geolookup_reg += '/geolookup/q/{},{}.json'.format(centy, centx)
request = urlopen(geolookup_reg)
geolookup_data = request.read().decode('utf-8')
Exemplo n.º 46
0
def simple_random():
    chart = SimpleLineChart(settings.width, settings.height, y_range=(0, 100))
    chart.add_data(helper.random_data())
    chart.download('line-simple-random.png')
Exemplo n.º 47
0
    miles.append(m)

# Position the mile marker labels along teh x axis
miles_label = chart.set_axis_labels(Axis.BOTTOM, miles)
chart.set_axis_positions(miles_label, positions)

# Label the x axis as "Miles"
miles_text = chart.set_axis_labels(Axis.BOTTOM, [
    "MILES",
])
chart.set_axis_positions(miles_text, [
    50,
])

# Save the chart
chart.download('%s_profile.png' % elv_img)

log.info("Creating weather summary")

# Get the bounding box centroid for georeferencing weather data
centx = minx + ((maxx - minx) / 2)
centy = miny + ((maxy - miny) / 2)

# WeatherUnderground API key
# You must register for free at wunderground.com
# to get a key to insert here.
api_key = "18a1726f53fa6efb"

# Get the location id of the route using the bounding box
# centroid and the geolookup api
geolookup_req = "http://api.wunderground.com/api/%s" % api_key
for m,i in measurements:
  pos = ((i*1.0)/len(elvs)) * 100
  positions.append(pos)
  miles.append(m)

# Position the mile marker labels along teh x axis
miles_label = chart.set_axis_labels(Axis.BOTTOM, miles)
chart.set_axis_positions(miles_label, positions)

# Label the x axis as "Miles"
miles_text = chart.set_axis_labels(Axis.BOTTOM, ["MILES",])
chart.set_axis_positions(miles_text, [50,])


# Save the chart
chart.download('%s_profile.png' % elv_img)

log.info("Creating weather summary")

# Get the bounding box centroid for georeferencing weather data
centx = minx + ((maxx-minx)/2)
centy = miny + ((maxy-miny)/2)

# WeatherUnderground API key
# You must register for free at wunderground.com
# to get a key to insert here.
api_key = "18a1726f53fa6efb"

# Get the location id of the route using the bounding box
# centroid and the geolookup api
geolookup_req = "http://api.wunderground.com/api/%s" % api_key
Exemplo n.º 49
0
# Add the chart data
data = [
    32, 34, 34, 32, 34, 34, 32, 32, 32, 34, 34, 32, 29, 29, 34, 34, 34, 37, 37,
    39, 42, 47, 50, 54, 57, 60, 60, 60, 60, 60, 60, 60, 62, 62, 60, 55, 55, 52,
    47, 44, 44, 40, 40, 37, 34, 34, 32, 32, 32, 31, 32
]
chart.add_data(data)

# Set the line colour to blue
chart.set_colours(['0000FF'])

# Set the vertical stripes
chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)

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

# The Y axis labels contains 0 to 100 skipping every 25, but remove the
# first number because it's obvious and gets in the way of the first X
# label.
left_axis = range(0, max_y + 1, 25)
left_axis[0] = ''
chart.set_axis_labels(Axis.LEFT, left_axis)

# X axis labels
chart.set_axis_labels(Axis.BOTTOM, \
    ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'])

chart.download('line-stripes.png')
Exemplo n.º 50
0
# Add the chart data
data = [
    32, 34, 34, 32, 34, 34, 32, 32, 32, 34, 34, 32, 29, 29, 34, 34, 34, 37,
    37, 39, 42, 47, 50, 54, 57, 60, 60, 60, 60, 60, 60, 60, 62, 62, 60, 55,
    55, 52, 47, 44, 44, 40, 40, 37, 34, 34, 32, 32, 32, 31, 32
]
chart.add_data(data)

# Set the line colour to blue
chart.set_colours(['0000FF'])

# Set the vertical stripes
chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)

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

# The Y axis labels contains 0 to 100 skipping every 25, but remove the
# first number because it's obvious and gets in the way of the first X
# label.
left_axis = range(0, max_y + 1, 25)
left_axis[0] = ''
chart.set_axis_labels(Axis.LEFT, left_axis)

# X axis labels
chart.set_axis_labels(Axis.BOTTOM, \
    ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'])

chart.download('line-stripes.png')
Exemplo n.º 51
0
        chart = SimpleLineChart(300, 325, y_range=[0, max_y])

        # Add the chart data
        data = []
        data.append(tests[0][2])
        data.append(tests[1][2])
        chart.add_data(data)

        # Set the line colour to blue
        chart.set_colours(['0000FF'])

        # Set the vertical stripes
        chart.fill_linear_stripes(Chart.CHART, 0, 'CCCCCC', 0.2, 'FFFFFF', 0.2)

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

        # The Y axis labels contains 0 to 100 skipping every 25, but remove the
        # first number because it's obvious and gets in the way of the first X
        # label.
        left_axis = range(0, max_y + 1, 25)
        left_axis[0] = ''
        chart.set_axis_labels(Axis.LEFT, left_axis)

        # X axis labels
        chart.set_axis_labels(Axis.BOTTOM, \
                              [1,2])

        chart.download(path_to_db + 'line-stripes.png')
        print chart.get_url()