Skip to content

Commit

Permalink
Update rfid lib with serial fix and UI improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbl4 committed Aug 24, 2023
1 parent 2478165 commit 21a7f42
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 58 deletions.
6 changes: 3 additions & 3 deletions CheckpointService/CheckpointService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<PackageReference Include="System.Reactive.Linq" Version="6.0.0" />
<PackageReference Include="LiteDB" Version="5.0.16" />
<PackageReference Include="maxbl4.Infrastructure" Version="1.0.47" />
<PackageReference Include="maxbl4.RfidDotNet" Version="1.0.73" />
<PackageReference Include="maxbl4.RfidDotNet.AlienTech" Version="1.0.73" />
<PackageReference Include="maxbl4.RfidDotNet.GenericSerial" Version="1.0.73" />
<PackageReference Include="maxbl4.RfidDotNet" Version="1.0.74" />
<PackageReference Include="maxbl4.RfidDotNet.AlienTech" Version="1.0.74" />
<PackageReference Include="maxbl4.RfidDotNet.GenericSerial" Version="1.0.74" />
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Component, OnInit } from '@angular/core';
import {ActivatedRoute, Router} from "@angular/router";
import {
DataClient, RiderEventInfoDto,
Checkpoint,
DataClient, Rider, RiderEventInfoDto, SessionDto,
TimingSessionDto,
TimingSessionUpdate
} from "@app/service/data-service-client";
import {NgbModal} from "@ng-bootstrap/ng-bootstrap";
import {WebSocketConnectionService} from "@app/service/web-socket-connection-service";
import {DateTime, Duration} from "luxon";

