public virtual void LoadSkimMatrices(IEnumerable <RosterEntry> entries, Dictionary <int, int> zoneMapping, Dictionary <int, int> transitStopAreaMapping, Dictionary <int, int> microzoneMapping)
        {
            SkimMatrices = new SkimMatrix[MatrixKeys.Length];

//			var cache = new Dictionary<string, List<float[]>>();
            var cache = new Dictionary <string, List <double[]> >();          // 20150703 JLB

            var currentFileName = "";

            foreach (var entry in entries.Where(x => x.FileType != null).Select(x => new { x.Name, x.Field, x.FileType, x.MatrixIndex, x.Scaling, x.Length }).Distinct().OrderBy(x => x.Name))
            {
                ISkimFileReader skimFileReader = null;

                //Issue #40 -- caching is to prevent same file from being read in multiple times. Can clear cache when we change files since group by name
                if (!entry.Name.Equals(currentFileName))
                {
                    cache.Clear();
                    currentFileName = entry.Name;
                }
                IFileReaderCreator creator = Global.Kernel.Get <SkimFileReaderFactory>().GetFileReaderCreator(entry.FileType);

                /*switch (entry.FileType) {
                 *      case "text_ij":
                 *              skimFileReader = new TextIJSkimFileReader(cache, _path, mapping);
                 *              break;
                 *      case "bin":
                 *              skimFileReader = new BinarySkimFileReader(_path, mapping);
                 *              break;
                 * }*/

                if (creator == null)
                {
                    if (entry.FileType == "deferred")
                    {
                        continue;
                    }

                    throw new SkimFileTypeNotSupportedException(string.Format("The specified skim file type of \"{0}\" is not supported.", entry.FileType));
                }
                Dictionary <int, int> mapping = zoneMapping;

                bool useTransitStopAreaMapping = (entry.Length == "transitstop");
                if (useTransitStopAreaMapping)
                {
                    mapping = transitStopAreaMapping;
                }

                bool useMicrozoneMapping = (entry.Length == "microzone");
                if (useMicrozoneMapping)
                {
                    mapping = microzoneMapping;
                }

                skimFileReader = creator.CreateReader(cache, _path, mapping);

                var skimMatrix = skimFileReader.Read(entry.Name, entry.Field, (float)entry.Scaling);

                SkimMatrices[entry.MatrixIndex] = skimMatrix;
            }

            foreach (
                var entry in
                entries.Where(x => x.FileType == null)
                .Select(x => new { x.Name, x.Field, x.FileType, x.MatrixIndex, x.Scaling, x.Length })
                .Distinct()
                .OrderBy(x => x.Name))
            {
                var skimMatrix = new SkimMatrix(null);
                SkimMatrices[entry.MatrixIndex] = skimMatrix;
            }
        }
Beispiel #2
0
        public virtual void LoadSkimMatrices(IEnumerable <RosterEntry> entries, Dictionary <int, int> zoneMapping, Dictionary <int, int> transitStopAreaMapping, Dictionary <int, int> microzoneMapping)
        {
            SkimMatrices = new SkimMatrix[MatrixKeys.Length];

            //            var cache = new Dictionary<string, List<float[]>>();
            var cache = new Dictionary <string, List <double[]> >(); // 20150703 JLB

            var currentFileName = "";

            foreach (var entry in entries.Where(x => x.FileType != null).Select(x => new { x.Name, x.Field, x.FileType, x.MatrixIndex, x.Scaling, x.Length }).Distinct().OrderBy(x => x.Name))
            {
                ISkimFileReader skimFileReader = null;

                //Issue #40 -- caching is to prevent same file from being read in multiple times. Can clear cache when we change files since group by name
                if (!entry.Name.Equals(currentFileName))
                {
                    cache.Clear();
                    currentFileName = entry.Name;
                }
                IFileReaderCreator creator = Global.ContainerDaySim.GetInstance <SkimFileReaderFactory>().GetFileReaderCreator(entry.FileType);

                /*switch (entry.FileType) {
                 *  case "text_ij":
                 *      skimFileReader = new TextIJSkimFileReader(cache, _path, mapping);
                 *      break;
                 *  case "bin":
                 *      skimFileReader = new BinarySkimFileReader(_path, mapping);
                 *      break;
                 * }*/

                if (creator == null)
                {
                    if (entry.FileType == "deferred")
                    {
                        continue;
                    }

                    throw new SkimFileTypeNotSupportedException(string.Format("The specified skim file type of \"{0}\" is not supported.", entry.FileType));
                }
                Dictionary <int, int> mapping = zoneMapping;

                bool useTransitStopAreaMapping = (entry.Length == "transitstop");
                if (useTransitStopAreaMapping)
                {
                    mapping = transitStopAreaMapping;
                }

                bool useMicrozoneMapping = (entry.Length == "microzone");
                if (useMicrozoneMapping)
                {
                    mapping = microzoneMapping;
                }

                skimFileReader = creator.CreateReader(cache, _path, mapping);

                var scaleFactor = (float)entry.Scaling;
                var skimMatrix  = skimFileReader.Read(entry.Name, entry.Field, scaleFactor);

                SkimMatrices[entry.MatrixIndex] = skimMatrix;

                //new code - report a summary of the skim matrix data
                var    numZones    = mapping.Count;
                var    numPositive = 0;
                double avgPositive = 0;
                for (var row = 0; row < numZones; row++)
                {
                    for (var col = 0; col < numZones; col++)
                    {
                        var value = skimMatrix.GetValue(row, col);
                        if (value > Constants.EPSILON)
                        {
                            numPositive++;
                            avgPositive += value / scaleFactor;
                        }
                    }
                }
                var pctPositive = Math.Round(numPositive * 100.0 / (numZones * numZones));
                var avgValue    = avgPositive / Math.Max(numPositive, 1);
                Global.PrintFile.WriteLine("Skim File {0}, {1} percent of values are positive, with average value {2}.", entry.Name, pctPositive, avgValue);
            }

            foreach (
                var entry in
                entries.Where(x => x.FileType == null)
                .Select(x => new { x.Name, x.Field, x.FileType, x.MatrixIndex, x.Scaling, x.Length })
                .Distinct()
                .OrderBy(x => x.Name))
            {
                var skimMatrix = new SkimMatrix(null);
                SkimMatrices[entry.MatrixIndex] = skimMatrix;
            }
        }