private bool Process(IBodyNameAndID sc, ISystem sys, bool reprocessPrimary = false) // background or foreground.. FALSE if you can't process it { SystemNode sn = GetOrCreateSystemNode(sys); ScanNode relatedScan = null; if ((sc.BodyDesignation == null || sc.BodyDesignation == sc.Body) && (sc.Body != sc.StarSystem || sc.BodyType != "Star")) { foreach (var body in sn.Bodies) { if ((body.fullname == sc.Body || body.customname == sc.Body) && (body.fullname != sc.StarSystem || (sc.BodyType == "Star" && body.level == 0) || (sc.BodyType != "Star" && body.level != 0))) { relatedScan = body; sc.BodyDesignation = body.fullname; break; } } } if (relatedScan == null) { foreach (var body in sn.Bodies) { if ((body.fullname == sc.Body || body.customname == sc.Body) && (body.fullname != sc.StarSystem || (sc.BodyType == "Star" && body.level == 0) || (sc.BodyType != "Star" && body.level != 0))) { relatedScan = body; break; } } } if (relatedScan != null && relatedScan.ScanData == null) { relatedScan.BodyLoc = sc; return(true); // We already have the scan } // handle Earth, starname = Sol // handle Eol Prou LW-L c8-306 A 4 a and Eol Prou LW-L c8-306 // handle Colonia 4 , starname = Colonia, planet 4 // handle Aurioum B A BELT // Kyloasly OY-Q d5-906 13 1 ScanNodeType starscannodetype = ScanNodeType.star; // presuming.. bool isbeltcluster = false; // Extract elements from name List <string> elements = ExtractElements(sc, sys, out isbeltcluster, out starscannodetype); // Bail out if no elements extracted if (elements.Count == 0) { System.Diagnostics.Trace.WriteLine($"Failed to add body {sc.Body} to system {sys.Name} - not enough elements"); return(false); } // Bail out if more than 5 elements extracted else if (elements.Count > 5) { System.Diagnostics.Trace.WriteLine($"Failed to add body {sc.Body} to system {sys.Name} - too deep"); return(false); } // Get custom name if different to designation string customname = GetCustomName(sc, sys); // Process elements ScanNode node = ProcessElements(sc, sys, sn, customname, elements, starscannodetype, isbeltcluster); if (node.BodyID != null) { sn.NodesByID[(int)node.BodyID] = node; } return(true); }
private bool Process(JournalScan sc, ISystem sys, bool reprocessPrimary = false) // background or foreground.. FALSE if you can't process it { SystemNode sn = GetOrCreateSystemNode(sys); // handle Earth, starname = Sol // handle Eol Prou LW-L c8-306 A 4 a and Eol Prou LW-L c8-306 // handle Colonia 4 , starname = Colonia, planet 4 // handle Aurioum B A BELT // Kyloasly OY-Q d5-906 13 1 ScanNodeType starscannodetype = ScanNodeType.star; // presuming.. bool isbeltcluster = false; // Extract elements from name List <string> elements = ExtractElements(sc, sys, out isbeltcluster, out starscannodetype); // Bail out if no elements extracted if (elements.Count == 0) { System.Diagnostics.Trace.WriteLine($"Failed to add body {sc.BodyName} to system {sys.Name} - not enough elements"); return(false); } // Bail out if more than 5 elements extracted else if (elements.Count > 5) { System.Diagnostics.Trace.WriteLine($"Failed to add body {sc.BodyName} to system {sys.Name} - too deep"); return(false); } // Get custom name if different to designation string customname = GetCustomName(sc, sys); // Process elements ScanNode node = ProcessElements(sc, sys, sn, customname, elements, starscannodetype, isbeltcluster); if (node.BodyID != null) { sn.NodesByID[(int)node.BodyID] = node; } // Process top-level star if (elements.Count == 1) { // Process any belts if present ProcessBelts(sc, node); // Process primary star in multi-star system if (elements[0].Equals("A", StringComparison.InvariantCultureIgnoreCase)) { CachePrimaryStar(sc, sys); // Reprocess if we've encountered the primary (A) star and we already have a "Main Star" if (reprocessPrimary && sn.starnodes.Any(n => n.Key.Length > 1 && n.Value.type == ScanNodeType.star)) { ReProcess(sn); } } } return(true); }
private List <string> ExtractElementsBodyAndID(IBodyNameAndID sc, ISystem sys, out bool isbeltcluster, out ScanNodeType starscannodetype) { starscannodetype = ScanNodeType.star; isbeltcluster = false; List <string> elements; string rest = IsStarNameRelatedReturnRest(sys.Name, sc.Body, sc.BodyDesignation); // extract any relationship between the system we are in and the name, and return it if so if (rest != null) // if we have a relationship.. { if (rest.Length > 0) { elements = rest.Split(' ').ToList(); if (elements.Count == 4 && elements[0].Length == 1 && char.IsLetter(elements[0][0]) && // A belt cluster N elements[1].Equals("belt", StringComparison.InvariantCultureIgnoreCase) && elements[2].Equals("cluster", StringComparison.InvariantCultureIgnoreCase)) { elements = new List <string> { MainStar, elements[0] + " " + elements[1], elements[2] + " " + elements[3] }; // reform into Main Star | A belt | Cluster N isbeltcluster = true; } else if (elements.Count == 5 && elements[0].Length >= 1 && // AA A belt cluster N elements[1].Length == 1 && char.IsLetter(elements[1][0]) && elements[2].Equals("belt", StringComparison.InvariantCultureIgnoreCase) && elements[3].Equals("cluster", StringComparison.InvariantCultureIgnoreCase)) { elements = new List <string> { elements[0], elements[1] + " " + elements[2], elements[3] + " " + elements[4] }; // reform into <star> | A belt | Cluster N isbeltcluster = true; } if (char.IsDigit(elements[0][0])) // if digits, planet number, no star designator { elements.Insert(0, MainStar); // no star designator, main star, add MAIN } else if (elements[0].Length > 1) // designator, is it multiple chars.. { starscannodetype = ScanNodeType.barycentre; } } else { elements = new List <string>(); // only 1 item, the star, which is the same as the system name.. elements.Add(MainStar); // Sol / SN:Sol should come thru here } } else { // so not part of starname elements = sc.Body.Split(' ').ToList(); // not related in any way (earth) so assume all bodyparts, and elements.Insert(0, MainStar); // insert the MAIN designator as the star designator } return(elements); }
private ScanNode ProcessElementsBodyAndID(IBodyNameAndID sc, ISystem sys, SystemNode sn, string customname, List <string> elements, ScanNodeType starscannodetype, bool isbeltcluster) { SortedList <string, ScanNode> currentnodelist = sn.StarNodes; // current operating node list, always made ScanNode previousnode = null; // trails subnode by 1 to point to previous node for (int lvl = 0; lvl < elements.Count; lvl++) { ScanNodeType sublvtype = starscannodetype; if (lvl > 0) { if (isbeltcluster) { sublvtype = lvl == 1 ? ScanNodeType.belt : ScanNodeType.beltcluster; } else { sublvtype = ScanNodeType.body; } } if (currentnodelist == null || !currentnodelist.TryGetValue(elements[lvl], out ScanNode subnode)) { if (currentnodelist == null) // no node list, happens when we are at least 1 level down as systemnode always has a node list, make one { currentnodelist = previousnode.Children = new SortedList <string, ScanNode>(new DuplicateKeyComparer <string>()); } string ownname = elements[lvl]; subnode = new ScanNode { OwnName = ownname, FullName = lvl == 0 ? (sys.Name + (ownname.Contains("Main") ? "" : (" " + ownname))) : previousnode.FullName + " " + ownname, ScanData = null, Children = null, NodeType = sublvtype, Level = lvl, }; currentnodelist.Add(ownname, subnode); } if (lvl == elements.Count - 1) { subnode.CustomName = customname; if (sc.BodyID != null) { subnode.BodyID = sc.BodyID; } if (sc.BodyType == "" || sc.BodyType == "Null" || sc.BodyType == "Barycentre") { subnode.NodeType = ScanNodeType.barycentre; } else if (sc.BodyType == "Belt") { subnode.NodeType = ScanNodeType.belt; } } previousnode = subnode; currentnodelist = previousnode.Children; } return(previousnode); }
public bool Process(JournalScan sc, EDDiscovery2.DB.ISystem sys) // FALSE if you can't process it { Tuple <string, long> withedsm = new Tuple <string, long>(sys.name, sys.id_edsm); Tuple <string, long> withoutedsm = new Tuple <string, long>(sys.name, 0); SystemNode sn; if (scandata.ContainsKey(withedsm)) // if with edsm (if id_edsm=0, then thats okay) { sn = scandata[withedsm]; } else if (scandata.ContainsKey(withoutedsm)) // if we now have an edsm id, see if we have one without it { sn = scandata[withoutedsm]; if (sys.id_edsm != 0) // yep, replace { scandata.Remove(new Tuple <string, long>(sys.name, 0)); scandata.Add(new Tuple <string, long>(sys.name, sys.id_edsm), sn); } } else { sn = new SystemNode() { system = sys, starnodes = new SortedList <string, ScanNode>(new DuplicateKeyComparer <string>()) }; scandata.Add(new Tuple <string, long>(sys.name, sys.id_edsm), sn); } // handle Earth, starname = Sol // handle Eol Prou LW-L c8-306 A 4 a and Eol Prou LW-L c8-306 // handle Colonia 4 , starname = Colonia, planet 4 // handle Aurioum B A BELT // Kyloasly OY-Q d5-906 13 1 List <string> elements; ScanNodeType starscannodetype = ScanNodeType.star; // presuming.. string rest = sc.IsStarNameRelatedReturnRest(sys.name); if (rest != null) // if we have a relationship.. { if (rest.Length > 0) { elements = rest.Split(' ').ToList(); if (char.IsDigit(elements[0][0])) // if digits, planet number, no star designator { elements.Insert(0, "Main Star"); // no star designator, main star, add MAIN } else if (elements[0].Length > 1) // designator, is it multiple chars.. { starscannodetype = ScanNodeType.barycentre; } } else { elements = new List <string>(); // only 1 item, the star, which is the same as the system name.. elements.Add("Main Star"); // Sol / SN:Sol should come thru here } } else { // so not part of starname elements = sc.BodyName.Split(' ').ToList(); // not related in any way (earth) so assume all bodyparts, and elements.Insert(0, "Main Star"); // insert the MAIN designator as the star designator } if (elements.Count >= 1) // okay, we have an element.. first is the star.. { ScanNode sublv0; if (!sn.starnodes.TryGetValue(elements[0], out sublv0)) // not found this node, add.. { sublv0 = new ScanNode() { ownname = elements[0], fullname = sys.name + (elements[0].Contains("Main") ? "" : (" " + elements[0])), scandata = null, children = null, type = starscannodetype }; sn.starnodes.Add(elements[0], sublv0); //System.Diagnostics.Debug.WriteLine("Added star " + star.fullname + " '" + star.ownname + "'" + " under '" + designator + "' type " + ty); } if (elements.Count >= 2) // we have a sub designator.. { ScanNode sublv1; if (sublv0.children == null || !sublv0.children.TryGetValue(elements[1], out sublv1)) { if (sublv0.children == null) { sublv0.children = new SortedList <string, ScanNode>(new DuplicateKeyComparer <string>()); } sublv1 = new ScanNode() { ownname = elements[1], fullname = sublv0.fullname + " " + elements[1], scandata = null, children = null, type = ScanNodeType.planet }; sublv0.children.Add(elements[1], sublv1); } if (elements.Count >= 3) { ScanNode sublv2; if (sublv1.children == null || !sublv1.children.TryGetValue(elements[2], out sublv2)) { if (sublv1.children == null) { sublv1.children = new SortedList <string, ScanNode>(new DuplicateKeyComparer <string>()); } sublv2 = new ScanNode() { ownname = elements[2], fullname = sublv0.fullname + " " + elements[1] + " " + elements[2], scandata = null, children = null, type = ScanNodeType.moon }; sublv1.children.Add(elements[2], sublv2); } if (elements.Count >= 4) { ScanNode sublv3; if (sublv2.children == null || !sublv2.children.TryGetValue(elements[3], out sublv3)) { if (sublv2.children == null) { sublv2.children = new SortedList <string, ScanNode>(new DuplicateKeyComparer <string>()); } sublv3 = new ScanNode() { ownname = elements[3], fullname = sublv0.fullname + " " + elements[1] + " " + elements[2] + " " + elements[3], scandata = null, children = null, type = ScanNodeType.submoon }; sublv2.children.Add(elements[3], sublv3); } if (elements.Count == 4) // okay, need only 4 elements now.. if not, we have not coped.. { sublv3.scandata = sc; } else { System.Diagnostics.Debug.WriteLine("Failed to add system " + sc.BodyName + " too long"); return(false); } } else { sublv2.scandata = sc; } } else { sublv1.scandata = sc; } } else { sublv0.scandata = sc; } return(true); } else { System.Diagnostics.Debug.WriteLine("Failed to add system " + sc.BodyName + " not enough elements"); return(false); } }