/// <summary> /// Extract data from text rows /// </summary> /// <param name="dataInfo">string data</param> /// <returns>array of data row</returns> internal KeyValuePairTable <int, DateTime, float, bool>[] ExtractTableData(StringBuilder[] dataInfo) { StringBuilder all = new StringBuilder(); // union data foreach (StringBuilder page in dataInfo) { all.Append(page); } // convert to array of string string[] rows = all .ToString() .Trim('\n') .Replace("\r", "") .Split('\n'); // create array of data var data = new KeyValuePairTable <int, DateTime, float, bool> [rows.Length]; // convert strint into data using multithreading Parallel.For(0, rows.Length, i => { var temp = rows[i].Trim().Split(' '); int.TryParse(temp[0], out int key); DateTime.TryParse(temp[1] + " " + temp[2], out DateTime datetime); float.TryParse(temp[3].Replace('.', ','), out float value); data[i] = new KeyValuePairTable <int, DateTime, float, bool>(key, datetime, value, temp.Length == 5); }); return(data); }
/// <summary> /// Parsing data of pdf-file from tables /// </summary> internal void ParsingFile() { stream.Position = 0; using (var reader = new PdfReader(stream)) using (var pdf = new PdfDocument(reader)) { reader.SetCloseStream(false); PageCount = pdf.GetNumberOfPages(); // get every page for analyse PdfPage[] pages = Enumerable .Range(0, PageCount) .Select(t => pdf.GetPage(t + 1)) .ToArray(); // data of every page (two diferent variants) HeadInfo = ParsingHeader(pages[0]); // find the limits { Regex regex = new Regex(@"З(\s*)а(\s*)д(\s*)а(\s*)н(\s+)д(\s*)и(\s*)а(\s*)п(\s*)а(\s*)з(\s*)о(\s*)н(\s+)т(\s*)е(\s*)м(\s*)п(\s*)е(\s*)р(\s*)а(\s*)т(\s*)у(\s*)р(\s+)м(\s*)е(\s*)ж(\s*)д(\s*)у(\s*):(\s+[+-]?\d+)°C и(\s+[+-]?\d+)°C", RegexOptions.IgnoreCase | RegexOptions.Compiled); Match match = regex.Match(HeadInfo.ToString()); string findS = match.Value; regex = new Regex(@"([+-]?\d+)", RegexOptions.Compiled); MatchCollection matches = regex.Matches(findS); List <float> results = new List <float>(); foreach (Match m in matches) { float.TryParse(m.Value, out float res); results.Add(res); } // save data LimitMin = results.Min(); LimitMax = results.Max(); } //TODO: delete last row for last page, when we will be create new pdf-file // data of names every columns ColumnInfo = ParsingColumns(pages[0]); // data from tables DataInfo = new StringBuilder[PageCount - 1]; // analyse tables all page without last using multithreading Parallel.For(0, DataInfo.Length, i => DataInfo[i] = ParsingTables(pages[i])); // convert string data to real data TableData = ExtractTableData(DataInfo); // save data TableDataBlock = new KeyValuePairTable <int, DateTime, float, bool> [TableData.Length]; TableData.CopyTo(TableDataBlock, 0); // data of Oy axis OyAxisInfo = ParsingOyAxis(pages[PageCount - 1]); // convert string data to real data DataOyAxis = ExtractOyAxis(OyAxisInfo); // data of Ox axis OxAxisInfo = ParsingOxAxis(pages[PageCount - 1]); // convert string data to real data DataOxAxis = ExtractOxAxis(OxAxisInfo); pdf.Close(); } }