Skip to content

Commit

Permalink
Merge pull request #96 from SwimResults/develop
Browse files Browse the repository at this point in the history
`v1.0.8` live status bar; fin swimming support; livetiming fixes
  • Loading branch information
konrad2002 authored Jun 7, 2024
2 parents 8f1fdc9 + debaa87 commit 2882ae6
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ export class LivetimingComponent implements OnInit, OnDestroy {
}

if (this.liveSettingsData.isLive) { // in live mode, set to finished when finished_at is set
console.log(st[0].heat.getFinishedAt())
this.heatFinished = (st.length > 0 && st[0].heat.getFinishedAtTime() != "0:00");
console.log(st[0].heat.getFinishedAt().getMilliseconds())
this.heatFinished = (st.length > 0 && st[0].heat.getFinishedAt().getMilliseconds() > 0);
}

if (this.liveSettingsData.isLive) {
Expand Down
6 changes: 6 additions & 0 deletions src/app/core/model/start/current-next-heat.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {Heat} from "./heat.model";

export interface CurrentNextHeat {
current?: Heat;
next?: Heat;
}
5 changes: 5 additions & 0 deletions src/app/core/service/api/start/heat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Heat} from "../../../model/start/heat.model";
import {ApiService} from "../api.service";
import {EventHeatInfo} from "../../../model/start/event-heat-info.model";
import {EventListHeats} from "../../../model/start/event-list-heats.model";
import {CurrentNextHeat} from "../../../model/start/current-next-heat.model";

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -34,6 +35,10 @@ export class HeatService extends BaseService{
return this.apiService.get(this.API_URL, "heat/meet/" + meeting + "/current");
}

getCurrentAndNextHeat(meeting: string): Observable<CurrentNextHeat> {
return this.apiService.get(this.API_URL, "heat/meet/" + meeting + "/current_next");
}

getHeatsByMeetingForEventList(meeting: string): Observable<EventListHeats> {
return this.apiService.get(this.API_URL, "heat/meet/" + meeting + "/event_list");
}
Expand Down
23 changes: 15 additions & 8 deletions src/app/shared/layout/live-bar/live-bar.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<div class="live-bar" *ngIf="currentHeat && event" [routerLink]="'/m/' + meetingId + '/live'" [queryParams]="{live: '1'}">

<div class="live-bar" *ngIf="meetingId" [routerLink]="'/m/' + meetingId + '/live'" [queryParams]="{live: '1'}">

<div class="bar-live">
<div class="blink">
Expand All @@ -8,13 +7,21 @@
</div>
</div>

<sr-heat-times [heat]="currentHeat"></sr-heat-times>
<ng-container *ngIf="statusText">
<div class="bar-content">
<span class="bar-status-text">{{statusText}}</span>
</div>
</ng-container>

<sr-icon-panel [textContent]="event.number + ''"></sr-icon-panel>
<ng-container *ngIf="!statusText && currentHeat && event" >

<div class="bar-content">
<span class="bar-event">{{'COMMON.EVENT.SINGULAR' | translate}} {{event.number}} - {{event.relay_distance ? event.relay_distance : event.distance}}m {{'COMMON.STYLE.' + event.style.name + '.NAME' | translate}} {{event.name_extension}} {{'COMMON.GENDER.' + event.gender + '.NAME' | translate}}</span>
<span>{{'COMMON.HEAT.SINGULAR' | translate}} {{currentHeat.number}} / {{maxHeat}}</span>
</div>
<sr-heat-times [heat]="currentHeat"></sr-heat-times>

<sr-icon-panel [textContent]="event.number + ''"></sr-icon-panel>

<div class="bar-content">
<span class="bar-event">{{'COMMON.EVENT.SINGULAR' | translate}} {{event.number}} - {{event.relay_distance ? event.relay_distance : event.distance}}m {{'COMMON.STYLE.' + event.style.name + '.NAME' | translate}} {{event.name_extension}} {{'COMMON.GENDER.' + event.gender + '.NAME' | translate}}</span>
<span>{{'COMMON.HEAT.SINGULAR' | translate}} {{currentHeat.number}} / {{maxHeat}}</span>
</div>
</ng-container>
</div>
6 changes: 6 additions & 0 deletions src/app/shared/layout/live-bar/live-bar.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

