コード例 #1
0
        public void SumChecker()
        {
            const string startpath = @"D:\LPGUnitTest\JsonCalculatorTest.EndToEndTest\results";
            var          di        = new DirectoryInfo(startpath);
            var          subdirs   = di.GetDirectories();

            foreach (DirectoryInfo subdir in subdirs)
            {
                var resultDirs = subdir.GetDirectories("Results");
                if (resultDirs.Length != 1)
                {
                    Logger.Info("No Results found in " + subdir.FullName);
                    continue;
                }

                var resultFiles = resultDirs[0].GetFiles("*.csv");
                List <CSVProfileReader> csvs = new List <CSVProfileReader>();
                foreach (FileInfo info in resultFiles)
                {
                    csvs.Add(CSVProfileReader.ReadFile(info.FullName));
                }

                var loadTypes = csvs.Select(x => x.Loadtype ?? throw new LPGException("lt was null")).Distinct().ToList();
                foreach (string loadType in loadTypes)
                {
                    var filtered = csvs.Where(x => x.Loadtype == loadType).ToList();
                    foreach (var reader in filtered)
                    {
                        Logger.Info(reader.Filename);
                    }
                }
            }
        }
コード例 #2
0
        public static CSVProfileReader ReadFile([JetBrains.Annotations.NotNull] string filename)
        {
            FileInfo fi = new FileInfo(filename);

            Logger.Info("Reading " + fi.Name);
            var filearr         = fi.Name.Split('.');
            CSVProfileReader cp = new CSVProfileReader(fi.Name, fi.FullName);

            if (filearr[0] == "Overall" && filearr[1] == "SumProfiles")
            {
                cp.Loadtype = filearr[2];
                cp.FileType = FileTypeEnum.Overall;
            }
            else if (filearr[0] == "SumProfiles" && filearr.Length == 4)
            {
                cp.Loadtype  = filearr[2];
                cp.FileType  = FileTypeEnum.SumProfile;
                cp.Household = filearr[1];
            }
            else
            {
                throw new LPGException("Unknown file type: " + fi.Name);
            }
            StreamReader sr     = new StreamReader(filename);
            string?      header = sr.ReadLine();

            if (header == null)
            {
                throw new LPGException("Header was null");
            }
            var headerarr = header.Split(';');

            cp.Headers.AddRange(headerarr);
            while (!sr.EndOfStream)
            {
                string?line = sr.ReadLine();
                if (line == null)
                {
                    throw new LPGException("Line was null");
                }
                var arr = line.Split(';');
                if (arr.Length > 2)
                {
                    cp.TimeSteps.Add(Convert.ToInt32(arr[0], CultureInfo.InvariantCulture));
                    cp.TimeStamps.Add(arr[1]);
                    var vals = new List <double>();
                    for (int i = 2; i < arr.Length; i++)
                    {
                        if (!string.IsNullOrWhiteSpace(arr[i]))
                        {
                            double d = Convert.ToDouble(arr[i], CultureInfo.InvariantCulture);
                            vals.Add(d);
                        }
                    }
                    cp.RowValues.Add(vals);
                }
            }
            sr.Close();
            double sum = 0;

            foreach (var row in cp.RowValues)
            {
                sum += row.Sum();
            }

            cp.SumAllValues = sum;
            return(cp);
        }