Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ EESAST 后端 API
- node 16 / npm
- yarn
- TypeScript
- Redis

### Before Dev

需要在测试端安装和启动Redis
具体见[Redis安装文档](https://redis.io/docs/latest/operate/oss_and_stack/install/archive/install-redis/)

### 工具

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"graphql": "16.14.0",
"graphql-request": "6.1.0",
"html-to-text": "10.0.0",
"ioredis": "5.10.1",
"isemail": "3.2.0",
"js-yaml": "4.1.1",
"jsonwebtoken": "9.0.2",
Expand Down
135 changes: 135 additions & 0 deletions src/hasura/contest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* @param {string} contest_id
* @returns {string} contest_name
*/
export const get_contest_name: any = async (contest_id: string) => {

Check warning on line 22 in src/hasura/contest.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
const query_contest_name: any = await client.request(

Check warning on line 23 in src/hasura/contest.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
gql`
query get_contest_name($contest_id: uuid!) {
contest(where: { id: { _eq: $contest_id } }) {
Expand All @@ -40,8 +40,8 @@
* @param {string} contest_name
* @returns {string} contest_id
*/
export const get_contest_id: any = async (contest_name: string) => {

Check warning on line 43 in src/hasura/contest.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
const query_contest_id: any = await client.request(

Check warning on line 44 in src/hasura/contest.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
gql`
query get_contest_id($contest_name: String!) {
contest(where: { name: { _eq: $contest_name } }) {
Expand All @@ -61,8 +61,8 @@
* @param {string} contest_id
* @returns {object} {arena_switch, code_upload_switch, playback_switch, playground_switch, stream_switch, team_switch}
*/
export const get_contest_settings: any = async (contest_id: string) => {

Check warning on line 64 in src/hasura/contest.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
const query_contest_settings: any = await client.request(

Check warning on line 65 in src/hasura/contest.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
gql`
query get_contest_settings($contest_id: uuid!) {
contest(where: { id: { _eq: $contest_id } }) {
Expand Down Expand Up @@ -99,11 +99,11 @@
* @param {string} contest_id
* @returns {string} team_id
*/
export const get_team_from_user: any = async (

Check warning on line 102 in src/hasura/contest.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
user_uuid: string,
contest_id: string,
) => {
const query_team_id: any = await client.request(

Check warning on line 106 in src/hasura/contest.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
gql`
query get_team_id($user_uuid: uuid!, $contest_id: uuid!) {
contest_team_member(
Expand All @@ -126,7 +126,7 @@
if (query_team_id.contest_team_member.length !== 0) {
return query_team_id.contest_team_member[0]?.team_id ?? null;
}
const query_team_from_leader: any = await client.request(

Check warning on line 129 in src/hasura/contest.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
gql`
query get_team_from_leader($user_uuid: uuid!, $contest_id: uuid!) {
contest_team(
Expand Down Expand Up @@ -156,7 +156,7 @@
* @param {string} team_id
* @returns {boolean} true if user is in the team, false otherwise
*/
export const check_user_team: any = async (

Check warning on line 159 in src/hasura/contest.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
user_uuid: string,
team_id: string,
) => {
Expand Down Expand Up @@ -1582,6 +1582,55 @@
);
};

export const add_team_RL_code: any = async (
team_id: string,
code_url: string,
) => {
const insert_team_RL_code: any = await client.request(
gql`
mutation add_team_RL_code($team_id: uuid!, $url: String!) {
insert_contest_team_RL_code_one(
object: { team_id: $team_id, url: $url }
) {
submit_id
team_id
created_at
url
}
}
`,
{
team_id: team_id,
url: code_url,
},
);

return insert_team_RL_code.insert_contest_team_RL_code_one;
};

export const get_team_RL_code_submissions: any = async (team_id: string) => {
const query_team_RL_code_submissions: any = await client.request(
gql`
query get_team_RL_code_submissions($team_id: uuid!) {
contest_team_RL_code(
where: { team_id: { _eq: $team_id } }
order_by: { created_at: asc }
) {
submit_id
team_id
created_at
url
}
}
`,
{
team_id: team_id,
},
);

return query_team_RL_code_submissions.contest_team_RL_code;
};

/**
*
* @param {uuid} contest_id ID
Expand Down Expand Up @@ -2713,6 +2762,37 @@
);
};

export const set_software_contest_deadline: any = async (
contest_id: string,
deadline: string,
) => {
const upsert_software_contest_deadline: any = await client.request(
gql`
mutation set_software_contest_deadline(
$contest_id: uuid!
$deadline: timestamptz!
) {
insert_contest_soft_code_deadline_one(
object: { contest_id: $contest_id, deadline: $deadline }
on_conflict: {
constraint: contest_soft_code_deadline_pkey
update_columns: [deadline]
}
) {
contest_id
deadline
}
}
`,
{
contest_id: contest_id,
deadline: deadline,
},
);

return upsert_software_contest_deadline.insert_contest_soft_code_deadline_one;
};

export const get_contest_id_from_team_id: any = async (team_id: string) => {
const query_contest_id_from_team_id: any = await client.request(
gql`
Expand All @@ -2728,3 +2808,58 @@
);
return query_contest_id_from_team_id.contest_team[0]?.contest_id ?? undefined;
};

/**
* Get all RL scores for a contest, ordered by score descending.
* @param {string} contest_id
* @returns {Array<{team_id, score, team_name}>}
*/
export const get_all_RL_scores: any = async (contest_id: string) => {
const result: any = await client.request(
gql`
query GetAllRLScores($contest_id: uuid!) {
contest_team_RL_score(
where: { contest_team: { contest_id: { _eq: $contest_id } } }
order_by: { score: desc_nulls_last }
) {
team_id
score
contest_team {
team_name
}
}
}
`,
{ contest_id },
);
return result.contest_team_RL_score ?? [];
};

/**
* Upsert (insert or update) a team's RL score.
* @param {string} team_id
* @param {number} score
* @returns {string} team_id
*/
export const upsert_team_RL_score: any = async (
team_id: string,
score: number,
) => {
const result: any = await client.request(
gql`
mutation UpsertTeamRLScore($team_id: uuid!, $score: Int!) {
insert_contest_team_RL_score_one(
object: { team_id: $team_id, score: $score }
on_conflict: {
constraint: contest_team_RL_score_pkey
update_columns: [score]
}
) {
team_id
}
}
`,
{ team_id, score },
);
return result.insert_contest_team_RL_score_one?.team_id ?? undefined;
};
32 changes: 32 additions & 0 deletions src/hasura/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,38 @@ export const set_llm_usage_by_uuid = async (
return query.update_llm_usage_by_pk;
};

export const update_llm_usage_by_uuid = async (
uuid: string,
tokens_to_add: number,
) => {
const query: any = await client.request(
gql`
mutation UpdateLlmUsageByUuid(
$uuid: uuid!
$tokens_to_add: bigint!
$updated_at: timestamptz!
) {
update_llm_usage_by_pk(
pk_columns: { uuid: $uuid }
_inc: { total_tokens_used: $tokens_to_add }
_set: { last_updated_at: $updated_at }
) {
uuid
total_tokens_used
token_limit
last_updated_at
}
}
`,
{
uuid,
tokens_to_add,
updated_at: new Date().toISOString(),
},
);
return query.update_llm_usage_by_pk;
};

export const get_user_llm_usage = async (student_no: string) => {
const query: any = await client.request(
gql`
Expand Down
37 changes: 0 additions & 37 deletions src/helpers/llm_cron.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/helpers/redis.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import http from "http";
import app from "./app";
import { GraphQLClient } from "graphql-request";
import { queue_element } from "./helpers/docker_queue";
import { llm_cron } from "./helpers/llm_cron";
// import docker_cron from "./helpers/docker_queue";

const debug = Debug("eesast-api");
Expand Down Expand Up @@ -36,8 +35,6 @@ export const docker_queue: queue_element[] = [];
// weekly_cron();
// weekly_init();

llm_cron();

const port = normalizePort(process.env.PORT || "28888");
app.set("port", port);

Expand Down
Loading
Loading