Пример #1
0
def layer():
    global NC_LAYER, NC_IMAGE  #, NC_SCORE

    print(utils.ribb("==", sep="="))
    print(utils.ribb("[%d] LAYER " % NC_LAYER, sep="="))
    print(utils.ribb("==", sep="="), "\n")

    # --- 1 step --- find all possible lines (that makes sense) ----------------
    print(utils.ribb(utils.head("SLID"), utils.clock(), "--- 1 step "))
    segments = pSLID(NC_IMAGE['main'])
    raw_lines = SLID(NC_IMAGE['main'], segments)
    lines = slid_tendency(raw_lines)

    # --- 2 step --- find interesting intersections (potentially a mesh grid) --
    print(utils.ribb(utils.head("LAPS"), utils.clock(), "--- 2 step "))
    points = LAPS(NC_IMAGE['main'], lines)
    #print(abs(49 - len(points)), NC_SCORE)
    #if NC_SCORE != -1 and abs(49 - len(points)) > NC_SCORE * 4: return
    #NC_SCORE = abs(49 - len(points))

    # --- 3 step --- last layer reproduction (for chessboard corners) ----------
    print(utils.ribb(utils.head(" LLR"), utils.clock(), "--- 3 step "))
    inner_points = LLR(NC_IMAGE['main'], points, lines)
    four_points = llr_pad(inner_points, NC_IMAGE['main'])  # padcrop

    # --- 4 step --- preparation for next layer (deep analysis) ----------------
    print(utils.ribb(utils.head("   *"), utils.clock(), "--- 4 step "))
    print(four_points)
    try:
        NC_IMAGE.crop(four_points)
    except:
        utils.warn("niestety, ale kolejna warstwa nie jest potrzebna")
        NC_IMAGE.crop(inner_points)

    print("\n")
Пример #2
0
 def test_head(self):
     self.assertEqual(head([1,2,3,4,5]) , 1)
     self.assertEqual(head([]) , None)
     self.assertEqual(
         head(get_recipients(message.split()))
         ,
         "@walrusthecat")
Пример #3
0
def playgame(date, feedId, provider, state):
    def adjustQuality(masterUrl):
        _720p60fps = "720p 60fps"
        qualityUrlDict = {
            "360p": "1200K/1200_{0}.m3u8",
            "540p": "2500K/2500_{0}.m3u8",
            "720p": "3500K/3500_{0}.m3u8"
        }
        current = addon.getSetting("quality")
        if current is None or current == _720p60fps or current == "":
            return masterUrl
        else:
            m3u8Path = qualityUrlDict.get(
                current, "3500K/3500_{0}.m3u8").format(
                    'slide' if state == 'In Progress' else 'complete-trimmed')
            xbmc.log(
                "Quality adjusted to '{0}', adjusting to {1}.".format(
                    current, m3u8Path), xbmc.LOGNOTICE)
            return masterUrl.rsplit('/', 1)[0] + "/" + m3u8Path

    def xbmcPlayer(url, mediaAuth):
        xbmc.log("XBMC trying to play URL [%s]" % (url), xbmc.LOGNOTICE)
        completeUrl = url + ("|Cookie=mediaAuth%%3D%%22%s%%22" % (mediaAuth))
        xbmc.Player().play(
            adjustQuality(url) + ("|Cookie=mediaAuth%%3D%%22%s%%22" %
                                  (mediaAuth)))
        #player.LazyManPlayer().play(adjustQuality(url) + ("|Cookie=mediaAuth%%3D%%22%s%%22" % (mediaAuth)))

    cdn = 'akc' if addon.getSetting("cdn") == "Akamai" else 'l3c'

    def getContentUrl(withCdn=True):
        actualCdn = cdn if withCdn else ""
        if provider == "NHL.tv":
            return "http://freegamez.ga/m3u8/%s/%s%s" % (date, feedId,
                                                         actualCdn)
        else:
            return "http://freegamez.ga/mlb/m3u8/%s/%s%s" % (date, feedId,
                                                             actualCdn)

    contentUrl = getContentUrl()
    xbmc.log("Trying to resolve from content-url: '" + contentUrl + "'",
             xbmc.LOGNOTICE)
    if not utils.head(contentUrl):
        contentUrl = getContentUrl(False)
        if not utils.head(contentUrl):
            xbmc.log("Cannot resolve content-url '" + contentUrl + "'",
                     xbmc.LOGERROR)
            raise ValueError("Invalid content-url '" + contentUrl + "'")
    response = urllib.urlopen(contentUrl)
    playUrl = response.read().replace('l3c', cdn)
    xbmc.log("Play URL resolved to : '" + playUrl + "'", xbmc.LOGNOTICE)
    mediaAuthSalt = utils.salt()
    if utils.get(playUrl, dict(mediaAuth=mediaAuthSalt)):
        xbmcPlayer(playUrl, mediaAuthSalt)
    else:
        otherCdn = 'akc' if cdn == 'l3c' else 'l3c'
        xbmc.log(
            "URL [%s] failed on GET, switching CDN from %s to %s" %
            (playUrl, cdn, otherCdn), xbmc.LOGNOTICE)
        xbmcPlayer(playUrl.replace(cdn, otherCdn), mediaAuthSalt)
