Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
Merge fafef77 into c28852c
Browse files Browse the repository at this point in the history
  • Loading branch information
jaebradley committed May 23, 2016
2 parents c28852c + fafef77 commit dbc9a0b
Show file tree
Hide file tree
Showing 7 changed files with 1,935 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/data/models/GameBoxScoreLeaders.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use es6';

import {Record} from 'immutable';
import TeamBoxScoreLeaders from './TeamBoxScoreLeaders';

const defaults = {
home : new TeamBoxScoreLeaders(),
home: new TeamBoxScoreLeaders(),
visitor: new TeamBoxScoreLeaders(),
};

Expand Down
4 changes: 3 additions & 1 deletion src/data/models/TeamBoxScoreLeaders.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use es6';

import {Record} from 'immutable';
import StatisticalLeaders from './StatisticalLeaders';

Expand All @@ -7,5 +9,5 @@ const defaults = {
rebounds: new StatisticalLeaders(),
};

export default class BoxScoreLeaders extends Record(defaults) {
export default class TeamBoxScoreLeaders extends Record(defaults) {
};
47 changes: 39 additions & 8 deletions src/translators/data/BoxScoreDataTranslator.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use es6';

import GameBoxScoreLeaders from '../../data/models/GameBoxScoreLeaders';
import TeamBoxScoreLeaders from '../../data/models/TeamBoxScoreLeaders';
import StatisticalLeaders from '../../data/models/StatisticalLeaders';
Expand All @@ -7,25 +9,54 @@ import Player from '../../data/models/Player';
export default class BoxScoreDataTranslator {
static translateStatLeaders(leaderData) {
const leaders = leaderData.leader.map(leader => new Player({firstName: leader.FirstName, lastName: leader.LastName}));
return new StatisticalLeaders({value: leaderData.StatValue, leaders: leaders});
return new StatisticalLeaders({value: parseInt(leaderData.StatValue), leaders: leaders});
}

static translateBoxScoreData(data) {
const visitorLeaders = data.sports_content.game.visitor.Leaders;
const homeLeaders = data.sports_content.game.home.Leaders;

let visitorPointsLeaders = new StatisticalLeaders();
if (visitorLeaders.hasOwnProperty('Points')) {
visitorPointsLeaders = BoxScoreDataTranslator.translateStatLeaders(visitorLeaders.Points);
}

let visitorAssistsLeaders = new StatisticalLeaders();
if (visitorLeaders.hasOwnProperty('Assists')) {
visitorAssistsLeaders = BoxScoreDataTranslator.translateStatLeaders(visitorLeaders.Assists);
}

let visitorReboundsLeaders = new StatisticalLeaders();
if (visitorLeaders.hasOwnProperty('Rebounds')) {
visitorReboundsLeaders = BoxScoreDataTranslator.translateStatLeaders(visitorLeaders.Rebounds);
}

let homePointsLeaders = new StatisticalLeaders();
if (homeLeaders.hasOwnProperty('Points')) {
homePointsLeaders = BoxScoreDataTranslator.translateStatLeaders(homeLeaders.Points);
}

let homeAssistsLeaders = new StatisticalLeaders();
if (homeLeaders.hasOwnProperty('Assists')) {
homeAssistsLeaders = BoxScoreDataTranslator.translateStatLeaders(homeLeaders.Assists);
}

let homeReboundsLeaders = new StatisticalLeaders();
if (homeLeaders.hasOwnProperty('Rebounds')) {
homeReboundsLeaders = BoxScoreDataTranslator.translateStatLeaders(homeLeaders.Rebounds);
}

const visitorBoxScoreLeaders = new TeamBoxScoreLeaders({
points: BoxScoreDataTranslator.translateStatLeaders(visitorLeaders.Points),
assists: BoxScoreDataTranslator.translateStatLeaders(visitorLeaders.Assists),
rebounds: BoxScoreDataTranslator.translateStatLeaders(visitorLeaders.Rebounds),
points: visitorPointsLeaders,
assists: visitorAssistsLeaders,
rebounds: visitorReboundsLeaders,
});

const homeBoxScoreLeaders = new TeamBoxScoreLeaders({
points: BoxScoreDataTranslator.translateStatLeaders(homeLeaders.Points),
assists: BoxScoreDataTranslator.translateStatLeaders(homeLeaders.Assists),
rebounds: BoxScoreDataTranslator.translateStatLeaders(homeLeaders.Rebounds),
points: homePointsLeaders,
assists: homeAssistsLeaders,
rebounds: homeReboundsLeaders,
});

return new GameBoxScoreLeaders({home: homeBoxScoreLeaders, visitor: visitorBoxScoreLeaders});
}
}
91 changes: 91 additions & 0 deletions test/BoxScoreDataTranslator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
'use es6';

import {expect, assert} from 'chai';
import BoxScoreDataTranslator from '../src/translators/data/BoxScoreDataTranslator';
import GameBoxScoreLeaders from '../src/data/models/GameBoxScoreLeaders';
import TeamBoxScoreLeaders from '../src/data/models/TeamBoxScoreLeaders';
import StatisticalLeaders from '../src/data/models/StatisticalLeaders';
import Player from '../src/data/models/Player';

import finalBoxScore from './data/boxscore/final.json';
import firstQuarterBoxScore from './data/boxscore/first-quarter.json';
import pregameBoxScore from './data/boxscore/pregame.json';

describe('Box score data translator', function() {
it('translate pregame box score data', function() {
assert.isOk(BoxScoreDataTranslator.translateBoxScoreData(pregameBoxScore).equals(new GameBoxScoreLeaders()), 'pregame box score and empty game box score leaders are equal');
});

it('translate first quarter box score data', function() {
const visitorPointsLeaders = new StatisticalLeaders({
value: 2,
leaders: [
new Player({firstName: 'Kevin', lastName: 'Durant'}),
new Player({firstName: 'Serge', lastName: 'Ibaka'}),
new Player({firstName: 'Andre', lastName: 'Roberson'}),
new Player({firstName: 'Steven', lastName: 'Adams'}),
]
});
const visitorAssistsLeaders = new StatisticalLeaders({
value: 2,
leaders: [new Player({firstName: 'Russell', lastName: 'Westbrook'})]
});
const visitorReboundsLeaders = new StatisticalLeaders({
value: 2,
leaders: [new Player({firstName: 'Steven', lastName: 'Adams'})]
})
const visitorBoxScoreLeaders = new TeamBoxScoreLeaders({
points: visitorPointsLeaders,
assists: visitorAssistsLeaders,
rebounds: visitorReboundsLeaders,
});

const homePointsLeaders = new StatisticalLeaders({
value: 4,
leaders: [new Player({firstName: 'Klay', lastName: 'Thompson'})]
});
const homeAssistsLeaders = new StatisticalLeaders({
value: 1,
leaders: [
new Player({firstName: 'Andrew', lastName: 'Bogut'}),
new Player({firstName: 'Stephen', lastName: 'Curry'}),
new Player({firstName: 'Draymond', lastName: 'Green'}),
]
});
const homeReboundsLeaders = new StatisticalLeaders({
value: 1,
leaders: [new Player({firstName: 'Draymond', lastName: 'Green'})]
})
const homeBoxScoreLeaders = new TeamBoxScoreLeaders({
points: homePointsLeaders,
assists: homeAssistsLeaders,
rebounds: homeReboundsLeaders,
});

const expected = new GameBoxScoreLeaders({home: homeBoxScoreLeaders, visitor: visitorBoxScoreLeaders});
expect(BoxScoreDataTranslator.translateBoxScoreData(firstQuarterBoxScore)).to.eql(expected);
});

it('translate first quarter stat leader', function() {
const visitorPointsLeaders = firstQuarterBoxScore.sports_content.game.visitor.Leaders.Points;
const visitorAssistsLeaders = firstQuarterBoxScore.sports_content.game.visitor.Leaders.Assists;

const expectedPoints = new StatisticalLeaders({
value: 2,
leaders: [
new Player({firstName: 'Kevin', lastName: 'Durant'}),
new Player({firstName: 'Serge', lastName: 'Ibaka'}),
new Player({firstName: 'Andre', lastName: 'Roberson'}),
new Player({firstName: 'Steven', lastName: 'Adams'}),
]
});

const expectedAssists = new StatisticalLeaders({
value: 2,
leaders: [new Player({firstName: 'Russell', lastName: 'Westbrook'})]
});

expect(BoxScoreDataTranslator.translateStatLeaders(visitorPointsLeaders)).to.eql(expectedPoints);
expect(BoxScoreDataTranslator.translateStatLeaders(visitorAssistsLeaders)).to.eql(expectedAssists);
});
});
Loading

0 comments on commit dbc9a0b

Please sign in to comment.