Esempio n. 1
0
    def widget(self, d):
        LOGFP = open("log.create-test-case.txt", "a")
        LOGFP.write("\n")
        LOGFP.write("-----------------------------------------------\n")
        LOGFP.write("%s/tools/create-test-case.sh ocsp-1 %s\n" %
                    (self._pwd, d))
        LOGFP.write("-----------------------------------------------\n")
        LOGFP.close()
        LOGFP = open("log.sign-widget.txt", "a")

        handle = Popen("%s/tools/create-test-case-modified.sh ocsp-1 %s" %
                       (self._pwd, d),
                       shell=True,
                       stdout=LOGFP,
                       stderr=LOGFP,
                       cwd="%s/tools" % (self._pwd),
                       close_fds=True)
        runTimer = Timer()

        while True:
            if (runTimer.elapsed() > 60):
                handle.terminate()
            # if

            handle.poll()

            if (handle.returncode != None):
                break
            # if
        # while

        LOGFP.write("-------------------- done --------------------\n")
        LOGFP.close()
        print " - created widget [returncode: %d]" % (handle.returncode)
Esempio n. 2
0
 def widget(self, d):
     LOGFP       = open("log.create-test-case.txt", "a")
     LOGFP.write("\n")
     LOGFP.write("-----------------------------------------------\n")
     LOGFP.write("%s/tools/create-test-case.sh ocsp-1 %s\n" % (self._pwd, d))
     LOGFP.write("-----------------------------------------------\n")
     LOGFP.close()
     LOGFP       = open("log.sign-widget.txt", "a")
     
     handle      = Popen("%s/tools/create-test-case-modified.sh ocsp-1 %s" % (self._pwd, d), shell=True, stdout=LOGFP, stderr=LOGFP, cwd="%s/tools" % (self._pwd), close_fds=True)
     runTimer    = Timer()
     
     while True:
         if (runTimer.elapsed() > 60):
             handle.terminate()
         # if
         
         handle.poll()
         
         if (handle.returncode != None):
             break
         # if
     # while
     
     LOGFP.write("-------------------- done --------------------\n")
     LOGFP.close()
     print " - created widget [returncode: %d]" % (handle.returncode)
Esempio n. 3
0
class FindUpDown(Action):
    def init(self):
        self.timer = Timer()
        self.iter = iter(GazePlats)
        self.curPlat = self.iter.next()

    def tick(self):
        if self.bb.visionInfo.see_ball:
            self.gazeBall()
            return self.success()
        else:
            if self.timer.elapsed() > 1:
                self.timer.restart()
                if not self.next_plat():
                    print "failure"
                    return self.failure()

            self.lookAt(self.curPlat.x, self.curPlat.y, 10, 10)
            print "lookAt ({}, {})".format(self.curPlat.x, self.curPlat.y)
            print "running"
        return self.running()

    def next_plat(self):
        try:
            self.curPlat = self.iter.next()
            # self.world.scanning = True
            return True
        except StopIteration:
            # GazePlats.reverse()
            # self.world.scanning = False
            self.iter = iter(GazePlats)
            self.curPlat = self.iter.next()
            return False
Esempio n. 4
0
class Patrol(Action):
    def init(self):
        self.timer = Timer()
        self.timer2 = Timer(2)
        self.straight = True

    def tick(self):
        # if not ballValid():
        #     return self.failure()
        print(self.timer2.elapsed())
        self.lookAt(0, 0)
        self.walk(3, 0, 0)

        if self.straight:
            self.walk(3, 0, 0)
        else:
            self.walk(3, 0, 3)

        if self.timer2.finished():
            if self.straight:
                self.straight = False
                self.timer2.restart()
            else:
                self.straight = True
                self.timer2.restart()

        return self.running()