Пример #4
0
 def py_code(self, args):
     xs = nats(1, args["length"])
     ys = nats(args["length"], 1)
     res = 0
     while (not isEmpty(xs)):
         res += binop(args["operation"], head(xs), head(ys))
         xs = tail(xs)
         ys = tail(ys)
     return res
Пример #5
0
 def py_code(self, args):
     xs = nats(1, args["length"])
     ys = nats(args["length"], 1)
     zs = []
     while (not isEmpty(xs)):
         zs = zs + [binop(args["operation"], head(xs), head(ys))]
         xs = tail(xs)
         ys = tail(ys)
     return zs
Пример #6
0
def find_site_ref(site,fna_filename):
    """WRONG: rev matches are indexed backwards"""
    genome = genome_from_fna(fna_filename)
    regexp = re.compile(site)
    fwd_matches = [(lambda (start,stop):(start,stop,+1))(m.span()) for m in regexp.finditer(genome)]
    rev_matches = [(lambda (start,stop):(start,stop,-1))(m.span()) for m in regexp.finditer(wc(genome))]
    matches = fwd_matches + rev_matches
    print matches
    if len(matches) == 1:
        print "found unique match for %s in %s" % (site,fna_filename)
        return head(matches)
    elif len(matches) > 1:
        print "found multiple matches for %s in %s" % (site,fna_filename)
        return head(matches)
    else:
        print "couldn't find' match for %s in %s" % (site,fna_filename)
        return (None,None,None)
Пример #7
0
 def place_ships(self):
     # Method to place all ships on the board
     if self.place_ship(ships.Carrier(player=self, board=self.board), 1):
         return
     if self.place_ship(ships.Battleship(player=self, board=self.board), 2):
         return
     if self.place_ship(ships.Cruiser(player=self, board=self.board), 3):
         return
     if self.place_ship(ships.Submarine(player=self, board=self.board), 4):
         return
     if self.place_ship(ships.Destroyer(player=self, board=self.board), 5):
         return
     # Give our output of the board
     utils.cls()
     utils.head("Player " + str(self.num) + " All Ships Placed!")
     print(" ")
     print(self.board)
     print(" ")
     if not self.game.debug:
         utils.get("Press [enter] to continue...")
Пример #8
0
 def auto_place_ships(self):
     # Method to auto-place all ships
     self.auto_place_ship(ships.Carrier(player=self, board=self.board))
     self.auto_place_ship(ships.Battleship(player=self, board=self.board))
     self.auto_place_ship(ships.Cruiser(player=self, board=self.board))
     self.auto_place_ship(ships.Submarine(player=self, board=self.board))
     self.auto_place_ship(ships.Destroyer(player=self, board=self.board))
     # Give our output of the board
     utils.cls()
     if self.bot:
         utils.head("Bot " + str(self.num) + " All Ships Placed!")
         print(" ")
         print("Board hidden!")
     else:
         utils.head("Player " + str(self.num) + " All Ships Placed!")
         print(" ")
         print(self.board)
     print(" ")
     if not self.game.debug:
         utils.get("Press [enter] to continue...")
