public void Verify_Data_Returned() { ProductAnalyticsAPIClient data = new ProductAnalyticsAPIClient(); long germPlasmId = 457931693752320; List <IFilter> postAPIFilters = new List <IFilter>(); UDRList udrList = GetSimpleUDRList(); IFilter[] filters = new List <IFilter>() { FilterBase.GetFilterDefinition("testSetSeason=2015:04", postAPIFilters, udrList) }.ToArray(); List <string> observations = new List <string>() { "MST", "YLD_BE", "SELIN", "TWT_BE" }; HttpClient httpClient = new HttpClient(); List <Dictionary <string, dynamic> > entryMeans; CancellationTokenSource cancellationToken = new CancellationTokenSource(TimeSpan.FromSeconds(90)); entryMeans = data.GetEntryMeansAsynch(contextMock.Object, httpClient, cancellationToken.Token, "USER_A", germPlasmId, filters, observations, "Apples", null).Result; Assert.NotEqual <int>(0, entryMeans.Count); httpClient.Dispose(); httpClient = null; }
public void Verify_UDR_List_Does_Not_Match_Geography() { UDRList list = GetSimpleUDRList(); Dictionary <string, dynamic> row = new Dictionary <string, dynamic>() { { "country", "Mexico" } }; Assert.Equal(false, list.ContainsUDR(new string[] { "North America" }, row)); }
public FilterApplicator(List <string> filters, UDRList udrList) { FilterBase filterBase; List <IFilter> postAPIFilters = new List <IFilter>(); List <IFilter> preAPIFilters = new List <IFilter>(); foreach (string filterString in filters) { filterBase = FilterBase.GetFilterDefinition(filterString, postAPIFilters, udrList); if (filterBase is APIBodyFilter || filterBase is QueryStringFilter) { preAPIFilters.Add(filterBase); } else { postAPIFilters.Add(filterBase); } } this.apiFilters = preAPIFilters.ToArray(); this.postAPIFilters = postAPIFilters.ToArray(); }
public static BaseBand Create(Dictionary <string, BaseBand> existingBands, ILambdaContext context, HttpClient httpClient, BandDefinition definition, IProductAnalyticsAPIClient client, UDRList udrList) { BandDefinition toUse = TranslateDefinition(definition); Func <BandDefinition, BaseBand> creationFunction = AllBands.GetCreator(toUse.BandName); BaseBand band; if (creationFunction != null) { band = creationFunction(toUse); } else if (toUse.BandingGroup == "Field Observations") { if (existingBands.TryGetValue(toUse.BandingGroup, out band) && band is FieldObservationBand) { ((FieldObservationBand)band).AddBandDefinition(toUse); } else { band = new FieldObservationBand(context, httpClient, toUse, client); existingBands.Add(toUse.BandingGroup, band); } return(band); } else if (toUse.Category == "Field Stress") { band = new FieldStressBand(context, httpClient, toUse, client); } else if (toUse.BandingGroup == "UDR") { if (!existingBands.TryGetValue(toUse.BandingGroup, out band)) { band = new UDRBand(toUse, udrList); existingBands.Add(toUse.BandingGroup, band); } return(band); } else if (toUse.BandingGroup == "TestMeans" && toUse.MinValue != null && toUse.MaxValue != null && toUse.Interval.HasValue) { band = new ObservationBand(toUse); } else if (toUse.MinValue != null && toUse.MaxValue != null && toUse.Interval.HasValue) { if (toUse.MinValue is DateTime) { band = new IntervalBandDateTime(toUse); } else if (toUse.MinValue is double) { band = new IntervalBandDouble(toUse); } else if (toUse.MinValue is long) { band = new IntervalBandLong(toUse); } else { throw new ArgumentOutOfRangeException($"Band: {toUse.BandName} is not handled or is not defined properly."); } } else if (toUse.MinValue == null || toUse.MaxValue == null || toUse.Interval == null) { band = new ColumnBand(toUse.BandName); } else { throw new ArgumentOutOfRangeException($"Band: {toUse.BandName} is not handled or is not defined properly."); } existingBands.Add(band.BandName, band); return(band); }
public void Process(ILambdaContext context, GermPlasmSNSRequest request, string topicArn) { string keyReportName = request.ReportName.Replace(' ', '`'); int reportId = request.ReportId; ulong count = this.persister.InitializeCounter(keyReportName, request.MyCount); if (count == (ulong)request.MyCount) { //Removed the CacheClean Up we can put it back //this.persister.CleanupCache(context, keyReportName, reportId); count = this.persister.InitializeCounter(keyReportName, request.MyCount); } string queueUrl = request.GPQueueUrl; context.Logger.LogLine($"starting to process against SQS: {queueUrl} and count: {count}"); // give lambda 20 secods to create a new notification to kick off a new lambda processor TimeSpan limit = new TimeSpan(0, 0, 20); bool remaining = true; // initialize Analytics API bool initialized = false; queue.Initialize(request); QueueGermPlasmEvent gpEvent; while (remaining && context.RemainingTime > limit) { context.Logger.LogLine($"getting from SQS: {queueUrl} with {context.RemainingTime} remaining"); try { // Load Q data gpEvent = this.queue.GetNext(context); if (gpEvent == null) { remaining = false; } else { if (!initialized) { this.persister.InitializeObservations(keyReportName, gpEvent.Observations); productAnalyticsAPIClient.Initialize(this.httpClient, bearerToken, gpEvent.UserId); this.headToHeadAPIClient.Initialize(this.httpClient, bearerToken, gpEvent.UserId); List <string> udrNames = gpEvent.Bands.Where(b => b.BandingGroup == "UDR").Select(b => b.BandName).ToList(); udrNames.AddRange(gpEvent.DataFilters.Where(df => df.StartsWith("UserDefinedRegions")).SelectMany(df => df.Split('=')[1].Split('&'))); this.udrList = new UDRList(this.udrData.GetUDRsForCrop(this.httpClient, gpEvent.Crop, udrNames).Result); initialized = true; } remaining = ProcessGermPlasmEvent(context, request, gpEvent); } } catch (AggregateException exc) { string error; foreach (Exception iExc in exc.InnerExceptions) { error = $"ERROR: queue: {queueUrl}: error: {iExc.ToString()}"; string slackResponse = slack.SlackIntegrationPostAsync(this.httpClient, error).Result; headToHeadAPIClient.ReportFailure(context, this.httpClient, reportId, "AggregateException = " + error); context.Logger.Log(error); context.Logger.Log(slackResponse); } remaining = false; } catch (Exception exc) { string error = $"ERROR: queue: {queueUrl}: error: {exc.ToString()}"; context.Logger.Log(error); string slackResponse = slack.SlackIntegrationPostAsync(this.httpClient, error).Result; headToHeadAPIClient.ReportFailure(context, this.httpClient, reportId, "Exception= " + error); context.Logger.Log(slackResponse); remaining = false; } } // need to queue a new processor to the SNS if (remaining) { // use notifier to send to first entrypoint topic notifier.SendSelfProcessStartAsync(context, request, topicArn).Wait(); } }
public override FilterBase CreateFilter(List <string> values, List <IFilter> postAPIFilters, UDRList udrList) { if (values.Count == 0) { throw new ArgumentOutOfRangeException($"{this.FilterName} must have values supplied"); } switch (this.FilterCategory) { case FilterCategory.APIReturnValueRangeBegin: case FilterCategory.APIReturnValueRangeEnd: { IFilter existingFilter = postAPIFilters.FirstOrDefault(f => f.ParameterName == this.FilterName); T value = coerceValue(values[0]); if (existingFilter == null) { return(new ReturnValueRangeFilter <T>(this, value)); } else { ((ReturnValueRangeFilter <T>)existingFilter).InitializeWithDefinition(this, value); return((ReturnValueRangeFilter <T>)existingFilter); } } default: throw new ArgumentOutOfRangeException($"cannot construct a filter of category: {this.FilterCategory.ToString()}."); } }
public APILookupFilter(FilterDefinition definition, List <string> values, UDRList udrList) : base(definition, values) { this.udrList = udrList; }
public UDRBand(BandDefinition definition, UDRList udrList) : base(definition.BandingGroup) { this.udrList = udrList ?? throw new ArgumentNullException("udrList"); }
public virtual FilterBase CreateFilter(List <string> values, List <IFilter> postAPIFilters, UDRList udrList) { switch (this.FilterCategory) { case FilterCategory.APIBody: return(new APIBodyFilter(this, values)); case FilterCategory.APIQueryString: return(new QueryStringFilter(this, values)); case FilterCategory.APIReturnValue: return(new ReturnValueFilter(this, values)); case FilterCategory.LookupFromAPIReturnValue: return(new APILookupFilter(this, values, udrList)); default: throw new ArgumentOutOfRangeException($"cannot construct a filter of category: {this.FilterCategory.ToString()}."); } }
public static FilterBase GetFilterDefinition(string filter, List <IFilter> postAPIFilters, UDRList udrList) { string[] filterParts = filter.Split('='); if (filterParts.GetLength(0) != 2) { throw new ArgumentException("filter must be in the form 'key=value1[&value2]'"); } List <string> values = filterParts[1].Split('&').ToList(); FilterDefinition filterDefinition; if (!filterList.TryGetValue(filterParts[0], out filterDefinition)) { return(null); } return(filterDefinition.CreateFilter(values, postAPIFilters, udrList)); }