Пример #1
0
        /// <summary>
        /// Gets the available sub data choices for the given data type.
        /// </summary>
        /// <param name="dataType">The data type to get the sub data choices for.</param>
        /// <returns>All available sub information.</returns>
        public static string[] GetSubDataChoices(HeatDataType dataType)
        {
            switch (dataType)
            {
            case HeatDataType.PolledLocation: return(Enum.GetNames(typeof(LocationDatapoint.LocationDataType)).ToArray());

            case HeatDataType.TimeIndependentTripData: return(Enum.GetNames(typeof(TimeIndependentTripDataPoint.TripDataType)).ToArray());

            case HeatDataType.StorageLocationInfo: return(Enum.GetNames(typeof(StorageLocationInfoDatapoint.StorageLocationInfoType)).ToArray());

            default: throw new ArgumentException("Unknown data-type: " + dataType);
            }
        }
Пример #2
0
        /// <summary>
        /// Extracts the datatype information from a heat statistics file.
        /// </summary>
        /// <param name="file">The file to determine the datatype for.</param>
        /// <returns>The data contained in the heat file.</returns>
        public static HeatDataType ParseHeatDataType(string file)
        {
            HeatDataType dataType = HeatDataType.PolledLocation;

            using (StreamReader sr = new StreamReader(file))
            {
                string content  = sr.ReadToEnd();
                int    tagStart = content.IndexOf(IOConstants.STAT_HEAT_TAG_START);
                int    tagEnd   = content.IndexOf(IOConstants.STAT_HEAT_TAG_END);
                if (tagStart < 0 || tagEnd < 0)
                {
                    throw new FormatException("Could not find heat data type identifier!");
                }
                string ident        = content.Substring(tagStart, tagEnd - tagStart).Replace(IOConstants.STAT_HEAT_TAG_START, "").Replace(IOConstants.STAT_HEAT_TAG_END, "");
                bool   parseSuccess = Enum.TryParse(ident, out dataType);
                if (!parseSuccess)
                {
                    throw new FormatException("Could not recognize heat data type of file: " + ident);
                }
            }
            return(dataType);
        }
Пример #3
0
        /// <summary>
        /// Read the datapoints from the location file.
        /// </summary>
        /// <param name="file">The path to the data-file.</param>
        private void ReadDataPoints(string file)
        {
            // Identify data type
            _dataType = ParseHeatDataType(file);
            // Init data
            _dataPoints = new List <HeatDatapoint>();
            if (_config.InitialBotPositions != null)
            {
                // Only use the initial bot positions
                _dataPoints.AddRange(_config.InitialBotPositions.Where(t => t.Item1 == _tier.GetInfoID())
                                     .Select(t => new LocationDatapoint()
                {
                    Tier = _tier.GetInfoID(), TimeStamp = 0, X = t.Item2, Y = t.Item3
                }));
            }
            else
            {
                // Read data
                using (StreamReader sr = new StreamReader(file))
                {
                    string line = "";
                    while ((line = sr.ReadLine()) != null)
                    {
                        line = line.Trim();
                        // Skip empty and comment lines
                        if (line.StartsWith(IOConstants.COMMENT_LINE) || string.IsNullOrWhiteSpace(line))
                        {
                            continue;
                        }

                        // Parse data
                        switch (_dataType)
                        {
                        case HeatDataType.PolledLocation:
                        {
                            LocationDatapoint datapoint = LocationDatapoint.FromCSV(line);
                            // Only add datapoint, if it belongs to the set of task types that shall be considered
                            if (_config.BotTaskFilter.Contains(datapoint.BotTask))
                            {
                                // Only add datapoint, if it belongs to the set time window (if a window is specified)
                                if (_config.DataTimeFilterLow == _config.DataTimeFilterHigh || _config.DataTimeFilterLow <= datapoint.TimeStamp && datapoint.TimeStamp < _config.DataTimeFilterHigh)
                                {
                                    // The datapoint made it through all filters - add it
                                    _dataPoints.Add(datapoint);
                                }
                            }
                        }
                        break;

                        case HeatDataType.TimeIndependentTripData:
                        {
                            _dataPoints.Add(TimeIndependentTripDataPoint.FromCSV(line));
                        }
                        break;

                        case HeatDataType.StorageLocationInfo:
                        {
                            StorageLocationInfoDatapoint datapoint = StorageLocationInfoDatapoint.FromCSV(line);
                            // Only add datapoint, if it belongs to the set time window (if a window is specified)
                            if (_config.DataTimeFilterLow == _config.DataTimeFilterHigh || _config.DataTimeFilterLow <= datapoint.TimeStamp && datapoint.TimeStamp < _config.DataTimeFilterHigh)
                            {
                                // The datapoint made it through all filters - add it
                                _dataPoints.Add(datapoint);
                            }
                        }
                        break;

                        default: throw new ArgumentException("Unknown data type: " + _dataType.ToString());
                        }
                    }
                }
            }
            // Remark success
            if (_dataPoints.Any())
            {
                _anyData = true;
            }
            else
            {
                _anyData = false;
            }
        }