private void GetObjectsFromFile(string path)
        {
            _firstFeatureMin  = double.MaxValue;
            _firstFeatureMax  = double.MinValue;
            _secondFeatureMin = double.MaxValue;
            _secondFeatureMax = double.MinValue;
            var objects = new List <ResearchObject>();

            using (StreamReader streamReader = new StreamReader(path))
            {
                string line    = streamReader.ReadLine();
                var    headers = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                _firstFeature  = headers[0];
                _secondFeature = headers[1];
                int lastId = 0;
                while ((line = streamReader.ReadLine()) != null)
                {
                    var    splitedLine   = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    double firstFeature  = double.Parse(splitedLine[0]);
                    double secondFeature = double.Parse(splitedLine[1]);

                    if (firstFeature < _firstFeatureMin)
                    {
                        _firstFeatureMin = firstFeature;
                    }
                    if (firstFeature > _firstFeatureMax)
                    {
                        _firstFeatureMax = firstFeature;
                    }
                    if (secondFeature < _secondFeatureMin)
                    {
                        _secondFeatureMin = secondFeature;
                    }
                    if (secondFeature > _secondFeatureMax)
                    {
                        _secondFeatureMax = secondFeature;
                    }

                    string mark = "";
                    if (headers.Length == 3 && splitedLine.Length == 3)
                    {
                        mark = splitedLine[2];
                    }
                    else
                    {
                        mark = lastId.ToString();
                        lastId++;
                    }
                    var obj = new ResearchObject(mark, new List <double>()
                    {
                        firstFeature, secondFeature
                    });
                    objects.Add(obj);
                }
            }
            _objectAmount = objects.Count;
            _objects      = objects;
        }
Пример #2
0
 void Start()
 {
     ros = ResearchObject.LoadAllFromFile();
     Debug.Log(ros.Count);
     ros.ForEach(ro => {
         GameObject panel       = (GameObject)Instantiate(prefab);
         panel.transform.parent = this.transform;
         panel.GetComponent <ResearchPanel> ().SetResearchObject(ro);
     });
 }
Пример #3
0
        public static ResearchObject ToResearchObject(this ResearchObjectEntity newEntity, ResearchObject oldEntity = null)
        {
            ResearchObject entity = oldEntity;

            if (entity == null)
            {
                entity = new ResearchObject();
            }
            entity.Name = newEntity.Name;

            return(entity);
        }
Пример #4
0
        public static ResearchObjectEntity ToResearchObjectEntity(this ResearchObject model)
        {
            if (model == null)
            {
                return(null);
            }

            ResearchObjectEntity entity = new ResearchObjectEntity();

            entity.Id   = model.Id;
            entity.Name = model.Name;
            return(entity);
        }
Пример #5
0
        public static double GetDistance(ResearchObject x, ResearchObject y)
        {
            if (x.Features.Count != y.Features.Count)
            {
                throw new Exception("Objects dimentions don't match!");
            }

            int    featuresCount = x.Features.Count;
            double distance      = 0;

            for (int i = 0; i < featuresCount; i++)
            {
                distance += Math.Pow((x.Features[i] - y.Features[i]), 2);
            }

            return(Math.Sqrt(distance));
        }
Пример #6
0
 // Use this for initialization
 public void SetResearchObject(ResearchObject obj)
 {
 }