public List <Stat> GetDocumentStats() { var results = table.AsEnumerable() .GroupBy(r => r.Field <string>("uploadedBy")) .Select(group => { Stat stat = new Stat(); stat.uploadedBy = group.Key; stat.fileCount = group.Count(); stat.totalFileSize = group.Sum(r => (long)r["fileSize"]); stat.totalAmount = group.Sum(r => ForexHelper.ToUSDAmount((decimal)r["totalAmount"], (string)r["currency"])); stat.totalAmountDue = group.Sum(r => ForexHelper.ToUSDAmount((decimal)r["totalAmountDue"], (string)r["currency"])); stat.documents = group.Select(r => { StatDocument doc = new StatDocument { id = (long)r[COLUMN_ID], uploadedTimeStamp = (DateTime)r["uploadedTimeStamp"], invoiceDate = (DateTime)r["invoiceDate"], vendorName = (string)r["vendorName"] }; return(doc); }).ToArray(); return(stat); }).ToList(); return(results); }
public void SaveForexData_Splitted60DataProvided_ShouldSetCorrectNamesFile() { var data = _service.PrepareData(60); _service.SaveForexData(data, 60, "SomePath"); _treeRepositoryMock.VerifySet(x => x.NamesFileContents = ForexHelper.BuildForexNamesFile(), Times.Once()); }
public void SaveForexData(IList <ForexDto> forexRecords, int period, string path) { _forexTreeDataRepository.Path = path; _forexTreeDataRepository.NamesFileContents = ForexHelper.BuildForexNamesFile(); foreach (var record in forexRecords) { _forexTreeDataRepository.CollectionName = Path.Combine(period.ToString(), "Forex_" + record.FileName); _forexTreeDataRepository.SaveData(record.ForexData); } }
public List <ForexDto> PrepareData(int splitPeriodSeconds) { var forexRecords = _forexCsvRepository.CsvLinesNormalized; var firstRecord = forexRecords[0]; var options = ForexHelper.InitializeForexTrackData(firstRecord); int index = 0; var forexSplitData = new List <ForexDto>(); var currentDto = new ForexDto { FileName = index.ToString(), ForexData = new List <ForexTreeData>() }; DateTime differenceTime = DateTime.ParseExact(firstRecord.Date, "yyyyMMdd HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture); for (var i = 0; i < forexRecords.Count; i++) { var record = forexRecords[i]; var dateTime = DateTime.ParseExact(record.Date, "yyyyMMdd HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture).Subtract(differenceTime); var seconds = (int)dateTime.TotalSeconds; if (seconds >= splitPeriodSeconds) { if (i < forexRecords.Count) { differenceTime = DateTime.ParseExact(forexRecords[i + 1].Date, "yyyyMMdd HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture); } options = ForexHelper.InitializeForexTrackData(record, options); forexSplitData.Add(currentDto); ForexHelper.SetCorrectMarketActions(currentDto); index++; currentDto = new ForexDto { FileName = index.ToString(), ForexData = new List <ForexTreeData>() }; } var treeRecord = ForexHelper.BuildForexTreeRecord(record, options); currentDto.ForexData.Add(treeRecord); options.CurrentRecord++; } if (forexSplitData.Contains(currentDto)) { return(forexSplitData); } forexSplitData.Add(currentDto); ForexHelper.SetCorrectMarketActions(currentDto); return(forexSplitData); }
public void PreviousSpreadIsZero_ShoudGetCorrectSpreadChange() { var record = new ForexRecord { Ask = 1.02, Bid = 1.01, CurrencyPair = "EURUSD", Date = "123" }; var options = new ForexTrackData { PreviousSpread = 0.0 }; var forexTreeData = ForexHelper.BuildForexTreeRecord(record, options); Assert.AreEqual(0.0, forexTreeData.SpreadChange); }