• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LearnLib / learnlib / 6433387082

06 Oct 2023 03:10PM UTC coverage: 92.296% (-0.007%) from 92.303%
6433387082

push

github

mtf90
update Falk's developer id

11573 of 12539 relevant lines covered (92.3%)

1.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.29
/oracles/filters/statistics/src/main/java/de/learnlib/filter/statistic/HistogramDataSet.java
1
/* Copyright (C) 2013-2023 TU Dortmund
2
 * This file is part of LearnLib, http://www.learnlib.de/.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package de.learnlib.filter.statistic;
18

19
import java.util.Map.Entry;
20
import java.util.SortedMap;
21
import java.util.TreeMap;
22

23
/**
24
 * A simple histogram data set.
25
 */
26
public class HistogramDataSet extends AbstractStatisticData {
27

28
    private final SortedMap<Long, Integer> histogram = new TreeMap<>();
2✔
29

30
    private long size;
31

32
    private long sum;
33

34
    private double mean;
35

36
    public HistogramDataSet(String name, String unit) {
37
        super(name, unit);
2✔
38
    }
2✔
39

40
    public void addDataPoint(Long value) {
41
        Integer i = histogram.get(value);
2✔
42
        if (i == null) {
2✔
43
            i = 0;
2✔
44
        }
45
        histogram.put(value, i + 1);
2✔
46
        sum += value;
2✔
47
        size++;
2✔
48
        mean = mean + ((((double) value) - mean) / size);
2✔
49
    }
2✔
50

51
    public SortedMap<Long, Integer> getHistogram() {
52
        return histogram;
×
53
    }
54

55
    public double getMean() {
56
        return mean;
2✔
57
    }
58

59
    public long getSize() {
60
        return size;
2✔
61
    }
62

63
    public long getSum() {
64
        return sum;
2✔
65
    }
66

67
    public double getMedian() {
68
        long idx = 0;
2✔
69
        for (Entry<Long, Integer> e : histogram.entrySet()) {
2✔
70
            int count = e.getValue();
2✔
71
            idx += count;
2✔
72
            if (idx >= size / 2) {
2✔
73
                return e.getKey();
2✔
74
            }
75
        }
×
76
        return 0.0;
2✔
77
    }
78

79
    @Override
80
    public String getSummary() {
81
        return getName() + " [" + getUnit() + "]: " + size + " (count), " + sum + " (sum), " + mean + " (mean), " +
2✔
82
               getMedian() + " (median)";
2✔
83
    }
84

85
    @Override
86
    public String getDetails() {
87
        StringBuilder sb = new StringBuilder();
2✔
88
        sb.append(getSummary()).append(System.lineSeparator());
2✔
89
        for (Entry<Long, Integer> e : histogram.entrySet()) {
2✔
90
            sb.append('\t')
2✔
91
              .append(e.getKey())
2✔
92
              .append(", ")
2✔
93
              .append(e.getValue())
2✔
94
              .append(System.lineSeparator());
2✔
95
        }
2✔
96
        return sb.toString();
2✔
97
    }
98

99
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc