2026-03-31 19:00:19 +02:00
|
|
|
package ecoparasite.population;
|
|
|
|
|
|
|
|
|
|
import ecoparasite.input.RawData;
|
|
|
|
|
import ecoparasite.input.RawDataOverflow;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
2026-04-01 14:34:07 +02:00
|
|
|
/**
|
|
|
|
|
* Permet de parser une population spécifique via les schémas fournis.
|
|
|
|
|
*/
|
2026-03-31 19:00:19 +02:00
|
|
|
public class PopulationParsing {
|
|
|
|
|
|
2026-04-01 14:34:07 +02:00
|
|
|
/**
|
|
|
|
|
* Permet, à partir d'un objet RawData, de parse les données tel que le fichier parasitesPeru est structuré.
|
|
|
|
|
*
|
|
|
|
|
* @param peruRawData
|
|
|
|
|
* @return Une liste des populations incluses.
|
|
|
|
|
*/
|
|
|
|
|
public static HashSet<Population> parseParasitesPeru(RawData peruRawData ){
|
2026-03-31 19:00:19 +02:00
|
|
|
|
|
|
|
|
HashMap<String,Population> response = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
int index = 1;
|
|
|
|
|
try {
|
|
|
|
|
while(true){ // Tant que l'on ne fait pas de débordements d'entrées.
|
|
|
|
|
|
|
|
|
|
HashMap<String,String> fields = peruRawData.getEntry(index);
|
|
|
|
|
|
|
|
|
|
String espece = fields.get("Espèce");
|
|
|
|
|
String parametre = fields.get("Paramètre");
|
|
|
|
|
|
2026-04-01 14:34:07 +02:00
|
|
|
// Récupère la population si elle existe déjà.
|
2026-03-31 19:00:19 +02:00
|
|
|
Population population = null;
|
|
|
|
|
if( response.containsKey( espece ) ){
|
|
|
|
|
population = response.get(espece);
|
|
|
|
|
} else {
|
|
|
|
|
population = new Population(espece);
|
|
|
|
|
response.put(espece, population);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Traiter le total
|
|
|
|
|
if( fields.containsKey( "Total" ) ){
|
|
|
|
|
if( population.getTotal() == null ){
|
|
|
|
|
population.setTotal( new PopulationArgs() );
|
|
|
|
|
}
|
|
|
|
|
PopulationParsing.applyValueForParasitesPeru( population.getTotal(), parametre, fields.get("Total") );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Traiter les années.
|
|
|
|
|
for( String k: fields.keySet() ){
|
|
|
|
|
if( k.equals( "Total" ) || k.equals("Paramètre") || k.equals("Espèce") ) // Déjà traité. Pas des années.
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
Integer year = Integer.parseInt(k);
|
|
|
|
|
|
|
|
|
|
PopulationArgs popArgsYear = null;
|
|
|
|
|
if( !population.getPerYear().containsKey(year) ){
|
|
|
|
|
popArgsYear = new PopulationArgs( year );
|
|
|
|
|
population.getPerYear().put(year, popArgsYear);
|
|
|
|
|
} else {
|
|
|
|
|
popArgsYear = population.getPerYear().get(year);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PopulationParsing.applyValueForParasitesPeru( popArgsYear, parametre, fields.get(k) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
response.put( espece, population );
|
|
|
|
|
index++;
|
|
|
|
|
}
|
2026-04-01 14:34:07 +02:00
|
|
|
} catch (RawDataOverflow e){ // Débordement, on a atteint la fin de l'objet RawData.
|
2026-03-31 19:00:19 +02:00
|
|
|
// Stop.
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-01 14:34:07 +02:00
|
|
|
return new HashSet<Population>( response.values() );
|
2026-03-31 19:00:19 +02:00
|
|
|
}
|
|
|
|
|
|
2026-04-01 14:34:07 +02:00
|
|
|
/**
|
|
|
|
|
* Permet d'appliquer la valeur au paramètre respectif en se basant sur le nom de la colonne.
|
|
|
|
|
*
|
|
|
|
|
* @param populationArgs Les paramètres de la population actuelle.
|
|
|
|
|
* @param column Le nom de la colonne dans le fichier CSV
|
|
|
|
|
* @param value La valeur a affecter
|
|
|
|
|
*/
|
2026-03-31 19:00:19 +02:00
|
|
|
private static void applyValueForParasitesPeru( PopulationArgs populationArgs, String column, String value ){
|
|
|
|
|
switch( column ){
|
|
|
|
|
case "N":
|
|
|
|
|
populationArgs.setNumber(Integer.parseInt(value));
|
|
|
|
|
break;
|
|
|
|
|
case "Longueur moyenne ± SD (cm)":
|
|
|
|
|
populationArgs.setLength( PopulationArgInterval.fromString( value ) );
|
|
|
|
|
break;
|
|
|
|
|
case "Poids moyen ± SD (g)":
|
|
|
|
|
populationArgs.setWidth( PopulationArgInterval.fromString( value ) );
|
|
|
|
|
break;
|
|
|
|
|
case "Prévalence (%)":
|
|
|
|
|
populationArgs.setPrevalence( PopulationArgInterval.fromString( value ) );
|
|
|
|
|
break;
|
|
|
|
|
case "IC 95%":
|
|
|
|
|
populationArgs.setIc( PopulationArgInterval.fromString( value ) );
|
|
|
|
|
break;
|
|
|
|
|
case "Intensité moyenne (étendue)":
|
|
|
|
|
populationArgs.setIntensity( Double.parseDouble( value.split( " " )[0] ) );
|
|
|
|
|
break;
|
|
|
|
|
case "Abondance moyenne":
|
|
|
|
|
populationArgs.setAbondance( Double.parseDouble( value ) );
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|