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; }
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); }); }
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); }
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); }
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)); }
// Use this for initialization public void SetResearchObject(ResearchObject obj) { }