function associationGenreAOeuvre(listeArtistes){
var genresDesArtistes = []
var categorisation;
var nbArtistes = listeArtistes.length
if (nbArtistes == 1){
var id = listeArtistes[0].id
if (listeArtistes[0].artisteMac == true)
var artiste = artistesMac.find( d => d.id == id)
else
var artiste = {genre: "Inconnu"}
if (artiste.genre != "Collectif"){
genresDesArtistes.push(artiste.genre)
}
else if (artiste.genre == "Collectif"){
var artistesDuCollectif = artiste.groupeArtistes
artistesDuCollectif.forEach( artisteDuCollectif => {
if (artisteDuCollectif.artisteMac == true){
var artisteConcerne = artistesMac.find( d => d.id == artisteDuCollectif.id)
genresDesArtistes.push(artisteConcerne.genre)
}
else
genresDesArtistes.push("Inconnu")
})
}
else
console.log("ATTENTION option 1: problème dans la comptabilisation des genres")
}
else {
// ***Option 2: s'il y a plusieurs artistes***
//pour chaque artiste
listeArtistes.forEach(a => {
//récupérer l'id de l'artiste ou du collectif
var id = a.id
//si l'artiste est dans la collection du MAC
if (a.artisteMac == true){
var artiste = artistesMac.find( d => d.id == id)
//si c'est bien un artiste individuel et non un collectif, on ajoute son genre à la liste
if (artiste.genre != "Collectif"){
genresDesArtistes.push(artiste.genre)
}
else {
// dans le cas où c'est un collectif, on passe à travers de la liste des artistes du collectif (dans la propriété groupeArtistes)
var artistesDuCollectif = artiste.groupeArtistes
artistesDuCollectif.forEach( artisteDuCollectif => {
// pour chaque artiste du collectif
if (artisteDuCollectif.artisteMac == true){
//si c'est artiste du MAC, on récupère son identifiant et on ajoute son genre à la liste des genresDesArtistes
var artisteConcerne = artistesMac.find( d => d.id == artisteDuCollectif.id)
genresDesArtistes.push(artisteConcerne.genre)
}
else
genresDesArtistes.push("Inconnu")
})
}
}
else //si l'artiste n'est pas dans la collection du MAC, on ajoute genre Inconnu
genresDesArtistes.push("Inconnu")
})
}
//comptabilisation des genres
var comptabilisationDesGenres;
//compte le nombre de Féminin, Masculin et Inconnu parmi les artistes
var nbFemmes = genresDesArtistes.filter(d => d == "Féminin").length
var nbHommes = genresDesArtistes.filter(d => d == "Masculin").length
var nbInconnus = genresDesArtistes.filter(d => d == "Inconnu").length
//on vérifie que le décompte est bon
if (genresDesArtistes.length != (nbFemmes+nbHommes+nbInconnus))
console.log("ATTENTION: erreur dans le décompte")
if (genresDesArtistes.length == nbFemmes){
comptabilisationDesGenres = "Féminin"
}
else if (genresDesArtistes.length == nbHommes)
comptabilisationDesGenres = "Masculin"
else if (genresDesArtistes.length == nbInconnus){
comptabilisationDesGenres = "Inconnu"
}
else if (genresDesArtistes.includes("Féminin") && genresDesArtistes.includes("Masculin"))
comptabilisationDesGenres = "Mixte"
else if (genresDesArtistes.includes("Inconnu") && genresDesArtistes.includes("Féminin"))
comptabilisationDesGenres = "Féminin & Inconnu"
else if (genresDesArtistes.includes("Inconnu") && genresDesArtistes.includes("Masculin"))
comptabilisationDesGenres = "Masculin & Inconnu"
else {
console.log("ATTENTION option 2: problème dans la comptabilisation des genres")
console.log(genresDesArtistes)
//il y a une œuvre avec 5 Masculin et 1 Collecif, il faudrait faire une option de plus pour ça, en attendant on met à inconnu
comptabilisationDesGenres = "Masculin & Inconnu"
}
// pas possible qu'il n'y ait que des artistes inconnus
// à partir de la comptabilisation des genres
switch(comptabilisationDesGenres) {
case "Féminin":
categorisation = "Féminin"
break;
case "Féminin & Inconnu":
categorisation = "Féminin"
break;
case "Masculin":
categorisation = "Masculin"
break;
case "Masculin & Inconnu":
categorisation = "Féminin"
break;
case "Mixte":
categorisation = "Mixte"
break;
case "Inconnu":
categorisation = "Inconnu"
break;
}
return categorisation
}