File size: 7,230 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 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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
import * as provider from './provider';
import type {
CodeforcesRatingResponse,
CodeforcesContestHistory,
CodeforcesSubmission,
SolvedProblem,
BlogEntry,
CodeforcesContest,
RecentAction,
CodeforcesProblem,
ContestStandings,
RatingChange,
Hack,
} from './types';
// Get user's rating
export async function getUserRating(username: string): Promise<CodeforcesRatingResponse> {
try {
const user = await provider.fetchUserInfo(username);
return {
username,
platform: 'codeforces',
rating: user.rating || 'Unrated',
level: user.rank || 'Unrated',
max_rating: user.maxRating || 'Unrated',
max_level: user.maxRank || 'Unrated',
contribution: user.contribution,
friendOfCount: user.friendOfCount,
avatar: user.avatar,
};
} catch (error: any) {
console.error(`Codeforces Error for ${username}:`, error.message);
throw new Error('Error fetching Codeforces rating');
}
}
// Get user's contest history
export async function getContestHistory(
username: string
): Promise<CodeforcesContestHistory[]> {
try {
return await provider.fetchContestHistory(username);
} catch (error: any) {
console.error(`Codeforces Error for ${username}:`, error.message);
throw new Error('Error fetching Codeforces contest history');
}
}
// Get user's submission status
export async function getUserStatus(
username: string,
from: number = 1,
count: number = 10
): Promise<CodeforcesSubmission[]> {
try {
return await provider.fetchUserStatus(username, from, count);
} catch (error: any) {
console.error(`Codeforces Error for ${username}:`, error.message);
throw new Error('Error fetching Codeforces user status');
}
}
// Get user's blog entries
export async function getUserBlogs(username: string): Promise<BlogEntry[]> {
try {
return await provider.fetchBlogEntries(username);
} catch (error: any) {
console.error(`Codeforces Error for ${username}:`, error.message);
throw new Error('Error fetching Codeforces user blog entries');
}
}
// Get user's solved problems
export async function getSolvedProblems(username: string): Promise<SolvedProblem[]> {
try {
const submissions = await provider.fetchAllSubmissions(username, 1, 1000);
const solvedProblemsSet = new Set<string>();
const solvedProblems: SolvedProblem[] = [];
submissions.forEach((submission) => {
if (submission.verdict === 'OK') {
const problemId = `${submission.problem.contestId}${submission.problem.index}`;
if (!solvedProblemsSet.has(problemId)) {
solvedProblemsSet.add(problemId);
solvedProblems.push({
id: problemId,
name: submission.problem.name,
rating: submission.problem.rating,
tags: submission.problem.tags,
link: `https://codeforces.com/contest/${submission.problem.contestId}/problem/${submission.problem.index}`,
});
}
}
});
return solvedProblems;
} catch (error: any) {
console.error(`Codeforces Error for ${username}:`, error.message);
throw new Error('Error fetching Codeforces solved problems');
}
}
// Get contests
export async function getContests(gym: boolean = false): Promise<CodeforcesContest[]> {
try {
return await provider.fetchContests(gym);
} catch (error: any) {
console.error('Codeforces Error:', error.message);
throw new Error('Error fetching Codeforces contests');
}
}
// Get recent actions
export async function getRecentActions(maxCount: number = 20): Promise<RecentAction[]> {
try {
return await provider.fetchRecentActions(maxCount);
} catch (error: any) {
console.error('Codeforces Error:', error.message);
throw new Error('Error fetching Codeforces recent actions');
}
}
// Get problemset problems
export async function getProblems(tags?: string): Promise<CodeforcesProblem[]> {
try {
const result = await provider.fetchProblems(tags);
return result.problems;
} catch (error: any) {
console.error('Codeforces Error:', error.message);
throw new Error('Error fetching Codeforces problemset');
}
}
// Get contest standings
export async function getContestStandings(
contestId: number,
from?: number,
count?: number,
handles?: string,
room?: number,
showUnofficial?: boolean
): Promise<ContestStandings> {
try {
return await provider.fetchContestStandings(contestId, from, count, handles, room, showUnofficial);
} catch (error: any) {
console.error('Codeforces Error:', error.message);
throw new Error('Error fetching Codeforces contest standings');
}
}
// Get rating changes
export async function getContestRatingChanges(contestId: number): Promise<RatingChange[]> {
try {
return await provider.fetchContestRatingChanges(contestId);
} catch (error: any) {
console.error('Codeforces Error:', error.message);
throw new Error('Error fetching Codeforces contest rating changes');
}
}
// Get contest hacks
export async function getContestHacks(contestId: number): Promise<Hack[]> {
try {
return await provider.fetchContestHacks(contestId);
} catch (error: any) {
console.error('Codeforces Error:', error.message);
throw new Error('Error fetching Codeforces contest hacks');
}
}
// Get contest status
export async function getContestStatus(
contestId: number,
handle?: string,
from?: number,
count?: number
): Promise<CodeforcesSubmission[]> {
try {
return await provider.fetchContestStatus(contestId, handle, from, count);
} catch (error: any) {
console.error('Codeforces Error:', error.message);
throw new Error('Error fetching Codeforces contest status');
}
}
// Get problemset recent status
export async function getProblemsetRecentStatus(count: number): Promise<CodeforcesSubmission[]> {
try {
return await provider.fetchProblemsetRecentStatus(count);
} catch (error: any) {
console.error('Codeforces Error:', error.message);
throw new Error('Error fetching Codeforces problemset recent status');
}
}
// Get blog entry
export async function getBlogEntry(blogEntryId: number): Promise<any> {
try {
return await provider.fetchBlogEntry(blogEntryId);
} catch (error: any) {
console.error('Codeforces Error:', error.message);
throw new Error('Error fetching Codeforces blog entry');
}
}
// Get blog comments
export async function getBlogComments(blogEntryId: number): Promise<any[]> {
try {
return await provider.fetchBlogComments(blogEntryId);
} catch (error: any) {
console.error('Codeforces Error:', error.message);
throw new Error('Error fetching Codeforces blog comments');
}
}
|