mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
rp;
This commit is contained in:
1 parent
51dc2e972d
commit
43ee86d34b
17 files changed
+177
-88
No files matched your search
+1
-1
@@ -1,4 +1,4 @@
|
||||
function* ranked(diter, equ = (a, b) => a === b) {
|
||||
function* ranked<T>(diter: T[], equ = (a: T, b: T) => a === b): Generator<[number, T], void> {
|
||||
let last = null;
|
||||
let r = 0;
|
||||
let count = 0;
|
||||
|
||||
+20
-6
@@ -1,15 +1,17 @@
|
||||
// Based on https://github.com/QAQrz/Codeforces-Rating-System/blob/master/rating.py
|
||||
|
||||
class User {
|
||||
uid: number;
|
||||
|
||||
rank: number;
|
||||
|
||||
old: number;
|
||||
|
||||
seed: number;
|
||||
|
||||
uid: number;
|
||||
seed?: number;
|
||||
|
||||
delta?: number;
|
||||
|
||||
new: number;
|
||||
new?: number;
|
||||
|
||||
constructor(rank: number, old: number, uid = 0) {
|
||||
this.rank = rank;
|
||||
@@ -22,7 +24,7 @@ class User {
|
||||
class RatingCalculator {
|
||||
users: User[];
|
||||
|
||||
constructor(users) {
|
||||
constructor(users: User[]) {
|
||||
this.users = [];
|
||||
for (const user of users) {
|
||||
this.users.push(new User(user.rank, user.old, user.uid));
|
||||
@@ -106,8 +108,20 @@ interface RatingOutputUser {
|
||||
}
|
||||
|
||||
export default function calculate(users: RatingInputUser[]): RatingOutputUser[] {
|
||||
let last_idx = 0;
|
||||
let last_rank = 1;
|
||||
for (let i = 1; i < users.length; i++) {
|
||||
if (users[i].rank > last_rank) {
|
||||
for (let j = last_idx; j < i; j++) users[j].rank = i;
|
||||
last_idx = i;
|
||||
last_rank = users[i].rank;
|
||||
}
|
||||
}
|
||||
for (let i = last_idx; i < users.length; i++) {
|
||||
users[i].rank = users.length;
|
||||
}
|
||||
const calculator = new RatingCalculator(users);
|
||||
return calculator.calculate();
|
||||
return calculator.calculate() as RatingOutputUser[];
|
||||
}
|
||||
|
||||
global.Hydro.lib.rating = calculate;
|
||||
@@ -2,6 +2,7 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import serialize from 'serialize-javascript';
|
||||
import nunjucks from 'nunjucks';
|
||||
import html2text from 'html-to-text';
|
||||
import { argv } from 'yargs';
|
||||
import * as markdown from './markdown';
|
||||
import * as misc from './misc';
|
||||
@@ -37,6 +38,7 @@ class Nunjucks extends nunjucks.Environment {
|
||||
this.addFilter('assign', (self, data) => Object.assign(self, data));
|
||||
this.addFilter('markdown', (self, html = false) => markdown.render(self, html));
|
||||
this.addFilter('ansi', (self) => misc.ansiToHtml(self));
|
||||
this.addFilter('inline', (self) => html2text.fromString(self).replace(/\n/gmi, ' '));
|
||||
this.addFilter('base64_encode', (s) => Buffer.from(s).toString('base64'));
|
||||
this.addFilter('bitand', (self, val) => self & val);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user