Beispiel #1
0
    def get(self):
        self.response.headers['Content-type'] = "text/plain"
        npp = 12
        category = 'apps_topselling_free'
        page = int(self.request.get("page"))
        url = 'http://market.android.com/details?id=%s&cat=GAME&start=%d&num=%d' % (
            category, page * npp, npp)
        html = urlfetch.fetch(url, deadline=10).content
        soup = BeautifulSoup(html)

        applist = soup.findAll('a', {"class": re.compile("title")})
        formatted = [(unicode(app.contents[0]),
                      unicode(app['href']).replace('/details?id=', ''))
                     for app in applist]
        n = page * npp
        for item in formatted:
            n += 1
            name, uniqueid = item
            r = Rank(key_name=str(n),
                     name=name,
                     uniqueid=uniqueid,
                     rank=n,
                     category=category)
            r.put()
        self.response.out.write("done")
def calc_average_max_rank(team):
    """
    Calculates the average and max player rank for a given team and sets it for the team
    :param team: Team, a Team object containing a list of players with set ranks
    :return: Team, the same object that was given but with its average and max rank set
    """

    logger.debug("calculating average and max rank for the team " + team.name)
    ranks = []
    for player in team.player_list:
        if player.rank is not None and player.rank.rating > 0:
            ranks.append(player.rank)
    count = len(ranks)
    rank_sum = 0
    list_ratings = []
    for rank in ranks:
        rank_sum += rank.rating
        list_ratings.append(rank.rating)
    if count == 0:
        average = 0
        max_rank = 0
    else:
        average = round(rank_sum / count)
        max_rank = max(list_ratings)
    team.average_rank = Rank(rating_lookup.get(average), average)
    team.max_rank = Rank(rating_lookup.get(max_rank), max_rank)
    return team
Beispiel #3
0
    def process_rank(self, row):
        rank_name = row[self.slices[self.indices['rank']]].strip()

        rank = Rank.execute_select({'name': rank_name})

        if rank:
            return rank[0].id

        rank = Rank.execute_select({'abbreviate': rank_name})

        if rank:
            return rank[0].id
Beispiel #4
0
def add_rank():
    json_data = request.get_json()

    rank = Rank(json_data['price'], json_data['name'], json_data['duration'], json_data['server_id'])

    if('description' in json_data):
        rank.description = json_data['description']

    db.session.add(rank)
    db.session.commit()

    return Response(status=201)
Beispiel #5
0
def add_player():
    error = None
    if request.method == 'POST':
        insert_data = dict(request.form)
        insert_data['is_active'] = 'is_active' in insert_data.keys()
        try:
            player_id = Player.execute_insert([insert_data])[0]
            flash('Гравець створений', 'isa_success')
            return redirect(url_for('.player_info', player_id=player_id))
        except mysql.connector.Error as err:
            flash(err.msg)

    cities = City.select_attrs(['id', 'name'])
    ranks = Rank.select_attrs(['id', 'name'])
    national_ranks = NationalRank.select_attrs(['id', 'name'])

    form = '\n'.join([
        '<div class="container">',
        f'<form action="/players/add" method="post">',
        render_text_input_row("last_name", "Прізвище"),
        render_text_input_row("first_name", "Ім'я"),
        render_select_row('city_id', "Місто", cities),
        render_number_input_row('rating', "Рейтинг", '100', '3000', '0.001'),
        render_select_row('rank_id', "Ранг", ranks),
        render_select_row('national_rank_id', "Розряд", national_ranks),
        render_text_input_row("pin", "EGF PIN"),
        render_checkbox_row('is_active', "Активний"),
        render_submit(),
        '</form>',
        '</div>',
    ])

    return render_template('add_player.html', form=form, error=error)
Beispiel #6
0
 def save_rank(self, rank_data_list):
     count = 0
     for rank_data in rank_data_list:
         _, create_result = Rank.get_or_create(**rank_data)
         if create_result:
             count += 1
     self.logger.info(u'存储 rank 数据完成,共:{}'.format(count))
