Skip to content

Commit a52de2f

Browse files
authored
optimize searching for possible plate matches (#100)
* don't pull back jpegs * Revert "don't pull back jpegs" This reverts commit 2eeba0a. * change to list * migration * fix up query * do it this way * negate that * fix ef error * cancel previous search * don't trigger refresh when already searching * try this to limit data being pulled back * try always returning static count * logging * this * add count back * default max date * html too * look 15 days in past * always reset * set dates on cleaR
1 parent f4c2f5f commit a52de2f

14 files changed

Lines changed: 583 additions & 32 deletions

OpenAlprWebhookProcessor/Alerts/AlertService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ private async Task ProcessAlertsAsync()
7474

7575
if (job.IsStrictMatch)
7676
{
77-
plateGroups = plateGroups.Where(x => x.Id == job.LicensePlateId || x.PossibleNumbers.Contains(job.LicensePlateId.ToString()));
77+
plateGroups = plateGroups.Where(x => x.Id == job.LicensePlateId || x.PossibleNumbers.Any(x => x.Number == job.LicensePlateId.ToString()));
7878
}
7979
else
8080
{

OpenAlprWebhookProcessor/ClientApp/src/app/plates/plates.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<mat-card-content>
6868
<mat-form-field appearance="fill" style="width: 80%;">
6969
<mat-label>Enter a date range</mat-label>
70-
<mat-date-range-input [rangePicker]="picker" >
70+
<mat-date-range-input [rangePicker]="picker" [max]="todaysDate">
7171
<input matStartDate [(ngModel)]="filterStartOn" placeholder="Start date">
7272
<input matEndDate [(ngModel)]="filterEndOn" placeholder="End date">
7373
</mat-date-range-input>

OpenAlprWebhookProcessor/ClientApp/src/app/plates/plates.component.ts

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { VehicleFilters } from './vehicleFilters';
1717
import { MatDialog } from '@angular/material/dialog';
1818
import { EditPlateComponent } from './edit-plate/edit-plate.component';
1919
import { LocalStorageService } from '@app/_services/local-storage.service';
20-
import { EnrichersService } from '@app/settings/enrichers/enrichers.service';
20+
import { timeStamp } from 'console';
2121

2222
@Component({
2323
selector: 'app-plates',
@@ -62,6 +62,7 @@ export class PlatesComponent implements OnInit, OnDestroy, AfterViewInit {
6262
public range: FormGroup;
6363
public plates: Plate[] = [];
6464
public totalNumberOfPlates: number;
65+
public todaysDate: Date;
6566

6667
public filterPlateNumber: string;
6768
public filterPlateNumberIsValid: boolean = true;
@@ -94,12 +95,12 @@ export class PlatesComponent implements OnInit, OnDestroy, AfterViewInit {
9495
private pageSizeCacheKey: string = "platePageSize";
9596
private pageNumber: number = 0;
9697

97-
private subscriptions = new Subscription();
98-
98+
private eventSubscriptions = new Subscription();
99+
private searchSubscription = new Subscription();
100+
99101
@ViewChild(MatPaginator) paginator: MatPaginator;
100102

101103
constructor(
102-
private enricherService: EnrichersService,
103104
private plateService: PlateService,
104105
private signalRHub: SignalrService,
105106
private snackbarService: SnackbarService,
@@ -119,27 +120,40 @@ export class PlatesComponent implements OnInit, OnDestroy, AfterViewInit {
119120
this.pageSize = pageSize != null ? parseInt(pageSize) : 25;
120121
this.searchPlates();
121122
this.populateFilters();
123+
this.setInitialDateFilter();
122124
}
123125

124126
ngOnDestroy(): void {
125-
this.subscriptions.unsubscribe();
127+
this.eventSubscriptions.unsubscribe();
128+
this.searchSubscription.unsubscribe();
126129
}
127130

128131
ngAfterViewInit(): void {
129132
this.subscribeForUpdates();
130133
}
131134

135+
public setInitialDateFilter() {
136+
this.todaysDate = new Date();
137+
this.filterStartOn = new Date();
138+
this.filterEndOn = new Date();
139+
140+
this.filterStartOn.setDate(new Date().getDate() - 15);
141+
this.filterEndOn = this.todaysDate;
142+
}
143+
132144
public editPlate(plateNumber: string) {
133145
this.openEditDialog(plateNumber);
134146
}
135147

136148
public subscribeForUpdates() {
137-
this.subscriptions.add(this.signalRHub.connectionStatusChanged.subscribe(status => {
149+
this.eventSubscriptions.add(this.signalRHub.connectionStatusChanged.subscribe(status => {
138150
this.isSignalrConnected = status;
139151
}));
140152

141-
this.subscriptions.add(this.signalRHub.licensePlateReceived.subscribe(_ => {
142-
this.searchPlates();
153+
this.eventSubscriptions.add(this.signalRHub.licensePlateReceived.subscribe(_ => {
154+
if (!this.isLoading) {
155+
this.searchPlates();
156+
}
143157
}));
144158
}
145159

@@ -159,8 +173,6 @@ export class PlatesComponent implements OnInit, OnDestroy, AfterViewInit {
159173
}
160174

161175
public searchPlates(plateNumber: string = '') {
162-
var request = new PlateRequest();
163-
164176
if (!this.filterPlateNumberIsValid) {
165177
return;
166178
}
@@ -172,6 +184,8 @@ export class PlatesComponent implements OnInit, OnDestroy, AfterViewInit {
172184
this.filterStartOn?.setUTCHours(0,0,0,0);
173185
this.filterEndOn?.setUTCHours(23,59,59,999);
174186

187+
var request = new PlateRequest();
188+
175189
request.pageNumber = this.pageNumber;
176190
request.pageSize = this.pageSize;
177191
request.endSearchOn = this.filterEndOn;
@@ -186,13 +200,18 @@ export class PlatesComponent implements OnInit, OnDestroy, AfterViewInit {
186200
request.vehicleType = this.filterVehicleType;
187201
request.vehicleRegion = this.filterVehicleRegion;
188202

203+
if (this.isLoading) {
204+
this.searchSubscription.unsubscribe();
205+
}
206+
189207
this.isLoading = true;
190-
this.plateService.searchPlates(request).subscribe(result => {
208+
this.searchSubscription = this.plateService.searchPlates(request).subscribe(result => {
191209
this.totalNumberOfPlates = result.totalCount;
192210
this.plates = result.plates;
193211
this.isLoading = false;
194212
}, error => {
195213
this.isLoading = false;
214+
this.snackbarService.create(`Error searching for plates, check the logs`, SnackBarType.Error)
196215
});
197216
}
198217

@@ -237,8 +256,8 @@ export class PlatesComponent implements OnInit, OnDestroy, AfterViewInit {
237256
}
238257

239258
public clearFilters() {
240-
this.filterEndOn = null;
241-
this.filterStartOn = null;
259+
this.setInitialDateFilter();
260+
242261
this.filterPlateNumber = '';
243262
this.filterPlateNumberIsValid = true;
244263
this.filterStrictMatch = false;

0 commit comments

Comments
 (0)