public void Run() { ServiceRepository services = new ServiceRepository(null, null, Logger, Config, null); ComplexMerger cm = new ComplexMerger(services, Stage.Complexes); var r = cm.ReadComplexesToMergeList(); Assert.Single(r); }
protected override void RunActualProcess() { Debug("Starting creating complexes"); Debug("Clearing tables"); var dbdst = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Complexes, Constants.PresentSlice); dbdst.RecreateTable <BuildingComplex>(); dbdst.RecreateTable <BuildingComplexStandorte>(); Debug("Energiebedarfsdaten"); P01_StartWithEnergieBedarfsdaten(); Debug("Feurungsstaetten"); P02_AddFeuerungsstaettenAdressDataAsComplexes(); Debug("GWRAdressen"); P03_AddGwrAdressen(); Debug("Trafokreis"); P04_AddTrafoStationData(); Debug("Merging as needed"); var merger = new ComplexMerger(Services, MyStage); merger.MergeBuildingComplexesAsNeeded(); Debug("Merged from " + merger.BeginCount + " to " + merger.EndCount); Debug("Finished"); CheckKomplexes(); }
protected override void RunActualProcess() { Debug("Valdiating Complex Standorte"); var dbRaw = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice); var dbComplex = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Complexes, Constants.PresentSlice); 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> >(); 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++; } } } } } } Debug("Merging as needed"); var merger = new ComplexMerger(Services, MyStage); merger.MergeBuildingComplexesAsNeeded(); Info("Merged from " + merger.BeginCount + " to " + merger.EndCount, "A_CreateComplexeService"); dbComplex.BeginTransaction(); foreach (var complex in buildingComplexes) { dbComplex.Save(complex); } Debug("Added Ids: " + addedIds); Debug("Added Standorte: " + addedStandorte); dbComplex.CompleteTransaction(); }
protected override void RunActualProcess() { Info("Starting to add trafoKreisInfo"); var dbsrc = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Raw, Constants.PresentSlice); var dbdst = Services.SqlConnectionPreparer.GetDatabaseConnection(Stage.Complexes, Constants.PresentSlice); var trafokreise = dbsrc.Fetch <TrafoKreisImport>(); var buildingComplexes = dbdst.Fetch <BuildingComplex>(); dbdst.BeginTransaction(); 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(Services, MyStage); merger.MergeBuildingComplexesAsNeeded(); Info("Merged from " + merger.BeginCount + " to " + merger.EndCount, "A_CreateComplexeService"); Info("Added trafokreis data"); Info("Added EGids: " + addedegids); Info("Added trafokreise: " + addedTrafoKreise + "/" + totalTrafoKreise); dbdst.CloseSharedConnection(); }