예제 #1
0
        public async Task <ActionResult <BirdAnalysisResult> > Index(string imageUrl)
        {
            if (string.IsNullOrWhiteSpace(imageUrl))
            {
                return(BadRequest());
            }

            try
            {
                var result = await _birdAnalyzer.AnalyzeImageFromUrlAsync(imageUrl);

                _telemetryClient.TrackEvent("BON_ImageAnalyzed", new Dictionary <string, string>
                {
                    { "BON_ImageUrl", imageUrl },
                    { "BON_IsBird", result.IsBird.ToString() },
                    { "BON_BirdCount", result.Animals.Count.ToString() },
                    { "BON_IsBirdConfidence", result.IsBirdConfidence?.ToString() ?? string.Empty },
                    { "BON_ImageDescription", result.Metadata.ImageDescription },
                    { "BON_IsInappropriateContent", result.IsInappropriateContent.ToString() },
                    { "BON_Source", "Api_V1" }
                });

                return(result);
            }
            catch (Exception ex)
            {
                _telemetryClient.TrackException(ex, new Dictionary <string, string>
                {
                    { "BON_ImageUrl", imageUrl },
                    { "BON_Source", "Api_V1" }
                });

                return(StatusCode((int)HttpStatusCode.ServiceUnavailable));
            }
        }
예제 #2
0
        public async Task <ActionResult <HomeIndexViewModel> > Index(string imageUrl)
        {
            var viewModel = new HomeIndexViewModel
            {
                ImageUrl = imageUrl,
                Samples  = _samples
            };

            if (!string.IsNullOrWhiteSpace(imageUrl))
            {
                try
                {
                    var result = await _birdAnalyzer.AnalyzeImageFromUrlAsync(imageUrl);

                    viewModel.Result = result;
                    _telemetryClient.TrackEvent("BON_ImageAnalyzed", new Dictionary <string, string>
                    {
                        { "BON_ImageUrl", imageUrl },
                        { "BON_IsBird", result.IsBird.ToString() },
                        { "BON_BirdCount", result.Animals.Count.ToString() },
                        { "BON_IsBirdConfidence", result.IsBirdConfidence?.ToString() ?? string.Empty },
                        { "BON_ImageDescription", result.Metadata.ImageDescription },
                        { "BON_IsSample", _samples.Values.Contains(imageUrl).ToString() },
                        { "BON_IsInappropriateContent", result.IsInappropriateContent.ToString() },
                        { "BON_Source", "Site" }
                    });
                }
                catch (Exception ex)
                {
                    viewModel.Result = BirdAnalysisResult.Empty;
                    _telemetryClient.TrackException(ex, new Dictionary <string, string>
                    {
                        { "BON_ImageUrl", imageUrl },
                        { "BON_Source", "Site" }
                    });
                }
            }

            viewModel.IsBirdText   = viewModel.Result?.IsBirdText ?? string.Empty;
            viewModel.CanonicalUrl = GetCanonicalUrl(viewModel);

            return(View(viewModel));
        }
예제 #3
0
        public async Task <ActionResult <BirdAnalysisResult> > Index(string imageUrl)
        {
            var viewModel = new HomeIndexViewModel
            {
                ImageUrl = imageUrl,
                Samples  = _samples
            };

            if (!string.IsNullOrWhiteSpace(imageUrl))
            {
                try
                {
                    var result = await _birdAnalyzer.AnalyzeImageFromUrlAsync(imageUrl);

                    viewModel.Result = result;
                    _telemetryClient.TrackEvent("BON_ImageAnalyzed", new Dictionary <string, string>
                    {
                        { "BON_ImageUrl", imageUrl },
                        { "BON_IsBird", result.IsBird.ToString() },
                        { "BON_BirdCount", result.Animals.Count.ToString() },
                        { "BON_IsBirdConfidence", result.IsBirdConfidence.ToString() },
                        { "BON_ImageDescription", result.Metadata.ImageDescription },
                    });
                }
                catch (Exception ex)
                {
                    viewModel.Result = null;
                    _telemetryClient.TrackException(ex, new Dictionary <string, string>
                    {
                        { "BON_ImageUrl", imageUrl }
                    });
                }
            }

            viewModel.IsBirdText   = GetIsBirdText(viewModel);
            viewModel.CanonicalUrl = GetCanonicalUrl(viewModel);

            return(View(viewModel));
        }