<commit_before>import Vue from "vue";
import VueRouter from "vue-router";
import { getRemoteData } from "../webapp/lib/utils";
import { EventBus } from "../webapp/mixins/event_bus";
import { checkAndReportAccessibility } from "lib/vue/accesibility";

if (Vue.config.devtools) {
  Vue.use(checkAndReportAccessibility)
}
Vue.use(VueRouter);
Vue.config.productionTip = false;

export class CostsController {
  constructor(options) {
    this.charts = {};

    const selector = "gobierto-visualizations-costs-app";

    // Mount Vue applications
    const entryPoint = document.getElementById(selector);

    if (entryPoint) {
      const htmlRouterBlock = `<router-view></router-view>`;

      entryPoint.innerHTML = htmlRouterBlock;

      const Home = () =>
        import("../webapp/containers/costs/Home.vue");
      const TableFirstLevel = () =>
        import("../webapp/containers/costs/table/TableFirstLevel.vue");
      const TableSecondLevel = () =>
        import("../webapp/containers/costs/table/TableSecondLevel.vue");
      const TableItem = () =>
        import("../webapp/containers/costs/table/TableItem.vue");

      Promise.resolve(getRemoteData(options.costsEndpoint)).then(rawData => {
        this.setGlobalVariables(rawData);

        const router = new VueRouter({
          mode: "history",
          routes: [
            {
              path: "/visualizaciones/costes/",
              name: "Home",
              component: Home,
              children: [
                {
                  path: "/visualizaciones/costes/:year?",
                  component: TableFirstLevel,
                  name: "TableFirstLevel"
                },
                {
                  path: "/visualizaciones/costes/:year?/:id?",
                  component: TableSecondLevel,
                  name: "TableSecondLevel"
                },
                {
                  path: "/visualizaciones/costes/:year?/:id?/:item?",
                  component: TableItem,
                  name: "TableItem"
                }
              ]
            }
          ],
          scrollBehavior(to) {
            let element;
            //Get a different position scroll
            if (to.name !== "TableFirstLevel") {
              element = document.getElementById(
                "gobierto-visualizations-title-detail"
              );
              element.scrollIntoView({ behavior: "smooth" });
            }
          }
        });

        const baseTitle = document.title;
        router.afterEach(to => {
          // Wait 2 ticks
          Vue.nextTick(() =>
            Vue.nextTick(() => {
              let title = baseTitle;
              if (to.name === "TableItem") {
                const { description: itemTitle } = to.params;

                if (itemTitle) {
                  title = `${itemTitle} ${baseTitle}`;
                }
              } else if (to.name === "TableSecondLevel") {
                const { description: itemTitle } = to.params;

                if (itemTitle) {
                  title = `${itemTitle} ${baseTitle}`;
                }
              }
              document.title = title;
            })
          );
        });

        this.vueApp = new Vue({
          router,
          data: Object.assign(options, this.data)
        }).$mount(entryPoint);

        EventBus.$on("mounted", () => {
          // Hide the external loader once the vueApp has been mounted in the DOM
          const loadingElement = document.querySelector(".js-loading");
          if (loadingElement) {
            loadingElement.classList.add("hidden");
          }
        });
      });
    }
  }

