This commit is contained in:
2026-04-08 09:50:40 +02:00
parent d0ae9baed6
commit 9da4c38a03
4 changed files with 153 additions and 0 deletions

30
data/test2.csv Normal file
View File

@@ -0,0 +1,30 @@
id,Especes,LT,Abdomen,Foie,Visceres,Autres,Total
1,Serra Spanish mackerel,257,7,1,0,18,26
2,Serra Spanish mackerel,252,263,5,0,356,624
3,Serra Spanish mackerel,254,51,1,12,76,140
4,Serra Spanish mackerel,242,158,6,0,222,386
5,Serra Spanish mackerel,254,67,1,10,94,172
6,Serra Spanish mackerel,251,140,1,0,159,300
7,Serra Spanish mackerel,258,281,5,0,310,596
8,Serra Spanish mackerel,250,113,2,6,153,274
9,Serra Spanish mackerel,244,81,2,0,89,172
10,Serra Spanish mackerel,244,,0,1,,247
11,Serra Spanish mackerel,-200,23,0,0,25,48
12,Serra Spanish mackerel,247,53,0,0,75,
13,Serra Spanish mackerel,250,11,0,0,19,30
14,Serra Spanish mackerel,264,72,7,0,105,184
15,Serra Spanish mackerel,258,18,2,0,38,58
16,Serra Spanish mackerel,268,3,0,2,7,12
17,Serra Spanish mackerel,244,5,0,0,5,10
18,Serra Spanish mackerel,236,18,0,0,22,40
19,Serra Spanish mackerel,,46,0,0,64,110
20,Serra Spanish mackerel,251,-5,0,0,162,268
21,Serra Spanish mackerel,166,0,0,0,0,0
22,Serra Spanish mackerel,166,1,0,0,1,2
23,Serra Spanish mackerel,162,4,1,0,7,12
24,Serra Spanish mackerel,169,0,0,0,0,0
25,Serra Spanish mackerel,170,0,0,0,0,0
26,Serra Spanish mackerel,176,0,0,,0,0
27,Serra Spanish mackerel,165,4,0,0,6,10
28,Serra Spanish mackerel,193,4,0,0,4,8
29,Serra Spanish mackerel,165,1,0,0,1,2
1 id Especes LT Abdomen Foie Visceres Autres Total
2 1 Serra Spanish mackerel 257 7 1 0 18 26
3 2 Serra Spanish mackerel 252 263 5 0 356 624
4 3 Serra Spanish mackerel 254 51 1 12 76 140
5 4 Serra Spanish mackerel 242 158 6 0 222 386
6 5 Serra Spanish mackerel 254 67 1 10 94 172
7 6 Serra Spanish mackerel 251 140 1 0 159 300
8 7 Serra Spanish mackerel 258 281 5 0 310 596
9 8 Serra Spanish mackerel 250 113 2 6 153 274
10 9 Serra Spanish mackerel 244 81 2 0 89 172
11 10 Serra Spanish mackerel 244 0 1 247
12 11 Serra Spanish mackerel -200 23 0 0 25 48
13 12 Serra Spanish mackerel 247 53 0 0 75
14 13 Serra Spanish mackerel 250 11 0 0 19 30
15 14 Serra Spanish mackerel 264 72 7 0 105 184
16 15 Serra Spanish mackerel 258 18 2 0 38 58
17 16 Serra Spanish mackerel 268 3 0 2 7 12
18 17 Serra Spanish mackerel 244 5 0 0 5 10
19 18 Serra Spanish mackerel 236 18 0 0 22 40
20 19 Serra Spanish mackerel 46 0 0 64 110
21 20 Serra Spanish mackerel 251 -5 0 0 162 268
22 21 Serra Spanish mackerel 166 0 0 0 0 0
23 22 Serra Spanish mackerel 166 1 0 0 1 2
24 23 Serra Spanish mackerel 162 4 1 0 7 12
25 24 Serra Spanish mackerel 169 0 0 0 0 0
26 25 Serra Spanish mackerel 170 0 0 0 0 0
27 26 Serra Spanish mackerel 176 0 0 0 0
28 27 Serra Spanish mackerel 165 4 0 0 6 10
29 28 Serra Spanish mackerel 193 4 0 0 4 8
30 29 Serra Spanish mackerel 165 1 0 0 1 2

7
data/test3.csv Normal file
View File

