예제 #1
0
def create_match():
    now = datetime.datetime.now()
    match = models.Match(date=now, team1score=0, team2score=0)
    db.session.add(match)
    db.session.commit()

    return jsonify({'id': match.id}), 201
예제 #2
0
def parse(text, filename):
    """Parse the raw text of a stat file. Requires a file name to check for a duplicate entry."""
    q = db.session.query(
        models.Match.parsed_file).filter(models.Match.parsed_file == filename)
    try:
        if (q.first()):
            logger.warning(
                " ~ ~ Duplicate parse entry detected.)\n ~ ~ Request filename: %s"
                + "\n ~ ~ Stored filename: %s", filename,
                q.first().parsed_file)
            return False
        else:
            logger.debug('Starting parse of %r' % filename)

        match = models.Match()
        match.parsed_file = filename
        # Regex is in format yyyy-dd-mm
        search_str = '^statistics_((?:19|20)\d{2})[\. .](0[1-9]|[12][0-9]|3[01])[\. .](0[1-9]|1[012])(?:.*)\.txt$'
        file_date = re.search(search_str, filename)
        if file_date is None or len(file_date.groups()) != 3:
            logger.warning('Invalid filename for timestamp: %r' % filename)
            return False
        match.date = datetime.date(int(file_date.group(1)),
                                   int(file_date.group(3)),
                                   int(file_date.group(2)))
        db.session.add(match)
        try:
            db.session.flush()
        except Exception:
            print("PANIC")
            logger.error('Error flushing DB session: {0}'.format(
                Exception.message))
            return False
        lines = text.splitlines()
        for line in lines:
            try:
                parse_line(line, match)
            except Exception:
                print("PANIC")
                logger.error('Error parsing line: {0}\n{1}'.format(
                    line, Exception.message))
                db.session.rollback()
                return False
            db.session.flush()
        db.session.commit()
    except Exception:
        logger.error('Error parsing line: {0}\n{1}'.format(
            line, Exception.message))
        return False
    return True
예제 #3
0
    def get(self, name):
        app.logger.debug("Summoner API endpoint called")
        name = name.lower()
        summoner = models.Summoner.query.filter(
            models.Summoner.name == name).first()
        status = {}
        status['summoner_name'] = name
        status['saved_matches'] = 0
        print(summoner)
        if summoner:
            status['exist'] = True
            return status
        else:
            s = riot.get_basic_summoner_info(name)
            s['matches'] = riot.get_matches(s['account_id'],
                                            app.config['FETCH_MATCH_COUNT'])
            summoner = models.Summoner(name=s['name'],
                                       account_id=int(s['account_id']),
                                       id=int(s['summoner_id']),
                                       level=int(s['level']))
            if 'lp' in s:
                summoner.lp = s['lp']
                summoner.rank = s['rank']

            status['downloaded_matches'] = len(s['matches'])
            for key, value in s['matches'].items():
                try:
                    match_id = int(key)
                    status['saved_matches'] += 1
                    game_time = int(value['match_info']['gameCreation'])
                    iso8650 = datetime.datetime.utcfromtimestamp(
                        game_time / 1000).strftime('%Y-%m-%d %H:%M:%S')
                    match = models.Match(id=match_id,
                                         datetime=iso8650,
                                         info=value['match_info'],
                                         timeline=value['timeline'])
                    summoner.matches.append(match)
                except:
                    print(value)
            db.session.merge(summoner)
            db.session.commit()

            return status
예제 #4
0
def get_match_id():
    """Returns a match id

    If an even number of players have connected creates a new match
    Else it adds the user as the 2nd player in the previously created match
    """
    global count
    match_id = len(models.Match.query.all())
    if count == 0:
        match_id = match_id + 1  # new match
        m = models.Match(id=match_id, p1=g.user)
        db.session.add(m)
        db.session.commit()
        count = 1
    else:
        m = models.Match.query.filter_by(id=match_id).first()
        m.p2 = g.user
        db.session.add(m)
        db.session.commit()
        count = 0
    return jsonify({'match_id': match_id})
예제 #5
0
def index():
    form = SearchForm()
    if form.validate_on_submit():
        flash("Parse requested for %s" % form.url_to_search)
        url_search = form.url_to_search._value()
        get_match = parser.spider(url_search)
        match = models.Match(url=get_match.match_url, date_play = datetime.datetime.now())
        db.session.add(match)
        for get_build in get_match.match_data:
            build = models.Build(champ_name = get_build.champName, match = match)
            db.session.add(build)
            for get_step in get_build.stepList:
                step = models.Step(time = get_step.time, build = build)
                db.session.add(step)
                for get_item in get_step.items:
                    item = models.Item(item = get_item.item_number, is_sold=get_item.is_sold, step=step)
                    db.session.add(item)
        db.session.commit()
        return redirect('/index')
    matches = models.Match.query.all()
    return render_template("index.html",
                           title='Home',
                           matches=matches,
                           form = form)
예제 #6
0
 def scheduleMatch(self, opponent, date, time):
     temp = models.Match(opponent=opponent,date=date,time=time)
     db.session.add(temp)
     db.session.commit()