/**
   * This method returns a hashmap where the key is for the year and the array is the months of the
   * year and the number of deaths per month.
   *
   * @return
   */
  public HashMap<Integer, int[]> dataForChartMuertes() {
    HashMap<Integer, int[]> map = new HashMap<>();
    ConectorBovino cb = new ConectorBovino();
    ArrayList<Bovino> bovinos = cb.getAll();

    int year;
    int month;
    Calendar cal = Calendar.getInstance();
    for (Bovino bovino : bovinos) {
      Date fm = bovino.getFecha_muerte();
      if (fm != null) {

        cal.setTime(fm);
        year = cal.get(Calendar.YEAR);
        month = cal.get(Calendar.MONTH) + 1;

        if (map.containsKey(year)) {
          int[] get = map.get(year);
          get[month] = get[month] + 1;
          map.put(year, get);
        } else {
          int[] a = new int[13];
          a[month] = 1;
          map.put(year, a);
        }
      }
    }

    return map;
  }
  /**
   * This method returns a hashmap where the key is for the year and the array is the months of the
   * year and the number of calfs born per month.
   *
   * @return
   */
  public HashMap<Integer, int[]> dataForChartNacimientos() {
    HashMap<Integer, int[]> map = new HashMap<>();
    ConectorBovino cb = new ConectorBovino();
    ArrayList<Bovino> bovinos = cb.getAll();

    int year;
    int month;
    Calendar cal = Calendar.getInstance();
    for (Bovino bovino : bovinos) {
      cal.setTime(bovino.getFecha_nacimiento());
      year = cal.get(Calendar.YEAR);
      month = cal.get(Calendar.MONTH) + 1;
      //            System.out.println("year="+year+" month="+month);

      if (map.containsKey(year)) {
        int[] get = map.get(year);
        get[month] = get[month] + 1;
        map.put(year, get);
      } else {
        int[] a = new int[13];
        a[month] = 1;
        map.put(year, a);
      }
    }

    return map;
  }
  /**
   * This method returns a hashmap of how many cows, bulls, novillos ...etc there is.
   *
   * @return
   */
  public HashMap<String, Integer> dataForChartEdadesySexo() {
    // Map<String, Integer>
    int vacas = 0;
    int toros = 0;
    int novillos = 0;
    int novillas = 0;
    int crias_f = 0;
    int crias_m = 0;

    ConectorBovino cb = new ConectorBovino();
    ArrayList<Bovino> bovinos = cb.getVivosyNoVendidos();
    String sexo;
    int meses;

    for (Bovino b : bovinos) {
      sexo = b.getSexo();
      if (sexo.equalsIgnoreCase("Hembra")) {
        // es hembra
        meses = getMonthsOld(b.getFecha_nacimiento());
        if (meses >= 24) {
          vacas++;
        }
        if (meses >= 12 && meses < 24) {
          novillas++;
        }
        if (meses < 12) {
          crias_f++;
        }
      } else {
        // es macho
        meses = getMonthsOld(b.getFecha_nacimiento());
        if (meses >= 24) {
          toros++;
        }
        if (meses >= 12 && meses < 24) {
          novillos++;
        }
        if (meses < 12) {
          crias_m++;
        }
      }
    }
    HashMap<String, Integer> map = new HashMap<>();
    map.put("vacas", vacas);
    map.put("toros", toros);
    map.put("novillas", novillas);
    map.put("novillos", novillos);
    map.put("becerras", crias_f);
    map.put("becerros", crias_m);

    return map;
  }
  /**
   * This method return a hashmap with the key representing the bovine race and value the numer of
   * animals that are that race.
   *
   * @return
   */
  public HashMap<String, Integer> chartRaza() {
    HashMap<String, Integer> map = new HashMap<>();
    ConectorBovino cb = new ConectorBovino();
    ArrayList<Bovino> bovinos = cb.getVivosyNoVendidos();

    String r;
    for (Bovino b : bovinos) {
      r = b.getRaza().getNombre();
      if (map.containsKey(r)) {
        Integer get = map.get(r);
        get = get + 1;
        map.put(r, get);
      } else {
        map.put(r, 1);
      }
    }

    return map;
  }