MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / CompletionStats

Class CompletionStats

src/main/java/fieldbox/execution/CompletionStats.java:14–146  ·  view source on GitHub ↗

Keeps stats on what completions tend to get completed

Source from the content-addressed store, hash-verified

12 * Keeps stats on what completions tend to get completed
13 */
14public class CompletionStats {
15
16 public static CompletionStats stats = new CompletionStats();
17
18 protected CompletionStats() {
19 }
20
21 LinkedHashMap<String, Double> counts = AutoPersist.persist("completion_statistics", () -> new LinkedHashMap<>(), x -> {
22 x.entrySet().forEach(y -> {
23 y.setValue(y.getValue() * 0.5f);
24 });
25 return x;
26 });
27
28 LinkedHashMap<String, String> uuidToCompletions = new LinkedHashMap<String, String>() {
29
30 @Override
31 protected boolean removeEldestEntry(Map.Entry<String, String> entry) {
32 return this.size() > 500;
33 }
34 };
35
36 public void autosuggestCommands(List<Triple<String, String, Runnable>> m) {
37 m.forEach(x -> {
38 uuidToCompletions.put(x.first, x.first);
39 });
40
41 m.sort((a, b) -> {
42 double cA = counts.getOrDefault(a.first, 0d);
43 double cB = counts.getOrDefault(b.first, 0d);
44 if (cA == cB) {
45 return String.CASE_INSENSITIVE_ORDER.compare(a.first, b.first);
46 } else {
47 return -Double.compare(cA, cB);
48 }
49 });
50
51 double[] n = {0};
52 int[] num = {0};
53 m.forEach(x -> {
54 Double cc = counts.get(x.first);
55 if (cc != null) {
56 num[0]++;
57 n[0] += cc;
58 }
59 });
60
61 if (num[0] == 0) {
62
63 } else {
64 List<Triple<String, String, Runnable>> out = m.stream().map(x -> {
65 Double cc = counts.get(x.first);
66 if (cc != null) {
67 double score = Math.max(1, Math.min(3, 3 * cc / (n[0] / num[0])));
68 String second = x.second + "</span><span class=\"stars\">" + num(score, "&#9733;") + " ";
69
70 Triple<String, String, Runnable> t = new Triple<>(x.first, second, x.third);
71

Callers

nothing calls this directly

Calls 4

persistMethod · 0.95
forEachMethod · 0.45
setValueMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected