Exemplo n.º 1
0
 def test_secondary_xy():
     chart = XY()
     chart.add(10 * '1', [(30, 5), (20, 12), (25, 4)])
     chart.add(10 * '1b', [(4, 12), (5, 8), (6, 4)], secondary=True)
     chart.add(10 * '2b', [(3, 24), (0, 17), (12, 9)], secondary=True)
     chart.add(10 * '2', [(8, 23), (21, 1), (5, 0)])
     return chart.render_response()
Exemplo n.º 2
0
Arquivo: tests.py Projeto: Kozea/pygal
    def test_xy_links():
        xy = XY(style=styles['neon'], interpolate='cubic')
        xy.add(
            '1234', [{
                'value': (10, 5),
                'label': 'Ten',
                'xlink': 'http://google.com?q=10'
            }, {
                'value': (20, 20),
                'tooltip': 'Twenty',
                'xlink': 'http://google.com?q=20'
            }, (30, 15), {
                'value': (40, -5),
                'label': 'Forty',
                'xlink': 'http://google.com?q=40'
            }]
        )

        xy.add(
            '4321', [(40, 10), {
                'value': (30, 3),
                'label': 'Thirty',
                'xlink': 'http://google.com?q=30'
            }, (20, 10), (10, 21)]
        )
        xy.x_labels = list(range(1, 50))
        xy.y_labels = list(range(1, 50))
        return xy.render_response()
Exemplo n.º 3
0
def generateGraph():
    '''
        Function that generates the graph which plots the traffic (packet
        size against time). This allows the client to monitor the traffic
        easily, hence improving the user experience while using the webpage.
        For future works, other properties of the packet object can also be
        plotted on the same axes for more detailed analyses and comparisons.
    '''
    # process pcap and create a pygal chart with packet sizes
    pkt_sizes = []
    cap = pyshark.FileCapture("trace/traffic.pcap", only_summaries=True)

    for packet in cap:  # for each packet in the pygal chart
        # create a point (X,Y) and add it to the list
        # X: the absolute time (in seconds) between the current packet and the first packet
        # Y: the length (in bytes) of the packet
        pkt_sizes.append((float(packet.time), int(packet.length)))

    # create pygal instance
    pkt_size_chart = XY(width=400,
                        height=300,
                        style=LightGreenStyle,
                        explicit_size=True)
    pkt_size_chart.title = 'PACKET SIZES OVER TIME'
    pkt_size_chart.x_title = 'Time (s)'
    pkt_size_chart.y_title = 'Packet Size (bytes)'

    # add points to chart and render html
    pkt_size_chart.add('Size', pkt_sizes)  # graph legend
    chart = pkt_size_chart.render().decode("utf-8")

    return chart
def plot(filename):
    pkt_arr = []
    cap = pyshark.FileCapture(filename, only_summaries=True)

    pkt_arr.append((1, 0.0))

    print(cap)
    for packet in cap:
        # Create a plot point where (x=protocol, y=bytes)
        pkt_arr.append((int(packet.no), float(packet.time)))

    print(pkt_arr)

    # Create pygal instance
    pkt_size_chart = XY(width=600,
                        height=400,
                        style=LightGreenStyle,
                        explicit_size=True)
    pkt_size_chart.title = 'Packets Analysis'

    pkt_size_chart.add('Time v/s No', pkt_arr)
    chart = pkt_size_chart.render()

    #print(chart)
    html = """{}""".format(chart)
    return html
Exemplo n.º 5
0
def static_pcap():
    if request.method == 'POST':
        #temporarily store upload pcap file
        print request
        traceFile = request.files['file']
        traceFile.save("temporary/temp_pcap_file.pcap")

        ft = filter_static.Static_Filter(
            fileName="temporary/temp_pcap_file.pcap")
        device_traffic_dict = ft.detect_Device()

        #line chart for individual device data sent historys
        pkt_line = XY(width=800, height=600, explicit_size=True)
        pkt_line.title = 'Device Package Curve'
        for key, list in device_traffic_dict.iteritems():
            pkt_line.add(key, list)
        chart = pkt_line.render()

        # bar chart for device data sent summary
        pkt_Bar = Bar(width=800, height=600, explicit_size=True)
        pkt_Bar.title = 'Device Package Sum'
        for key, list in device_traffic_dict.iteritems():
            zipped = map(sum, zip(*list))
            pkt_Bar.add(key, zipped[1])
        pkt_Bar = pkt_Bar.render()

        del ft
        html = """{} {}""".format(chart, pkt_Bar)
        return html

    else:
        return current_app.send_static_file('static.html')
