shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.walker.etaa;
 
import com.walker.etaa.util.AlgorithmUtils;
 
import java.util.List;
import java.util.Random;
 
public class TestExtract {
 
//    @Test
    public void testRandomAlgorithm(){
        for(int j=0; j<10; j++){
            int[] result = AlgorithmUtils.getRandomIndexArray(100, j+5);
            if(result != null){
                for(int i : result){
                    System.out.print(i);
                    System.out.print(",");
                }
                System.out.println("-----------------");
            }
        }
    }
 
//    @Test
    public void testExtractAverageItem() throws ExtractFailedException{
        DemoSimpleExtractor extractor = new DemoSimpleExtractor();
        QuestionExtractOptions options = new QuestionExtractOptions();
        options.setGlobalConfig("default", "", "历史", 2);
//        options.addOption("国际历史", null, QuestionType.TrueOrFalse, null, 2);
//        options.addOption("国际历史", null, QuestionType.SelectMultiple, null, 2);
        options.addOption("国际历史", null, null, 2);
        List list = (List)extractor.extract(options);
    }
 
//    @Test
    public void testExtractAverage() throws ExtractFailedException{
        DemoSimpleExtractor extractor = new DemoSimpleExtractor();
        QuestionExtractOptions options = new QuestionExtractOptions();
        options.setGlobalConfig("default", "", "数学", 10);
        options.setExtractStrategy(ExtractStrategy.Average);    // 设置凑齐策略:默认随机
        List list = (List)extractor.extract(options);
    }
 
//    @Test
    public void testAverageIndex(){
        int existTotal = 200;
        int requiredTotal = 32;
        int span = existTotal / requiredTotal;
 
        Random random = new Random();
        int offset = random.nextInt(10);
        System.out.println("offset = " + offset);
        if(span == 1){
            for(int i=0; i<requiredTotal; i++){
                System.out.println("get " + (i+1));
            }
            return;
        } else if(span > 1){
            int current = offset;
            if(current == 0){
                current = 1;
            }
 
            int last = AlgorithmUtils.getAverageLastIndex(current, span, requiredTotal);
            while(last > existTotal){
                System.out.println("最后元素超过了'existTotal',last = " + last);
                if(span > 1){
                    span --;
                } else if(offset > 1){
                    offset --;
                } else {
                    System.out.println("已经无法降低抽取间隔了,退出循环");
                    break;
                }
                last = AlgorithmUtils.getAverageLastIndex(current, span, requiredTotal);
            }
 
            for(int i=0; i<requiredTotal; i++){
                if(i > 0){
                    current += span;
                }
                System.out.println("get " + (current));
            }
            return;
        }
    }
}