Esempio n. 1
0
        protected override void RunActualProcess()
        {
            Log(MessageType.Info, "Starting creating complexes");
            Log(MessageType.Info, "Clearing tables", "A_CreateComplexeService");
            ClearComplexTables();
            Log(MessageType.Info, "Energiebedarfsdaten", "A_CreateComplexeService");
            P01_StartWithEnergieBedarfsdaten();
            Log(MessageType.Info, "Feurungsstaetten", "A_CreateComplexeService");
            P02_AddFeuerungsstaettenAdressDataAsComplexes();
            Log(MessageType.Info, "GWRAdressen", "A_CreateComplexeService");
            P03_AddGwrAdressen();
            Log(MessageType.Info, "Trafokreis", "A_CreateComplexeService");
            P04_AddTrafoStationData();
            Log(MessageType.Info, "Merging as needed", "A_CreateComplexeService");
            var merger = new ComplexMerger(SqlConnection, Services.MyLogger);

            merger.MergeBuildingComplexesAsNeeded();
            Log(MessageType.Info, "Merged from " + merger.BeginCount + " to " + merger.EndCount, "A_CreateComplexeService");
            Log(MessageType.Info, "Finished", "A_CreateComplexeService");
            CheckKomplexes();
        }
        protected override void RunActualProcess()
        {
            Log(MessageType.Info, "Starting to add trafoKreisInfo");
            var dbsrc             = SqlConnection.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice).Database;
            var dbdst             = SqlConnection.GetDatabaseConnection(Stage.Complexes, Constants.PresentSlice).Database;
            var trafokreise       = dbsrc.Fetch <TrafoKreisImport>();
            var buildingComplexes = dbdst.Fetch <BuildingComplex>();

            dbdst.BeginTransaction();
            Log(MessageType.Info, "Using Trafokreis data");
            var addedegids       = 0;
            var addedTrafoKreise = 0;
            var totalTrafoKreise = 0;

            foreach (var tk in trafokreise)
            {
                if (!string.IsNullOrWhiteSpace(tk.DESCRIPTIO))
                {
                    totalTrafoKreise++;
                }

                if (tk.U_OBJ_ID_I == null)
                {
                    continue;
                }

                var complexes = buildingComplexes.Where(x => x.GebäudeObjectIDs.Contains(tk.U_OBJ_ID_I.Value)).ToList();
                if (complexes.Count == 0)
                {
                    //new id that I dont have yet
                    continue;
                }

                if (complexes.Count > 1)
                {
                    //new id that I dont have yet
                    throw new Exception("more than one complex with the same gebäudeid");
                }

                var complex = complexes[0];
                //fehlende egids einlesen
                if (tk.U_EGID_ISE != null && tk.U_EGID_ISE != 0 && !complex.EGids.Contains(tk.U_EGID_ISE.Value))
                {
                    complex.EGids.Add(tk.U_EGID_ISE.Value);
                    addedegids++;
                }

                var tkDesc = tk.DESCRIPTIO.Trim();
                if (!complex.TrafoKreise.Contains(tkDesc))
                {
                    complex.TrafoKreise.Add(tkDesc);
                }

                if (!string.IsNullOrWhiteSpace(tk.u_Nr_Dez_E))
                {
                    complex.ErzeugerIDs.Add(tk.u_Nr_Dez_E);
                }

                var xkoord   = tk.HKOORD;
                var ykoord   = tk.VKOORD;
                var addKoord = true;
                foreach (var coord in complex.LocalnetCoords)
                {
                    if (Math.Abs(coord.X - xkoord) < 0.0000001 && Math.Abs(ykoord - coord.Y) < 0.000001)
                    {
                        addKoord = false;
                    }
                }

                if (addKoord)
                {
                    complex.LocalnetCoords.Add(new GeoCoord(xkoord, ykoord));
                }

                dbdst.Save(complex);
                addedTrafoKreise++;
            }

            dbdst.CompleteTransaction();
            //merging
            var merger = new ComplexMerger(SqlConnection, Services.MyLogger);

            merger.MergeBuildingComplexesAsNeeded();
            Log(MessageType.Info, "Merged from " + merger.BeginCount + " to " + merger.EndCount, "A_CreateComplexeService");

            Log(MessageType.Info, "Added trafokreis data");
            Log(MessageType.Info, "Added EGids: " + addedegids);
            Log(MessageType.Info, "Added trafokreise: " + addedTrafoKreise + "/" + totalTrafoKreise);
            dbdst.CloseSharedConnection();
        }
        protected override void RunActualProcess()
        {
            Log(MessageType.Info, "Valdiating Complex Standorte");
            var dbRaw                = SqlConnection.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice).Database;
            var dbComplex            = SqlConnection.GetDatabaseConnection(Stage.Complexes, Constants.PresentSlice).Database;
            var localnet             = dbRaw.Fetch <Localnet>();
            var buildingComplexes    = dbComplex.Fetch <BuildingComplex>();
            var standorteByGebäudeID = new Dictionary <int, List <string> >();
            var gebäudeIDByStandort  = new Dictionary <string, List <int> >();

            dbComplex.BeginTransaction();
            foreach (var lo in localnet)
            {
                var id       = lo.ObjektIDGebäude ?? throw new Exception("Was null");
                var standort = lo.Objektstandort;
                if (string.IsNullOrWhiteSpace(standort))
                {
                    continue;
                }

                if (!standorteByGebäudeID.ContainsKey(id))
                {
                    standorteByGebäudeID.Add(id, new List <string>());
                }

                if (!standorteByGebäudeID[id].Contains(standort))
                {
                    standorteByGebäudeID[id].Add(standort);
                }

                if (!gebäudeIDByStandort.ContainsKey(standort))
                {
                    gebäudeIDByStandort.Add(standort, new List <int>());
                }

                if (!gebäudeIDByStandort[standort].Contains(id))
                {
                    gebäudeIDByStandort[standort].Add(id);
                }
            }

            var addedStandorte = 0;
            var addedIds       = 0;

            while (addedStandorte > 0 || addedIds > 0)
            {
                foreach (var complex in buildingComplexes)
                {
                    foreach (var cid in complex.GebäudeObjectIDs)
                    {
                        var cStandorte = complex.ObjektStandorte;
                        var lStandorte = standorteByGebäudeID[cid];
                        if (!Constants.ScrambledEquals(cStandorte, lStandorte))
                        {
                            foreach (var s in lStandorte)
                            {
                                if (!cStandorte.Contains(s))
                                {
                                    cStandorte.Add(s);
                                    addedStandorte++;
                                }
                            }
                        }
                    }

                    foreach (var cstandort in complex.ObjektStandorte)
                    {
                        var cids = complex.GebäudeObjectIDs;
                        var lIds = gebäudeIDByStandort[cstandort];
                        if (!Constants.ScrambledEquals(cids, lIds))
                        {
                            foreach (var id in lIds)
                            {
                                if (!cids.Contains(id))
                                {
                                    cids.Add(id);
                                    addedIds++;
                                }
                            }
                        }
                    }
                }
            }

            Log(MessageType.Info, "Merging as needed", "A_CreateComplexeService");
            var merger = new ComplexMerger(SqlConnection, Services.MyLogger);

            merger.MergeBuildingComplexesAsNeeded();
            Log(MessageType.Info, "Merged from " + merger.BeginCount + " to " + merger.EndCount, "A_CreateComplexeService");

            foreach (var complex in buildingComplexes)
            {
                dbComplex.Save(complex);
            }

            Log(MessageType.Info, "Added Ids: " + addedIds);
            Log(MessageType.Info, "Added Standorte: " + addedStandorte);
            dbComplex.CompleteTransaction();
        }