Exemplo n.º 6
0
    def test_xy_links():
        xy = XY(style=styles["neon"], interpolate="cubic")
        xy.add(
            "1234",
            [
                {"value": (10, 5), "label": "Ten", "xlink": "http://google.com?q=10"},
                {"value": (20, 20), "tooltip": "Twenty", "xlink": "http://google.com?q=20"},
                (30, 15),
                {"value": (40, -5), "label": "Forty", "xlink": "http://google.com?q=40"},
            ],
        )

        xy.add(
            "4321",
            [(40, 10), {"value": (30, 3), "label": "Thirty", "xlink": "http://google.com?q=30"}, (20, 10), (10, 21)],
        )
        xy.x_labels = list(range(1, 50))
        xy.y_labels = list(range(1, 50))
        return xy.render_response()
Exemplo n.º 7
0
async def handle(request):
    name = whitelist(request.match_info.get('name', "Cave"))
    db = await connect('records.sqlite')
    cr = await db.execute(
        f'SELECT time, temperature, setpoint, outside FROM events WHERE thermostat="{name}" ORDER BY time'
    )
    chart = XY(title=f'Recent temperature trend in {name}',
               x_title='Hours',
               y_title='degress celsius')
    setseries = []
    tempseries = []
    outsideseries = []
    now = time()
    for row in await cr.fetchall():
        dt = (row[0] - now) / 3600
        tempseries.append((dt, row[1]))
        setseries.append((dt, row[2]))
        if row[3]:
            outsideseries.append((dt, row[3]))
    chart.add('temp', tempseries)
    chart.add('set', setseries)
    chart.add('outside', outsideseries)
    return web.Response(body=chart.render(), content_type='image/svg+xml')
Exemplo n.º 8
0
    def test_xy_links():
        xy = XY(style=styles['neon'], interpolate='cubic')
        xy.add('1234', [
            {'value': (10, 5),
             'label': 'Ten',
             'xlink': 'http://google.com?q=10'},
            {'value': (20, 20),
             'tooltip': 'Twenty',
             'xlink': 'http://google.com?q=20'},
            (30, 15),
            {'value': (40, -5),
             'label': 'Forty',
             'xlink': 'http://google.com?q=40'}
        ])

        xy.add('4321', [(40, 10), {
            'value': (30, 3),
            'label': 'Thirty',
            'xlink': 'http://google.com?q=30'
        }, (20, 10), (10, 21)])
        xy.x_labels = list(range(1, 50))
        xy.y_labels = list(range(1, 50))
        return xy.render_response()
Exemplo n.º 9
0
def plot(filename):
    pkt_sizes = []
    cap = pyshark.FileCapture(filename, only_summaries=True)
    for packet in cap:
        # Create a plot point where (x=time, y=bytes)
        pkt_sizes.append((float(packet.time), int(packet.length)))
    # Create pygal instance
    pkt_size_chart = XY(width=400, height=300, style=LightGreenStyle, explicit_size=True)
    pkt_size_chart.title = 'Packet Sizes'
    # Add points to chart and render chart html
    pkt_size_chart.add('Size', pkt_sizes)
    chart = pkt_size_chart.render()
    print(chart)
    html = """{}""".format(chart)
    return html 
def plot(filename):
    pkt_sizes = []
    cap = pyshark.FileCapture(filename, only_summaries=True)
    # cap = pyshark.FileCapture(filename)
    for packet in cap:

        #print(type(packet.time))
        l = float(packet.time)
        pkt_sizes.append((float(packet.start), float(packet.time)))

    pkt_size_chart = XY(width=600,
                        height=500,
                        style=LightGreenStyle,
                        explicit_size=True)
    pkt_size_chart.title = 'DNS response time'

    pkt_size_chart.add('Time', pkt_sizes)
    chart = pkt_size_chart.render()
    print(chart)
    html = """{}""".format(chart)
    return html