Пример #9
0
    def shot_output(self, output, player):
        # Prints the output in a human-readable way
        # Do some animation here...

        if self.game.quiet:
            return

        subject = "Bot " if self.bot else "Player "
        subject += str(self.num)
        target = "Bot " if player.bot else "Player "
        target += str(player.num)

        anim = 0  # 0 = miss, 1 = hit, 2 = sunk
        title = "MISSED!"
        if output["shot"][0]:
            anim = 1
            title = "HIT!"
            if output["shot"][1]:
                anim = 2
                title = "SUNK {}'s {}!".format(target, output["ship"].type)

        if self.game.anims:
            # Animate!
            a = animations.Animate()
            if anim == 0:
                a.miss()
            elif anim == 1:
                a.hit()
            elif anim == 2:
                a.sunk()

        utils.cls()
        utils.head(subject + " Shot!")
        print(" ")
        print(subject + " " + title)
        print(" ")

        if not self.game.debug:
            utils.get("Press [enter] to continue...")
Пример #10
0
def find_site(site,fna_filename,return_all=False):
    genome = genome_from_fna(fna_filename)
    fwd_regexp = re.compile(site)
    rev_regexp = re.compile(wc(site))
    fwd_matches = [(lambda (start,stop):(start,stop,+1))(m.span()) for m in fwd_regexp.finditer(genome)]
    rev_matches = [(lambda (start,stop):(start,stop,-1))(m.span()) for m in rev_regexp.finditer(genome)]
    matches = fwd_matches + rev_matches
    #print matches
    if len(matches) == 1:
        print "found unique match for %s in %s" % (site,fna_filename)
        return head(matches) if not return_all else matches
    elif len(matches) > 1:
        print "found multiple matches for %s in %s" % (site,fna_filename)
        return (None,None,None) if not return_all else matches
    else:
        print "couldn't find' match for %s in %s" % (site,fna_filename)
        return (None,None,None) if not return_all else []
Пример #11
0
    def take_shot(self, player, status=None):
        if self.bot:
            return self.auto_take_shot(player)
        # Displays the current board and compares to the player's board for hit detection
        while True:
            utils.cls()
            utils.head("Player " + str(self.num) + "'s Turn")
            print(" ")
            if status:
                print(status)
                print(" ")
            print(
                self.board.mux_boards(
                    player.board.print_board(hidden=True, title="Enemy"),
                    self.board.print_board(title="You")))
            print(" ")
            menu = utils.get("Where would you like to shoot? (A1, B3, etc):  ")

            if not len(menu):
                continue

            if menu.lower() == "random":
                return self.shoot_random(player)

            coords = self.board.check_point(menu)
            if coords == None:
                # Not Valid!
                utils.cls()
                utils.head("Player " + str(self.num) + " Misfire!")
                print(" ")
                print("That is not a valid coordinate!")
                print(" ")
                utils.get("Press [enter] to try again...")
                continue

            # Valid coord - check if we already shot there
            if coords in player.board.shots:
                # Already shot here
                utils.cls()
                utils.head("Player " + str(self.num) + " Misfire!")
                print(" ")
                print("You have already fired there!")
                print(" ")
                utils.get("Press [enter] to try again...")
                continue

            # Valid - add it
            self.shot_output(player.board.take_shot(coords), player)
            return "Player {} fired at {}{}".format(
                self.num,
                list("ABCDEFGHIJ")[coords[0]], 10 - coords[1])
Пример #12
0
 def received_message(self, message):
     message = json.loads(message.data)
     message_type = inverse(MESSAGES, head(message))
     method = getattr(self, message_type.lower(),
                      self.raise_not_implemented)
     method(*tail(message))
Пример #13
0
def playhighlight(url):
    xbmc.log("XBMC trying to play URL [%s]" % (url), xbmc.LOGNOTICE)
    mediaAuth = utils.salt()
    if utils.head(url, dict(mediaAuth=mediaAuth)):
        completeUrl = url + ("|Cookie=mediaAuth%%3D%%22%s%%22" % (mediaAuth))
        xbmc.Player().play(completeUrl)
Пример #14
0
#prints the amount of rows that are in each dataset
from utils import line_count
print("---Number of rows from each dataset---\n")
print("Super Bowl History:")
line_num = line_count('data/datasets_superbowl.csv')
print(line_num)
print("\nSuper Bowl Ads:")
line_num = line_count('data/datasets_superbowl-ads.csv')
print(line_num)

