test_class.file: vortex-api/src/test/java/mil/army/usace/hec/vortex/math/NormalizerTest.java
test_class.identifier: NormalizerTest
test_case.body: @Test
      void DtoArraysAreNormalized() {
          VortexGrid dto1 = mock(VortexGrid.class);
          when(dto1.data()).thenReturn(new float[]{0,Float.NaN,2,4,2,2,2,2});
          when(dto1.startTime()).thenReturn(ZonedDateTime.of(0, 1, 1,0,0,0,0, ZoneId.of("UTC")));
          when(dto1.endTime()).thenReturn(ZonedDateTime.of(0, 1, 1,0,0,0,0, ZoneId.of("UTC")));
  
          VortexGrid dto2 = mock(VortexGrid.class);
          when(dto2.data()).thenReturn(new float[]{0,2,2,4,2,2,2,1});
          when(dto2.startTime()).thenReturn(ZonedDateTime.of(0, 1, 1,0,0,0,0, ZoneId.of("UTC")));
          when(dto2.endTime()).thenReturn(ZonedDateTime.of(0, 1, 1,0,0,0,0, ZoneId.of("UTC")));
  
          VortexGrid dto3 = mock(VortexGrid.class);
          when(dto3.data()).thenReturn(new float[]{0,2,Float.NaN,6,2,8,2,2});
          when(dto3.startTime()).thenReturn(ZonedDateTime.of(0, 1, 1,0,0,0,0, ZoneId.of("UTC")));
          when(dto3.endTime()).thenReturn(ZonedDateTime.of(0, 1, 1,0,0,0,0, ZoneId.of("UTC")));
  
          List<VortexGrid> inputs = new ArrayList<>();
          inputs.add(dto1);
          inputs.add(dto2);
  
          List<VortexGrid> normals = new ArrayList<>();
          normals.add(dto3);
  
          List<VortexGrid> normalized = Normalizer.normalize(inputs, normals);
  
          float[] expected1 = new float[]{0, Float.NaN, 2, 3, 1, 4, 1, Float.parseFloat("1.333")};
  
          float[] normalized1 = normalized.get(0).data();
          for (int i = 0; i < normalized1.length; i++){
              try {
                  assertEquals(expected1[i], normalized1[i], 1E-3);
              }catch(AssertionError e){
                  System.out.println("Error index: " + i);
                  throw e;
              }
          }
  
          float[] expected2 = new float[]{0, 2, 2, 3, 1, 4, 1, Float.parseFloat("0.667")};
  
          float[] normalized2 = normalized.get(1).data();
          for (int i = 0; i < normalized2.length; i++) {
              try {
                  assertEquals(expected2[i], normalized2[i], 1E-3);
              } catch (AssertionError e) {
                  System.out.println("Error index: " + i);
                  throw e;
              }
          }
      }
