text: /*jshint esversion: 6 */
  
  const pros_muns = {
    mat: {
      province: 'Matanzas',
      province_id: 'mat',
      DPA_province_code: '25',
      muns: {
        25.03: {
          DPA_municipality_code: '25.03',
          municipality: 'Martí',
        },
        25.02: {
          DPA_municipality_code: '25.02',
          municipality: 'Cárdenas',
        },
        25.01: {
          DPA_municipality_code: '25.01',
          municipality: 'Matanzas',
        },
        25.08: {
          DPA_municipality_code: '25.08',
          municipality: 'Limonar',
        },
        25.09: {
          DPA_municipality_code: '25.09',
          municipality: 'Unión de Reyes',
        },
        25.05: {
          DPA_municipality_code: '25.05',
          municipality: 'Perico',
        },
        25.06: {
          DPA_municipality_code: '25.06',
          municipality: 'Jovellanos',
        },
        25.07: {
          DPA_municipality_code: '25.07',
          municipality: 'Pedro Betancourt',
        },
        25.13: {
          DPA_municipality_code: '25.13',
          municipality: 'Los Arabos',
        },
        25.04: {
          DPA_municipality_code: '25.04',
          municipality: 'Colón',
        },
        25.11: {
          DPA_municipality_code: '25.11',
          municipality: 'Jagüey Grande',
        },
        25.12: {
          DPA_municipality_code: '25.12',
          municipality: 'Calimete',
        },
        '25.10': {
          DPA_municipality_code: '25.10',
          municipality: 'Cienaga de Zapata',
        },
      },
    },
    lha: {
      province: 'La Habana',
      province_id: 'lha',
      DPA_province_code: '23',
      muns: {
        23.06: {
          DPA_municipality_code: '23.06',
          municipality: 'Habana del Este',
        },
        23.03: {
          DPA_municipality_code: '23.03',
          municipality: 'Centro Habana',
        },
        23.05: {
          DPA_municipality_code: '23.05',
          municipality: 'Regla',
        },
        23.02: {
          DPA_municipality_code: '23.02',
          municipality: 'Plaza de la Revolución',
        },
        23.04: {
          DPA_municipality_code: '23.04',
          municipality: 'La Habana Vieja',
        },
        '23.10': {
          DPA_municipality_code: '23.10',
          municipality: 'Cerro',
        },
        23.09: {
          DPA_municipality_code: '23.09',
          municipality: 'Diez de Octubre',
        },
        23.07: {
          DPA_municipality_code: '23.07',
          municipality: 'Guanabacoa',
        },
        23.08: {
          DPA_municipality_code: '23.08',
          municipality: 'San Miguel del Padrón',
        },
        23.01: {
          DPA_municipality_code: '23.01',
          municipality: 'Playa',
        },
        23.14: {
          DPA_municipality_code: '23.14',
          municipality: 'Arroyo Naranjo',
        },
        23.13: {
          DPA_municipality_code: '23.13',
          municipality: 'Boyeros',
        },
        23.11: {
          DPA_municipality_code: '23.11',
          municipality: 'Marianao',
        },
        23.15: {
          DPA_municipality_code: '23.15',
          municipality: 'Cotorro',
        },
        23.12: {
          DPA_municipality_code: '23.12',
          municipality: 'La Lisa',
        },
      },
    },
    may: {
      province: 'Mayabeque',
      province_id: 'may',
      DPA_province_code: '24',
      muns: {
        24.04: {
          DPA_municipality_code: '24.04',
          municipality: 'Santa Cruz del Norte',
        },
        24.02: {
          DPA_municipality_code: '24.02',
          municipality: 'San José de las Lajas',
        },
        24.03: {
          DPA_municipality_code: '24.03',
          municipality: 'Jaruco',
        },
        24.05: {
          DPA_municipality_code: '24.05',
          municipality: 'Madruga',
        },
        24.01: {
          DPA_municipality_code: '24.01',
          municipality: 'Bejucal',
        },
        24.11: {
          DPA_municipality_code: '24.11',
          municipality: 'Quivicán',
        },
        24.08: {
          DPA_municipality_code: '24.08',
          municipality: 'Güines',
        },
        24.07: {
          DPA_municipality_code: '24.07',
          municipality: 'San Nicolás',
        },
        24.06: {
          DPA_municipality_code: '24.06',
          municipality: 'Nueva Paz',
        },
        '24.10': {
          DPA_municipality_code: '24.10',
          municipality: 'Batabanó',
        },
        24.09: {
          DPA_municipality_code: '24.09',
          municipality: 'Melena del Sur',
        },
      },
    },
    vcl: {
      province: 'Villa Clara',
      province_id: 'vcl',
      DPA_province_code: '26',
      muns: {
        26.03: {
          DPA_municipality_code: '26.03',
          municipality: 'Sagua La Grande',
        },
        26.01: {
          DPA_municipality_code: '26.01',
          municipality: 'Corralillo',
        },
        26.02: {
          DPA_municipality_code: '26.02',
          municipality: 'Quemado de Güines',
        },
        26.11: {
          DPA_municipality_code: '26.11',
          municipality: 'Santo Domingo',
        },
        '26.10': {
          DPA_municipality_code: '26.10',
          municipality: 'Cifuentes',
        },
        26.12: {
          DPA_municipality_code: '26.12',
          municipality: 'Ranchuelo',
        },
        26.09: {
          DPA_municipality_code: '26.09',
          municipality: 'Santa Clara',
        },
        26.13: {
          DPA_municipality_code: '26.13',
          municipality: 'Manicaragua',
        },
        26.04: {
          DPA_municipality_code: '26.04',
          municipality: 'Encrucijada',
        },
        26.05: {
          DPA_municipality_code: '26.05',
          municipality: 'Camajuaní',
        },
        26.06: {
          DPA_municipality_code: '26.06',
          municipality: 'Caibarién',
        },
        26.07: {
          DPA_municipality_code: '26.07',
          municipality: 'Remedios',
        },
        26.08: {
          DPA_municipality_code: '26.08',
          municipality: 'Placetas',
        },
      },
    },
    art: {
      province: 'Artemisa',
      province_id: 'art',
      DPA_province_code: '22',
      muns: {
        22.05: {
          DPA_municipality_code: '22.05',
          municipality: 'Bauta',
        },
        22.04: {
          DPA_municipality_code: '22.04',
          municipality: 'Caimito',
        },
        22.02: {
          DPA_municipality_code: '22.02',
          municipality: 'Mariel',
        },
        22.01: {
          DPA_municipality_code: '22.01',
          municipality: 'Bahía Honda',
        },
        22.06: {
          DPA_municipality_code: '22.06',
          municipality: 'San Antonio de los Baños',
        },
        22.09: {
          DPA_municipality_code: '22.09',
          municipality: 'Artemisa',
        },
        22.03: {
          DPA_municipality_code: '22.03',
          municipality: 'Guanajay',
        },
        22.08: {
          DPA_municipality_code: '22.08',
          municipality: 'Alquízar',
        },
        22.07: {
          DPA_municipality_code: '22.07',
          municipality: 'Güira de Melena',
        },
        '22.10': {
          DPA_municipality_code: '22.10',
          municipality: 'Candelaria',
        },
        22.11: {
          DPA_municipality_code: '22.11',
          municipality: 'San Cristóbal',
        },
      },
    },
    pri: {
      province: 'Pinar del Río',
      province_id: 'pri',
      DPA_province_code: '21',
      muns: {
        21.05: {
          DPA_municipality_code: '21.05',
          municipality: 'La Palma',
        },
        21.04: {
          DPA_municipality_code: '21.04',
          municipality: 'Viñales',
        },
        21.06: {
          DPA_municipality_code: '21.06',
          municipality: 'Los Palacios',
        },
        21.03: {
          DPA_municipality_code: '21.03',
          municipality: 'Minas de Matahambre',
        },
        21.07: {
          DPA_municipality_code: '21.07',
          municipality: 'Consolación del sur',
        },
        21.02: {
          DPA_municipality_code: '21.02',
          municipality: 'Mantua',
        },
        21.08: {
          DPA_municipality_code: '21.08',
          municipality: 'Pinar del Río',
        },
        '21.10': {
          DPA_municipality_code: '21.10',
          municipality: 'San Juan y Martínez',
        },
        21.11: {
          DPA_municipality_code: '21.11',
          municipality: 'Guane',
        },
        21.09: {
          DPA_municipality_code: '21.09',
          municipality: 'San Luis',
        },
        21.01: {
          DPA_municipality_code: '21.01',
          municipality: 'Sandino',
        },
      },
    },
    cfg: {
      province: 'Cienfuegos',
      province_id: 'cfg',
      DPA_province_code: '27',
      muns: {
        27.02: {
          DPA_municipality_code: '27.02',
          municipality: 'Rodas',
        },
        27.04: {
          DPA_municipality_code: '27.04',
          municipality: 'Lajas',
        },
        27.01: {
          DPA_municipality_code: '27.01',
          municipality: 'Aguada de Pasajeros',
        },
        27.03: {
          DPA_municipality_code: '27.03',
          municipality: 'Palmira',
        },
        27.05: {
          DPA_municipality_code: '27.05',
          municipality: 'Cruces',
        },
        27.06: {
          DPA_municipality_code: '27.06',
          municipality: 'Cumanayagua',
        },
        27.07: {
          DPA_municipality_code: '27.07',
          municipality: 'Cienfuegos',
        },
        27.08: {
          DPA_municipality_code: '27.08',
          municipality: 'Abreus',
        },
      },
    },
    ijv: {
      province: 'Isla de la Juventud',
      province_id: 'ijv',
      DPA_province_code: '40.01',
      muns: {
        40.01: {
          DPA_municipality_code: '40.01',
          municipality: 'Isla de la Juventud',
        },
      },
    },
    ssp: {
      province: 'Sancti Spíritus',
      province_id: 'ssp',
      DPA_province_code: '28',
      muns: {
        28.06: {
          DPA_municipality_code: '28.06',
          municipality: 'Trinidad',
        },
        28.01: {
          DPA_municipality_code: '28.01',
          municipality: 'Yaguajay',
        },
        28.04: {
          DPA_municipality_code: '28.04',
          municipality: 'Cabaiguán',
        },
        28.05: {
          DPA_municipality_code: '28.05',
          municipality: 'Fomento',
        },
        28.03: {
          DPA_municipality_code: '28.03',
          municipality: 'Taguasco',
        },
        28.02: {
          DPA_municipality_code: '28.02',
          municipality: 'Jatibonico',
        },
        28.07: {
          DPA_municipality_code: '28.07',
          municipality: 'Sancti Spíritus',
        },
        28.08: {
          DPA_municipality_code: '28.08',
          municipality: 'La Sierpe',
        },
      },
    },
    cav: {
      province: 'Ciego de Ávila',
      province_id: 'cav',
      DPA_province_code: '29',
      muns: {
        29.02: {
          DPA_municipality_code: '29.02',
          municipality: 'Morón',
        },
        29.01: {
          DPA_municipality_code: '29.01',
          municipality: 'Chambas',
        },
        29.06: {
          DPA_municipality_code: '29.06',
          municipality: 'Florencia',
        },
        29.05: {
          DPA_municipality_code: '29.05',
          municipality: 'Ciro Redondo',
        },
        29.03: {
          DPA_municipality_code: '29.03',
          municipality: 'Bolivia',
        },
        29.04: {
          DPA_municipality_code: '29.04',
          municipality: 'Primero de Enero',
        },
        29.07: {
          DPA_municipality_code: '29.07',
          municipality: 'Majagua',
        },
        29.08: {
          DPA_municipality_code: '29.08',
          municipality: 'Ciego de Ávila',
        },
        '29.10': {
          DPA_municipality_code: '29.10',
          municipality: 'Baraguá',
        },
        29.09: {
          DPA_municipality_code: '29.09',
          municipality: 'Venezuela',
        },
      },
    },
    cam: {
      province: 'Camagüey',
      province_id: 'cam',
      DPA_province_code: '30',
      muns: {
        30.05: {
          DPA_municipality_code: '30.05',
          municipality: 'Nuevitas',
        },
        30.02: {
          DPA_municipality_code: '30.02',
          municipality: 'Esmeralda',
        },
        30.03: {
          DPA_municipality_code: '30.03',
          municipality: 'Sierra de Cubitas',
        },
        30.04: {
          DPA_municipality_code: '30.04',
          municipality: 'Minas',
        },
        30.01: {
          DPA_municipality_code: '30.01',
          municipality: 'Carlos Manuel de Céspedes',
        },
        30.09: {
          DPA_municipality_code: '30.09',
          municipality: 'Florida',
        },
        30.08: {
          DPA_municipality_code: '30.08',
          municipality: 'Camagüey',
        },
        30.06: {
          DPA_municipality_code: '30.06',
          municipality: 'Guáimaro',
        },
        30.07: {
          DPA_municipality_code: '30.07',
          municipality: 'Sibanicú',
        },
        '30.10': {
          DPA_municipality_code: '30.10',
          municipality: 'Vertientes',
        },
        30.11: {
          DPA_municipality_code: '30.11',
          municipality: 'Jimaguayú',
        },
        30.13: {
          DPA_municipality_code: '30.13',
          municipality: 'Santa Cruz del Sur',
        },
        30.12: {
          DPA_municipality_code: '30.12',
          municipality: 'Najasa',
        },
      },
    },
    ltu: {
      province: 'Las Tunas',
      province_id: 'ltu',
      DPA_province_code: '31',
      muns: {
        31.01: {
          DPA_municipality_code: '31.01',
          municipality: 'Manatí',
        },
        31.03: {
          DPA_municipality_code: '31.03',
          municipality: 'Jesús Menéndez',
        },
        31.02: {
          DPA_municipality_code: '31.02',
          municipality: 'Puerto Padre',
        },
        31.05: {
          DPA_municipality_code: '31.05',
          municipality: 'Las Tunas',
        },
        31.06: {
          DPA_municipality_code: '31.06',
          municipality: 'Jobabo',
        },
        31.07: {
          DPA_municipality_code: '31.07',
          municipality: 'Colombia',
        },
        31.08: {
          DPA_municipality_code: '31.08',
          municipality: 'Amancio',
        },
        31.04: {
          DPA_municipality_code: '31.04',
          municipality: 'Majibacoa',
        },
      },
    },
    hol: {
      province: 'Holguín',
      province_id: 'hol',
      DPA_province_code: '32',
      muns: {
        32.03: {
          DPA_municipality_code: '32.03',
          municipality: 'Banes',
        },
        32.01: {
          DPA_municipality_code: '32.01',
          municipality: 'Gibara',
        },
        32.02: {
          DPA_municipality_code: '32.02',
          municipality: 'Rafael Freyre',
        },
        32.07: {
          DPA_municipality_code: '32.07',
          municipality: 'Calixto García',
        },
        32.06: {
          DPA_municipality_code: '32.06',
          municipality: 'Holguín',
        },
        32.05: {
          DPA_municipality_code: '32.05',
          municipality: 'Báguanos',
        },
        32.04: {
          DPA_municipality_code: '32.04',
          municipality: 'Antilla',
        },
        32.11: {
          DPA_municipality_code: '32.11',
          municipality: 'Mayarí',
        },
        32.08: {
          DPA_municipality_code: '32.08',
          municipality: 'Cacocum',
        },
        32.14: {
          DPA_municipality_code: '32.14',
          municipality: 'Moa',
        },
        32.12: {
          DPA_municipality_code: '32.12',
          municipality: 'Frank País',
        },
        '32.10': {
          DPA_municipality_code: '32.10',
          municipality: 'Cueto',
        },
        32.09: {
          DPA_municipality_code: '32.09',
          municipality: 'Urbano Noris',
        },
        32.13: {
          DPA_municipality_code: '32.13',
          municipality: 'Sagua de Tánamo',
        },
      },
    },
    gra: {
      province: 'Granma',
      province_id: 'gra',
      DPA_province_code: '33',
      muns: {
        33.01: {
          DPA_municipality_code: '33.01',
          municipality: 'Río Cauto',
        },
        33.02: {
          DPA_municipality_code: '33.02',
          municipality: 'Cauto Cristo',
        },
        33.04: {
          DPA_municipality_code: '33.04',
          municipality: 'Bayamo',
        },
        33.03: {
          DPA_municipality_code: '33.03',
          municipality: 'Jiguaní',
        },
        33.05: {
          DPA_municipality_code: '33.05',
          municipality: 'Yara',
        },
        33.06: {
          DPA_municipality_code: '33.06',
          municipality: 'Manzanillo',
        },
        33.13: {
          DPA_municipality_code: '33.13',
          municipality: 'Guisa',
        },
        33.12: {
          DPA_municipality_code: '33.12',
          municipality: 'Buey Arriba',
        },
        33.11: {
          DPA_municipality_code: '33.11',
          municipality: 'Bartolomé Masó',
        },
        33.08: {
          DPA_municipality_code: '33.08',
          municipality: 'Media Luna',
        },
        33.09: {
          DPA_municipality_code: '33.09',
          municipality: 'Niquero',
        },
        '33.10': {
          DPA_municipality_code: '33.10',
          municipality: 'Pilón',
        },
        33.07: {
          DPA_municipality_code: '33.07',
          municipality: 'Campechuela',
        },
      },
    },
    stg: {
      province: 'Santiago de Cuba',
      province_id: 'stg',
      DPA_province_code: '34',
      muns: {
        34.04: {
          DPA_municipality_code: '34.04',
          municipality: 'Segundo Frente',
        },
        34.02: {
          DPA_municipality_code: '34.02',
          municipality: 'Mella',
        },
        34.01: {
          DPA_municipality_code: '34.01',
          municipality: 'Contramaestre',
        },
        34.03: {
          DPA_municipality_code: '34.03',
          municipality: 'San Luis',
        },
        34.07: {
          DPA_municipality_code: '34.07',
          municipality: 'Palma Soriano',
        },
        34.05: {
          DPA_municipality_code: '34.05',
          municipality: 'Songo La Maya',
        },
        34.08: {
          DPA_municipality_code: '34.08',
          municipality: 'Tercer Frente',
        },
        34.06: {
          DPA_municipality_code: '34.06',
          municipality: 'Santiago de Cuba',
        },
        34.09: {
          DPA_municipality_code: '34.09',
          municipality: 'Guamá',
        },
      },
    },
    gtm: {
      province: 'Guantánamo',
      province_id: 'gtm',
      DPA_province_code: '35',
      muns: {
        35.09: {
          DPA_municipality_code: '35.09',
          municipality: 'Guantánamo',
        },
        35.03: {
          DPA_municipality_code: '35.03',
          municipality: 'Yateras',
        },
        35.01: {
          DPA_municipality_code: '35.01',
          municipality: 'El Salvador',
        },
        35.02: {
          DPA_municipality_code: '35.02',
          municipality: 'Manuel Tames',
        },
        '35.10': {
          DPA_municipality_code: '35.10',
          municipality: 'Niceto Pérez',
        },
        35.08: {
          DPA_municipality_code: '35.08',
          municipality: 'Caimanera',
        },
        35.07: {
          DPA_municipality_code: '35.07',
          municipality: 'San Antonio del Sur',
        },
        35.04: {
          DPA_municipality_code: '35.04',
          municipality: 'Baracoa',
        },
        35.06: {
          DPA_municipality_code: '35.06',
          municipality: 'Imías',
        },
        35.05: {
          DPA_municipality_code: '35.05',
          municipality: 'Maisí',
        },
      },
    },
  };
  
  const province_order = {
    lha: 2,
    mat: 4,
    cfg: 6,
    ssp: 7,
    ltu: 10,
    hol: 12,
    gra: 11,
    stg: 13,
    ijv: 15,
    cam: 9,
    cav: 8,
    vcl: 5,
    gtm: 14,
    pri: 0,
    art: 1,
    may: 3,
  };
  
  $.predict = {
    loaded: {},
    load_promise: function (url) {
      let result;
      if (url in $.predict.loaded) {
        result = Object.assign({}, $.predict.loaded[url]);
      } else {
        result = $.ajax({
          url: url,
          dataType: 'json',
          cache: false,
          success: function (data) {
            $.predict.loaded[url] = Object.assign({}, data);
          },
        });
      }
      return result;
    },
    load: function (url, callback) {
      if (url in $.predict.loaded) {
        return callback(Object.assign({}, $.predict.loaded[url]));
      }
      cache = false;
      $.ajax({
        url: url,
        dataType: 'json',
        cache: cache,
        success: function (data) {
          $.predict.loaded[url] = Object.assign({}, data);
          callback(data);
        },
      });
    },
    plot: (url, selector) => {
      $.predict.load(url, (data) => {
        plotPredict(data.data, data.days, selector);
      });
    },
    plot_promises: (promises, selectors) => {
      $.when(...promises).done(function () {
        let counter = 0;
        let smaller_length = Number.MAX_SAFE_INTEGER;
  
        // find smaller lenght of over the gropu we are plotting
        for (let key of Object.keys(arguments)) {
          let data;
          if (!arguments[key].data) {
            data = arguments[key][0];
          } else {
            data = arguments[key];
          }
          smaller_length = Math.min(smaller_length, data.data[2].y.length);
        }
        // slice and plot
        for (let key of Object.keys(arguments)) {
          let data;
          if (!arguments[key].data) {
            data = arguments[key][0];
          } else {
            data = arguments[key];
          }
  
          // cumpte lenght of the real data
          const non_predic_length =
            smaller_length - (data.data[2].y.length - data.data[0].y.length);
  
          // slice all plots to fit with the smallest lenght
          let datad = [];
          for (let i = 0; i < data.data.length; i++) {
            plot_data_cp = Object.assign({}, data.data[i]);
            if (i === 0 || i === 1) {
              plot_data_cp.y = plot_data_cp.y.slice(
                plot_data_cp.y.length - non_predic_length >= 0
                  ? plot_data_cp.y.length - non_predic_length
                  : 0
              );
            } else {
              plot_data_cp.y = plot_data_cp.y.slice(
                plot_data_cp.y.length - smaller_length >= 0
                  ? plot_data_cp.y.length - smaller_length
                  : 0
              );
            }
            datad.push(plot_data_cp);
          }
  
          let data_days = data.days.slice(
            data.days.length - smaller_length +1>= 0
              ? data.days.length - smaller_length + 1
              : 0
          );
  
          // plot in prallel
          setTimeout(
            (datay, days, selector) => {
              plotPredict(datay, days, selector);
            },
            0,
            datad,
            data_days,
            selectors[counter]
          );
  
          counter++;
        }
      });
    },
  };
  
  function plotPredict(plots, days, selector) {
    const types = {};
    const columns = [];
    let less_size = days.length;
    for (const plot of plots) {
      types[plot.name] = plot['c3-plot'];
      const col = [plot.name, ...plot.y];
      columns.push(col);
      if (plot.y.length < less_size) {
        less_size = plot.y.length;
      }
    }
  
    const pred = ['Predicción'];
    for (let i = 1; i < columns[2].length; i++) {
      pred.push(0);
    }
  
    let totalMethods = 0;
    for (let i = 2; i < columns.length; i++) {
      if (columns[i][1] !== null) {
        totalMethods++;
        for (let y = 1; y < columns[i].length; y++) {
          pred[y] = pred[y] + columns[i][y];
        }
      }
    }
  
    for (let i = 1; i < pred.length; i++) {
      pred[i] = pred[i] / totalMethods;
    }
  
    types[pred[0]] = 'spline';
  
    columns.push(pred);
  
    columns.push(['Fecha', ...days]);
  
    var graph = c3.generate({
      bindto: selector,
      data: {
        x: 'Fecha',
        columns: columns,
        type: 'scatter',
        types: types,
      },
      tooltip: {
        format: {
          value: function (value, r, id, index) {
            return value.toFixed(0); // 0 lugares despues de la coma
          },
        },
      },
      grid: {
        x: {
          lines: [
            { value: days[less_size], text: 'Pronóstico', position: 'start' },
          ],
        },
      },
      axis: {
        x: {
          padding: {
            left: 1,
            right: 1,
          },
          label: 'Fecha',
          type: 'categorical',
          tick: {
            values: [0, less_size, days.length - 1],
          },
          padding: {
            left: 2,
            right: 4,
          },
        },
        y: {
          label: {
            text: '# Infectados',
            position: 'outer-middle',
          },
        },
      },
    });
  
    for (var i = 2; i < columns.length - 2; i++) {
      graph.hide(columns[i][0]);
    }
  }
  
  $locator = $('#location-select');
  const sorted_provinces = Object.keys(province_order).sort(
    (p1, p2) => province_order[p1] > province_order[p2]
  );
  
  for (const pr of sorted_provinces) {
    const value = pros_muns[pr].province_id;
    const text = pros_muns[pr].province;
    $locator.append('<option value="' + value + '">' + text + '</option>');
  }
  
  function run() {
    const province_id = $locator.val();
    const general_view = $locator.val() === 'cuba';
    let url = `data/predictions/${
      general_view ? 'cuba' : pros_muns[province_id].DPA_province_code
    }.json`;
    const header = general_view
      ? 'Cuba'
      : province_id !== 'ijv'
      ? `Provincia - ${pros_muns[province_id].province}`
      : `Municipio especial - ${pros_muns[province_id].province}`;
    $('#predict-header').text(header);
  
    const load_data = [];
    const selectors = [];
  
    //$.predict.plot(url, '#predict-cuba');
    load_data.push($.predict.load_promise(url));
    selectors.push('#predict-cuba');
  
    const container$ = $('#other-predictions');
    container$.empty();
    if (general_view) {
      let counter = 1;
      for (const pr of sorted_provinces) {
        const el = `
        <div class="card-deck">
          <section class="card common-bg">
            <div class="card-header">Provincia - ${pros_muns[pr].province}</div>
            <div class="card-body">
              <div class="predictions" id="predict-cuba-${counter}"></div>
            </div>
          </section>
        </div>
        `;
        container$.append(el);
        url = `data/predictions/${pros_muns[pr].DPA_province_code}.json`;
        const sel = `#predict-cuba-${counter}`;
        //$.predict.plot(url, sel);
        load_data.push($.predict.load_promise(url));
        selectors.push(sel);
        counter += 1;
      }
    } else {
      if (province_id === 'ijv') {
        return;
      }
      let counter = 1;
      muns = Object.keys(pros_muns[province_id].muns).sort();
      for (const mn of muns) {
        const mun = pros_muns[province_id].muns[mn];
        const el = `
        <div class="card-deck">
          <section class="card common-bg">
            <div class="card-header">Municipio - ${mun.municipality}</div>
            <div class="card-body">
              <div class="predictions" id="predict-cuba-${counter}"></div>
            </div>
          </section>
        </div>
        `;
        container$.append(el);
        url = `data/predictions/${mun.DPA_municipality_code}.json`;
        const sel = `#predict-cuba-${counter}`;
        //$.predict.plot(url, sel);
        load_data.push($.predict.load_promise(url));
        selectors.push(sel);
        counter += 1;
      }
    }
    $.predict.plot_promises(load_data, selectors);
  }
  
  $locator.on('change', function (e) {
    run();
  });
  
  run();
  