  setGlobalVariables(rawData) {
    //Convert strings with some format to Numbers without format
    function convertStringToNumbers(amount) {
      if (amount === "") {
        return nanToZero(amount);
      } else {
        return Number(parseFloat(amount));
      }
    }

    //Some values are empty, so we need to transform to zero
    function nanToZero(val) {
      val = +val || 0;
      return val;
    }

    //Array with all the strings that we've to convert to Number
    const amountStrings = [
      "costdirecte",
      "costindirecte",
      "costtotal",
      "costperhabit",
      "costpersonal",
      "costrestadir",
      "ingressos",
      "taxapreupub",
      "subvencions",
      "ingressos_cost",
      "costdirectepers",
      "costdirebens",
      "costdirservext",
      "costdirtransf",
      "costdirequip",
      "costdirfin"
    ];

    const population = ["128291", "129661"];

    let yearsCosts = [...new Set(rawData.map(item => item.any_))];
    console.log("yearsCosts", yearsCosts);

    for (let index = 0; index < rawData.length; index++) {
      let d = rawData[index];

      const ix = yearsCosts.findIndex(x => x === d["any_"])
      d.population = population[ix]

      for (let amounts = 0; amounts < amountStrings.length; amounts++) {
        d[amountStrings[amounts]] = convertStringToNumbers(
          d[amountStrings[amounts]]
        );
      }
    }

    let groupDataByYears = [];

    //Create an array of objects with all years
    for (let index = 0; index < yearsCosts.length; index++) {
      const data = rawData.reduce((acc, item) => {
        if (item.any_ === yearsCosts[index]) {
          acc.push({ ...item, population: population[index] });
        }
        return acc;
      }, []);
      const dataGroup = groupDataByYear(data, yearsCosts[index]);<commit_msg>remove console<commit_after>import Vue from "vue";
import VueRouter from "vue-router";
import { getRemoteData } from "../webapp/lib/utils";
import { EventBus } from "../webapp/mixins/event_bus";
import { checkAndReportAccessibility } from "lib/vue/accesibility";

if (Vue.config.devtools) {
  Vue.use(checkAndReportAccessibility)
}
Vue.use(VueRouter);
Vue.config.productionTip = false;

export class CostsController {
  constructor(options) {
    this.charts = {};

    const selector = "gobierto-visualizations-costs-app";

    // Mount Vue applications
    const entryPoint = document.getElementById(selector);

    if (entryPoint) {
      const htmlRouterBlock = `<router-view></router-view>`;

      entryPoint.innerHTML = htmlRouterBlock;

      const Home = () =>
        import("../webapp/containers/costs/Home.vue");
      const TableFirstLevel = () =>
        import("../webapp/containers/costs/table/TableFirstLevel.vue");
      const TableSecondLevel = () =>
        import("../webapp/containers/costs/table/TableSecondLevel.vue");
      const TableItem = () =>
        import("../webapp/containers/costs/table/TableItem.vue");

      Promise.resolve(getRemoteData(options.costsEndpoint)).then(rawData => {
        this.setGlobalVariables(rawData);

        const router = new VueRouter({
          mode: "history",
          routes: [
            {
              path: "/visualizaciones/costes/",
              name: "Home",
              component: Home,
              children: [
                {
                  path: "/visualizaciones/costes/:year?",
                  component: TableFirstLevel,
                  name: "TableFirstLevel"
                },
                {
                  path: "/visualizaciones/costes/:year?/:id?",
                  component: TableSecondLevel,
                  name: "TableSecondLevel"
                },
                {
                  path: "/visualizaciones/costes/:year?/:id?/:item?",
                  component: TableItem,
                  name: "TableItem"
                }
              ]
            }
          ],
          scrollBehavior(to) {
            let element;
            //Get a different position scroll
            if (to.name !== "TableFirstLevel") {
              element = document.getElementById(
                "gobierto-visualizations-title-detail"
              );
              element.scrollIntoView({ behavior: "smooth" });
            }
          }
        });

        const baseTitle = document.title;
        router.afterEach(to => {
          // Wait 2 ticks
          Vue.nextTick(() =>
            Vue.nextTick(() => {
              let title = baseTitle;
              if (to.name === "TableItem") {
                const { description: itemTitle } = to.params;

                if (itemTitle) {
                  title = `${itemTitle} ${baseTitle}`;
                }
              } else if (to.name === "TableSecondLevel") {
                const { description: itemTitle } = to.params;

                if (itemTitle) {
                  title = `${itemTitle} ${baseTitle}`;
                }
              }
              document.title = title;
            })
          );
        });

        this.vueApp = new Vue({
          router,
          data: Object.assign(options, this.data)
        }).$mount(entryPoint);

        EventBus.$on("mounted", () => {
          // Hide the external loader once the vueApp has been mounted in the DOM
          const loadingElement = document.querySelector(".js-loading");
          if (loadingElement) {
            loadingElement.classList.add("hidden");
          }
        });
      });
    }
  }

  setGlobalVariables(rawData) {
    //Convert strings with some format to Numbers without format
    function convertStringToNumbers(amount) {
      if (amount === "") {
        return nanToZero(amount);
      } else {
        return Number(parseFloat(amount));
      }
    }

    //Some values are empty, so we need to transform to zero
    function nanToZero(val) {
      val = +val || 0;
      return val;
    }

    //Array with all the strings that we've to convert to Number
    const amountStrings = [
      "costdirecte",
      "costindirecte",
      "costtotal",
      "costperhabit",
      "costpersonal",
      "costrestadir",
      "ingressos",
      "taxapreupub",
      "subvencions",
      "ingressos_cost",
      "costdirectepers",
      "costdirebens",
      "costdirservext",
      "costdirtransf",
      "costdirequip",
      "costdirfin"
    ];

    const population = ["128291", "129661"];

    let yearsCosts = [...new Set(rawData.map(item => item.any_))];

    for (let index = 0; index < rawData.length; index++) {
      let d = rawData[index];

      const ix = yearsCosts.findIndex(x => x === d["any_"])
      d.population = population[ix]

      for (let amounts = 0; amounts < amountStrings.length; amounts++) {
        d[amountStrings[amounts]] = convertStringToNumbers(
          d[amountStrings[amounts]]
        );
      }
    }

    let groupDataByYears = [];

    //Create an array of objects with all years
    for (let index = 0; index < yearsCosts.length; index++) {
      const data = rawData.reduce((acc, item) => {
        if (item.any_ === yearsCosts[index]) {
          acc.push({ ...item, population: population[index] });
        }
        return acc;
      }, []);
      const dataGroup = groupDataByYear(data, yearsCosts[index]);
{'fraction_non_alphanumeric': 0.12846139739592885, 'fraction_numerical': 0.003117549972492206, 'mean_word_length': 1.7774382480264834, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6346062', 'n_tokens_mistral': 3109, 'n_tokens_neox': 2977, 'n_words': 628}