@@ -0,0 +1,7 @@
Espèce,zone,N,Prevalence,LT mm,Masse g
Salmo salar,Atlantique Ouest,21,100,210,-3
Clupea harengus,Atlantique Nord,10,80,150,200
Merluccius,Atlantique Nord,5,90,750,
Dicentrarchus labrax,Atlantique Nord,12,65,680,
Scomber scombrus,Atlantique Nord,6,30,280,630
Merluccius,Atlantique Nord,2,100,720,1720
1 Espèce zone N Prevalence LT mm Masse g
2 Salmo salar Atlantique Ouest 21 100 210 -3
3 Clupea harengus Atlantique Nord 10 80 150 200
4 Merluccius Atlantique Nord 5 90 750
5 Dicentrarchus labrax Atlantique Nord 12 65 680
6 Scomber scombrus Atlantique Nord 6 30 280 630
7 Merluccius Atlantique Nord 2 100 720 1720

View File

@@ -0,0 +1,91 @@
package ecoparasite.poisson;
import ecoparasite.input.DataParsing;
import ecoparasite.input.InvalidParsingException;
import ecoparasite.input.RawData;
import ecoparasite.input.RawDataOverflow;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Objects;
import static java.lang.Double.valueOf;
public class MackerelSerra extends Poisson implements DataParsing {
/**
* Constructeur de MackerelSerra
* @param length
* @param infestation
*/
public MackerelSerra(String id, Double length, Double infestation) {
super(id, length, null, infestation);
}
/**
* Implémentation de la fonction parse de DataParsing.
* Renvoie un tableau de poissons à partir d'un RawData.
*
* @param data Notre RawData
* @param parseTypeId L'ID du type de parsing, ignoré ici.
* @return Le tableau de poissons.
* @throws RawDataOverflow Si on a un dépassement de données dans notre RawData.
* @throws InvalidParsingException
*/
public static HashSet<Poisson> parse(RawData data, int parseTypeId) throws RawDataOverflow, InvalidParsingException {
return MackerelSerra.parse(data);
}
/**
* Implémentation de la fonction parse de Dataparsing
* @param data Notre RawData.
* @return tableau des poissons
* @throws RawDataOverflow Si on a un dépassement de données dans notre RawDataOverflow.
*/
public static HashSet<Poisson> parse(RawData data) throws RawDataOverflow {
HashMap<String,String> temp = new HashMap<>();
HashSet<Poisson> fishSet;
fishSet = new HashSet<>();
for (int i = 0; i < data.getData().getFirst().size(); i++) {
temp = data.getEntry(i);
String id = !Objects.equals(temp.get("id"), "") ? (temp.get("id")) : null;
Double size = !Objects.equals(temp.get("LT"), "") ? valueOf(temp.get("LT")) : null;
Double infes = !Objects.equals(temp.get("Total"), "") ? valueOf(temp.get("Total")) : null;
Poisson newP = new MackerelSerra(id,size,infes);
newP.setFishParts( MackerelSerra.parsePartiePoisson(temp) );
fishSet.add(newP);
}
return fishSet;
}
/**
*
* @param entry
* @return
*/
private static HashSet<PartiePoisson> parsePartiePoisson(HashMap<String,String> entry){
HashSet<PartiePoisson> response = new HashSet<>();
for( String k: entry.keySet() ){
if( k.contains("Foie") || k.contains("Abdomen") || k.contains("Visceres") || k.contains("Autres")){
String bodyPart = k;
Double value = !Objects.equals(entry.get(k), "") ? valueOf(entry.get(k)) : null;
PartiePoisson p = new PartiePoisson(bodyPart, value);
response.add(p);
}
}
return response;
}
}

View File

@@ -0,0 +1,25 @@
package ecoparasite.poisson;
import ecoparasite.input.InputFactory;
import ecoparasite.input.InputFileException;
import ecoparasite.input.RawData;
import ecoparasite.input.RawDataOverflow;
import org.junit.jupiter.api.Test;
import java.util.HashSet;
import static org.junit.jupiter.api.Assertions.*;
class MackerelSerraTest {
@Test
void parse() throws InputFileException, RawDataOverflow {
RawData test = InputFactory.readData( "test2.csv" , ",");
HashSet<Poisson> fishs = MackerelSerra.parse( test );
for( Poisson poisson : fishs){
System.out.println(poisson);
}
}
}