<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# libavg - Media Playback Engine.
# Copyright (C) 2003-2013 <NAME>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Current versions can be found at www.libavg.de
#
# Original author of this file is <NAME> <<EMAIL>>

from libavg import *

import random
import math
import time

R = 40.0
g_Trigger = True


class SpeedDiv(app.MainDiv):
    def onArgvExtenderCreated(self, argvExtender):
        usage = '%prog [options]\n' \
                'Checks libavg performance by creating lots of polygon nodes. ' \
                'Displays a frame time graph and executes for 20 secs.'
        argvExtender.parser.set_usage(usage)

        argvExtender.parser.add_option('--hole-polygon', '-y', dest='hole',
                action='store_true', default=False,
                help='generate polygons with holes')
        argvExtender.parser.add_option('--create-nodes', '-c', dest='create',
                action='store_true', default=False,
                help='destroy and recreate all nodes every 400 ms')
        argvExtender.parser.add_option('--move', '-m', dest='move',
                action='store_true', default=False,
                help='move nodes every frame')
        argvExtender.parser.add_option('--vsync', '-s', dest='vsync',
                action='store_true', default=False,
                help='sync output to vertical refresh')
        argvExtender.parser.add_option('--num-objs', '-n', dest='numObjs',
                type='int', default=40,
                help='number of polygons to create [Default: 40]')
        argvExtender.parser.add_option('--num-points', '-x', dest='numPoints',
                type='int', default=10,
                help='number of points in each polygon [Default: 10]')
        argvExtender.parser.add_option('--profile', '-p', dest='profile',
                action='store_true', default=False,
                help='enable profiling output, note that profiling makes things slower')

    def onArgvExtenderApplied(self, argvExtender):
        opts, args = argvExtender.parsedArgs

        self.__optHole = opts.hole
        self.__optCreate = opts.create
        self.__optMove = opts.move
        self.__optVsync = opts.vsync
        self.__optNumObjs = opts.numObjs
        if self.__optNumObjs < 1:
            self.__optNumObjs = 40
        self.__optNumPoints = opts.numPoints
        if self.__optNumPoints < 10:
            self.__optNumPoints = 10
        elif self.__optNumPoints % 2 != 0:
            self.__optNumPoints -= 1

        log = avg.logger
        if opts.profile:
            log.setCategories(log.PROFILE | log.CONFIG | log.WARNING | log.ERROR)
        else:
            log.setCategories(log.CONFIG | log.WARNING | log.ERROR)

    def onInit(self):
        if not self.__optVsync:
            player.setFramerate(1000)

        self.mediadir = utils.getMediaDir(None, 'data')
        tstart = time.time()
        self.__createNodes()
        print 'Time to create nodes: %f' % (time.time()-tstart)
        app.instance.debugPanel.toggleWidget(app.debugpanel.FrametimeGraphWidget)
        if self.__optCreate:
            player.setInterval(400, self.__createNodes)
        # Ignore the first frame for the 20 sec-limit so long startup times don't
        # break things.
        player.setTimeout(0, lambda: player.setTimeout(20000, player.stop))

    def onFrame(self, dt):
         if self.__optMove:
            self.__moveNodes()

    def __createNodes(self):
        self.__nodes = []
        for i in xrange(self.__optNumObjs):
            pos = (random.randrange(800-64), random.randrange(600-64))
            polyPos = self.__calPolyCords(pos, R)
            holes = []
            if self.__optHole:
                holes = (self.__calPolyCords(pos, R/2), )
            node = avg.PolygonNode(parent=self, pos=polyPos, fillopacity=1, holes=holes)
            self.__nodes.append(node)
        if self.__optCreate:
            player.setTimeout(300, self.__deleteNodes)<commit_msg>libavg_app: Removed unused code in utils/checkpolygonspeed.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

# libavg - Media Playback Engine.
# Copyright (C) 2003-2013 <NAME>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Current versions can be found at www.libavg.de
#
# Original author of this file is <NAME> <<EMAIL>>

from libavg import *

import random
import math
import time

R = 40.0
g_Trigger = True


class SpeedDiv(app.MainDiv):
    def onArgvExtenderCreated(self, argvExtender):
        usage = '%prog [options]\n' \
                'Checks libavg performance by creating lots of polygon nodes. ' \
                'Displays a frame time graph and executes for 20 secs.'
        argvExtender.parser.set_usage(usage)

        argvExtender.parser.add_option('--hole-polygon', '-y', dest='hole',
                action='store_true', default=False,
                help='generate polygons with holes')
        argvExtender.parser.add_option('--create-nodes', '-c', dest='create',
                action='store_true', default=False,
                help='destroy and recreate all nodes every 400 ms')
        argvExtender.parser.add_option('--move', '-m', dest='move',
                action='store_true', default=False,
                help='move nodes every frame')
        argvExtender.parser.add_option('--vsync', '-s', dest='vsync',
                action='store_true', default=False,
                help='sync output to vertical refresh')
        argvExtender.parser.add_option('--num-objs', '-n', dest='numObjs',
                type='int', default=40,
                help='number of polygons to create [Default: 40]')
        argvExtender.parser.add_option('--num-points', '-x', dest='numPoints',
                type='int', default=10,
                help='number of points in each polygon [Default: 10]')
        argvExtender.parser.add_option('--profile', '-p', dest='profile',
                action='store_true', default=False,
                help='enable profiling output, note that profiling makes things slower')

    def onArgvExtenderApplied(self, argvExtender):
        opts, args = argvExtender.parsedArgs

        self.__optHole = opts.hole
        self.__optCreate = opts.create
        self.__optMove = opts.move
        self.__optVsync = opts.vsync
        self.__optNumObjs = opts.numObjs
        if self.__optNumObjs < 1:
            self.__optNumObjs = 40
        self.__optNumPoints = opts.numPoints
        if self.__optNumPoints < 10:
            self.__optNumPoints = 10
        elif self.__optNumPoints % 2 != 0:
            self.__optNumPoints -= 1

        log = avg.logger
        if opts.profile:
            log.setCategories(log.PROFILE | log.CONFIG | log.WARNING | log.ERROR)
        else:
            log.setCategories(log.CONFIG | log.WARNING | log.ERROR)

    def onInit(self):
        if not self.__optVsync:
            player.setFramerate(1000)

        tstart = time.time()
        self.__createNodes()
        print 'Time to create nodes: %f' % (time.time()-tstart)
        app.instance.debugPanel.toggleWidget(app.debugpanel.FrametimeGraphWidget)
        if self.__optCreate:
            player.setInterval(400, self.__createNodes)
        # Ignore the first frame for the 20 sec-limit so long startup times don't
        # break things.
        player.setTimeout(0, lambda: player.setTimeout(20000, player.stop))

    def onFrame(self, dt):
         if self.__optMove:
            self.__moveNodes()

    def __createNodes(self):
        self.__nodes = []
        for i in xrange(self.__optNumObjs):
            pos = (random.randrange(800-64), random.randrange(600-64))
            polyPos = self.__calPolyCords(pos, R)
            holes = []
            if self.__optHole:
                holes = (self.__calPolyCords(pos, R/2), )
            node = avg.PolygonNode(parent=self, pos=polyPos, fillopacity=1, holes=holes)
            self.__nodes.append(node)
        if self.__optCreate:
            player.setTimeout(300, self.__deleteNodes)
{'fraction_non_alphanumeric': 0.10540310572218677, 'fraction_numerical': 0.017017655817911082, 'mean_word_length': 2.4468475073313782, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5506617', 'n_tokens_mistral': 2794, 'n_tokens_neox': 2595, 'n_words': 777}