示例#1
0
        private async Task <List <RecognizedObject> > GetIdentifiedPlatesAsync(string base64, double latitude, double longitude)
        {
            PlateAPIResponse cloudResponse = await GetPlateAPIResponseAsync(base64);

            cloudResponse.UpdateMatchesPattern(AppSettings.Configuration.PlatePattern);
            List <PlateAPIResult>   matchingResults  = cloudResponse.Results.Where(result => result.MatchesPattern).ToList();
            List <RecognizedObject> identifiedPlates = new List <RecognizedObject>();

            matchingResults.ForEach(matching =>
            {
                Plate plate = _plateRepository.GetByPlateNumber(matching.Plate);
                if (plate != null)
                {
                    Timestamp timestamp = _timestampRepository.GetLatestModelTimestamp(plate.Id);
                    bool seenBefore     = true;
                    if (timestamp == null || timestamp.DateAndTime == null)
                    {
                        seenBefore = false;
                        timestamp  = new Timestamp()
                        {
                            DateAndTime    = DateTime.UtcNow.ToUTC2().GetFormattedDateAndTime(),
                            MissingModelId = plate.Id,
                            Latitude       = latitude,
                            Longitude      = longitude
                        };
                    }
                    RecognizedObject recognizedObject = new RecognizedObject()
                    {
                        Id        = plate.Id,
                        FirstName = plate.FirstName,
                        LastName  = plate.LastName,
                        Reason    = plate.Reason,
                        Type      = ModelType.Plate,
                        Message   = plate.NumberPlate,
                        LastSeen  = timestamp.DateTime.GetFormattedDateAndTime()
                    };
                    if (seenBefore && timestamp.DateTime > DateTime.UtcNow.ToUTC2().AddMinutes(-1))
                    {
                        timestamp.DateAndTime = DateTime.UtcNow.ToUTC2().GetFormattedDateAndTime();
                        _timestampRepository.Edit(timestamp);
                    }
                    else
                    {
                        _timestampRepository.Add(new Timestamp()
                        {
                            DateAndTime    = DateTime.UtcNow.ToUTC2().GetFormattedDateAndTime(),
                            MissingModelId = plate.Id,
                            Latitude       = latitude,
                            Longitude      = longitude
                        });
                    }
                    recognizedObject.TimestampId = _timestampRepository.GetLatestModelTimestamp(plate.Id).Id;
                    identifiedPlates.Add(recognizedObject);
                }
            });
            return(identifiedPlates);
        }