Esempio n. 5
0
class GoalieScanField(Action):
    """
    Head skill: Find ball, when robot is not turning, scan field, else look down
    """
    def init(self):
        self.timer = Timer()
        self.iter = iter(GazePlats)
        self.curPlat = self.iter.next()

    def tick(self):
        if self.bb.parameters.attackRight:
            print 'f**k right'
            self.bb.reset_particle_point(
                VecPos(-self.bb.parameters.GoaliePointX, 0))
        else:
            print 'f**k left'
            self.bb.reset_particle_point(
                VecPos(self.bb.parameters.GoaliePointX, 0))
        self.crouch()
        if self.bb.see_ball:
            self.gazeBall()
            if self.bb.attackRight:
                if self.bb.ball_global.x < -450 + ATTACK_DIATANCE_X and abs(
                        self.bb.ball_global.y) < 200:
                    print 'GoalieScanField Succcess'
                    return self.success()
                else:
                    return self.running()
            else:
                if self.bb.ball_global.x > 450 - ATTACK_DIATANCE_X and abs(
                        self.bb.ball_global.y) < 200:
                    print 'GoalieScanField Succcess'
                    return self.success()
                else:
                    return self.running()
        else:
            if self.timer.elapsed() > 1:
                self.timer.restart()
                self.next_plat()
            self.lookAt(self.curPlat.x, self.curPlat.y, 10, 10)
        # print('LookAround running')
        return self.running()

    def next_plat(self):
        try:
            self.curPlat = self.iter.next()
            # self.world.scanning = True
            return True
        except StopIteration:
            # GazePlats.reverse()
            # self.world.scanning = False
            self.iter = iter(GazePlats)
            self.curPlat = self.iter.next()
            return False
Esempio n. 6
0
    def _sign(self, f, d, cert):
        p12 = "%s/keys/%s.rsa.p12" % (self._pwd, cert)

        if (f == "author-signature.xml"):
            sig = "-a"
            sid = "%s-author" % (d)
        else:
            sig = "-o %s" % (f)

            if (f[9] == "1"): sid = "%s" % (d)
            else: sid = "%s-%s" % (d, f[9])
        # if elif

        crt = "%s/keys/2.rsa.cert.pem" % (self._pwd)
        wgt = "%s/test-cases/ocsp-1/%s" % (self._pwd, d)

        LOGFP = open("log.sign-widget.txt", "a")
        LOGFP.write("\n")
        LOGFP.write("----------------------------------------------\n")
        LOGFP.write(
            "%s/tools/sign-widget.sh --pwd secret --pkcs12  %s %s -i w3c-testsuite-id-ocsp-1-%s -c %s %s"
            % (self._pwd, p12, sig, sid, crt, wgt))
        LOGFP.write("----------------------------------------------\n")
        LOGFP.close()
        LOGFP = open("log.sign-widget.txt", "a")

        #        print "   - run: %s/tools/sign-widget.sh --pwd secret --pkcs12  %s %s -i w3c-testsuite-id-ocsp-1-%s -c %s %s" % (self._pwd, p12, sig, sid, crt, wgt)
        handle = Popen(
            "%s/tools/sign-widget-modified.sh --pwd secret --pkcs12  %s %s -i w3c-testsuite-id-ocsp-1-%s -c %s %s"
            % (self._pwd, p12, sig, sid, crt, wgt),
            shell=True,
            stdout=LOGFP,
            stderr=LOGFP,
            cwd="%s/tools" % (self._pwd),
            close_fds=True)
        runTimer = Timer()

        while True:
            if (runTimer.elapsed() > 60):
                handle.terminate()
            # if

            handle.poll()

            if (handle.returncode != None):
                break
            # if
        # while

        LOGFP.write("-------------------- done --------------------\n")
        LOGFP.close()
        print "   - %s [returncode: %d]" % (f, handle.returncode)
