コード例 #1
0
ファイル: RowParser.cs プロジェクト: alsohas/forest_core
        private static DictTripStruct GetDictFromRow(TripStruct tripStruct, Dictionary <long, int> dictionary)
        {
            var d = new DictTripStruct();

            dictionary.TryGetValue(tripStruct.destination, out var destination);
            d.SetDestination(destination);
            d.priors = new int[tripStruct.priors.Length];
            for (var i = 0; i < tripStruct.priors.Length; i++)
            {
                d.priors[i] = dictionary[tripStruct.priors[i]];
            }
            return(d);
        }
コード例 #2
0
ファイル: RowParser.cs プロジェクト: alsohas/forest_core
        public static List <DictTripStruct> Read(int step)
        {
            var reverseMappedDict = DictGenerator.LoadReverseMappedDict();
            var allCSV            = new List <string>();
            var allRecord         = new List <DictTripStruct>();

            var baseFolderName = $"{Parameters.BaseFolder}map_matched_csv_{step}";
            var innerFolders   = Directory.GetDirectories(baseFolderName);

            foreach (var folder in innerFolders)
            {
                allCSV = allCSV.Concat(Directory.GetFiles(folder)).ToList();
            }

            using (var pbar = new ProgressBar(allCSV.Count, $"Step {step} CSV Files", new ProgressBarOptions()))
            {
                foreach (var csvFile in allCSV)
                {
                    using (var reader = new StreamReader(csvFile))
                        using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))
                        {
                            var records = csv.GetRecords <TripRow>();
                            foreach (var record in records)
                            {
                                record.FormatPriors();
                                var s = new TripStruct {
                                    priors = record.GetPriors(), destination = record.destination
                                };
                                var d = GetDictFromRow(s, reverseMappedDict);
                                allRecord.Add(d);
                            }
                        }

                    pbar.Tick();
                }
            }

            GC.Collect();
            return(allRecord);
        }