public async Task DeleteBucket([FromBody] BucketModel bucket) { BucketsApi buckets = new BucketsApi(); dynamic token = await OAuthController.GetInternalAsync(); buckets.Configuration.AccessToken = token.access_token; await buckets.DeleteBucketAsync(bucket.bucketKey); }
public async Task <dynamic> DeleteBucket([FromBody] CreateBucketModel bucket) { BucketsApi buckets = new BucketsApi(); dynamic token = await OAuthController.GetInternalAsync(); buckets.Configuration.AccessToken = token.access_token; await buckets.DeleteBucketAsync(bucket.bucketKey); //or //buckets.DeleteBucket(bucket.bucketKey); return(Task.CompletedTask); }
public async Task <dynamic> DeleteBucket([FromBody] DeleteBucketModel objInfo) { // get the bucket... BucketsApi Buck = new BucketsApi(); dynamic token = await OAuthController.GetInternalAsync(); Buck.Configuration.AccessToken = token.access_token; await Buck.DeleteBucketAsync(objInfo.bucketKey); return(Task.CompletedTask); }
public async Task DeleteBucket() { var createBucket = await _bucketsApi.CreateBucketAsync(GenerateName("robot sensor"), RetentionRule(), _organization); Assert.IsNotNull(createBucket); var foundBucket = await _bucketsApi.FindBucketByIdAsync(createBucket.Id); Assert.IsNotNull(foundBucket); // delete task await _bucketsApi.DeleteBucketAsync(createBucket); var ioe = Assert.ThrowsAsync <HttpException>(async() => await _bucketsApi.FindBucketByIdAsync(createBucket.Id)); Assert.AreEqual("bucket not found", ioe.Message); }
static async Task Main(string[] args) { ILoggerFactory loggerFactory = LoggerFactory.Create(builder => { builder .AddFilter("Microsoft", LogLevel.Warning) .AddFilter("System", LogLevel.Warning) .AddFilter("phetracker.Program", LogLevel.Debug) .AddConsole(c => { c.TimestampFormat = "[HH:mm:ss] "; }); }); ILogger logger = loggerFactory.CreateLogger <Program>(); logger.LogInformation("Init services...."); populationData = LoadPopulationData(); Maps maps = new Maps(); var trustsData = maps.GetTrustsForLtlas(); logger.LogInformation("Starting..."); string dataFilePath = "datacache.json"; logger.LogInformation("Downloading data from API"); APIClient client = new APIClient(logger); CaseData data = new CaseData(); var trustData = await client.GetNHSTrustData(); var processedTrustData = new List <NhsTrustDataPoint>(); if (System.IO.File.Exists(dataFilePath)) { logger.LogInformation("Using Cached data delete data.json to load fresh data"); data = JsonConvert.DeserializeObject <CaseData>(System.IO.File.ReadAllText(dataFilePath)); } else { var caseDataV1 = await client.GetLTLAData(logger); data.ltlas = new List <CaseRecord>(); data.metadata = new Metadata(); foreach (var item in caseDataV1) { data.ltlas.Add(new CaseRecord() { kind = "localAuthorityCases", areaCode = item.areaCode, areaName = item.areaName, dailyLabConfirmedCases = item.newCasesBySpecimenDate, specimenDate = item.date, }); } var caseDataString = JsonConvert.SerializeObject(data); System.IO.File.WriteAllText(dataFilePath, caseDataString); } // always process the hospital data // Build trust data structure var trustDataDictionary = trustData.GroupBy(y => y.areaName).ToDictionary(y => y.Key, z => { return(z.ToDictionary(v => v.date)); }); foreach (var ltla in data.ltlas.GroupBy(y => y.areaName)) { try { var hospitals = trustsData[ltla.Key]; foreach (var hospital in hospitals) { var hospitalData = trustDataDictionary[hospital.OrganisationName]; foreach (var dataPoint in hospitalData) { Console.WriteLine("Adding datapoint for ltal" + ltla.Key); dataPoint.Value.ltlaName = ltla.Key; processedTrustData.Add(dataPoint.Value); } } } catch (System.Exception) { Console.WriteLine("Failed to find hospitals for ltla:" + ltla.Key); } } // Combine and dedupe (for regions) case data var allCaseData = data.ltlas; var pheBucketName = "pheCovidData"; var orgId = "05d0f71967e52000"; var Token = "hYf9V7UQge2McZNCTKerUkPwLvqncruS2hczL9jJX3ohSP-zJ7Yt1Za5J33qNcKkn_rI7pU3SiWHbV5waBt4dA==".ToCharArray(); using (var influxDBClient = InfluxDBClientFactory.Create("http://localhost:9999", Token)) using (var writeApi = influxDBClient.GetWriteApi()) { BucketsApi bucketsApi = influxDBClient.GetBucketsApi(); try { var pheBucketInstance = await bucketsApi.FindBucketByNameAsync(pheBucketName); await bucketsApi.DeleteBucketAsync(pheBucketInstance); } catch (Exception e) { logger.LogError("Failed to delete bucket, may not exist" + e.ToString(), e); } var bucket = await bucketsApi.CreateBucketAsync(pheBucketName, orgId); var points = new List <PointData>(allCaseData.Count); foreach (var record in allCaseData) { var recordPer100k = ConvertToPer100kValue(record); var point = PointData.Measurement("confirmedCases") .Tag("localAuth", record.areaName) .Tag("localAuthKind", record.kind) .Tag("localAuthCode", record.areaCode) .Field("daily", record.dailyLabConfirmedCases ?? 0) .Field("daily100k", recordPer100k?.dailyLabConfirmedCases ?? 0) .Field("total", record.dailyTotalLabConfirmedCasesRate) .Field("total100k", recordPer100k?.dailyTotalLabConfirmedCasesRate ?? 0) .Timestamp(record.specimenDate.ToUniversalTime(), WritePrecision.S); points.Add(point); } foreach (var record in processedTrustData) { var point = PointData.Measurement("trustData") .Tag("localAuth", record.ltlaName) .Tag("trust", record.areaName) .Field("newAdmissions", record.newAdmissions ?? 0) .Field("cases", record.hospitalCases ?? 0) .Field("mvBeds", record.covidOccupiedMVBeds ?? 0) .Timestamp(record.date.ToUniversalTime(), WritePrecision.S); points.Add(point); } writeApi.WritePoints(pheBucketName, orgId, points); } }
static async Task Main(string[] args) { ILoggerFactory loggerFactory = LoggerFactory.Create(builder => { builder .AddFilter("Microsoft", LogLevel.Warning) .AddFilter("System", LogLevel.Warning) .AddFilter("phetracker.Program", LogLevel.Debug) .AddConsole(c => { c.TimestampFormat = "[HH:mm:ss] "; }); }); ILogger logger = loggerFactory.CreateLogger <Program>(); logger.LogInformation("Init services...."); populationData = LoadPopulationData(); logger.LogInformation("Starting..."); HttpClient client = new HttpClient(); var caseDataString = await client.GetStringAsync("https://coronavirus.data.gov.uk/downloads/json/coronavirus-cases_latest.json"); CaseData data = JsonConvert.DeserializeObject <CaseData>(caseDataString); var hash = GetHashString(caseDataString); data.metadata.hash = hash; // Combine and dedupe (for regions) case data var allCaseData = data.ltlas; var pheBucketName = "pheCovidData"; var orgId = "05d0f71967e52000"; var Token = "hYf9V7UQge2McZNCTKerUkPwLvqncruS2hczL9jJX3ohSP-zJ7Yt1Za5J33qNcKkn_rI7pU3SiWHbV5waBt4dA==".ToCharArray(); using (var influxDBClient = InfluxDBClientFactory.Create("http://localhost:9999", Token)) using (var writeApi = influxDBClient.GetWriteApi()) { BucketsApi bucketsApi = influxDBClient.GetBucketsApi(); try { var pheBucketInstance = await bucketsApi.FindBucketByNameAsync(pheBucketName); await bucketsApi.DeleteBucketAsync(pheBucketInstance); } catch (Exception e) { logger.LogError("Failed to delete bucket, may not exist" + e.ToString(), e); } var bucket = await bucketsApi.CreateBucketAsync(pheBucketName, orgId); foreach (var record in allCaseData) { var recordPer100k = ConvertToPer100kValue(record); var point = PointData.Measurement("confirmedCases") .Tag("localAuth", record.areaName) .Tag("localAuthKind", record.kind) .Tag("localAuthCode", record.areaCode) .Field("daily", record.dailyLabConfirmedCases ?? 0) .Field("daily100k", recordPer100k?.dailyLabConfirmedCases ?? 0) .Field("total", record.dailyTotalLabConfirmedCasesRate) .Field("total100k", recordPer100k?.dailyTotalLabConfirmedCasesRate ?? 0) .Timestamp(record.specimenDate.ToUniversalTime(), WritePrecision.S); writeApi.WritePoint(pheBucketName, orgId, point); } } }