/// <summary> /// Calcualtes which cluster the lcoaiton point belongs to, if none found a cluster is made with the lcoation point being the only memeber /// </summary> /// <returns> Temp: JSON object of the cluster </returns> public string Calculate_Cluster() { //ReadMOCKLocaitonsLocaitons(); bool cluster_found = false; foreach (Location location in LocationList) { if (Clusters != null) { //location.Carrier_Data_Point = point.Carrier; foreach (Cluster cluster in Clusters) { cluster_found = cluster.Check_If_Belong(location); if (cluster_found) { cluster.AddLocation(location); cluster.Structurize(); break; } } } else { Clusters = new List <Cluster>(); } // location didnt fit into any cluster, create its own if (!cluster_found) { if (!TestMode) { Clusters.Add(new Cluster(location, DatabaseEngine.Get_Cluster_ID(), DatabaseEngine)); } else { Clusters.Add(new Cluster(location, 1, DatabaseEngine)); Clusters[Clusters.Count - 1].Structurize(); } } } //temp string output = ""; int clustercount = 0; if (!TestMode) { foreach (Cluster cluster in Clusters) { output += "Cluster: " + clustercount; foreach (Location loc in cluster.Coordinates) { output += loc.ToString(); } clustercount++; output += "\n\n"; DatabaseEngine.Insert_Cluster(cluster); } } return(output); }