test_case.class_method_signature: NormalizerTest.DtoArraysAreNormalized()
test_case.full_signature: @Test void DtoArraysAreNormalized()
test_case.identifier: DtoArraysAreNormalized
test_case.invocations: mock thenReturn when data thenReturn when startTime of of thenReturn when endTime of of mock thenReturn when data thenReturn when startTime of of thenReturn when endTime of of mock thenReturn when data thenReturn when startTime of of thenReturn when endTime of of add add add normalize parseFloat data get assertEquals println parseFloat data get assertEquals println
test_case.modifiers: @Test
test_case.parameters: ()
test_case.return: void
test_case.signature: void DtoArraysAreNormalized()
focal_class.declarator: logger = Logger.getLogger(Normalizer.class.getName())
focal_class.modifier: private static
focal_class.original_string: private static Logger logger = Logger.getLogger(Normalizer.class.getName());
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: formatter = DateTimeFormatter.ofPattern("dd-MMM-yyyy HH:mm").withZone(ZoneId.of("UTC"))
focal_class.modifier: private static
focal_class.original_string: private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MMM-yyyy HH:mm").withZone(ZoneId.of("UTC"));
focal_class.type: DateTimeFormatter
focal_class.var_name: formatter
focal_class.declarator: pathToSource
focal_class.modifier: private
focal_class.original_string: private String pathToSource;
focal_class.type: String
focal_class.var_name: pathToSource
focal_class.declarator: pathToNormals
focal_class.modifier: private
focal_class.original_string: private String pathToNormals;
focal_class.type: String
focal_class.var_name: pathToNormals
focal_class.declarator: sourceVariables
focal_class.modifier: private
focal_class.original_string: private Set<String> sourceVariables;
focal_class.type: Set<String>
focal_class.var_name: sourceVariables
focal_class.declarator: normalsVariables
focal_class.modifier: private
focal_class.original_string: private Set<String> normalsVariables;
focal_class.type: Set<String>
focal_class.var_name: normalsVariables
focal_class.declarator: startTime
focal_class.modifier: private
focal_class.original_string: private ZonedDateTime startTime;
focal_class.type: ZonedDateTime
focal_class.var_name: startTime
focal_class.declarator: endTime
focal_class.modifier: private
focal_class.original_string: private ZonedDateTime endTime;
focal_class.type: ZonedDateTime
focal_class.var_name: endTime
focal_class.declarator: interval
focal_class.modifier: private
focal_class.original_string: private Duration interval;
focal_class.type: Duration
focal_class.var_name: interval
focal_class.declarator: destination
focal_class.modifier: private
focal_class.original_string: private Path destination;
focal_class.type: Path
focal_class.var_name: destination
focal_class.declarator: writeOptions
focal_class.modifier: private
focal_class.original_string: private Options writeOptions;
focal_class.type: Options
focal_class.var_name: writeOptions
focal_class.file: vortex-api/src/main/java/mil/army/usace/hec/vortex/math/Normalizer.java
focal_class.identifier: Normalizer
focal_class.class_method_signature: Normalizer.Normalizer(NormalizerBuilder builder)
focal_class.full_signature: private  Normalizer(NormalizerBuilder builder)
focal_class.identifier: Normalizer
focal_class.modifiers: private
focal_class.parameters: (NormalizerBuilder builder)
focal_class.signature:  Normalizer(NormalizerBuilder builder)
focal_class.class_method_signature: Normalizer.builder()
focal_class.full_signature: public static NormalizerBuilder builder()
focal_class.identifier: builder
focal_class.modifiers: public static
focal_class.parameters: ()
focal_class.return: NormalizerBuilder
focal_class.signature: NormalizerBuilder builder()
focal_class.class_method_signature: Normalizer.normalize()
focal_class.full_signature: public void normalize()
focal_class.identifier: normalize
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void normalize()
focal_class.class_method_signature: Normalizer.normalize(List<VortexGrid> source, List<VortexGrid> normals)
focal_class.full_signature: static List<VortexGrid> normalize(List<VortexGrid> source, List<VortexGrid> normals)
focal_class.identifier: normalize
focal_class.modifiers: static
focal_class.parameters: (List<VortexGrid> source, List<VortexGrid> normals)
focal_class.return: List<VortexGrid>
focal_class.signature: List<VortexGrid> normalize(List<VortexGrid> source, List<VortexGrid> normals)
focal_class.class_method_signature: Normalizer.validate(List<VortexGrid> source, List<VortexGrid> normals)
focal_class.full_signature: private static boolean validate(List<VortexGrid> source, List<VortexGrid> normals)
focal_class.identifier: validate
focal_class.modifiers: private static
focal_class.parameters: (List<VortexGrid> source, List<VortexGrid> normals)
focal_class.return: boolean
focal_class.signature: boolean validate(List<VortexGrid> source, List<VortexGrid> normals)
focal_class.class_method_signature: Normalizer.logValidationFailure(String origin, VortexGrid reference, VortexGrid invalid)
focal_class.full_signature: private static void logValidationFailure(String origin, VortexGrid reference, VortexGrid invalid)
focal_class.identifier: logValidationFailure
focal_class.modifiers: private static
focal_class.parameters: (String origin, VortexGrid reference, VortexGrid invalid)
focal_class.return: void
focal_class.signature: void logValidationFailure(String origin, VortexGrid reference, VortexGrid invalid)
focal_method.body: public void normalize(){
  
          logger.info(() -> "Normalization started...");
  
          List<VortexData> source = new ArrayList<>();
          sourceVariables.forEach(variable -> source.addAll(
                  DataReader.builder()
                          .path(pathToSource)
                          .variable(variable)
                          .build()
                          .getDtos()));
  
          List<VortexData> normals = new ArrayList<>();
          normalsVariables.forEach(variable -> normals.addAll(
                  DataReader.builder()
                          .path(pathToNormals)
                          .variable(variable)
                          .build()
                          .getDtos()));
  
          AtomicReference<ZonedDateTime> intervalStart = new AtomicReference<>();
          intervalStart.set(startTime);
  
          AtomicInteger count = new AtomicInteger();
          while (intervalStart.get().isBefore(endTime)){
              ZonedDateTime start = intervalStart.get();
              ZonedDateTime end = intervalStart.get().plus(interval);
  
              List<VortexGrid> sourceFiltered = source.stream().filter(grid -> ((grid.startTime().isEqual(start) || grid.startTime().isAfter(start))
                      && (grid.endTime().isEqual(end) || grid.endTime().isBefore(end))))
                      .map(grid -> (VortexGrid)grid)
                      .collect(Collectors.toList());
  
              if (sourceFiltered.isEmpty()) {
                  logger.warning(() -> format("No source grids for period %s to %s", formatter.format(start), formatter.format(end)));
              }
  
              List<VortexGrid> normalsFiltered = normals.stream().filter(grid -> ((grid.startTime().equals(start) || grid.startTime().isAfter(start))
                      && (grid.endTime().isEqual(end) || grid.endTime().isBefore(end))))
                      .map(grid -> (VortexGrid)grid)
                      .collect(Collectors.toList());
  
              if (normalsFiltered.isEmpty()){
                  logger.warning(() -> format("No normals grids for period %s to %s", formatter.format(start), formatter.format(end)));
              }
  
              List<VortexGrid> output = normalize(sourceFiltered, normalsFiltered);
  
              output.forEach(grid -> {
                  List<VortexData> data = new ArrayList<>();
                  data.add(grid);
  
                  DataWriter writer = DataWriter.builder()
                          .data(data)
                          .destination(destination)
                          .options(writeOptions)
                          .build();
  
                  writer.write();
              });
  
              intervalStart.set(end);
              count.addAndGet(output.size());
          }
          logger.info(() -> format("Normalization complete: %s grids normalized.", count.get()));
      }
focal_method.class_method_signature: Normalizer.normalize()
focal_method.full_signature: public void normalize()
focal_method.identifier: normalize
focal_method.invocations: info forEach addAll getDtos build variable path builder forEach addAll getDtos build variable path builder set isBefore get get plus get collect map filter stream isEqual startTime isAfter startTime isEqual endTime isBefore endTime toList isEmpty warning format format format collect map filter stream equals startTime isAfter startTime isEqual endTime isBefore endTime toList isEmpty warning format format format normalize forEach add build options destination data builder write set addAndGet size info format get
focal_method.modifiers: public
focal_method.parameters: ()
focal_method.return: void
focal_method.signature: void normalize()