Skip to content

Commit

Permalink
feat(stats): repeat the last stat on gametime
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveVanOpstal committed Nov 1, 2016
1 parent 7c096d9 commit df042fa
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 38 deletions.
73 changes: 39 additions & 34 deletions src/client/services/stats.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ describe('StatsService', () => {
};

let championStatsResults = {
'Attack Range': [{time: 0, value: 125}],
'Attack Range': [{time: 0, value: 125}, {time: 3600000, value: 125}],
'Attack Damage': [
{time: 0, value: 64.73}, {time: 59294, value: 68.35}, {time: 139765, value: 71.97},
{time: 241412, value: 75.59}, {time: 364235, value: 79.21}, {time: 508235, value: 82.83},
{time: 673412, value: 86.45}, {time: 859765, value: 90.07}, {time: 1067294, value: 93.69},
{time: 1296000, value: 97.31}, {time: 1545882, value: 100.93}, {time: 1816941, value: 104.55},
{time: 2109176, value: 108.17}, {time: 2422588, value: 111.79},
{time: 2757176, value: 115.41}, {time: 3112941, value: 119.03},
{time: 3489882, value: 122.65}, {time: 3888000, value: 126.27}
{time: 3489882, value: 122.65}, {time: 3888000, value: 126.27},
{time: 3600000, value: 126.27}
],
'armor': [{time: 0, value: 24.38}]
'armor': [{time: 0, value: 24.38}, {time: 3600000, value: 24.38}]
};

let items: Array<Item> = [
Expand All @@ -55,19 +56,23 @@ describe('StatsService', () => {

let itemStatsResults = {
'MP': [
{time: 0, value: 4.17}, {time: 10, value: 254.17}, {time: 59294, value: 258.33},
{time: 139765, value: 262.5}, {time: 241412, value: 266.67}, {time: 364235, value: 270.83},
{time: 508235, value: 275}, {time: 673412, value: 279.17}, {time: 859765, value: 283.33},
{time: 1067294, value: 287.5}, {time: 1296000, value: 350}, {time: 1545882, value: 355},
{time: 1816941, value: 360}, {time: 2109176, value: 365}, {time: 2422588, value: 370},
{time: 2757176, value: 375}, {time: 3112941, value: 380}, {time: 3489882, value: 385},
{time: 3888000, value: 390}
{time: 0, value: 4.17}, {time: 10, value: 254.17}, {time: 59294, value: 258.33},
{time: 139765, value: 262.5}, {time: 241412, value: 266.67}, {time: 364235, value: 270.83},
{time: 508235, value: 275}, {time: 673412, value: 279.17}, {time: 859765, value: 283.33},
{time: 1067294, value: 287.5}, {time: 1296000, value: 350}, {time: 1545882, value: 355},
{time: 1816941, value: 360}, {time: 2109176, value: 365}, {time: 2422588, value: 370},
{time: 2757176, value: 375}, {time: 3112941, value: 380}, {time: 3489882, value: 385},
{time: 3888000, value: 390}, {time: 3600000, value: 390}
],
'Magic Damage': [
{time: 0, value: 0}, {time: 10, value: 15}, {time: 1296000, value: 20},
{time: 3600000, value: 20}
],
'Magic Damage': [{time: 0, value: 0}, {time: 10, value: 15}, {time: 1296000, value: 20}],
'Movement Speed': [
{time: 0, value: 0}, {time: 2420000, value: 101.52}, {time: 2422588, value: 101.73},
{time: 2750000, value: 203.47}, {time: 2757176, value: 203.9}, {time: 3112941, value: 204.33},
{time: 3489882, value: 204.77}, {time: 3888000, value: 205.2}
{time: 3489882, value: 204.77}, {time: 3888000, value: 205.2},
{time: 3600000, value: 205.2}
]
};

Expand All @@ -77,54 +82,54 @@ describe('StatsService', () => {
];

it('should process when samples are valid',
async(inject([StatsService, DataService], (service: StatsService, build: DataService) => {
spyOn(build.stats, 'notify');
build.samples.notify(samples);
expect(build.stats.notify).toHaveBeenCalled();
async(inject([StatsService, DataService], (service: StatsService, data: DataService) => {
spyOn(data.stats, 'notify');
data.samples.notify(samples);
expect(data.stats.notify).toHaveBeenCalled();
expect(service.levelTimeMarks).toHaveEqualContent(levelTimeMarks);
})));

it('should not process when samples are invalid',
async(inject([StatsService, DataService], (service: StatsService, build: DataService) => {
spyOn(build.stats, 'notify');
build.samples.notify({xp: [], gold: []});
expect(build.stats.notify).not.toHaveBeenCalled();
async(inject([StatsService, DataService], (service: StatsService, data: DataService) => {
spyOn(data.stats, 'notify');
data.samples.notify({xp: [], gold: []});
expect(data.stats.notify).not.toHaveBeenCalled();
expect(service.levelTimeMarks).not.toBeDefined();
})));

it('should not process when there are no samples',
async(inject([StatsService, DataService], (service: StatsService, build: DataService) => {
build.pickedItems.notify(undefined);
build.stats.subscribe((stats) => {
async(inject([StatsService, DataService], (service: StatsService, data: DataService) => {
data.pickedItems.notify(undefined);
data.stats.subscribe((stats) => {
fail('unexpected success');
});
})));

it('should not calculate when there are no stats',
async(inject([StatsService, DataService], (service: StatsService, build: DataService) => {
build.samples.notify(samples);
build.pickedItems.notify(undefined);
build.stats.subscribe((stats) => {
async(inject([StatsService, DataService], (service: StatsService, data: DataService) => {
data.samples.notify(samples);
data.pickedItems.notify(undefined);
data.stats.subscribe((stats) => {
expect(stats).toHaveEqualContent({});
});
})));

it('should process champion stats',
async(inject(
[MockBackend, StatsService, DataService],
(backend: MockMockBackend, service: StatsService, build: DataService) => {
build.samples.notify(samples);
(backend: MockMockBackend, service: StatsService, data: DataService) => {
data.samples.notify(samples);
backend.success(champion);
build.stats.subscribe((stats) => {
data.stats.subscribe((stats) => {
expect(stats).toHaveEqualContent(championStatsResults);
});
})));

it('should process item stats',
async(inject([StatsService, DataService], (service: StatsService, build: DataService) => {
build.samples.notify(samples);
build.pickedItems.notify(items);
build.stats.subscribe((stats) => {
async(inject([StatsService, DataService], (service: StatsService, data: DataService) => {
data.samples.notify(samples);
data.pickedItems.notify(items);
data.stats.subscribe((stats) => {
expect(stats).toHaveEqualContent(itemStatsResults);
});
})));
Expand Down
10 changes: 6 additions & 4 deletions src/client/services/stats.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ export class StatsService {
private items: Array<Item>;
private champion: any;

constructor(private router: Router, private build: DataService, private lolApi: LolApiService) {
build.pickedItems.subscribe(items => {
constructor(private router: Router, private data: DataService, private lolApi: LolApiService) {
data.pickedItems.subscribe(items => {
this.items = items;
this.process();
});
build.samples.subscribe(samples => {
data.samples.subscribe(samples => {
let lastXpMark = samples.xp[samples.xp.length - 1];
if (!lastXpMark) {
return;
Expand Down Expand Up @@ -84,7 +84,7 @@ export class StatsService {
let stats = this.calculate();

stats = this.makeIterable(stats);
this.build.stats.notify(stats);
this.data.stats.notify(stats);
}

private translateItemStats() {
Expand Down Expand Up @@ -247,6 +247,8 @@ export class StatsService {
arr.sort((a, b) => {
return a.time > b.time ? 1 : -1;
});
var last = arr[arr.length - 1];
arr.push({time: settings.gameTime, value: last.value});
result[name] = arr;
}
return result;
Expand Down

0 comments on commit df042fa

Please sign in to comment.