Exemplo n.º 11
0
 def test_fill_with_none():
     graph = XY(fill=True)
     graph.add('1', [(1, 2), (3, 3), (3.5, 5), (5, 1)])
     graph.add('2', [(1, 9), (None, 5), (5, 23)])
     return graph.render_response()
Exemplo n.º 12
0
 def test_secondary_xy():
     chart = XY()
     chart.add(10 * '1', [(30, 5), (20, 12), (25, 4)])
     chart.add(10 * '1b', [(4, 12), (5, 8), (6, 4)], secondary=True)
     chart.add(10 * '2b', [(3, 24), (0, 17), (12, 9)], secondary=True)
     chart.add(10 * '2', [(8, 23), (21, 1), (5, 0)])
     chart.value_formatter = lambda x: str(int(x)) + '+'
     return chart.render_response()
Exemplo n.º 13
0
 def test_xy_single():
     graph = XY(interpolate='cubic')
     graph.add('Single', [(1, 1)])
     return graph.render_response()
Exemplo n.º 14
0
                for m in range(n + 1):
                    if m == k:
                        continue
                    p *= sin(0.5 * (X - x[m])) / sin(0.5 * (x[k] - x[m]))
                s += y[k] * p
            yield X, s

"""
These functions takes two lists of points x and y and
returns an iterator over the interpolation between all these points
with `precision` interpolated points between each of them

"""
INTERPOLATIONS = {
    'quadratic': quadratic_interpolate,
    'cubic': cubic_interpolate,
    'hermite': hermite_interpolate,
    'lagrange': lagrange_interpolate,
    'trigonometric': trigonometric_interpolate
}


if __name__ == '__main__':
    from pygal import XY
    points = [(.1, 7), (.3, -4), (.6, 10), (.9, 8), (1.4, 3), (1.7, 1)]
    xy = XY(show_dots=False)
    xy.add('normal', points)
    xy.add('quadratic', quadratic_interpolate(*zip(*points)))
    xy.add('cubic', cubic_interpolate(*zip(*points)))
    xy.render_in_browser()
Exemplo n.º 15
0
 def ltcomparison_svg(self, lapIds, labels=None, curr_url=None):
     if not config.config.HTTP_CONFIG.enable_svg_generation:
         return ""
     lapIds = lapIds.strip().split(",")
     lapIds = list(map(lambda x: int(x), lapIds))
     if not labels is None:
         labels = dict(zip(lapIds, labels.split(",")))
     lapIds = OrderedDict(zip(lapIds, [None] * len(lapIds))).keys()
     ci = db.comparisonInfo(lapIds, __sync=True)()
     track = None
     tracksame = 1
     car = None
     carsame = 1
     if len(ci) == 0:
         return ""
     for lapid in ci:
         if track is None:
             track = ci[lapid]['uitrack']
         if track != ci[lapid]['uitrack']:
             tracksame = 0
         if car is None:
             car = ci[lapid]['uicar']
         if car != ci[lapid]['uicar']:
             carsame = 0
     if tracksame and carsame:
         title = "Lap Comparison %s @ %s" % (car, track)
     elif tracksame:
         title = "Lap Comparison on %s" % track
     else:
         title = "Lap Comparison (warning: different tracks!)"
     line_chart = XY(pygalConfig,
                     fill=False,
                     dots_size=1,
                     interpolate='hermite',
                     interpolation_precision=1,
                     include_x_axis=True,
                     x_title='Track Position [m]',
                     y_title='Velocity [km/h]',
                     title=title,
                     legend_at_bottom=True,
                     legend_font_size=12,
                     truncate_legend=30)
     maxN = 1
     #line_chart.title("Lap comparison"), ci[lapid]['uitrack']
     for lapid in lapIds:
         if not lapid in ci:
             continue
         st, wp, vel, nsp = decompress(ci[lapid]['historyinfo'])
         v = map(lambda x: 3.6 * math.sqrt(x[0]**2 + x[1]**2 + x[2]**2),
                 vel)
         l = ci[lapid]['length']
         if not l is None:
             nsp = list(map(lambda x: min(l, max(0, x * l)), nsp))
         if not labels is None:
             lb = labels[lapid] + ":"
         else:
             lb = ""
         if carsame:
             cb = ""
         else:
             cb = ", %s" % ci[lapid]['uicar']
         legend = "%s%s by %s%s" % (
             lb, format_time(ci[lapid]['laptime'],
                             False), ci[lapid]['player'], cb)
         line_chart.add(legend, zip(nsp, v))
         maxN = max(len(nsp), maxN)
     precision = max(1, min(10, int(1600 / maxN)))
     line_chart.interpolation_precision = precision
     return line_chart.render()
