import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;

public class Measures {
  public static double average(Path path) throws IOException {
    double sum = 0.0;
    int size = 0;
    try(BufferedReader reader = Files.newBufferedReader(path)) {
      String line;
      while((line = reader.readLine()) != null) {
        String[] words = line.split(",");
        
        // parse the values to double skipping the date (the first word)
        double[] values = Arrays.stream(words).skip(1).mapToDouble(Double::parseDouble).toArray();
        
        for(double value: values) {
          sum += value;
        }
        size += values.length;
      }
    }
    if (size == 0) {
      return Double.NaN;
    }
    return sum / size;
  }
  
  public static void main(String[] args) throws IOException {
    Path path = Paths.get("measures.csv");
    System.out.println("average " + Measures.average(path));
  }
}