Beispiel #7
0
def get_ranks(user):
    tmp = db_select(
        "dmob_user_rating",
        where_condition="user = %s",
        values=(user.id, ),
    )
    from models import Rank
    return [Rank(*x) for x in tmp]
Beispiel #8
0
 def get(self):
     self.response.headers['Content-type']="text/plain"
     npp = 12
     category = 'apps_topselling_free'
     page = int(self.request.get("page"))
     url = 'http://market.android.com/details?id=%s&cat=GAME&start=%d&num=%d' % (category,page*npp,npp)
     html = urlfetch.fetch(url,deadline=10).content
     soup = BeautifulSoup(html)
     
     applist = soup.findAll('a',{"class":re.compile("title")})
     formatted = [(unicode(app.contents[0]),unicode(app['href']).replace('/details?id=','')) for app in applist]
     n = page*npp
     for item in formatted:
         n+=1
         name,uniqueid = item
         r = Rank(key_name=str(n), name=name, uniqueid=uniqueid, rank=n, category=category)
         r.put()
     self.response.out.write("done")
Beispiel #9
0
def parse_rank(response, index, keywords):
    """rank 结果解析器
    """
    keyword = keywords[index]
    rank = Rank(keyword=keyword)
    rank.update = date.today()
    next_index = _get_next_page(0, index, 1, len(keywords))
    try:
        json_ranks = response.json().get('value', None)
        if json_ranks is not None and len(json_ranks) > 0:
            ranking_list = list()
            for item in json_ranks:
                ranking_list.append({
                    'product_id': item['id'],
                    'ranking': item['pageNO'] + item['rowNO']/100,
                })
            rank.ranking = ranking_list
    except JSONDecodeError:
        next_index = index

    return next_index, rank
Beispiel #10
0
def parse_rank(response, index, keywords):
    """rank 结果解析器
    """
    keyword = keywords[index]
    rank = Rank(keyword=keyword)
    rank.update = date.today()
    next_index = _get_next_page(0, index, 1, len(keywords))
    try:
        json_ranks = response.json().get('value', None)
        if json_ranks is not None and len(json_ranks) > 0:
            ranking_list = list()
            for item in json_ranks:
                ranking_list.append({
                    'product_id': item['id'],
                    'ranking': item['pageNO'] + item['rowNO']/100,
                })
            rank.ranking = ranking_list
    except JSONDecodeError:
        next_index = index

    return next_index, rank
Beispiel #11
0
 def update_ratings(self):
     self.update_score()
     rated_members = self.members
     old_rating = [x.user.rating for x in rated_members]
     old_volatility = [x.user.volatility for x in rated_members]
     actual_rank = list(range(1, len(rated_members) + 1))
     times_rated = [len(x.user.rank) for x in rated_members]
     new_rating, new_volatility = recalculate_ratings(
         old_rating, old_volatility, actual_rank, times_rated)
     for x in range(len(rated_members)):
         database.add_rank(
             Rank(None, rated_members[x].user.id, new_rating[x],
                  new_volatility[x]))
def add_player_rank(player: Player):
    """
    Call stalk player functions and adds a Rank to the given Player
    :param player: Player, a Player object with a summoner_name
    :return: Player, Player object with the same summoner_name and a set Rank
    """

    sum_name = player.summoner_name
    elo = stalk_player_opgg(sum_name).lower()
    if elo in rank_lookup:
        rating = rank_lookup.get(elo)
    else:
        rating = 0
    rank = Rank(rating_lookup.get(rating), rating)
    return Player(player.summoner_name, rank)
Beispiel #13
0
Datei: web.py Projekt: i19/tagger
def get_rank_children():
    resp = Resp()
    rank_id = request.form.get("id", 1)
    rank = Rank.get_by_id(rank_id)
    recursion = request.form.get("recursion", "")
    if recursion.lower() == "true":
        recursion = True
    else:
        recursion = False

    if not recursion:
        children = rank.get_children()
        resp.data = children
        return resp
    else:
        rank_tree = get_rank_tree(rank)
        resp.data = rank_tree
    return resp
