WCAHistoLimits implements  WCAConstants { public void load(Network network, HistoDbClient histoDbClient) throws IOException, InterruptedException { Set<HistoDbAttributeId> attributeIds = new LinkedHashSet<>(); for (Load l : network.getLoads()) { if (l.getLoadType() != LoadType.FICTITIOUS) { attributeIds.add(new HistoDbNetworkAttributeId(l.getId(), HistoDbAttr.P)); } } for (DanglingLine dl : network.getDanglingLines()) { attributeIds.add(new HistoDbNetworkAttributeId(dl.getId(), HistoDbAttr.P0)); } for (Generator g : network.getGenerators()) { attributeIds.add(new HistoDbNetworkAttributeId(g.getId(), HistoDbAttr.P)); } HistoDbStats stats = histoDbClient.queryStats(attributeIds, histoInterval, HistoDbHorizon.SN, true); for (Load l : network.getLoads()) { String id = l.getId(); loadLimits.put(id, range(id, HistoDbAttr.P, stats)); } for (DanglingLine dl : network.getDanglingLines()) { String id = dl.getId(); danglingLineLimits.put(id, range(id, HistoDbAttr.P0, stats)); } for (Generator g : network.getGenerators()) { String id = g.getId(); generatorLimits.put(id, range(id, HistoDbAttr.P, stats)); } } WCAHistoLimits(Interval histoInterval); void load(Network network, HistoDbClient histoDbClient); void write(DataSource dataSource, StringToIntMapper<AmplSubset> mapper);  }
@Test public void testLoad() throws IOException, InterruptedException { Interval histoInterval = Interval.parse("2013-01-01T00:00:00+01:00/2013-01-31T23:59:00+01:00"); Network network = NetworkTest1Factory.create(); HistoDbClient histoDbClient = Mockito.mock(HistoDbClient.class); HistoDbStats histoDbStats = new HistoDbStats(); histoDbStats.setValue(HistoDbStatsType.MIN, new HistoDbNetworkAttributeId(network.getLoads().iterator().next().getId(), HistoDbAttr.P), 0f); histoDbStats.setValue(HistoDbStatsType.MAX, new HistoDbNetworkAttributeId(network.getLoads().iterator().next().getId(), HistoDbAttr.P), 20f); histoDbStats.setValue(HistoDbStatsType.MIN, new HistoDbNetworkAttributeId(network.getGenerators().iterator().next().getId(), HistoDbAttr.P), 200f); histoDbStats.setValue(HistoDbStatsType.MAX, new HistoDbNetworkAttributeId(network.getGenerators().iterator().next().getId(), HistoDbAttr.P), 900f); Mockito.when(histoDbClient.queryStats(Matchers.anySet(), Matchers.eq(histoInterval), Matchers.eq(HistoDbHorizon.SN), Matchers.eq(true))) .thenReturn(histoDbStats); StringToIntMapper<AmplSubset> mapper = new StringToIntMapper<>(AmplSubset.class); AmplUtil.fillMapper(mapper, network); WCAHistoLimits histoLimits = new WCAHistoLimits(histoInterval); histoLimits.load(network, histoDbClient); String fileContent = String.join(System.lineSeparator(), "#loads historical data " + histoInterval, "#\"num\" \"min p (MW)\" \"max p (MW)\" \"id\"", "1 0.00000 20.0000 \""+ network.getLoads().iterator().next().getId() + "\""); String fileContentexpected = String.join(System.lineSeparator(), "#loads historical data " + histoInterval, "#\"num\" \"min p (MW)\" \"max p (MW)\" \"id\"", "1 0.00000 20.0000 \""+ "load1" + "\""); assertEquals(fileContent, fileContentexpected); }