Skip to content

[GSoC] Updated Docs #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Aug 24, 2020
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
2 changes: 1 addition & 1 deletion API/nearby_by_user_and_duration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Nearby Edits by a User API

This API is used to check if a username is valid or not.
This API is used to get nearby edits by a user.

## Base URL
`https://tools.wmflabs.org/commons-android-app/tool-commons-android-app`
Expand Down
2 changes: 1 addition & 1 deletion API/update_avatar.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Update Leaderboard Avatar API

This API is used to check if a username is valid or not.
This API is used to update a leaderboard user avatar.

## Base URL
`https://tools.wmflabs.org/commons-android-app/tool-commons-android-app`
Expand Down
45 changes: 45 additions & 0 deletions API/update_leaderboard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Update Leaderboard API

This API is used to update a leaderboard user data.

## Base URL
`https://tools.wmflabs.org/commons-android-app/tool-commons-android-app`

## Endpoint
`/update_leaderboard.py`

## Request Type
`GET`

## Response Type
`JSON`

## Required Parameters

- **user** - This is username of the user, for example **Syced** (if username has **whitespaces** then replace them with `_` )


## Example Request

```
curl --location --request GET 'https://commons-android-app.toolforge.org/tool-commons-android-app/update_leaderboard.py?user=Syced'
```

## Example Responses

```
{
"status": "200",
"message": "Data Updated",
"user": "Syced"
}
```

**Note: Returns error if params are invalid**
```
{
"status": "400",
"message": "Invalid Parameters",
"user": null
}
```
2 changes: 1 addition & 1 deletion API/uploads_by_user_and_duration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Uploads by a User API

This API is used to check if a username is valid or not.
This API is used to get uploads by a user.

## Base URL
`https://tools.wmflabs.org/commons-android-app/tool-commons-android-app`
Expand Down
2 changes: 1 addition & 1 deletion API/used_images_by_user_and_duration.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Unique Used Images by a User API

This API is used to check if a username is valid or not.
This API is used to get unique used images by a user.

## Base URL
`https://tools.wmflabs.org/commons-android-app/tool-commons-android-app`
Expand Down
104 changes: 103 additions & 1 deletion DB_Schema/leaderboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ After that run the following commands

![show-tables](images/show-tables.png)

```
MariaDB [s53794__leaderboard]> show tables;
+-------------------------------+
| Tables_in_s53794__leaderboard |
+-------------------------------+
| leaderboard_nearby |
| leaderboard_upload |
| leaderboard_used |
| leaderboard_user |
+-------------------------------+
4 rows in set (0.01 sec)

```

- `> desc leaderboard_user;`

- `> desc leaderboard_used;`
Expand All @@ -35,6 +49,51 @@ After that run the following commands

![desc-tables](images/desc-tables.png)

```
MariaDB [s53794__leaderboard]> desc leaderboard_user;
+-------------+-----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------------+------+-----+---------+----------------+
| username | varbinary(255) | NO | UNI | NULL | |
| user_id | int(5) unsigned | NO | PRI | NULL | auto_increment |
| user_avatar | varchar(255) | NO | | NULL | |
+-------------+-----------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

MariaDB [s53794__leaderboard]> desc leaderboard_used;
+----------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------------+------+-----+---------+-------+
| user_id | int(5) unsigned | NO | MUL | NULL | |
| weekly | bigint(20) unsigned | NO | | NULL | |
| yearly | bigint(20) unsigned | NO | | NULL | |
| all_time | bigint(20) unsigned | NO | | NULL | |
+----------+---------------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

MariaDB [s53794__leaderboard]> desc leaderboard_upload;
+----------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------------+------+-----+---------+-------+
| user_id | int(5) unsigned | NO | MUL | NULL | |
| weekly | bigint(20) unsigned | NO | | NULL | |
| yearly | bigint(20) unsigned | NO | | NULL | |
| all_time | bigint(20) unsigned | NO | | NULL | |
+----------+---------------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

MariaDB [s53794__leaderboard]> desc leaderboard_nearby;
+----------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------------+------+-----+---------+-------+
| user_id | int(5) unsigned | NO | MUL | NULL | |
| weekly | bigint(20) unsigned | NO | | NULL | |
| yearly | bigint(20) unsigned | NO | | NULL | |
| all_time | bigint(20) unsigned | NO | | NULL | |
+----------+---------------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
```

## Create Database

```
Expand All @@ -55,5 +114,48 @@ Note: make sure to use `__` double underscore
## To Create Tables Run a SQL file like

```
mysql -u root -p --no-data dbname > create_leaderboard_tables.sql
$ cd scripts/create_leaderboard_tables
$ mysql -u root -p --no-data dbname < create_leaderboard_tables.sql
```

## Pull from Repo

```
$ become commons-android-app

$ cd public_html/tool-commons-android-app

$ git pull origin master

```

## Create config.yaml

```
$ nano config.yaml
```

Example config.yaml file
```
DB_HOST: tools.db.svc.eqiad.wmflabs
DB_USER: s53794
DB_PASS: {your_password}
DB_NAME: s53794__leaderboard
```

## Start API Webservice

```
$ webservice --backend=gridengine lighttpd start
```

## Make Cron Job

```
$ crontab -e
```

Example cronjob to refresh leaderboard after every 2 hours
```
0 */2 * * * cd /data/project/commons-android-app/public_html/tool-commons-android-app/scripts/refresh_leaderboard && /usr/bin/jsub -N cron-29 -once -quiet -cwd /usr/bin/python3.5 refresh_leaderboard.py
```