A lot of things.
- Change tests directory location. - Fix Merlu CSV UTF8 encoding. - Make classes for ParasitesPeru2021.csv Parsing.
This commit is contained in:
97
src/ecoparasite/population/PopulationParsing.java
Normal file
97
src/ecoparasite/population/PopulationParsing.java
Normal file
@@ -0,0 +1,97 @@
|
||||
package ecoparasite.population;
|
||||
|
||||
import ecoparasite.input.RawData;
|
||||
import ecoparasite.input.RawDataOverflow;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class PopulationParsing {
|
||||
|
||||
public static HashMap<String,Population> parseParasitesPeru(RawData peruRawData ){
|
||||
|
||||
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");
|
||||
System.out.println(espece);
|
||||
String parametre = fields.get("Paramètre");
|
||||
|
||||
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++;
|
||||
}
|
||||
} catch (RawDataOverflow e){
|
||||
// Stop.
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user