diff --git a/API/nearby_by_user_and_duration.md b/API/nearby_by_user_and_duration.md index f1a591f..3538821 100644 --- a/API/nearby_by_user_and_duration.md +++ b/API/nearby_by_user_and_duration.md @@ -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` diff --git a/API/update_avatar.md b/API/update_avatar.md index 43aeaeb..5c9afba 100644 --- a/API/update_avatar.md +++ b/API/update_avatar.md @@ -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` diff --git a/API/update_leaderboard.md b/API/update_leaderboard.md new file mode 100644 index 0000000..fed1968 --- /dev/null +++ b/API/update_leaderboard.md @@ -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 +} +``` \ No newline at end of file diff --git a/API/uploads_by_user_and_duration.md b/API/uploads_by_user_and_duration.md index 0fc58e3..8bc6042 100644 --- a/API/uploads_by_user_and_duration.md +++ b/API/uploads_by_user_and_duration.md @@ -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` diff --git a/API/used_images_by_user_and_duration.md b/API/used_images_by_user_and_duration.md index bce4c14..71b9e93 100644 --- a/API/used_images_by_user_and_duration.md +++ b/API/used_images_by_user_and_duration.md @@ -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` diff --git a/DB_Schema/leaderboard.md b/DB_Schema/leaderboard.md index d3f7253..4cbd1de 100644 --- a/DB_Schema/leaderboard.md +++ b/DB_Schema/leaderboard.md @@ -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;` @@ -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 ``` @@ -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 ```