Project

General

Profile

« Previous | Next » 

Revision bfda4dd3

Added by Patrick Plitzner over 4 years ago

ref #7095 Implement specimen generator to test for huge data sets

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/SpecimenGenerator.java
1
/**
2
* Copyright (C) 2018 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
10

  
11
import java.util.ArrayList;
12
import java.util.Collection;
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.Random;
16
import java.util.UUID;
17

  
18
import eu.etaxonomy.cdm.api.service.ITermService;
19
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
20
import eu.etaxonomy.cdm.model.description.CategoricalData;
21
import eu.etaxonomy.cdm.model.description.Character;
22
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
23
import eu.etaxonomy.cdm.model.description.Feature;
24
import eu.etaxonomy.cdm.model.description.FeatureNode;
25
import eu.etaxonomy.cdm.model.description.QuantitativeData;
26
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
27
import eu.etaxonomy.cdm.model.description.State;
28
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
29
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
30
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
31
import eu.etaxonomy.taxeditor.store.CdmStore;
32

  
33
/**
34
 * @author pplitzner
35
 * @since Jan 11, 2018
36
 *
37
 */
38
public class SpecimenGenerator {
39

  
40
    private static final int SPECIMEN_COUNT = 1000;
41

  
42
    public Collection<SpecimenOrObservationBase> generate(){
43
        Collection<SpecimenOrObservationBase> specimens = new HashSet<>();
44
        List<DescriptionElementBase> descriptionElements = new ArrayList<>();
45

  
46
        descriptionElements.add(generateQuantitativeData("leaf", "length"));
47
        descriptionElements.add(generateCategoricalData("leaf", "color"));
48

  
49
        for(int i=0;i<SPECIMEN_COUNT;i++){
50
            specimens.add(generateSpecimen(descriptionElements));
51
        }
52
        return specimens;
53
    }
54

  
55
    private SpecimenOrObservationBase generateSpecimen(List<DescriptionElementBase> descriptionElements){
56
        DerivedUnit specimen = DerivedUnit.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
57
        SpecimenDescription description = SpecimenDescription.NewInstance(specimen);
58
        descriptionElements.forEach(descriptionElement->{
59
            initQuantitativeData(descriptionElement);
60
            description.addElement(descriptionElement);
61
        });
62
        specimen.setAccessionNumber("GEN");
63
        return specimen;
64
    }
65

  
66
    private QuantitativeData generateQuantitativeData(String structure, String property){
67
//        Character character = Character.NewInstance(generateFeatureNode(structure), generateFeatureNode(property));
68
        Character character = (Character) CdmStore.getService(ITermService.class).load(UUID.fromString("4e3b8ff8-87fc-4919-b390-fb13a22540ab"));
69
        QuantitativeData data = QuantitativeData.NewInstance(character);
70
        return data;
71
    }
72

  
73
    private CategoricalData generateCategoricalData(String structure, String property){
74
//        Character character = Character.NewInstance(generateFeatureNode(structure), generateFeatureNode(property));
75
        Character character = (Character) CdmStore.getService(ITermService.class).load(UUID.fromString("43e3a556-5619-4d20-99d8-aaccab84a914"));
76
        CategoricalData data = CategoricalData.NewInstance(character);
77
        return data;
78
    }
79

  
80
    private void initQuantitativeData(DescriptionElementBase descriptionElement){
81
        if(descriptionElement.isInstanceOf(QuantitativeData.class)){
82
            QuantitativeData data = HibernateProxyHelper.deproxy(descriptionElement, QuantitativeData.class);
83
            Random random = new Random();
84
            data.setMinimum(random.nextFloat()*10, null);
85
            data.setMaximum(random.nextFloat()*10, null);
86
        }
87
        else if(descriptionElement.isInstanceOf(CategoricalData.class)){
88
            CategoricalData data = HibernateProxyHelper.deproxy(descriptionElement, CategoricalData.class);
89
            Random random = new Random();
90
            String nextInt = "State: "+random.nextInt();
91

  
92
            State state = State.NewInstance(nextInt, nextInt, nextInt);
93
            data.addStateData(state);
94
        }
95
    }
96

  
97
    private FeatureNode generateFeatureNode(String label){
98
        Feature feature = Feature.NewInstance(label, label, label);
99
        FeatureNode featureNode = FeatureNode.NewInstance(feature);
100
        return featureNode;
101
    }
102

  
103
}

Also available in: Unified diff