public AutoTextDataProvider(AutoTextData dataIn) { var data = dataIn; _metricData = data.MetricData; Blocks = data.Blocks; // Normalize casing Array.ForEach(data.Blocks, x => Array.ForEach(x.BlockItems, y => { y.MetricCode = y.MetricCode.ToUpper(); y.VariableCodes = y.VariableCodes == null ? null : Array.ConvertAll(y.VariableCodes, z => z.ToUpper()); })); Array.ForEach(data.Metrics, x => x.Code = x.Code.ToUpper()); Array.ForEach(data.Variables, x => x.Code = x.Code.ToUpper()); // Init lookups _metricToId = data.Metrics.ToDictionary(x => x.Code, x => x.Id, StringComparer.OrdinalIgnoreCase); _variableToId = data.Variables.ToDictionary(x => x.Code, x => x.Id, StringComparer.OrdinalIgnoreCase); // Set direction based on value foreach (var metricData in data.MetricData) { foreach (var variableData in metricData.VariableData) { variableData.Direction = DirectionType.FLAT; if (variableData.PercentChange >= 0.05) { var isPositive = (variableData.CurrentValue - variableData.PreviousValue) > 0; variableData.Direction = isPositive ? DirectionType.POSITIVE : DirectionType.NEGATIVE; } } } }
public AutoTextMain(AutoTextDefinitions definitions, AutoTextData data) { DefinitionsProvider = new AutoTextDefinitionsProvider(definitions); DataProvider = new AutoTextDataProvider(data); // Setup macro variables MacroVariables = new MacroVariables(); MacroVariables.Add(definitions.MacroVariables); // Setup direction Direction = new Direction(definitions.Synonyms); }