Beispiel #1
0
        public override void Process()
        {
            var tasks = new List <Task>();

            var nodes = _dataGroup.Descendants("element");

            foreach (var node in nodes.ToList())
            {
                IdfElement d      = null;
                var        elType = node.Attribute("type").Value;

                switch (elType)
                {
                case "Switch":
                    d = new IdfSwitch(node, this);
                    break;

                case "Transformer":
                    d = new IdfTransformer(node, this);
                    break;

                case "Line":
                    d = new IdfLine(node, this);
                    break;

                case "Load":
                    d = new IdfLoad(node, this);
                    break;

                case "Feeder":
                    d = new IdfFeeder(node, this);
                    break;

                case "Substation Circuit":
                    d = new IdfCircuit(node, this);
                    break;

                case "Regulator":
                    d = new IdfRegulator(node, this);
                    break;

                case "Substation":
                    d = new IdfSubstation(node, this);
                    break;

                case "Capacitor":
                    d = new IdfCapacitor(node, this);
                    break;

                case "Area":
                    d = new IdfArea(node, this);
                    break;

                case "Region":
                    d = new IdfRegion(node, this);
                    break;

                case "Source":
                    d = new IdfSource(node, this);
                    break;

                case "Generator":
                    d = new IdfGenerator(node, this);
                    break;

                default:
                    break;
                }
                if (d != null)
                {
                    d.Process();
                }
            }
        }
