File size: 2,439 Bytes
3d23b0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { mapRating } from './constants';
import * as provider from './provider';
import type { AtCoderRating, UserHistory, ContestStandings } from './types';

export async function getUserRating(username: string): Promise<AtCoderRating> {
    try {
        const data = await provider.fetchUserRating(username);
        return {
            username,
            display_name: data.display_name,
            platform: 'atcoder',
            rating: data.rating,
            max_rating: data.max_rating,
            level: mapRating(data.rating),
            rank: data.rank,
            contests_participated: data.contests_participated,
            last_competed: data.last_competed,
            kyu: data.kyu,
            country: data.country,
            birth_year: data.birth_year,
            avatar: data.avatar,
        };
    } catch (error: any) {
        console.error(`AtCoder Error for ${username}:`, error.message);
        throw new Error('Failed to fetch AtCoder user data');
    }
}

export async function getUserHistory(username: string): Promise<UserHistory[]> {
    try {
        return await provider.fetchUserHistory(username);
    } catch (error: any) {
        console.error(`AtCoder History Error for ${username}:`, error.message);
        throw new Error('Failed to fetch AtCoder user history');
    }
}

export async function getContestStandings(contestId: string, extended: boolean = false): Promise<ContestStandings> {
    try {
        return await provider.fetchContestStandings(contestId, extended);
    } catch (error: any) {
        console.error(`AtCoder Standings Error for ${contestId}:`, error.message);
        throw new Error('Failed to fetch AtCoder contest standings');
    }
}

export async function getContestResults(contestId: string): Promise<any> {
    try {
        return await provider.fetchContestResults(contestId);
    } catch (error: any) {
        console.error(`AtCoder Results Error for ${contestId}:`, error.message);
        throw new Error('Failed to fetch AtCoder contest results');
    }
}

export async function getVirtualStandings(contestId: string, showGhost: boolean = true): Promise<any> {
    try {
        return await provider.fetchVirtualStandings(contestId, showGhost);
    } catch (error: any) {
        console.error(`AtCoder Virtual Standings Error for ${contestId}:`, error.message);
        throw new Error('Failed to fetch AtCoder virtual standings');
    }
}