コード例 #1
0
        public async Task <ActionResult <dynamic> > GetCovidInfoAsync()
        {
            CovidResponse PullRequests = new CovidResponse();

            PullRequests = await _clientFactory.GetAsync <CovidResponse>("https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases2_v1/FeatureServer/2/query?where=1%3D1&outFields=Country_Region,Lat,Long_,Confirmed,Deaths,Recovered,UID,ISO3&returnGeometry=false&outSR=4326&f=json");


            return(Ok(PullRequests));
        }
コード例 #2
0
ファイル: CovidDataService.cs プロジェクト: kiran94/covid19
        public override async Task Get(CovidRequest request, IServerStreamWriter <CovidResponse> responseStream, ServerCallContext context)
        {
            using var span = this.tracer.BuildSpan(nameof(CovidDataService.Get))
                             .WithTag(nameof(request.CountryRegion), request.CountryRegion)
                             .WithTag(nameof(request.ProvinceState), request.ProvinceState)
                             .WithTag(nameof(request.County), request.County)
                             .WithTag(nameof(request.Fields), request.Fields?.ToString())
                             .WithTag(nameof(request.DatesCase), request.DatesCase.ToString())
                             .WithTag(nameof(request.AbsoluteDates), request.AbsoluteDates?.ToString())
                             .WithTag(nameof(request.RelativeDates), request.RelativeDates?.ToString())
                             .StartActive();

            var data = this.timeseries.Query();

            if (!string.IsNullOrWhiteSpace(request.CountryRegion))
            {
                data = data.Where(x => x.CountryRegion == request.CountryRegion);
            }

            request.ProvinceState = request.ProvinceState ?? "";
            request.County        = request.County ?? "";

            data = data.Where(x => x.ProvinceState == request.ProvinceState);
            data = data.Where(x => x.County == request.County);

            if (request.Fields.Any())
            {
                data = data.Where(x => request.Fields.Contains(x.Field));
            }

            if (request.DatesCase == CovidRequest.DatesOneofCase.RelativeDates)
            {
                throw new NotImplementedException("Relative Dates not Implemented");
            }
            else if (request.AbsoluteDates != null)
            {
                var dates = request.AbsoluteDates.Dates.Select(x => x.ToDateTime().Date);
                data = data.Where(x => dates.Contains(x.Date));
            }

            await foreach (var record in data.AsAsyncEnumerable())
            {
                var c = new CovidResponse()
                {
                    CountryRegion = record.CountryRegion,
                    ProvinceState = record.ProvinceState,
                    County        = record.County,
                    Field         = record.Field,
                    Date          = Timestamp.FromDateTime(DateTime.SpecifyKind(record.Date, DateTimeKind.Utc)),
                    Value         = record.Value ?? 0
                };

                await responseStream.WriteAsync(c);
            }
        }