Exemplo n.º 16
0
def drawGraph():
    xy = XY(stroke=False)
    xy.title = 'Correlation'
    xy.add('A', [(0, 0), (.1, .2), (.3, .1), (.5, 1), (.8, .6), (1, 1.08),
                 (1.3, 1.1), (2, 3.23), (2.43, 2)])
    xy.add('B', [(.1, .15), (.12, .23), (.4, .3), (.6, .4), (.21, .21),
                 (.5, .3), (.6, .8), (.7, .8)])
    xy.add('C', [(.05, .01), (.13, .02), (1.5, 1.7), (1.52, 1.6), (1.8, 1.63),
                 (1.5, 1.82), (1.7, 1.23), (2.1, 2.23), (2.3, 1.98)])
    xy.render_to_png('mygraph.png')
    xy.render_in_browser()
Exemplo n.º 17
0
 def test_fill_with_none():
     graph = XY(fill=True)
     graph.add('1', [(1, 2), (3, 3), (3.5, 5), (5, 1)])
     graph.add('2', [(1, 9), (None, 5), (5, 23)])
     return graph.render_response()
Exemplo n.º 18
0
 def ltcomparisonmap_svg(self, lapIds, labels=None, curr_url=None):
     if not config.config.HTTP_CONFIG.enable_svg_generation:
         return ""
     lapIds = lapIds.strip().split(",")
     lapIds = list(map(lambda x: int(x), lapIds))
     if not labels is None:
         labels = dict(zip(lapIds, labels.split(",")))
     lapIds = OrderedDict(zip(lapIds, [None] * len(lapIds))).keys()
     ci = db.comparisonInfo(lapIds, __sync=True)()
     if len(ci) == 0:
         return ""
     track = None
     tracksame = 1
     car = None
     carsame = 1
     for lapid in ci:
         if track is None:
             uitrack = ci[lapid]['uitrack']
             track = ci[lapid]['track']
         if track != ci[lapid]['track']:
             tracksame = 0
         if car is None:
             car = ci[lapid]['uicar']
         if car != ci[lapid]['uicar']:
             carsame = 0
     if tracksame and carsame:
         title = "Lap Comparison %s @ %s" % (car, uitrack)
     elif tracksame:
         title = "Lap Comparison on %s" % uitrack
     else:
         raise RuntimeError
     td = self.trackAndCarDetails()['tracks']
     td = dict(map(lambda x: (x['acname'], x), td))
     self.trackmap(track=track, curr_url=curr_url)
     if track in td and td[track]['mapdata']:
         mapdata = pickle.loads(td[track]['mapdata'])
         scale = 1. / float(mapdata['ini']['scale'])
         offsetx = float(mapdata['ini']['xoffset'])
         offsetz = float(mapdata['ini']['zoffset'])
         width = float(mapdata['ini']['width'])
         height = float(mapdata['ini']['height'])
         map_chart = XY(
             pygalConfig,
             fill=False,
             show_dots=False,
             inverse_y_axis=True,
             #interpolate='hermite',
             include_x_axis=True,
             title=title,
             show_legend=False,
             width=width,
             height=height,
             show_y_labels=False,
             show_minor_x_labels=False,
             background_image="trackmap?track=%s" % track)
         for lapid in lapIds:
             if not lapid in ci:
                 continue
             st, wp, vel, nsp = decompress(ci[lapid]['historyinfo'])
             x = [max(0, min(width, (x[0] + offsetx) * scale)) for x in wp]
             y = [max(0, min(height, (x[2] + offsetz) * scale)) for x in wp]
             map_chart.add('', list(zip(x, y)))
         map_chart.add('', [(0, 0)])
         map_chart.add('', [(width, height)])
         return map_chart.render()
     else:
         return ""