def main():
    timer = Timer()
    timer.start()
    start = time.time()
    k = 1
    alpha = 0

    min_distance = 10000000000

    if int(argv[2]) == 0:
        argv[2] = 1

    c = 'Method\n'
    c += '1) K-Best\n'
    c += '2) RCL\n'
    c += 'method: '
    method = int(input(c))

    if method == 1:
        k = int(input('K: '))

    if method == 2:
        alpha = float(input('ALPHA (0 a 1): '))

    for i in range(0, int(argv[2])):
        # print(f'\niteration: {i + 1}')

        nearest_neighbor = NearestNeighbor(k, alpha, method)
        tour = nearest_neighbor.run()

        # print(nearest_neighbor.resultPath(tour))
        # print(f'Nearest Neighbor: {nearest_neighbor.distanceTour(tour)}')

        local_search = localSearch(tour)
        neighbor_tour = local_search.firstIncome()

        # print(f'LS: {nearest_neighbor.distanceTour(neighbor_tour)}')
        # Path(neighbor_tour)
        # print('******************************************')

        distance = local_search.distanceTour(neighbor_tour)
        if distance < min_distance:
            min_distance = distance
            min_tour = local_search.resultPath(neighbor_tour)

        if (time.time() - start) > (60 * 2):
            break

    print('----- Final Result -----\n')
    print(f'Minimum tour: {min_tour}')
    print(f'Minimum distance: {min_distance}')
    print(timer.elapsed('Time of execution: ') + ' seconds')
Esempio n. 8
0
    def _sign(self, f, d, cert):
        p12 = "%s/keys/%s.rsa.p12" % (self._pwd, cert)
        
        if (f == "author-signature.xml"):
            sig = "-a"
            sid = "%s-author" % (d)
        else:
            sig = "-o %s" % (f)
            
            if (f[9] == "1"):   sid = "%s" % (d)
            else:               sid = "%s-%s" % (d, f[9])
        # if elif
        
        crt = "%s/keys/2.rsa.cert.pem" % (self._pwd)
        wgt = "%s/test-cases/ocsp-1/%s" % (self._pwd, d)
        
        LOGFP       = open("log.sign-widget.txt", "a")
        LOGFP.write("\n")
        LOGFP.write("----------------------------------------------\n")
        LOGFP.write("%s/tools/sign-widget.sh --pwd secret --pkcs12  %s %s -i w3c-testsuite-id-ocsp-1-%s -c %s %s" % (self._pwd, p12, sig, sid, crt, wgt))
        LOGFP.write("----------------------------------------------\n")
        LOGFP.close()
        LOGFP       = open("log.sign-widget.txt", "a")
        
#        print "   - run: %s/tools/sign-widget.sh --pwd secret --pkcs12  %s %s -i w3c-testsuite-id-ocsp-1-%s -c %s %s" % (self._pwd, p12, sig, sid, crt, wgt)
        handle      = Popen("%s/tools/sign-widget-modified.sh --pwd secret --pkcs12  %s %s -i w3c-testsuite-id-ocsp-1-%s -c %s %s" % (self._pwd, p12, sig, sid, crt, wgt), shell=True, stdout=LOGFP, stderr=LOGFP, cwd="%s/tools" % (self._pwd), close_fds=True)
        runTimer    = Timer()
        
        while True:
            if (runTimer.elapsed() > 60):
                handle.terminate()
            # if
            
            handle.poll()
            
            if (handle.returncode != None):
                break
            # if
        # while
        
        LOGFP.write("-------------------- done --------------------\n")
        LOGFP.close()
        print "   - %s [returncode: %d]" % (f, handle.returncode)
Esempio n. 9
0
class GoalieLookDown(Action):
    """
    Head skill: Find ball, when robot is not turning, scan field, else look down
    """
    def init(self):
        self.timer = Timer()
        self.iter = iter(GazePlats)
        self.curPlat = self.iter.next()

    def tick(self):
        print 'goalie look down tick'
        # print("*********LookAround tick")
        if self.gazeBall():
            # if ball is seen, then reinit FindBall
            self.iter = iter(GazePlats)
            self.curPlat = self.iter.next()
            # print('LookAround success')
            return self.success()

        else:
            if self.timer.elapsed() > 1:
                self.timer.restart()
                self.next_plat()
            self.lookAt(self.curPlat.x, self.curPlat.y, 10, 10)
        # print('LookAround running')
        return self.success()

    def next_plat(self):
        try:
            self.curPlat = self.iter.next()
            # self.world.scanning = True
            return True
        except StopIteration:
            # GazePlats.reverse()
            # self.world.scanning = False
            self.iter = iter(GazePlats)
            self.curPlat = self.iter.next()
            return False
