Exemplo n.º 1
0
def ParseError(msg, request, status=400):
    caltitle    = request.POST.get("title", '')
    callocation = request.POST.get("location", '')
    shiftinput  = request.POST.get("roster", None)

    if not caltitle:
        caltitle = request.GET.get("title", '')
    if not callocation:
        callocation = request.GET.get("location", '')

    dbroster = Roster(
        event_title=caltitle,
        event_location=callocation,
        raw_roster=shiftinput,
        method='site',
        created=dtnow(),
        success=False,
        error=msg
    )

    if request.POST.get('bm', False):
        dbroster.method = 'bookmarklet'
        dbroster.version = request.POST.get('v', '_none_')

    dbroster.save()

    return JSONError(msg, status)
Exemplo n.º 2
0
def parse(request):
    if not request.POST:
        return JSONError('Method must be POST')

    bookmarklet = request.POST.get('bm', False)

    raw = request.POST.get('roster', False)
    if not raw:
        return ParseError('Roster not specified', request)

    title = request.POST.get("title", "")
    location = request.POST.get("location", "")

    sat_regex_str = r'(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s{1,5}(\d{2}),?\s{1,5}(2\d{3})'
    matched_sat = re.findall(sat_regex_str, raw)

    if len(matched_sat) != 1:
        return ParseError('Could not determine dates for the roster. Make sure you copy from "Schedule begins" onwards', request)

    try:
        sat, roster, hours = parse_roster(raw)
        hours = hours.seconds / 60.0 / 60.0
        dump = {'sat': sat, 'roster': roster}
    except Exception:
        return ParseError('Unexpected error interpreting the roster.', request)

    if len(roster) < 1:
        return ParseError('Found no shifts.', request)

    accesstoken = makeAccessCode(10)
    method = 'bookmarklet' if bookmarklet else 'site'

    dbroster = Roster(
        token=accesstoken,
        event_title=limit(title, 100),
        event_location=limit(location, 100),
        method=method,
        created=dtnow(),
        success=True,
        dump=pickle.dumps(dump),
    )
    dbroster.save()

    json_response = {
        "status": "success",
        "hours": hours,
        "accesstoken": accesstoken,
        "bookmarklet": bookmarklet,
    }
    return HttpResponse(json.dumps(json_response), content_type='application/json; charset=utf8')
Exemplo n.º 3
0
def process_roster(data, match_id, team_id=None, guild_id=None):
    test = db.session.query(Roster).get(data['id'])
    if not test:
        r = Roster(id=data['id'], match_id=match_id,
                   acesEarned=data['attributes']['stats']['acesEarned'],
                   gold=data['attributes']['stats']['gold'],
                   heroKills=data['attributes']['stats']['heroKills'],
                   krakenCaptures=data['attributes']['stats']['krakenCaptures'],
                   side=data['attributes']['stats']['side'],
                   turrentKills=data['attributes']['stats']['turretKills'],
                   turrentsRemaining=data['attributes']['stats']['turretsRemaining'],
                   team_api=data['relationships']['team']['data'])
        if team_id:
            r.team_id = team_id
        if guild_id:
            r.guild_id = guild_id

        db.session.add(r)

        try:
            db.session.commit()
        except SQLAlchemyError as e:
            db.session.rollback()
            app.logger.error('ERROR: Session rollback - reason "%s"' % str(e))
Exemplo n.º 4
0
def main_form():

    if request.form:
        # print(request.form)
        # print(request.form['name'])

        # add new record
        new_data = Roster(
            name=request.form['name'], 
            age=request.form['age']) 
            # joined=request.form['joined'])

        db.session.add(new_data)
        db.session.commit()

        flash('New data was successfully added!')
        return redirect(url_for('index'))

    return render_template("form.html")    