Exemplo n.º 19
0
                s += y[k] * p
            yield X, s

INTERPOLATIONS = {
    'quadratic': quadratic_interpolate,
    'cubic': cubic_interpolate,
    'hermite': hermite_interpolate,
    'lagrange': lagrange_interpolate,
    'trigonometric': trigonometric_interpolate
}


if __name__ == '__main__':
    from pygal import XY
    points = [(.1, 7), (.3, -4), (.6, 10), (.9, 8), (1.4, 3), (1.7, 1)]
    xy = XY(show_dots=False)
    xy.add('normal', points)
    xy.add('quadratic', quadratic_interpolate(*zip(*points)))
    xy.add('cubic', cubic_interpolate(*zip(*points)))
    xy.add('lagrange', lagrange_interpolate(*zip(*points)))
    xy.add('trigonometric', trigonometric_interpolate(*zip(*points)))
    xy.add('hermite catmul_rom', hermite_interpolate(
        *zip(*points), type='catmul_rom'))
    xy.add('hermite finite_difference', hermite_interpolate(
        *zip(*points), type='finite_difference'))
    xy.add('hermite cardinal -.5', hermite_interpolate(
        *zip(*points), type='cardinal', c=-.5))
    xy.add('hermite cardinal .5', hermite_interpolate(
        *zip(*points), type='cardinal', c=.5))
    xy.add('hermite kochanek_bartels .5 .75 -.25', hermite_interpolate(
        *zip(*points), type='kochanek_bartels', c=.5, b=.75, t=-.25))
Exemplo n.º 20
0
def dynamic_pcap():
    if request.method == 'POST':
        #temporarily store upload pcap file
        time = int(request.form['time'])

        ft = filter_dynamic.Dynamic_Filter(time=time)
        try:
            data_lists = ft.live_Capture(
            )  #[ARP_Collection, APR_Package, IP_Collection, IP_Package]
        except:
            sys.exit("no package detected")

        ARP_Collection = data_lists[0]
        APR_Package = data_lists[1]
        IP_Collection = data_lists[2]
        IP_Package = data_lists[3]

        #line chart for ARP DELTA Information
        pkt_line_ARP = XY(width=800, height=600, explicit_size=True)
        pkt_line_ARP.title = 'Time delta for ARP'
        for key, list in ARP_Collection.iteritems():
            pkt_line_ARP.add(key, list)
        chart_ARP_Delta = pkt_line_ARP.render()

        # line chart for ARP Package Information
        pkt_line_ARP = XY(width=800, height=600, explicit_size=True)
        pkt_line_ARP.title = 'Package Info for ARP'
        for key, list in APR_Package.iteritems():
            pkt_line_ARP.add(key, list)
        chart_ARP_Package = pkt_line_ARP.render()

        pkt_line_IP = XY(width=800, height=600, explicit_size=True)
        pkt_line_IP.title = 'Time delta for IP'
        for key, list in IP_Collection.iteritems():
            pkt_line_IP.add(key, list)
        chart_IP_Delta = pkt_line_IP.render()

        pkt_line_IP = XY(width=800, height=600, explicit_size=True)
        pkt_line_IP.title = 'Package Info for IP'
        for key, list in IP_Package.iteritems():
            pkt_line_IP.add(key, list)
        chart_IP_Package = pkt_line_IP.render()

        del ft
        html = """{} {} <br/> {} {}""".format(chart_ARP_Package,
                                              chart_ARP_Delta,
                                              chart_IP_Package, chart_IP_Delta)
        return html

    else:
        return current_app.send_static_file('dynamic.html')
