|
| 1 | +/* |
| 2 | + * © 2025. TU Dortmund University, |
| 3 | + * Institute of Energy Systems, Energy Efficiency and Energy Economics, |
| 4 | + * Research group Distribution grid planning and operation |
| 5 | +*/ |
| 6 | +package edu.ie3.datamodel.io.provider; |
| 7 | + |
| 8 | +import edu.ie3.datamodel.io.factory.timeseries.BdewLoadProfileFactory; |
| 9 | +import edu.ie3.datamodel.io.factory.timeseries.LoadProfileFactory; |
| 10 | +import edu.ie3.datamodel.io.factory.timeseries.RandomLoadProfileFactory; |
| 11 | +import edu.ie3.datamodel.models.profile.BdewStandardLoadProfile; |
| 12 | +import edu.ie3.datamodel.models.profile.LoadProfile; |
| 13 | +import edu.ie3.datamodel.models.profile.NbwTemperatureDependantLoadProfile; |
| 14 | +import java.util.*; |
| 15 | +import java.util.stream.Collectors; |
| 16 | +import java.util.stream.Stream; |
| 17 | + |
| 18 | +/** Interface defining a provider for {@link LoadProfile}s and their {@link LoadProfileFactory}. */ |
| 19 | +public interface LoadProfileProvider { |
| 20 | + |
| 21 | + /** A list of all {@link LoadProfile}, that are known. */ |
| 22 | + List<? extends LoadProfile> loadedProfiles = |
| 23 | + ServiceLoader.load(LoadProfileProvider.class).stream() |
| 24 | + .map(ServiceLoader.Provider::get) |
| 25 | + .map(LoadProfileProvider::getProfiles) |
| 26 | + .flatMap(Collection::stream) |
| 27 | + .toList(); |
| 28 | + |
| 29 | + /** A map of all known {@link LoadProfile} to their {@link LoadProfileFactory}. */ |
| 30 | + Map<? extends LoadProfile, ? extends LoadProfileFactory<?, ?>> profileToFactories = |
| 31 | + ServiceLoader.load(LoadProfileProvider.class).stream() |
| 32 | + .map(ServiceLoader.Provider::get) |
| 33 | + .map(LoadProfileProvider::getFactories) |
| 34 | + .flatMap(map -> map.entrySet().stream()) |
| 35 | + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); |
| 36 | + |
| 37 | + /** Returns a list of {@link LoadProfile}s. */ |
| 38 | + List<? extends LoadProfile> getProfiles(); |
| 39 | + |
| 40 | + /** Returns a map of {@link LoadProfile} to {@link LoadProfileFactory}. */ |
| 41 | + Map<LoadProfile, LoadProfileFactory<?, ?>> getFactories(); |
| 42 | + |
| 43 | + /** |
| 44 | + * Default load profile provider. This class is used to provide the {@link LoadProfile}s defined |
| 45 | + * in the PSDM. |
| 46 | + */ |
| 47 | + final class DefaultLoadProfileProvider implements LoadProfileProvider { |
| 48 | + |
| 49 | + @Override |
| 50 | + public List<? extends LoadProfile> getProfiles() { |
| 51 | + return Stream.of( |
| 52 | + BdewStandardLoadProfile.values(), |
| 53 | + NbwTemperatureDependantLoadProfile.values(), |
| 54 | + LoadProfile.RandomLoadProfile.values(), |
| 55 | + LoadProfile.DefaultLoadProfiles.values()) |
| 56 | + .flatMap(Arrays::stream) |
| 57 | + .toList(); |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public Map<LoadProfile, LoadProfileFactory<?, ?>> getFactories() { |
| 62 | + BdewLoadProfileFactory bdewLoadProfileFactory = new BdewLoadProfileFactory(); |
| 63 | + |
| 64 | + Map<LoadProfile, LoadProfileFactory<?, ?>> factories = new HashMap<>(); |
| 65 | + |
| 66 | + Arrays.stream(BdewStandardLoadProfile.values()) |
| 67 | + .forEach(profile -> factories.put(profile, bdewLoadProfileFactory)); |
| 68 | + |
| 69 | + factories.put( |
| 70 | + LoadProfile.RandomLoadProfile.RANDOM_LOAD_PROFILE, new RandomLoadProfileFactory()); |
| 71 | + |
| 72 | + return factories; |
| 73 | + } |
| 74 | + } |
| 75 | +} |
0 commit comments