Beispiel #14
0
def edit_player(player_id):
    if request.method == 'POST':
        update_data = dict(request.form)
        update_data['is_active'] = 'is_active' in update_data.keys()
        try:
            Player.execute_update(player_id, **update_data)
            flash('Дані гравця оновлені', 'isa_success')
            return redirect(url_for('.players'))
        except mysql.connector.Error as err:
            flash(err.msg, 'isa_error')

        return redirect(url_for('.player_info', player_id=player_id))

    player = Player.execute_select({'id': player_id})[0]

    cities = City.select_attrs(['id', 'name'])
    ranks = Rank.select_attrs(['id', 'name'])
    national_ranks = NationalRank.select_attrs(['id', 'name'])

    form = '\n'.join([
        '<div class="container">',
        f'<form action="/players/{player_id}/edit" method="post">',
        render_text_input_row("last_name", "Прізвище", player.last_name),
        render_text_input_row("first_name", "Ім'я", player.first_name),
        render_select_row('city_id', "Місто", cities, player.city.id),
        render_number_input_row('rating', "Рейтинг", '100', '3000', '0.001',
                                player.rating),
        render_select_row('rank_id', "Ранг", ranks, player.rank.id),
        render_select_row('national_rank_id', "Розряд", national_ranks,
                          player.national_rank.id),
        render_text_input_row("pin", "EGF PIN", player.pin),
        render_checkbox_row('is_active', "Активний", player.is_active),
        render_submit(),
        '</form>',
        '</div>',
    ])

    return render_template('edit_player.html', player=player, form=form)
Beispiel #15
0
 def get_user_rankings(self,request):
   Rank.make_rankings()
   ranks = Rank.query().order(Rank.rank)
   return RankForms(items=[rank.to_form() for rank in ranks])
Beispiel #16
0
 def get(self):
     apps = Rank.all().filter(
         'category', 'apps_topselling_free').order("rank").fetch(500)
     self.render_template("index.html", {"apps": apps})
