---
# System prepended metadata

title: KIT AtCoder Management
tags: [atcoder, EN, kit-atcoder_management, Bot, Slack]

---

# KIT AtCoder Management

###### tags: `Slack` `EN` `Bot` `atcoder` `kit-atcoder_management`

## Flow Sequence
Note: 
-    AtCoder_api:
        -    For Languages: https://kenkoooo.com/atcoder/atcoder-api/results?user=yeohsoonkeat
        -    For rating: https://atcoder.jp/users/yeohsoonkeat/history/json
1. Connecting slack to atcoder
```sequence
SlackUser -> Bot: !atcoder connect 'username'
Bot -> SlackUser: reply with token `(...)`
SlackUser -> Atcoder_site: append token to `Affiliation` in Profile
SlackUser -> Bot: !atcoder confirm
Bot -> Atcoder_site: confirm token\n with `Affiliation`
Bot -> SlackUser: Reply Success
Bot -> AtCoder_management_api: send SlackUser and atcoder username
AtCoder_management_api -> cluster_api: request batch, vc
AtCoder_management_api -> atcoderDB: if (slackid) SlackID <--> atcoder, batch, vc\nelse update
```
2. After Connection add data to sheet every 30min:
    ```sequence
        AtCoder_management_api-> AtCoder_db: get username, batch, vc
        AtCoder_management_api -> AtCoder_api: get user history, problems
        AtCoder_api -> AtCoder_management_api: max rating, languages
        AtCoder_management_api -> AtcoderDB: update rating into records
        AtCoder_management_api-> AtCoder_sheets: student_rating, vc_average_rating
    ```
3. slack data commands
    *  `!atcoder_rating @user` (not yet connected)
    ```sequence
        SlackUser -> Bot: !atcoder_rating @user
        Bot -> AtCoder_management_api: user id
        AtCoder_management_api -> Atcoder_db: check username
        AtCoder_management_api -> Bot: false
        Bot -> SlackUser: Connection instruction
    ```
    * `!atcoder_rating @user` (connected)
    ```sequence
        SlackUser -> Bot: !atcoder_rating @user
        Bot -> AtCoder_management_api: user id
        AtCoder_management_api -> Atcoder_db: check username
        Atcoder_db -> AtCoder_management_api: username
        AtCoder_management_api -> AtCoder_api: user history
        AtCoder_api -> AtCoder_management_api: max rating
        AtCoder_management_api -> Bot: max rating
        Bot -> SlackUser: reply thread \nmax rating
    ```
    * `!atcoder_vc_rating 'vc name'`
    ```sequence
        SlackUser-> Bot: !atcoder_vc_rating 'vc'
        Bot -> AtCoder_management_api: vc name
        AtCoder_management_api -> AtCoder_db: atcoder name with vc
        AtCoder_db -> AtCoder_management_api: atcoder higest, lowest\n average
        Bot -> SlackUser: reply thread max Rating
    ```
    * `!atcoder_batch_rating 'batch number'`
    ```sequence
        SlackUser-> Bot: !atcoder_batch_rating 'batch'
        Bot -> AtCoder_management_api: batch
        AtCoder_management_api -> AtCoder_db: atcoder by batch
        AtCoder_db -> AtCoder_management_api: atcoder highest \n lowest, average
        Bot -> SlackUser: reply thread max Rating
    ```
##    Purpose:
1. **Spreadsheet**:
    * Getting student max rating at atcoder to spreadsheet
    * Getting virtual company average rating and max rating at atcoder to spreadsheet

2. **Slackbot**:
    * make command for getting max rating of individual
    * make command for getting VC rating info
    * make command for getting student rating info

### 1. **Spreadsheet**:
*    Sheet1: **student_score**
        *    content: 
                * Slack-Username
                * Email
                * Batch
                * Virtual Company (can be blank)
                * Rating
*    Sheet2: **VC_score**
        *    content:
                * VC name
                * Average rating
                * Maximum rating
                * VC members
                * VC atcoder members
                * VC atcoder user (%)

### 2. **To use Slackbot `!atcoder` command**:

#### **Total Score of individual**
*    **How to use:** `!atcoder_rating @user`
    1. Write `!atcoder_rating`
    2. mention `@user` of the student
    3. Enter
* This command will reply the **student** *total score* in atcoder to the thread

#### **Score info of VC**
*    **How to use:** `!atcoder_vc_rating 'vc_name'`
    1. Write `!atcoder_vc_rating`
    2. type the `vc_name` of the vc
    3. Enter
* This command will reply the **VC** *[highest rating, lowest rating, average rating]* in atcoder to the thread

#### **Score info of batch**
*    **How to use:** `!atcoder_batch_rating 'batch number'`
    1. Write `!atcoder_batch_rating
    2. type the `batch` of the vc
    3. Enter
* This command will reply the **batch** *[highest rating, ,lowest rating, average rating]* in atcoder to the thread
## About Database (sqlite):
sample `student` table
```json
 {
     id: 1,
     slack_id: 'Uxxxxxxxx',
     slack_username: 'Yeoh Soon Keat',
     atcoder_username: 'yeohsoonkeat',
     vc_name: 'C4K',
     batch: 6,
     rating: 0,
     createdAt: Date(),
     updatedAt : Date()
 }
```
schema `student`
```SQL
CREATE TABLE `atcoder_users` (
    `id` INTEGER PRIMARY KEY AUTOINCREMENT,
    `slack_id` VARCHAR(50),
    `slack_username` VARCHAR(100),
    `atcoder_username` VARCHAR(100),
    `vc_name` VARCHAR(100),
    `batch` INTEGER,
    `rating` INTEGER,
    `createdAt` DATETIME NOT NULL,
    `updatedAt` DATETIME NOT NULL
);
```
## Usage(atcoder slack command)
### 1.Connect to the atcoder account
```
   !atcoder connect atcoder_username
    
   Example:
   !atcoder connect waricoma
```
#### 1.1 Copy your token then pass to your atcoder profile

![](https://i.imgur.com/WFjlw4p.jpg)

#### 1.2 Go to atcoder profile => General setting

![](https://i.imgur.com/0mmiFOI.png)

#### 1.3 Go back to slack
```
    type:
    !atcoder confirm
```
![](https://i.imgur.com/VJTxh5B.png)

### 2. Get the student atcoder rating

```
    !atcoder_rating @student_slackName
    
    Example:
    !atcoder_rating @waricoma
```
### 3. Get the virtual company rating
```
    !atcoder_vc_rating virtual_company_name
    
    Example:
    !atcoder_vc_rating c4k
```
### 4. Get the batch rating

```
    !atcoder_batch_rating batch_number
    
    Example:
    !atcoder_batch_rating 7
```