@Component({
selector: 'app-timing-session-view',
Expand All @@ -21,7 +23,10 @@ import {WebSocketConnectionService} from "@app/service/web-socket-connection-ser
<button class="ml-2" mat-raised-button color="primary"
(click)="refreshRating()">
<i class="material-icons">refresh</i>Пересчитать
</button> ({{update?.updated?.toFormat("HH:mm:ss")}})
</button>
Начало: {{timingSessionDto.startTime?.toFormat("HH:MM:ss")}}
Осталось: {{durationLeft}}
Обновлено: {{update?.updated?.toFormat("HH:mm:ss")}}
<form (submit)="appendRiderId()" *ngIf="timingSessionDto.isRunning">
<div class="input-group mb-3">
<input type="number" class="form-control hide-arrows"
Expand All @@ -39,6 +44,7 @@ import {WebSocketConnectionService} from "@app/service/web-socket-connection-ser
<td>№</td>
<td>Класс</td>
<td>ФИО</td>
<td>Финиш</td>
<td>Круги</td>
<td *ngFor="let l of laps;let i = index">Круг {{i + 1}}</td>
</tr>
Expand All @@ -47,6 +53,7 @@ import {WebSocketConnectionService} from "@app/service/web-socket-connection-ser
<td>{{r.rider?.number}}</td>
<td>{{r.rider?.class?.name}}</td>
<td>{{r.rider?.lastName}} {{r.rider?.firstName}}</td>
<td>{{r.finished}}</td>
<td>{{r.lapCount}}</td>
<td *ngFor="let l of laps;let i = index">
<ng-container *ngIf="r.laps && r.laps.length > i">
Expand All @@ -55,6 +62,21 @@ import {WebSocketConnectionService} from "@app/service/web-socket-connection-ser
</td>
</tr>
</table>
<h3>50 последних отметок</h3>
<table class="table table-bordered" *ngIf="recentCheckpoints">
<thead>
<tr>
<td>Время</td>
<td>№</td>
<td>ФИО</td>
</tr>
</thead>
<tr *ngFor="let r of recentCheckpoints">
<td>{{getRelativeTime(r.timestamp)}}</td>
<td>{{getRider(r.riderId)?.number ?? r.riderId}}</td>
<td>{{getRiderName(r.riderId) ?? "#" + r.riderId}}</td>
</tr>
</table>
`,
styles: [
]
Expand All @@ -64,10 +86,12 @@ export class TimingSessionViewComponent implements OnInit {
public sessionId: string = "";
public eventId: string = "";
public manualRiderId = "";
private riders?: Map<string, RiderEventInfoDto>;
timingSessionDto: TimingSessionDto = new TimingSessionDto();
update?: TimingSessionUpdate;
laps: any[] = [];
sessionDto: SessionDto = new SessionDto();
private riderMap?: Map<string, Rider>;
public recentCheckpoints: Checkpoint[] | undefined;

constructor(private route:ActivatedRoute, private dataClient: DataClient,
private router: Router,
Expand All @@ -86,61 +110,61 @@ export class TimingSessionViewComponent implements OnInit {
if (x?.timingSessionId != this.id)
return;
this.update = x;
this.mapRiders(x.riders);
this.sliceCheckpoints(x.resolvedCheckpoints);
this.laps = new Array(x.maxLapCount);
});
this.dataClient.getTimingSessionRating(this.id).subscribe(x => {
if (x?.timingSessionId != this.id)
return;
this.update = x;
this.mapRiders(x.riders);
this.sliceCheckpoints(x.resolvedCheckpoints);
this.laps = new Array(x.maxLapCount);
});

// this.dataClient.listRiderEventInfo(this.id)
// .pipe(switchMap(x => {
// this.mapRiders(x);
// return this.dataClient.getTimingSessionRating(this.id);
// }))
// .subscribe();
});
}

// private joinRiders(x?: TimingSessionUpdate) {
// if (!x){
// this.rating = [];
// return;
// }
// this.rating = <IRoundPositionWithRider[]>x.rating ?? [];
// let maxLaps = 0;
// for (let r of this.rating) {
// r.rider = this.getRider(r.riderId);
// if (maxLaps < (r.laps?.length ?? 0)) {
// maxLaps = r.laps!.length;
// }
// }
// this.laps = new Array(maxLaps);
// }
private sliceCheckpoints(resolvedCheckpoints: Checkpoint[] | undefined){
this.recentCheckpoints = resolvedCheckpoints?.reverse().slice(0, 50);
}
private mapRiders(riders: Rider[] | undefined) {
if (!riders) return;
this.riderMap = new Map<string, Rider>();
for (let r of riders){
if (r.id) this.riderMap.set(r.id, r);
}
}

public getRider(id?:string){
if (id && this.riderMap) {
return this.riderMap.get(id);
}
return undefined;
}

public getRiderName(id?:string){
const r = this.getRider(id);
if (!r) return undefined;
return `${r.lastName} ${r.firstName}`;
}

loadSession(){
this.dataClient.getTimingSession(this.id)
.subscribe(x => this.timingSessionDto = x);
this.dataClient.getSession(this.sessionId)
.subscribe(x => this.sessionDto = x);
}

// mapRiders(riderInfos: RiderEventInfoDto[]){
// let map = new Map<string, RiderEventInfoDto>();
// for (let r of riderInfos){
// if (r.id) {
// map.set(r.id, r);
// }
// }
// this.riders = map;
// }

getRider(id?:string):RiderEventInfoDto{
if (id) {
return this.riders?.get(id) ?? new RiderEventInfoDto({lastName: id});
} else {
return new RiderEventInfoDto();
get durationLeft(): string{
if (this.timingSessionDto.startTime && this.sessionDto.finishCriteria?.duration) {
const elapsed = DateTime.now().diff(this.timingSessionDto?.startTime);
if (elapsed.as('seconds') > this.sessionDto.finishCriteria.duration.as('seconds')) {
return "-" + elapsed.plus(this.sessionDto.finishCriteria.duration.negate()).toFormat("hh:mm:ss");
}else
return this.sessionDto.finishCriteria.duration.plus(elapsed.negate()).toFormat("hh:mm:ss");
}
return "00:00:00";
}

resumeTimingSession() {
Expand All @@ -159,4 +183,11 @@ export class TimingSessionViewComponent implements OnInit {
refreshRating() {
this.dataClient.getTimingSessionRating(this.id, true).subscribe();
}

getRelativeTime(timestamp: DateTime | undefined) {
if (timestamp && this.timingSessionDto.startTime) {
return timestamp.diff(this.timingSessionDto.startTime).toFormat("hh:mm:ss");
}
return "00:00:00";
}
}
2 changes: 1 addition & 1 deletion DataService/publish-docker.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#1.0.2
#1.0.3

function Main()
{
Expand Down
14 changes: 7 additions & 7 deletions Logic/CheckpointService/RfidService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ private void ConfigureAggregator(RfidOptions options)

private bool ShouldStartRfid(RfidOptions options)
{
if (options.Enabled
&& systemClock.UtcNow.UtcDateTime - options.Timestamp > TimeSpan.FromDays(1))
{
options.Enabled = false;
checkpointRepository.SetRfidOptions(options, false);
return false;
}
// if (options.Enabled
// && systemClock.UtcNow.UtcDateTime - options.Timestamp > TimeSpan.FromDays(1))
// {
// options.Enabled = false;
// checkpointRepository.SetRfidOptions(options, false);
// return false;
// }

return options.Enabled;
}
Expand Down
11 changes: 7 additions & 4 deletions Logic/EventModel/Runtime/TimingSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public void Reload(bool subscribeToRealtimeData = true)
}
}));

var cps = checkpointRepository.ListCheckpoints(timingSession.StartTime, timingSession.StopTime);
var cps = checkpointRepository.ListCheckpoints(timingSession.StartTime, timingSession.StopTime)
.Where(x => !x.Aggregated);
foreach (var cp in cps)
{
checkpointHandler.AppendCheckpoint(cp);
Expand All @@ -102,7 +103,10 @@ public void Reload(bool subscribeToRealtimeData = true)
}));
var cpSubject = new Subject<Checkpoint>();
disposable.Add(cpSubject);
disposable.Add(messageHub.Subscribe<Checkpoint>(cpSubject.OnNext));
disposable.Add(messageHub.Subscribe<Checkpoint>(cp =>
{
if (!cp.Aggregated) cpSubject.OnNext(cp);
}));
disposable.Add(cpSubject
.Subscribe(checkpointHandler.AppendCheckpoint));
}
Expand Down Expand Up @@ -136,7 +140,7 @@ private void CreateRiderIdLookups(Dictionary<string, List<RiderClassRegistration
}

public TimingSessionUpdate GetTimingSessionUpdate()
{
{
var update = new TimingSessionUpdate
{
Id = Id.Value,
Expand All @@ -160,7 +164,6 @@ private WebModel.RoundPosition MapRating(RoundPosition o)
public void Dispose()
{
disposable.DisposeSafe();
checkpointHandler.DisposeSafe();
}
}
}
6 changes: 3 additions & 3 deletions Logic/Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<PackageReference Include="BraaapWeb.Client" Version="1.0.7" />
<PackageReference Include="LiteDB" Version="5.0.16" />
<PackageReference Include="maxbl4.Infrastructure" Version="1.0.47" />
<PackageReference Include="maxbl4.RfidDotNet" Version="1.0.73" />
<PackageReference Include="maxbl4.RfidDotNet.AlienTech" Version="1.0.73" />
<PackageReference Include="maxbl4.RfidDotNet.GenericSerial" Version="1.0.73" />
<PackageReference Include="maxbl4.RfidDotNet" Version="1.0.74" />
<PackageReference Include="maxbl4.RfidDotNet.AlienTech" Version="1.0.74" />
<PackageReference Include="maxbl4.RfidDotNet.GenericSerial" Version="1.0.74" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" Version="7.0.9" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
Expand Down

0 comments on commit 21a7f42

Please sign in to comment.