Esempio n. 10
0
class Striker(Action):
    def init(self):
        self.strike = Strike()
        self.seekball = SeekBall()
        self.ready = False
        self.lostBallTimer = Timer()
        self.seekballFuck = SeekBall_Fuck()

    def tick(self):
        if self.bb.see_ball:
            self.lostBallTimer.restart()

        if self.lostBallTimer.elapsed() > 15:
            self.gotoGlobal(self.bb.get_default_dest())

            if self.got_dest_loose(self.bb.get_default_dest()):
                self.lostBallTimer.restart()

        elif self.bb.closest_to_ball() or self.bb.team_lost_ball():
            self.ready = False
            self.strike.tick()

        else:
            """
            Face ball if see ball, else seek ball
            Approach close to ball
            Keep 1m away, don't block attack path
            """

            if self.bb.see_ball:
                bally = self.bb.ball_global.y
                ballx = self.bb.ball_global.x

                rx = self.bb.robot_pos.x
                ry = self.bb.robot_pos.y

                dx = rx - ballx
                dy = ry - bally

                dist = sqrt(dx * dx + dy * dy)

                # for attack right case
                change = False
                if attackRight():
                    if ballx > rx or abs(bally -
                                         ry) > 150 or dist > 200 or dist < 50:
                        if ry > bally:
                            y = bally + 100
                        else:
                            y = bally - 100

                        angle = degree_between(self.bb.robot_pos,
                                               self.bb.ball_global)
                        if not self.gotoGlobal(VecPos(ballx + 100, y, angle)):
                            change = True
                else:
                    if ballx < rx or abs(bally -
                                         ry) > 150 or dict > 200 or dist < 50:
                        if ry > bally:
                            y = bally + 100
                        else:
                            y = bally - 100

                        angle = degree_between(self.bb.robot_pos,
                                               self.bb.ball_global)
                        if not self.gotoGlobal(VecPos(ballx + 100, y, angle)):
                            change = True

                trackBall.tick()
                if not change:
                    self.faceBall()

            else:
                # to do, max turn cnt, else go back
                self.seekball.tick()

        return self.running()

    def wait(self):
        """
        Crouch and face ball and scan field
        """
        self.faceBall()

    def push(self):
        """
        Push forward waiting for a pass
        :return:
        """
        y = self.bb.robot_pos.y
        if self.bb.parameters.attackRight:
            dest = VecPos(200, y, 0)
        else:
            dest = VecPos(-200, y, 180)

        if not self.got_dest_loose(dest):
            self.gotoGlobalOmni(dest)
            self.ready = False
        else:
            self.ready = True
Esempio n. 11
0
if __name__ == '__main__':

    #
    # CONFIG BEGIN
    #

    # account_file = 'DataSources/company_names.txt'
    account_file = 'DataSources/notweets_test.txt'
    output_directory = "DataSets"
    begin = dt.date(2010, 1, 1)
    end = dt.date(2017, 12, 31)

    #
    # CONFIG END
    #

    with open(account_file, 'r') as f:
        handles = f.readlines()

    handles = [h.rstrip('\n') for h in handles]

    timer = Timer()
    for handle in handles:
        timer.start()
        # query = TweetQuery(handle, output_directory, "weekly")
        query = TweetQuery(handle, output_directory, "monthly")
        cnt = query.download_tweets_to_csv(begin, end)
        timer.stop()
        logging.info("SUCCESS (company=%s tweets=%s duration=%s)", handle, cnt,
                     timer.elapsed())