Exemplo n.º 21
0
 def test_secondary_xy():
     chart = XY()
     chart.add(10 * '1', [(30, 5), (20, 12), (25, 4)])
     chart.add(10 * '1b', [(4, 12), (5, 8), (6, 4)], secondary=True)
     chart.add(10 * '2b', [(3, 24), (0, 17), (12, 9)], secondary=True)
     chart.add(10 * '2', [(8, 23), (21, 1), (5, 0)])
     return chart.render_response()
Exemplo n.º 22
0
                for m in range(n + 1):
                    if m == k:
                        continue
                    p *= sin(0.5 * (X - x[m])) / sin(0.5 * (x[k] - x[m]))
                s += y[k] * p
            yield X, s


"""
These functions takes two lists of points x and y and
returns an iterator over the interpolation between all these points
with `precision` interpolated points between each of them

"""
INTERPOLATIONS = {
    'quadratic': quadratic_interpolate,
    'cubic': cubic_interpolate,
    'hermite': hermite_interpolate,
    'lagrange': lagrange_interpolate,
    'trigonometric': trigonometric_interpolate
}

if __name__ == '__main__':
    from pygal import XY
    points = [(.1, 7), (.3, -4), (.6, 10), (.9, 8), (1.4, 3), (1.7, 1)]
    xy = XY(show_dots=False)
    xy.add('normal', points)
    xy.add('quadratic', quadratic_interpolate(*zip(*points)))
    xy.add('cubic', cubic_interpolate(*zip(*points)))
    xy.render_in_browser()
Exemplo n.º 23
0
 def test_xy_single():
     graph = XY(interpolate='cubic')
     graph.add('Single', [(1, 1)])
     return graph.render_response()
Exemplo n.º 24
0
Arquivo: tests.py Projeto: Kozea/pygal
 def test_secondary_xy():
     chart = XY()
     chart.add(10 * '1', [(30, 5), (20, 12), (25, 4)])
     chart.add(10 * '1b', [(4, 12), (5, 8), (6, 4)], secondary=True)
     chart.add(10 * '2b', [(3, 24), (0, 17), (12, 9)], secondary=True)
     chart.add(10 * '2', [(8, 23), (21, 1), (5, 0)])
     chart.value_formatter = lambda x: str(int(x)) + '+'
     return chart.render_response()
Exemplo n.º 25
0
 def test_xy_single():
     graph = XY(interpolate="cubic")
     graph.add("Single", [(1, 1)])
     return graph.render_response()
Exemplo n.º 26
0
def captured_dynamic_pcap():
    if request.method == 'POST':
        traceFile = request.files['file']
        data_lists = json.load(traceFile)

        ARP_Collection = data_lists[0]
        APR_Package = data_lists[1]
        IP_Collection = data_lists[2]
        IP_Package = data_lists[3]

        # line chart for ARP DELTA Information
        pkt_line_ARP = XY(width=800, height=600, explicit_size=True)
        pkt_line_ARP.title = 'Time delta for ARP'
        for key, list in ARP_Collection.iteritems():
            pkt_line_ARP.add(key, list)
        chart_ARP_Delta = pkt_line_ARP.render()

        # line chart for ARP Package Information
        pkt_line_ARP = XY(width=800, height=600, explicit_size=True)
        pkt_line_ARP.title = 'Package Info for ARP'
        for key, list in APR_Package.iteritems():
            pkt_line_ARP.add(key, list)
        chart_ARP_Package = pkt_line_ARP.render()

        pkt_line_IP = XY(width=800, height=600, explicit_size=True)
        pkt_line_IP.title = 'Time delta for IP'
        for key, list in IP_Collection.iteritems():
            pkt_line_IP.add(key, list)
        chart_IP_Delta = pkt_line_IP.render()

        pkt_line_IP = XY(width=800, height=600, explicit_size=True)
        pkt_line_IP.title = 'Package Info for IP'
        for key, list in IP_Package.iteritems():
            pkt_line_IP.add(key, list)
        chart_IP_Package = pkt_line_IP.render()

        html = """{} {} <br/> {} {}""".format(chart_ARP_Package,
                                              chart_ARP_Delta,
                                              chart_IP_Package, chart_IP_Delta)
        return html

    else:
        return current_app.send_static_file('captured_dynamic.html')