#prints all columns and one row from each dataset
from utils import head
print("All columns and one row from each dataset\n")
print("Super Bowl History:")
print(head('data/datasets_superbowl.csv', 2))
print("\nSuper Bowl Ads:")
print(head('data/datasets_superbowl-ads.csv', 2))

#-------------------------------------------------------#

# There are 10 columns in the Super Bowl History CSV:

# Date: date, Date of Super Bowl
# SB: string, Super Bowl name
# Winner: sting, Winning team
# Winner Pts: int, Points scored by winning team
# Loser: string, Losing team
# Loser Pts: int, Points scored by losing team
# MVP: string, Most Valuable Player award recepient
# Stadium: string, Stadium name of Super Bowl
Пример #15
0
 def received_message(self, message):
     message = json.loads(message.data)
     message_type = inverse(MESSAGES, head(message))
     method = getattr(self, message_type.lower(),
                      self.raise_not_implemented)
     method(*tail(message))
Пример #16
0
    def place_ship(self, ship, num):
        # Method to place a single ship
        while True:
            utils.cls()
            utils.head("Player " + str(self.num) + " Placing " + ship.type +
                       ", {}/{}".format(num, self.tship))
            print(" ")
            print(ship.type + ", {} {}.".format(
                ship.size, "space" if ship.size == 1 else "spaces"))
            print(" ")
            print(ship.picture)
            print(" ")
            print(self.board)
            print(" ")
            menu = utils.get(
                "Where would you like to place this ship? (A1, B3, etc):  ")

            if menu.lower() == "random":
                self.auto_place_ship(ship)
                return None

            if menu.lower() == "random all":
                self.auto_place_ships()
                return True

            coords = self.board.check_point(menu)
            if coords == None:
                # Not Valid!
                utils.cls()
                utils.head(ship.type + " Placement Error!")
                print(" ")
                print("That is not a valid coordinate!")
                print(" ")
                utils.get("Press [enter] to try again...")
                continue
            # Here is where we'd pick a direction
            ship.x, ship.y = coords[0], coords[1]

            utils.cls()
            utils.head("Player " + str(self.num) + " Orienting " + ship.type +
                       ", {}/{}".format(num, self.tship))
            print(" ")
            print(ship.type + ", {} {}.".format(
                ship.size, "space" if ship.size == 1 else "spaces"))
            print(" ")
            print(ship.picture)
            print(" ")
            print(self.board.print_board(opt=(ship.x, ship.y, ship.char)))
            print(" ")
            menu = utils.get(
                "Please type the direction (Up, Down, Left, Right):  ")

            if menu.lower() == "random":
                self.auto_place_ship(ship)
                return None

            if menu.lower() == "random all":
                self.auto_place_ships()
                return True

            if not menu.lower() in [
                    "up", "down", "left", "right", "u", "d", "l", "r"
            ]:
                utils.cls()
                utils.head(ship.type + " Placement Error!")
                print(" ")
                print("Improper direction!")
                print(" ")
                utils.get("Press [enter] to try again...")
                continue

            ship.direction = [
                "up", "down", "left", "right", "u", "d", "l", "r"
            ].index(menu.lower())
            if ship.direction > 3:
                ship.direction -= 4

            print(ship.direction)

            if not self.board.add_ship(ship):
                utils.cls()
                utils.head(ship.type + " Placement Error!")
                print(" ")
                print(
                    "That direction either overlaps another ship, or is out of bounds!"
                )
                print(" ")
                utils.get("Press [enter] to try again...")
                continue

            # Ship placed at this point!
            return None
Пример #17
0
pubmed_file = FR("../PUBMED_DATA/pubmed_data_2606.txt",
                 sep="\t",
                 suppress_newlines=True,
                 skiplines=1,
                 encoding="CP1252",
                 strip_chars_pattern=strippattern)

drugs_file = FR("../DRUG_LISTS/full_drug_list.txt",
                sep=";",
                suppress_newlines=True,
                encoding="utf-16")

pubmed = pubmed_file.readlines()
drugs = drugs_file.readlines()

utils.head(pubmed, stop=1)

match = {}

for article in pubmed:
    match[int(article[1])] = []

print(len(match))

tf = TF(len(drugs))

for names in drugs:
    for article in pubmed:
        found = False
        title = article[5]
        description = article[6]