private List <ScreenerCatalog> AddCalculatedFields(List <ScreenerCatalog> list) { var catalog = list.Where(x => x.Name == "DividendYield").FirstOrDefault(); string max = (ParseDouble(catalog.Properties.Max) * 100).ToString(); string min = (ParseDouble(catalog.Properties.Min) * 100).ToString(); var divPctCatalog = new ScreenerCatalog { Name = "DividendYieldPct", Type = "int", Properties = new ScreenerProp { Max = max, Min = min, IsAvailable = true } }; list.Add(divPctCatalog); return(list); }
private List <ScreenerCatalog> GetRange() { var propertyInfos = typeof(RBaseScreener).GetProperties(); var screener = _ingestionDbContext.RBaseScreeners.ToList(); List <ScreenerCatalog> ranges = new List <ScreenerCatalog>(); foreach (var pInfo in propertyInfos) { if (ScreenerProperties.Contains(pInfo.Name)) { ScreenerCatalog range = new ScreenerCatalog { Name = pInfo.Name, Properties = new ScreenerProp() }; var propertyValues = screener.Select(m => typeof(RBaseScreener).GetProperty(pInfo.Name)?.GetValue(m, null)).Distinct() .Where(m => m != null).ToList(); if (Nullable.GetUnderlyingType(pInfo.PropertyType) == typeof(decimal)) { range.Type = "double"; if (propertyValues.Any()) { List <decimal> values = propertyValues.OfType <decimal>().ToList(); range.Properties.Max = values.Max().ToString(); range.Properties.Min = values.Min().ToString(); range.Properties.IsAvailable = true; } else { range.Properties.IsAvailable = false; } } else if (Nullable.GetUnderlyingType(pInfo.PropertyType) == typeof(int)) { range.Type = "int"; if (propertyValues.Any()) { List <int> values = propertyValues.OfType <int>().ToList(); range.Properties.Max = values.Max().ToString(); range.Properties.Min = values.Min().ToString(); range.Properties.IsAvailable = true; } else { range.Properties.IsAvailable = false; } } else if (Nullable.GetUnderlyingType(pInfo.PropertyType) == typeof(long)) { range.Type = "long"; if (propertyValues.Any()) { List <long> values = propertyValues.OfType <long>().ToList(); range.Properties.Max = values.Max().ToString(); range.Properties.Min = values.Min().ToString(); range.Properties.IsAvailable = true; } else { range.Properties.IsAvailable = false; } } else if (pInfo.PropertyType == typeof(string)) { var kvPairs = propertyValues.Select(m => new ScreenerCollection { Text = m.ToString(), Value = m.ToString() }).ToList(); range.Properties.Collection = kvPairs; range.Type = "string"; range.Properties.IsAvailable = true; } if (range.Type == null) { range.Type = "others"; range.Properties.IsAvailable = false; } ranges.Add(range); } } return(ranges); }