Beispiel #2
0
        public void Go(Options o)
        {
            DateTime start = DateTime.Now;

            ValidateOptions(o);
            PrintLogHeader();

            if (!o.BlankModel)
            {
                var model = Model.Deserialize(o.Model);
                if (model != null)
                {
                    Model = model;
                }
                else
                {
                    Info("Creating a new model...");
                }
            }

            if (!DataManager.I.Load("", true))
            {
                Fatal("Failed to initialize the datamanager");
                return;
            }
            DataManager.I.Save("Datamanager.json");
            if (!ProcessImportConfiguration())
            {
                Fatal("Failed to process Import configuration, skipping everything else");
                return;
            }

            //Add parallel transformer sets to the import configuration
            FileManager.ImportConfig.GlobalGroups.Add(new XElement("group", new XAttribute("id", "Transformer Parallel Sets"), new XAttribute("name", "Transformer Parallel Sets")));
            //Add line types to the import configuration
            FileManager.ImportConfig.GlobalGroups.Add(new XElement("group", new XAttribute("id", "Line Types"), new XAttribute("name", "Line Types")));
            //Add custom scada linking to the import configuration
            FileManager.ImportConfig.GlobalGroups.Add(new XElement("group", new XAttribute("id", "SCADA"), new XAttribute("name", "Custom SCADA Links")));
            //Add bookmarks to the import configuration
            FileManager.ImportConfig.GlobalGroups.Add(new XElement("group", new XAttribute("id", "Bookmarks"), new XAttribute("name", "Bookmarks")));


            ProcessGeographic();

            Model.ValidateConnectivity();
            Model.ValidateBaseVoltages();
            Model.ValidatePhasing();
            Model.CalculateNominalFeeders();
            Model.TraceLoadAllocation();

            if (Fatals == 0)
            {
                Model.Serialize($"{o.OutputPath}\\model");

                var gFile = new StreamWriter($"{o.OutputPath}\\groups.dat");
                foreach (var g in Model.GetGroups())
                {
                    gFile.WriteLine(g);
                }
                gFile.Close();

                //TODO:
                //if this is a new model, and a group list was provided, then
                //compare the groups in the list of groups from the last import to the groups FILE MANAGER from this import
                //any groups that were present in the last model, but aren't in this model should be deleted
                try
                {
                    XDocument xdoc    = new XDocument();
                    XElement  xdata   = new XElement("data", new XAttribute("type", "Electric Distribution"), new XAttribute("timestamp", "TODO"), new XAttribute("format", "1.0"));
                    XElement  xgroups = new XElement("groups");
                    xdoc.Add(xdata);
                    xdata.Add(xgroups);



                    List <string> groupstodelete = new List <string>();
                    Info(o.GroupFile);
                    Info(o.BlankModel.ToString());
                    if (!string.IsNullOrWhiteSpace(o.GroupFile) && o.BlankModel)
                    {
                        var groups = File.ReadAllLines(o.GroupFile);
                        foreach (var group in groups)
                        {
                            if (!FileManager.Groups.ContainsKey(group))
                            {
                                groupstodelete.Add(group);
                                xgroups.Add(new XElement("group", new XAttribute("id", group)));

                                Warn("Group was in previous import, but not in this import", group, "");
                            }
                        }
                    }
                    FileManager.InjectDeletedGroups(groupstodelete);
                    xdoc.Save(Path.Combine(Program.Options.OutputPath, "EnricherDeletedGroups.xml"));
                }
                catch (Exception ex)
                {
                    Err($"Problem comparing groups from previous export: ${ex.Message}");
                }

                if (true)
                {
                    //TODO move this into the nodemodel??
                    Info("Verifying connected device upstream side consistency...");
                    foreach (var d in Model.Devices.Values.Where(s => (s.Type == DeviceType.Switch) && s.Connectivity && s.SwitchState))
                    {
                        var asset = DataManager.I.RequestRecordById <AdmsSwitch>(d.Name);
                        if (asset != null)
                        {
                            if (asset.AsBool("NotifyUpstreamSide") ?? false)
                            {
                                var upstream = asset.AsInt("NominalUpstreamSide");
                                if ((upstream ?? 0) != d.Upstream)
                                {
                                    Warn($"Calculated nominal upstream side for switch [{d.Name}] ({d.Upstream}) is different from adms database ({upstream})");
                                }
                            }
                        }
                    }
                }
                ProcessGraphics();
                if (o.ExportShapeFiles)
                {
                    Model.ExportToShapeFile($"{o.OutputPath}\\");
                }

                Model.ExportDeviceCoordinates();
                IdfLine.ExportConductors();
            }
            else
            {
                Info("Skipping model serialization and flow checking due to the ocurrence of previous fatal errors");
            }
            if (Fatals > 0)
            {
                Info("Output was not generated due to one or more fatal errors. Please review the log for more detail.");
            }
            else
            {
                Info("Saving the output IDF...");
                FileManager.SaveFiles(o.OutputPath);

                //TODO: this is a temporary measure
                File.Copy(Path.Combine(Program.Options.DataPath, "ExternalInfo.xml"), Path.Combine(Program.Options.OutputPath, "ExternalInfo.xml"), true);
                File.Copy(Path.Combine(Program.Options.DataPath, "Parallel Sets.xml"), Path.Combine(Program.Options.OutputPath, "Parallel Sets.xml"), true);
                File.Copy(Path.Combine(Program.Options.DataPath, "Conductors.xml"), Path.Combine(Program.Options.OutputPath, "Conductors.xml"), true);
                File.Copy(Path.Combine(Program.Options.DataPath, "CustomSCADALinks.xml"), Path.Combine(Program.Options.OutputPath, "CustomSCADALinks.xml"), true);
                File.Copy(Path.Combine(Program.Options.DataPath, "Bookmarks.xml"), Path.Combine(Program.Options.OutputPath, "Bookmarks.xml"), true);
            }
            TimeSpan runtime = DateTime.Now - start;

            Info($"Stats: Tx:{Model.TxCount} Line:{Model.LineCount} Line5:{Model.Line5Count} Line25:{Model.Line25Count} Load:{Model.LoadCount} Switch:{Model.SwitchCount} Reg:{Model.RegCount} Feeder:{Model.FeederCount} Nodes: {Model.Nodes.Count} Runtime:{runtime.TotalMinutes} min");
            Info($"Stats: Debug:{Debugs} Info:{Infos} Warn:{Warns} Error:{Errors} Fatal:{Fatals}");
        }