Skip to content

Commit

Permalink
[6.6.0] Improvements for historic seasons
Browse files Browse the repository at this point in the history
  • Loading branch information
tdittmann committed Sep 7, 2024
1 parent 9aa2ed8 commit edbb660
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 13 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "de.timodittmann.scd"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 652000
versionName "6.5.2"
versionCode 660000
versionName "6.6.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="de.timodittmann.scd" version="6.5.2" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget id="de.timodittmann.scd" version="6.6.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>SC Dahenfeld</name>
<description>An awesome SC Dahenfeld app.</description>
<author email="info@timo-dittmann.de" href="http://timo-dittmann.de/">Timo Dittmann</author>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sc-dahenfeld",
"version": "6.5.2",
"version": "6.6.0",
"author": "Timo Dittmann",
"homepage": "http://timo-dittmann.de/",
"scripts": {
Expand Down
8 changes: 8 additions & 0 deletions requests.http
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@ Authorization: Basic {{authUsername}} {{authPassword}}

### GET Persons by project ID
GET https://sc-dahenfeld.de/components/com_tdwapp/v9/persons?teamId=200
Authorization: Basic {{authUsername}} {{authPassword}}

### GET Team Informations by project ID
GET https://sc-dahenfeld.de/components/com_tdwapp/v9/teamInformation?id=191
Authorization: Basic {{authUsername}} {{authPassword}}

### GET Historic Ranking by project ID
GET https://sc-dahenfeld.de/components/com_tdwapp/v9/historicRanking?projectId=191
Authorization: Basic {{authUsername}} {{authPassword}}
2 changes: 1 addition & 1 deletion src/app/dataproviders/soccer/matches/match.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ export class MatchService {
return this.httpService
.get<MatchJson[]>(environment.backendUrl + 'matches?teamId=' + teamId + '&teamOnly=' + teamOnly)
.pipe(map((pMatch) => pMatch.map(this.matchMapper.mapFrom)))
.pipe(tap((pMatch) => [...pMatch].sort((a, b) => a.compareTo(b))));
.pipe(map((pMatch) => [...pMatch].sort((a, b) => a.compareTo(b))));
}
}
4 changes: 2 additions & 2 deletions src/app/dataproviders/soccer/person/person.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ export class PersonService {
return this.httpService
.get<PersonJson[]>(environment.backendUrl + 'persons')
.pipe(map((players) => players.map((value) => this.playerMapper.mapFrom(value))))
.pipe(tap((players) => players.sort((a, b) => a.compareTo(b))));
.pipe(map((players) => [...players].sort((a, b) => a.compareTo(b))));
}

loadPersonsByProjectId(projectId: number): Observable<Person[]> {
return this.httpService
.get<PersonJson[]>(environment.backendUrl + 'persons?teamId=' + projectId)
.pipe(map((players) => players.map((value) => this.playerMapper.mapFrom(value))))
.pipe(tap((players) => players.sort((a, b) => a.compareTo(b))));
.pipe(map((players) => [...players].sort((a, b) => a.compareTo(b))));
}

loadPerson(personId: number, projectId: number): Observable<Person> {
Expand Down
12 changes: 12 additions & 0 deletions src/app/dataproviders/soccer/ranking/historicRankingJson.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export interface HistoricRankingJson {
id: string;
name: string;
logo: string;
matches: string;
won: string;
draw: string;
lost: string;
goalsFor: string;
goalsAgainst: string;
points: string;
}
44 changes: 44 additions & 0 deletions src/app/dataproviders/soccer/ranking/historicRankingMapper.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { HistoricRankingMapper } from './historicRankingMapper';
import { HistoricRankingJson } from './historicRankingJson.model';
import { RankingTeam } from '../../../core/domain/rankingTeam.model';

describe('Mapper', () => {
let mapper: HistoricRankingMapper;

beforeEach(() => {
mapper = new HistoricRankingMapper();
});

it('should handle null values for mapFrom', () => {
expect(mapper.mapFrom(null)).toBe(null);
});

it('should map from json to core model', () => {
const actual: HistoricRankingJson = {
id: '1',
name: 'SC Dahenfeld',
logo: '/images/scd.png',
matches: '30',
won: '29',
draw: '1',
lost: '0',
goalsFor: '100',
goalsAgainst: '12',
points: '90',
};

const expected: RankingTeam = new RankingTeam();
expected.id = 1;
expected.name = 'SC Dahenfeld';
expected.image = '/images/scd.png';
expected.matches = 30;
expected.wins = 29;
expected.draws = 1;
expected.losses = 0;
expected.goalsFor = 100;
expected.goalsAgainst = 12;
expected.points = 90;

expect(mapper.mapFrom(actual)).toEqual(expected);
});
});
23 changes: 23 additions & 0 deletions src/app/dataproviders/soccer/ranking/historicRankingMapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { HistoricRankingJson } from './historicRankingJson.model';
import { RankingTeam } from '../../../core/domain/rankingTeam.model';

export class HistoricRankingMapper {
mapFrom(param: HistoricRankingJson): RankingTeam {
if (!param) {
return null;
}

const rankingTeam = new RankingTeam();
rankingTeam.id = parseInt(param.id, 10);
rankingTeam.name = param.name;
rankingTeam.image = param.logo;
rankingTeam.matches = parseInt(param.matches, 10);
rankingTeam.wins = parseInt(param.won, 10);
rankingTeam.draws = parseInt(param.draw, 10);
rankingTeam.losses = parseInt(param.lost, 10);
rankingTeam.goalsFor = parseInt(param.goalsFor, 10);
rankingTeam.goalsAgainst = parseInt(param.goalsAgainst, 10);
rankingTeam.points = parseInt(param.points, 10);
return rankingTeam;
}
}
21 changes: 21 additions & 0 deletions src/app/dataproviders/soccer/ranking/ranking.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Observable } from 'rxjs';
import { environment } from '../../../../environments/environment';
import { map, tap } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { HttpService } from '../../http.service';
import { HistoricRankingMapper } from './historicRankingMapper';
import { RankingTeam } from '../../../core/domain/rankingTeam.model';
import { HistoricRankingJson } from './historicRankingJson.model';