def init_db():
    # import all modules here that might define models so that
    # they will be registered properly on the metadata.  Otherwise
    # you will have to import them first before calling init_db()
    from models import Ship, Race, Crew, Rank
    Base.metadata.drop_all(bind=engine)
    Base.metadata.create_all(bind=engine)

    # Create the fixtures
    vulcan = Race(name='Vulcan')
    db_session.add(vulcan)
    human = Race(name='Human')
    db_session.add(human)
    kelpien = Race(name='Kelpien')
    db_session.add(kelpien)
    synthetic = Race(name='Synthetic')
    db_session.add(synthetic)
    kelpien = Race(name='Kelpien')
    db_session.add(kelpien)
    synthetic = Race(name='Synthetic')
    db_session.add(synthetic)
    klingon = Race(name='Klingon')
    db_session.add(klingon)
    barzan = Race(name='Barzan')
    db_session.add(barzan)

    captain = Rank(name='Captain')
    db_session.add(captain)
    first_officer = Rank(name='First Officer')
    db_session.add(first_officer)
    chief_engineer = Rank(name='Chief Engineer')
    db_session.add(chief_engineer)
    science_officer = Rank(name='Science Officer')
    db_session.add(science_officer)
    chief_medical_officer = Rank(name='Chief Medical Officer')
    db_session.add(chief_medical_officer)
    communication_officer = Rank(name=' Communication Officer')
    db_session.add(communication_officer)
    ensign = Rank(name='Ensign')
    db_session.add(ensign)
    helmsman = Rank(name='Helmsman')
    db_session.add(helmsman)
    security_chief = Rank(name='Security Chief')
    db_session.add(security_chief)
    operations_officer = Rank(name='Operations Officer')
    db_session.add(operations_officer)
    transporter_chief = Rank(name='Transporter Chief')
    db_session.add(transporter_chief)

    discovery = Ship(name='U.S.S Discovery')
    db_session.add(discovery)
    enterprise = Ship(name='U.S.S. Enterprise')
    db_session.add(enterprise)

    jl = Crew(name='Jean-Luc Picard',
              ship=enterprise,
              race=human,
              rank=captain)
    db_session.add(jl)
    pike = Crew(name='Christopher Pike',
                ship=discovery,
                race=human,
                rank=captain)
    db_session.add(pike)
    lorca = Crew(name='Gabriel Lorca',
                 ship=discovery,
                 race=human,
                 rank=captain)
    db_session.add(lorca)

    riker = Crew(name='William Riker',
                 ship=enterprise,
                 race=human,
                 rank=first_officer)
    db_session.add(riker)
    saru = Crew(name='Saru', ship=discovery, race=kelpien, rank=first_officer)
    db_session.add(saru)

    la = Crew(name='Geordi La Forge',
              ship=enterprise,
              race=human,
              rank=chief_engineer)
    db_session.add(la)
    reno = Crew(name='Jett Reno',
                ship=discovery,
                race=human,
                rank=chief_engineer)
    db_session.add(reno)

    data = Crew(name='Data',
                ship=enterprise,
                race=synthetic,
                rank=science_officer)
    db_session.add(data)
    burn = Crew(name='Michael Burnham',
                ship=discovery,
                race=human,
                rank=science_officer)
    db_session.add(burn)

    b_crusher = Crew(name='Beverly Crusher',
                     ship=enterprise,
                     race=human,
                     rank=chief_medical_officer)
    db_session.add(b_crusher)
    pulaski = Crew(name='Katherine Pulaski',
                   ship=enterprise,
                   race=human,
                   rank=chief_medical_officer)
    db_session.add(pulaski)
    hugh = Crew(name='Hugh Culbe',
                ship=discovery,
                race=human,
                rank=chief_medical_officer)
    db_session.add(hugh)
    tracy = Crew(name='Tracy Pollard',
                 ship=discovery,
                 race=human,
                 rank=chief_medical_officer)
    db_session.add(tracy)

    pend = Crew(name='Pendleton',
                ship=enterprise,
                race=human,
                rank=communication_officer)
    db_session.add(pend)
    ra = Crew(name='R.A. Bryce',
              ship=discovery,
              race=human,
              rank=communication_officer)
    db_session.add(ra)

    wc = Crew(name='Wesley Crusher',
              ship=enterprise,
              race=human,
              rank=helmsman)
    db_session.add(wc)
    keyla = Crew(name='Keyla Detmer',
                 ship=discovery,
                 race=human,
                 rank=helmsman)
    db_session.add(keyla)

    worf = Crew(name='Worf',
                ship=enterprise,
                race=klingon,
                rank=security_chief)
    db_session.add(worf)
    nhan = Crew(name='Nhan', ship=discovery, race=barzan, rank=security_chief)
    db_session.add(nhan)

    data = Crew(name='Data',
                ship=enterprise,
                race=synthetic,
                rank=operations_officer)
    db_session.add(data)
    joann = Crew(name='Joann Owosekun',
                 ship=discovery,
                 race=human,
                 rank=operations_officer)
    db_session.add(joann)

    miles = Crew(name='Miles O’Brien',
                 ship=enterprise,
                 race=human,
                 rank=transporter_chief)
    db_session.add(miles)
    airiam = Crew(name='Airiam',
                  ship=discovery,
                  race=synthetic,
                  rank=transporter_chief)
    db_session.add(airiam)

    w_c2 = Crew(name='Wesley Crusher',
                ship=enterprise,
                race=human,
                rank=ensign)
    db_session.add(w_c2)
    st = Crew(name='Sylvia Tilly', ship=discovery, race=human, rank=ensign)
    db_session.add(st)

    db_session.commit()
Beispiel #18
0
 def get(self):
     apps = Rank.all().filter('category','apps_topselling_free').order("rank").fetch(500)
     self.render_template("index.html",{"apps":apps})