//public Measure ProcessLine(string line, string fileName, ApiPlant plant) public Measure ProcessLine(DateTime ProdDate, double measure, ApiPlant plant) { var source = _confProvider.GetMeasureSourceFor1HResolution(); var datavariable = _confProvider.GetDataVariable(); var resolution = _confProvider.GetResolution(); var utcDateTime = extractUtcDateFromFileLine(ProdDate, plant.TimeZone); var utcDate = string.Format("{0:yyyyMMdd}", utcDateTime.Date); var utcHour = utcDateTime.Hour; var utcMinute = utcDateTime.Minute; var utcSecond = utcDateTime.Second; // convert from MW to KW var multiplier = _confProvider.GetMeasureValueMultiplier(); var value = measure * multiplier; var percentage = 1; var reliability = 0; return new Measure(plant.Id, source, datavariable, utcDate, utcHour, utcMinute, utcSecond, value, percentage, reliability, resolution); }
private void processFile(string filenamePath, ApiPlant plant) { FileStream _fileStream = new FileStream(filenamePath, FileMode.Open, FileAccess.Read); IWorkbook _workbook = WorkbookFactory.Create(_fileStream); _fileStream.Close(); // End initialize string sheetName = findCurrentSheet(_workbook); if (sheetName == " ") { _logger.Warn("No sheet name matched current month"); var processedFileTextToAppend = _configProvider.GetFtpProcessedFilesPath(); _ftpClient.MoveFtpProcessedFile(filenamePath, processedFileTextToAppend, ".nodata"); return; } ISheet _workSheet = _workbook.GetSheet(sheetName); IList<Measure> measures = getAllMeasuresFromSheet(_workSheet, plant); if (measures == null || !measures.Any()) { _logger.Warn("No measures found inside the file"); // jvr we check as processed even when no data is found var processedFileTextToAppend = _configProvider.GetFtpProcessedFilesPath(); _ftpClient.MoveFtpProcessedFile(filenamePath, processedFileTextToAppend, ".nodata"); return; } _logger.InfoFormat("Found {0} measures to send", measures.Count); sendMeasures(filenamePath, measures); }
public void iterateData() { var mockConfigProvider = new Mock<IConfigurationProvider>(); mockConfigProvider.Setup(x => x.GetHourlyPlantsString()).Returns("MAREE01"); mockConfigProvider.Setup(x => x.GetMeasureSourceFor1HResolution()).Returns("CLIENTE1H"); mockConfigProvider.Setup(x => x.GetDataVariable()).Returns("E"); mockConfigProvider.Setup(x => x.GetResolution()).Returns("1H"); mockConfigProvider.Setup(x => x.GetEXIMToGnarumOffsetHours()).Returns(-1); mockConfigProvider.Setup(x => x.GetMeasureValueMultiplier()).Returns(1000); var apiPlant = new ApiPlant { Id = "NALBAN01", Technology = "EO", CountryCode = "ES", RegionCode = "28", TimeZone = "E. Europe Standard Time", Latitude = 40.4293, Longitude = -3.6574, Power = 22668 }; var mockPlantService = new Mock<IPlantService>(); mockPlantService.Setup(x => x.GetPlant("NALBAN01")).Returns(apiPlant); string filenamePath = @"TestData\Production NALBANT Jan-Jul22 2015.xls"; FileStream _fileStream = new FileStream(filenamePath, FileMode.Open, FileAccess.Read); IWorkbook _workbook = WorkbookFactory.Create(_fileStream); _fileStream.Close(); //formulas of the Workbook are evaluated and an instance of a data formatter is created IFormulaEvaluator formulaEvaluator = new HSSFFormulaEvaluator(_workbook); DataFormatter dataFormatter = new HSSFDataFormatter(new CultureInfo("en-US")); MeasureFileExtracter measureFile = new MeasureFileExtracter(mockConfigProvider.Object, mockPlantService.Object); // End initialize ISheet _worksheet = _workbook.GetSheet("Iul 2015"); int FirstRow = 0; int LastDay = 0; foreach (IRow row in _worksheet) { //Index to find sheet header (first row) if (row.GetCell(0) != null && row.GetCell(1).NumericCellValue == 1) { FirstRow = row.RowNum; int c = 1; //Index to find last column (day) with value while (row.GetCell(c).NumericCellValue <= 31) { LastDay = row.GetCell(c).ColumnIndex; //check that there is some value for the iterated day by going to the SUM cell at the end if (_worksheet.GetRow(FirstRow + 25).GetCell(c).NumericCellValue == 0) { break; } c++; } break; } } //DataTable results = new DataTable(); //results.Columns.Add("Date", typeof(DateTime)); //results.Columns.Add("Value", typeof(double)); DateTime now = DateTime.Now; DateTime ProdDate = new DateTime(now.Year, now.Month, 1); DateTime InitialDate = new DateTime(now.Year, now.Month, 1); bool TheEnd = false; double Data = 0; var result = new List<Measure>(); //start iteration per day for (int day = 1; day <= LastDay; day++) { //get every hour in the sheet for (int hour = 1; hour <= 24; hour++) { //it will finish reading when a blank cell is found var check = _worksheet.GetRow(FirstRow + hour).GetCell(day); if (check.ToString() == "") { TheEnd = true; break; } Data = _worksheet.GetRow(FirstRow + hour).GetCell(day).NumericCellValue; // ProdDate = ProdDate(now.Year, now.Month, 1); ProdDate = InitialDate.Date.AddDays(day - 1).AddHours(hour); var measure = measureFile.ProcessLine(ProdDate, Data, apiPlant); result.Add(measure); } if (TheEnd == true) { break; } } Assert.AreEqual(Data, 0.254); }
private IList<Measure> getAllMeasuresFromSheet(ISheet WorkSheet, ApiPlant Plant) { // first iteration to extract row and column index from the measure´s table int FirstRow = 0; int LastDay = 0; foreach (IRow row in WorkSheet) { //Index to find sheet header (first row) if (row.GetCell(0) != null && row.GetCell(1).NumericCellValue == 1) { FirstRow = row.RowNum; int c = 1; //Index to find last column (day) with value while (row.GetCell(c).NumericCellValue <= 31) { LastDay = row.GetCell(c).ColumnIndex; //check that there is some value for the iterated day by going to the SUM cell at the end if (WorkSheet.GetRow(FirstRow + 25).GetCell(c).NumericCellValue == 0) { break; } c++; } break; } } // set current month DateTime now = DateTime.Now; DateTime ProdDate = new DateTime(now.Year, now.Month, 1); DateTime InitialDate = new DateTime(now.Year, now.Month, 1); // initialize variables bool TheEnd = false; double Data = 0; var result = new List<Measure>(); //start iteration per day for (int day = 1; day <= LastDay; day++) { //get every hour in the sheet for (int hour = 1; hour <= 24; hour++) { //it will finish reading when a blank cell is found var check = WorkSheet.GetRow(FirstRow + hour).GetCell(day); if (check.ToString() == "") { TheEnd = true; break; } Data = WorkSheet.GetRow(FirstRow + hour).GetCell(day).NumericCellValue; // ProdDate = ProdDate(now.Year, now.Month, 1); ProdDate = InitialDate.Date.AddDays(day - 1).AddHours(hour); var measure = _fileExtracter.ProcessLine(ProdDate, Data, Plant); result.Add(measure); } if (TheEnd == true) { break; } } return result; }