protected virtual bool GetMatchedRecords( IOrderedEnumerable<IRecord> recordsFilteredByDate, IModelInput modelInput, out IDictionary<string, IList<IRecord>> matchedRecords ) { matchedRecords = new Dictionary<string, IList<IRecord>>(); if (!recordsFilteredByDate.AnySave()) { return false; } foreach (var record in recordsFilteredByDate) { foreach (var term in modelInput.FilterTerms) { var distinctMatchedDescription = GetMatchedDistinctDescription(record.Description, term); record.DistinctDescription = distinctMatchedDescription; if (string.IsNullOrEmpty(distinctMatchedDescription)) { continue; } if (matchedRecords.ContainsKey(distinctMatchedDescription)) { matchedRecords[distinctMatchedDescription].Add(record); } else { matchedRecords.Add(distinctMatchedDescription, new List<IRecord>() { record }); } break; } } return matchedRecords.Any(); }
protected virtual bool GetMatchedRecords ( IOrderedEnumerable <IRecord> recordsFilteredByDate, IModelInput modelInput, out IDictionary <string, IList <IRecord> > matchedRecords ) { matchedRecords = new Dictionary <string, IList <IRecord> >(); if (!recordsFilteredByDate.AnySave()) { return(false); } foreach (var record in recordsFilteredByDate) { foreach (var term in modelInput.FilterTerms) { var distinctMatchedDescription = GetMatchedDistinctDescription(record.Description, term); record.DistinctDescription = distinctMatchedDescription; if (string.IsNullOrEmpty(distinctMatchedDescription)) { continue; } if (matchedRecords.ContainsKey(distinctMatchedDescription)) { matchedRecords[distinctMatchedDescription].Add(record); } else { matchedRecords.Add(distinctMatchedDescription, new List <IRecord>() { record }); } break; } } return(matchedRecords.Any()); }
public override IModelOutput Analyze(IModelInput input) { var accountConductInput = input as AccountConductInput; if (accountConductInput == null) { throw new BsaInputParameterException("The parameter AccountConductInput cannot be null."); } var dateRangeInDays = accountConductInput.DateRangeInDays; if (dateRangeInDays == 0) { throw new BsaInputParameterException("The DateRangeInDays value cannot be 0 or less than 0."); } if (accountConductInput.FilterType != FilterType.FilterIn) { throw new BsaInputParameterException("The FilterType value must be FilterIn"); } if (accountConductInput.FilterPolarity != FilterPolarity.NegativeValues) { throw new BsaInputParameterException("The FilterPolarity value for this model must be Nagative"); } if (input.BankRecords == null) { throw new BsaInputParameterException("The BankRecords value cannot be null"); } if (!input.BankRecords.Records.AnySave()) { throw new BsaInputParameterException("The records value cannot be null or empty"); } var leastDateTime = DateTime.UtcNow.AddDays(-dateRangeInDays); var recordsFilteredByDate = accountConductInput.BankRecords.Records.Where(record => DateTime.Compare(record.TransactionDate, leastDateTime) >= 0 && record.Amount < 0) .OrderBy(record => record.Description); IDictionary <string, IList <IRecord> > matchedRecords; if (!GetMatchedRecords(recordsFilteredByDate, accountConductInput, out matchedRecords)) { return(null); } //var summary //Output result 1 var groupSummaries = new List <AccountConductGroupSummary>(); foreach (var keyValuePair in matchedRecords) { var groupSummary = new AccountConductGroupSummary(); groupSummary.Records = keyValuePair.Value.ToList(); groupSummary.DistinctDescription = keyValuePair.Key; groupSummary.Count = keyValuePair.Value.Count; groupSummary.Sum = keyValuePair.Value.Sum(record => record.Amount); groupSummaries.Add(groupSummary); } //Output result 2 var allMatchedRecords = matchedRecords.Values.SelectMany(keyValue => keyValue).Where(value => value != null) .OrderByDescending(record => record.TransactionDate); var overallSum = allMatchedRecords.Sum(record => record.Amount); var overallCount = allMatchedRecords.Count(); var modeRecentRecord = allMatchedRecords.FirstOrDefault(); if (modeRecentRecord == null) { return(null); } var overallSummary = new AccountConductOverallSummary(); overallSummary.AccountConductGroupSummaries = groupSummaries; overallSummary.DateRangeInDays = input.DateRangeInDays; overallSummary.MostRecentAmount = modeRecentRecord.Amount; overallSummary.MostRecentDate = modeRecentRecord.TransactionDate; overallSummary.DailySum = Math.Round(overallSum / input.DateRangeInDays, 4); overallSummary.DailyCount = Math.Round((double)overallCount / input.DateRangeInDays, 4); overallSummary.Sum = overallSum; overallSummary.Count = overallCount; overallSummary.Records = allMatchedRecords.ToList(); return(overallSummary); }
public abstract IModelOutput Analyze(IModelInput input);
public override IModelOutput Analyze(IModelInput input) { var accountConductInput = input as AccountConductInput; if (accountConductInput == null) { throw new BsaInputParameterException("The parameter AccountConductInput cannot be null."); } var dateRangeInDays = accountConductInput.DateRangeInDays; if (dateRangeInDays == 0) { throw new BsaInputParameterException("The DateRangeInDays value cannot be 0 or less than 0."); } if (accountConductInput.FilterType != FilterType.FilterIn) { throw new BsaInputParameterException("The FilterType value must be FilterIn"); } if (accountConductInput.FilterPolarity != FilterPolarity.NegativeValues) { throw new BsaInputParameterException("The FilterPolarity value for this model must be Nagative"); } if (input.BankRecords == null) { throw new BsaInputParameterException("The BankRecords value cannot be null"); } if (!input.BankRecords.Records.AnySave()) { throw new BsaInputParameterException("The records value cannot be null or empty"); } var leastDateTime = DateTime.UtcNow.AddDays(-dateRangeInDays); var recordsFilteredByDate = accountConductInput.BankRecords.Records.Where(record => DateTime.Compare(record.TransactionDate, leastDateTime) >= 0 && record.Amount<0) .OrderBy(record=>record.Description); IDictionary<string, IList<IRecord>> matchedRecords; if (!GetMatchedRecords(recordsFilteredByDate, accountConductInput, out matchedRecords)) { return null; } //var summary //Output result 1 var groupSummaries = new List<AccountConductGroupSummary>(); foreach (var keyValuePair in matchedRecords) { var groupSummary = new AccountConductGroupSummary(); groupSummary.Records = keyValuePair.Value.ToList(); groupSummary.DistinctDescription = keyValuePair.Key; groupSummary.Count = keyValuePair.Value.Count; groupSummary.Sum = keyValuePair.Value.Sum(record => record.Amount); groupSummaries.Add(groupSummary); } //Output result 2 var allMatchedRecords = matchedRecords.Values.SelectMany(keyValue => keyValue).Where(value=>value!=null) .OrderByDescending(record=>record.TransactionDate); var overallSum = allMatchedRecords.Sum(record => record.Amount); var overallCount = allMatchedRecords.Count(); var modeRecentRecord = allMatchedRecords.FirstOrDefault(); if (modeRecentRecord == null) { return null; } var overallSummary = new AccountConductOverallSummary(); overallSummary.AccountConductGroupSummaries = groupSummaries; overallSummary.DateRangeInDays = input.DateRangeInDays; overallSummary.MostRecentAmount = modeRecentRecord.Amount; overallSummary.MostRecentDate = modeRecentRecord.TransactionDate; overallSummary.DailySum = Math.Round(overallSum / input.DateRangeInDays,4); overallSummary.DailyCount = Math.Round((double)overallCount / input.DateRangeInDays,4); overallSummary.Sum = overallSum; overallSummary.Count = overallCount; overallSummary.Records = allMatchedRecords.ToList(); return overallSummary; }
public AnalyzerInput(IModel model, IModelInput input) { Model = model; ModelInput = input; }
public override IModelOutput Analyze(IModelInput input) { throw new NotImplementedException(); }