summaryrefslogtreecommitdiff
path: root/src/report-service.js
blob: 2469ea93baad2fc44992a8603504c538e9c1a223 (plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import * as maps from './maps/maps';

const POPULAR_THRESHOLD = 1.0; // percent

export default class ReportService {
  constructor() {
    this.report = require('../data/95fb1cdb/report.json')
      .filter((entry) => entry.Actor != undefined); // bad data from API downtime
    this.metadata = require('../data/95fb1cdb/metadata.json');

    this.reports = new Map();
    this.totalPicks = new Map();
    this.top10Relevancy = new Map();
    this.topPicks = new Map();
    this.topWins = new Map();
    this.topRareWins = new Map();
    this.topEpicWins = new Map();
    this.topLegendaryWins = new Map();
    this.topLeveledUp = new Map();
    this.topLeveledDown = new Map();
    this.topUnpopularWins = new Map();
    this.totalMatches = 0;
    this.actors = [];
    this.modes = this.metadata.config.api.modes;

    for(let mode of this.modes) {
      const relevancy = (entry) => (entry.Count / this.totalPicks.get(mode)) * entry.Winner;
      const playersPerMatch = maps.playersPerMatch(mode);

      this.reports.set(mode, this.report.filter((entry) => entry.Mode == mode));
      this.totalPicks.set(mode, this.report.map((entry) => entry.Count).reduce((agg, cur) => agg + cur, 0));
      this.totalMatches += this.totalPicks.get(mode) / maps.playersPerMatch(mode);
      this.top10Relevancy.set(mode, this.reports.get(mode)
        .sort((entry1, entry2) => relevancy(entry2) - relevancy(entry1))
        .slice(0, 10));
      this.topPicks.set(mode, this.reports.get(mode).sort((entry1, entry2) => entry2.Count - entry1.Count)[0]);
      this.topWins.set(mode, this.reports.get(mode)
        .filter((entry) => 100 * playersPerMatch * entry.Count / this.totalPicks.get(mode) > POPULAR_THRESHOLD)
        .sort((entry1, entry2) => entry2.Winner - entry1.Winner)[0]);
      this.topUnpopularWins.set(mode, this.reports.get(mode)
        .filter((entry) => 100 * playersPerMatch * entry.Count / this.totalPicks.get(mode) <= POPULAR_THRESHOLD)
        .sort((entry1, entry2) => entry2.Winner - entry1.Winner)[0]);
      this.topRareWins.set(mode, this.reports.get(mode)
        .filter((entry) => maps.getTalentRarity(entry.Talent) == 'Rare' && 100 * playersPerMatch * entry.Count / this.totalPicks.get(mode))
        .sort((entry1, entry2) => entry2.Winner - entry1.Winner)[0]);
      this.topEpicWins.set(mode, this.reports.get(mode)
        .filter((entry) => maps.getTalentRarity(entry.Talent) == 'Epic' && 100 * playersPerMatch * entry.Count / this.totalPicks.get(mode))
        .sort((entry1, entry2) => entry2.Winner - entry1.Winner)[0]);
      this.topLegendaryWins.set(mode, this.reports.get(mode)
        .filter((entry) => maps.getTalentRarity(entry.Talent) == 'Legendary' && 100 * playersPerMatch * entry.Count / this.totalPicks.get(mode))
        .sort((entry1, entry2) => entry2.Winner - entry1.Winner)[0]);
      this.topLeveledUp.set(mode, this.reports.get(mode).sort((entry1, entry2) => {
        if (!entry1.Level) return 1;
        if (!entry2.Level) return -1;
        return entry1.Level < entry2.Level ? 1 : -1;
      })[0]);
      this.topLeveledDown.set(mode, this.reports.get(mode).sort((entry1, entry2) => {
        if (!entry1.Level) return 1;
        if (!entry2.Level) return -1;

        return entry1.Level < entry2.Level ? -1 : 1;
      })[0]);

      if (this.actors.length == 0) {
        this.actors = [...new Set(this.reports.get(mode).map((entry) => entry.Actor))];
      }
    }
  }

  getReport(mode) {
    return this.reports.get(mode);
  }

  getTotalPicks(mode) {
    return this.totalPicks.get(mode);
  }

  getTopPick(mode) {
    return this.topPicks.get(mode);
  }

  getTop10Picks(mode) {
    return this.top10Relevancy.get(mode);
  }

  getHighestLevelAvg(mode) {
    return this.topLeveledUp.get(mode);
  }

  getLowestLevelAvg(mode) {
    return this.topLeveledDown.get(mode);
  }

  getTopWin(mode) {
    return this.topWins.get(mode);
  }

  getTopUnpopularWin(mode) {
    return this.topUnpopularWins.get(mode);
  }

  getTopRareWins(mode) {
    return this.topRareWins.get(mode);
  }

  getTopEpicWins(mode) {
    return this.topEpicWins.get(mode);
  }

  getTopLegendaryWins(mode) {
    return this.topLegendaryWins.get(mode);
  }

  getBestUnpopular(mode) {
    return this.topUnpopular.get(mode);
  }

  getActors() {
    return this.actors;
  }

  getModes() {
    return this.modes;
  }

  getTotalMatches() {
    return this.totalMatches;
  }

  getLastUpdate() {
    return this.metadata.lastUpdate;
  }
}