@Injectable()
export class RankingService {
private historicRankingMapper = new HistoricRankingMapper();

constructor(private httpService: HttpService) {}

public loadHistoricRanking(projectId: number): Observable<RankingTeam[]> {
return this.httpService
.get<HistoricRankingJson[]>(environment.backendUrl + 'historicRanking?projectId=' + projectId)
.pipe(map((ranking) => ranking.map(this.historicRankingMapper.mapFrom)));
}
}
2 changes: 1 addition & 1 deletion src/app/presentation/pages/imprint/imprint.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { App } from '@capacitor/app';
})
export class ImprintPage implements OnInit {
heading: string;
version = '6.5.2';
version = '6.6.0';
developer = 'Timo Dittmann';
darkMode = false;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<app-page-state [loading]="isLoading" [error]="isError"></app-page-state>

<div class="container ion-padding" *ngIf="ranking.length > 0">
<ion-segment (ionChange)="recalculateRanking($event)" value="total" mode="ios">
<ion-segment
*ngIf="!isHistoricRanking"
(ionChange)="recalculateRanking($event)"
value="total"
mode="ios"
>
<ng-template ngFor let-rankingType [ngForOf]="rankingTypes">
<ion-segment-button [value]="rankingType.value">
<ion-label>{{ rankingType.label }}</ion-label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MatchService } from '../../../../dataproviders/soccer/matches/match.ser
import { Match } from '../../../../core/domain/match.model';
import { RankingTeam } from '../../../../core/domain/rankingTeam.model';
import { RankingUtil } from '../../../../util/RankingUtil';
import { RankingService } from '../../../../dataproviders/soccer/ranking/ranking.service';

@Component({
selector: 'app-team-detail-ranking',
Expand All @@ -20,20 +21,37 @@ export class TeamDetailRankingComponent implements OnInit {

matches: Match[] = [];
ranking: RankingTeam[] = [];
isHistoricRanking = false;

isLoading = true;
isError = false;

constructor(private fixtureService: MatchService) {}
constructor(
private matchService: MatchService,
private rankingService: RankingService,
) {}

ngOnInit(): void {
if (this.projectId > 0) {
this.fixtureService.loadAllMatchesByTeamId(this.projectId).subscribe({
this.matchService.loadAllMatchesByTeamId(this.projectId).subscribe({
next: (matches) => {
this.matches = matches;

this.ranking = RankingUtil.calculateRanking(matches, null);

// For historic rankings we don't have matches and need to load the ranking separately.
if (matches.length === 0) {
this.isHistoricRanking = true;
this.rankingService.loadHistoricRanking(this.projectId).subscribe({
next: (ranking) => {
this.ranking = RankingUtil.calculateHistoricRanking(ranking);
},
error: (error) => {
this.isError = true;
console.error(error);
},
});
}

this.isLoading = false;
},
error: (error) => {
Expand Down
3 changes: 2 additions & 1 deletion src/app/presentation/pages/team-detail/team-detail.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import { FormsModule } from '@angular/forms';
import { TeamDetailStatisticsModalComponent } from './statistics/statistics-modal/team-detail-statistics-modal.component';
import { PersonFilter } from './statistics/statistics-modal/person.filter';
import { DynamicContentModule } from '../../shared/dynamic-content/dynamic-content.module';
import { RankingService } from '../../../dataproviders/soccer/ranking/ranking.service';

@NgModule({
providers: [TeamInformationService, ArticleService, MatchService, PersonService],
providers: [TeamInformationService, ArticleService, MatchService, PersonService, RankingService],
imports: [
CommonModule,
FormsModule,
Expand Down
7 changes: 7 additions & 0 deletions src/app/util/RankingUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export class RankingUtil {
return ranking;
}

static calculateHistoricRanking(ranking: RankingTeam[]) {
const finalRanking = [...ranking];
finalRanking.sort((a, b) => a.compareTo(b));
finalRanking.forEach((value, index) => (value.place = index + 1));
return finalRanking;
}

private static handleMatch(
ranking: RankingTeam[],
teamId: number,
Expand Down

0 comments on commit edbb660

Please sign in to comment.