aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/api/Stats.ts
blob: a334918a85f7dc231000b8768f6f2fbad4ef40e6 (plain) (blame)
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
import axios from "axios";
import { url } from "./Api";

export interface PortalCountData {
  date: string;
  count: number;
}

export interface RecordsTimelineResponse {
  timeline_singleplayer: PortalCountData[];
  timeline_multiplayer: PortalCountData[];
}

export interface ScoreLog {
  game: {
    id: number;
    name: string;
    image: string;
    is_coop: boolean;
    category_portals: null;
  };
  user: {
    steam_id: string;
    user_name: string;
  };
  map: {
    id: number;
    name: string;
    image: string;
    is_disabled: boolean;
    portal_count: number;
    difficulty: number;
  };
  score_count: number;
  date: string;
}

export async function get_portal_count_history(): Promise<RecordsTimelineResponse | undefined> {
  const response = await axios.get(url("stats/timeline"));
  if (!response.data.data) {
    return undefined;
  }
  return response.data.data;
}

export async function get_recent_scores(): Promise<ScoreLog[]> {
  const response = await axios.get(url("stats/scores"));
  if (!response.data.data) {
    return [];
  }
  return response.data.data.scores.slice(0, 5);
}