<commit_before>"use strict";
let express = require("express");
let router = express.Router();
const logError = require("../helpers/log-error.js");
let { db, FEATURED } = require("../helpers/db");

function shuffle(array) {
  const shuffledArray = array.slice();
  for (let i = shuffledArray.length - 1; i > 0; i--) {
    let j = Math.floor(Math.random() * (i + 1));
    [shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
  }
  return shuffledArray;
}

function getHeroFeatures() {
  return shuffle([
    {
      imageCredit: "Housing Institute of Buenos Aires",
      imageUrl:
        "https://s3.amazonaws.com/participedia.prod/ee8da85d-d17e-4bfb-a500-0fc2e3dfd72a-In%20the%20Participatory%20Community%20Boards%20the%20plans%20presented%20by%20the%20Housing%20Institute%20are%20shaped.",
      entryTitle:
        'Participatory Slum Upgrading Process in the City of Buenos Aires: The "Villa 20" Case',
      entryUrl: "/case/5988",
      country: "Argentina",
    },
    {
      imageCredit:
        "Research Team, University of the Western Cape: Professor <NAME>, <NAME> and <NAME>",
      imageUrl:
        "https://s3.amazonaws.com/participedia.prod/b5294e0a-e875-4ece-afe1-a242f851a5c3",
      entryTitle:
        "Decommissioning South African Social Services: Participatory Field Research in Delft",
      entryUrl: "/case/5834",
      country: "South Africa",
    },
    {
      imageCredit: "<NAME>",
      imageUrl:
        "https://s3.amazonaws.com/participedia.prod/d97cf067-9b0b-4d80-bc38-aee5b8553c8c",
      entryTitle: "George Floyd Protests",
      entryUrl: "/case/6590",
      country: "United States",
    },
    {
      imageUrl: "/images/homepage/hero-map-static.png",
      entryTitle: "Explore Cases & Organizations by Location",
      entryUrl: "#map",
    },
  ]);
}

async function getThingStatistic() {
  const stats = {
    cases: 0,
    methods: 0,
    organizations: 0,
    collections: 0,
  };
  const results = await db.any(
    "SELECT type, COUNT(*) as total FROM things GROUP BY type"
  );
  results.map(result => {
    let type = `${result.type}s`;
    if (stats.hasOwnProperty(type)) {
      stats[type] = parseInt(result.total);
    }
  });
  return stats;
}

async function getTotalCountries() {
  const results = await db.any(
    "SELECT country FROM things WHERE type IN ('case', 'organization') and country <> '' GROUP BY country"
  );
  let total = 0;
  if (results && results.length) {
    total = parseInt(results.length);
  }
  return total;<commit_msg>Don't include hidden in home statistics<commit_after>"use strict";
let express = require("express");
let router = express.Router();
const logError = require("../helpers/log-error.js");
let { db, FEATURED } = require("../helpers/db");

function shuffle(array) {
  const shuffledArray = array.slice();
  for (let i = shuffledArray.length - 1; i > 0; i--) {
    let j = Math.floor(Math.random() * (i + 1));
    [shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
  }
  return shuffledArray;
}

function getHeroFeatures() {
  return shuffle([
    {
      imageCredit: "Housing Institute of Buenos Aires",
      imageUrl:
        "https://s3.amazonaws.com/participedia.prod/ee8da85d-d17e-4bfb-a500-0fc2e3dfd72a-In%20the%20Participatory%20Community%20Boards%20the%20plans%20presented%20by%20the%20Housing%20Institute%20are%20shaped.",
      entryTitle:
        'Participatory Slum Upgrading Process in the City of Buenos Aires: The "Villa 20" Case',
      entryUrl: "/case/5988",
      country: "Argentina",
    },
    {
      imageCredit:
        "Research Team, University of the Western Cape: Professor <NAME>, <NAME> and <NAME>",
      imageUrl:
        "https://s3.amazonaws.com/participedia.prod/b5294e0a-e875-4ece-afe1-a242f851a5c3",
      entryTitle:
        "Decommissioning South African Social Services: Participatory Field Research in Delft",
      entryUrl: "/case/5834",
      country: "South Africa",
    },
    {
      imageCredit: "<NAME>",
      imageUrl:
        "https://s3.amazonaws.com/participedia.prod/d97cf067-9b0b-4d80-bc38-aee5b8553c8c",
      entryTitle: "George Floyd Protests",
      entryUrl: "/case/6590",
      country: "United States",
    },
    {
      imageUrl: "/images/homepage/hero-map-static.png",
      entryTitle: "Explore Cases & Organizations by Location",
      entryUrl: "#map",
    },
  ]);
}

async function getThingStatistic() {
  const stats = {
    cases: 0,
    methods: 0,
    organizations: 0,
    collections: 0,
  };
  const results = await db.any(
    "SELECT type, COUNT(*) as total FROM things WHERE hidden = false GROUP BY type"
  );
  results.map(result => {
    let type = `${result.type}s`;
    if (stats.hasOwnProperty(type)) {
      stats[type] = parseInt(result.total);
    }
  });
  return stats;
}

async function getTotalCountries() {
  const results = await db.any(
    "SELECT country FROM things WHERE type IN ('case', 'organization') and country <> '' GROUP BY country"
  );
  let total = 0;
  if (results && results.length) {
    total = parseInt(results.length);
  }
  return total;
{'fraction_non_alphanumeric': 0.1409829645584492, 'fraction_numerical': 0.03955355394556491, 'mean_word_length': 3.2075782537067545, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 6, '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': '1168500', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1693, 'n_words': 391}