Exemplo n.º 5
0
        except Exception, e:
            print 'No previous team stats', e

        if not teams:
            teams = Team.objects.filter(universe=universe)
            shuffle(list(teams))
        draft_preference = {}
        nbr_positions = 0 
        for team in teams:
            try:
                r = Roster.objects.get(universe=universe,
                                     year=current_year,
                                     team=team)
            except:
                r = Roster(universe=universe,
                                     year=current_year,
                                     team=team)
                r.save()
            draft_preference[team] = deepcopy(json.loads(team.draft_position_order))
            draft_preference[team] = determine_draft_needs(draft_preference[team], r)
            if nbr_positions < len(draft_preference[team]):
                    nbr_positions=len(draft_preference[team])
        draft_order=[]
        for i in xrange(nbr_positions):
            for team in teams:
                    try:
                            draft_order.append((team, draft_preference[team][i]))
                    except:
                            pass
        for pick_team, pick_position in draft_order:
            players = Player.objects.filter(universe=universe,
Exemplo n.º 6
0
def transform(data):
    response = []
    matches = data['data']
    for match in matches:
        telemetry_id = match['relationships']['assets']['data'][0]['id']
        telemetry_data = [
            i for i in data['included'] if i['id'] == telemetry_id
        ][0]
        processed_telemetry_data = TelemetryData(
            telemetry_id=telemetry_data['id'],
            name=telemetry_data['attributes']['name'],
            url=telemetry_data['attributes']['URL'],
            createdAt=datetime.datetime.strptime(
                telemetry_data['attributes']['createdAt'],
                '%Y-%m-%dT%H:%M:%SZ'))
        logging.error(telemetry_data)

        # TODO use api
        events = requests.get(processed_telemetry_data.url).json()
        processed_telemetry = transform_telemetry(events)
        # logging.error(processed_telemetry)

        processed_match = Match(
            match_id=match['id'],
            createdAt=datetime.datetime.strptime(
                match['attributes']['createdAt'], '%Y-%m-%dT%H:%M:%SZ'),
            duration=match['attributes']['duration'],
            gameMode=match['attributes']['gameMode'],
            shardId=match['attributes']['shardId'],
            patchVersion=match['attributes']['patchVersion'],
            endGameReason=match['attributes']['stats']['endGameReason'],
            queue=match['attributes']['stats']['queue'],
            rosters=[],
            telemetry_data=processed_telemetry_data,
            telemetry=processed_telemetry)

        rosters = []
        for roster in match['relationships']['rosters']['data']:
            roster_data = [
                i for i in data['included'] if i['id'] == roster['id']
            ][0]
            processed_roster = Roster(
                roster_id=roster_data['id'],
                aces_earned=roster_data['attributes']['stats']['acesEarned'],
                gold=roster_data['attributes']['stats']['gold'],
                heroKills=roster_data['attributes']['stats']['heroKills'],
                krakenCaptures=roster_data['attributes']['stats']
                ['krakenCaptures'],
                side=roster_data['attributes']['stats']['side'],
                turretKills=roster_data['attributes']['stats']['turretKills'],
                turretsRemaining=roster_data['attributes']['stats']
                ['turretsRemaining'],
                participants=[])

            participants = []
            for participant in roster_data['relationships']['participants'][
                    'data']:
                participant_data = [
                    i for i in data['included'] if i['id'] == participant['id']
                ][0]
                player_data = [
                    i for i in data['included'] if i['id'] ==
                    participant_data['relationships']['player']['data']['id']
                ][0]
                processed_player = transform_player(player_data)

                processed_participant = Participant(
                    participant_id=participant_data['id'],
                    player=processed_player,
                    actor=participant_data['attributes']['actor'],
                    kills=participant_data['attributes']['stats']['kills'],
                    assists=participant_data['attributes']['stats']['assists'],
                    deaths=participant_data['attributes']['stats']['deaths'],
                    crystalMineCaptures=participant_data['attributes']['stats']
                    ['crystalMineCaptures'],
                    goldMindCaptures=participant_data['attributes']['stats']
                    ['crystalMineCaptures'],
                    krakenCaptures=participant_data['attributes']['stats']
                    ['krakenCaptures'],
                    turretCaptures=participant_data['attributes']['stats']
                    ['turretCaptures'],
                    winner=participant_data['attributes']['stats']['winner'],
                    farm=participant_data['attributes']['stats']['farm'],
                    minionKills=participant_data['attributes']['stats']
                    ['minionKills'],
                    nonJungleMinionKills=participant_data['attributes']
                    ['stats']['nonJungleMinionKills'],
                    jungleKills=participant_data['attributes']['stats']
                    ['jungleKills'],
                    firstAfkTime=participant_data['attributes']['stats']
                    ['firstAfkTime'],
                    wentAfk=participant_data['attributes']['stats']['wentAfk'],
                    skinKey=participant_data['attributes']['stats']['skinKey'],
                    karmaLevel=participant_data['attributes']['stats']
                    ['karmaLevel'],
                    level=participant_data['attributes']['stats']['level'],
                    skillTier=participant_data['attributes']['stats']
                    ['skillTier'],
                    itemGrants=[
                        Item(name=i, uses=j)
                        for i, j in participant_data['attributes']['stats']
                        ['itemGrants'].items()
                    ],
                    itemSells=[
                        Item(name=i, uses=j)
                        for i, j in participant_data['attributes']['stats']
                        ['itemSells'].items()
                    ],
                    itemUses=[
                        Item(name=i, uses=j)
                        for i, j in participant_data['attributes']['stats']
                        ['itemUses'].items()
                    ],
                    items=[
                        Item(name=i) for i in participant_data['attributes']
                        ['stats']['items']
                    ],
                )
                participants.append(processed_participant)

            processed_roster.participants = participants
            rosters.append(processed_roster)

        processed_match.rosters = rosters
        response.append(processed_match)
    return response