.bar-content {
width: calc(100% - 116px);

.bar-status-text {
font-weight: bold;
display: block;
text-align: center;
}
}

.bar-content,
Expand Down
77 changes: 73 additions & 4 deletions src/app/shared/layout/live-bar/live-bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ export class LiveBarComponent implements OnInit, OnDestroy {
liveUpdateInterval: number = 15000;

currentHeat?: HeatImpl
nextHeat?: HeatImpl
maxHeat: number = 1;
event?: MeetingEventImpl;

statusText?: string;

private interval: any;

constructor(
Expand All @@ -36,10 +39,13 @@ export class LiveBarComponent implements OnInit, OnDestroy {

fetchCurrentHeat() {
if (!this.meetingId) return;
this.heatService.getCurrentHeat(this.meetingId).subscribe(data => {
this.currentHeat = new HeatImpl(data);
this.heatService.getCurrentAndNextHeat(this.meetingId).subscribe(data => {
if (data.current) this.currentHeat = new HeatImpl(data.current); else this.currentHeat = undefined;
if (data.next) this.nextHeat = new HeatImpl(data.next); else this.nextHeat = undefined;

this.updateStatusText();

if (this.meetingId) {
if (this.meetingId && this.currentHeat) {
this.heatService.getEventHeatInfo(this.meetingId, this.currentHeat.event).subscribe(data => {
if (data && data.amount)
this.maxHeat = data.amount
Expand All @@ -51,10 +57,73 @@ export class LiveBarComponent implements OnInit, OnDestroy {
});
}

updateStatusText() {
console.log("[LIVE BAR STATUS] refresh live bar status");

if (this.currentHeat) {
let now = new Date(); // to check, how long current heat is over
let finish = this.currentHeat.getFinishedAt(); // to check how long it is over and how much time until next
let current = this.currentHeat.getStartDelayEstimation(); // to compare dates of current and next


if (finish.getTime() > 1000) { // current heat is over
let d = now.getTime() - finish.getTime();

if (d > 1 * 60 * 1000) { // current heat is over for more than 1 minute

if (!this.nextHeat) { // no next heat
this.statusText = "Ende der Veranstaltung. Kommt gut nach Hause!";
} else {

let currentPlan = this.currentHeat.getEstimatedStart();
let nextPlan = this.nextHeat.getEstimatedStart();

let next = this.nextHeat.getStartDelayEstimation(); // to check, if next is today, and if it is a break
// TODO: do not check planned time, but finish and start time (has problems with testing the day before)

let d2 = next.getTime() - finish.getTime();

console.log("current heat is over for a while and next heat exists")

console.log(current);
console.log(finish);
console.log(next);
console.log("----");
console.log(currentPlan);
console.log(nextPlan);

// need to compare start dates, since estimations can be different when testing on another day
if (currentPlan.getDate() === nextPlan.getDate()) {
if (d2 > 60 * 60 * 1000) {
this.statusText = "Pause. Es geht weiter um " + this.nextHeat.getStartDelayEstimationTime() + " Uhr";
} else {
this.statusText = undefined;
}
} else {
this.statusText = "Bis Morgen. Erster Start um " + this.nextHeat.getStartDelayEstimationTime() + " Uhr";
}
}
} else {
this.statusText = undefined;
}

} else {
this.statusText = undefined;
}
} else {
if (this.nextHeat !== undefined) {
console.log("before meeting");
this.statusText = "Der Wettkampf beginnt um " + this.nextHeat.getStartDelayEstimationTime();
} else {
this.statusText = undefined;
}
}
}

startLiveCycle() {
this.interval = setInterval(() => {
console.log("LIVE CYCLE RUNNING: interval: " + this.liveUpdateInterval + " rnd: " + Math.random());
this.fetchCurrentHeat()
this.fetchCurrentHeat();
}, this.liveUpdateInterval);
}

Expand Down
15 changes: 15 additions & 0 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@
},
"UNDEFINED": {
"NAME": "Schwimmen"
},
"FINSWIMMING": {
"NAME": "FS"
},
"DISTANCE_DIVING": {
"NAME": "ST"
},
"BIFIN": {
"NAME": "BF"
},
"APNOE": {
"NAME": "AP"
},
"SB": {
"NAME": "SB"
}
},
"GENDER": {
Expand Down

0 comments on commit 2882ae6

Please sign in to comment.