Closed madhurgupta10 closed 4 years ago
@maskaravivek @nicolas-raoul I would like to discuss my API implementation with you.
I think we will have a GET request to fetch the leaderboard users with parameter as duration (all-time, monthly, weekly). This would return use username, ranks, uploads.
http://example.com/api?duration=monthly
[
{
"username": "Madhurgupta10",
"uploads": 10,
"rank": 1
},
{
"username": "some_user_1",
"uploads": 8,
"rank": 2
},
{
"username": "some_user_2",
"uploads": 6,
"rank": 3
},
{
"username": "some_user_3",
"uploads": 4,
"rank": 4
},
{
"username": "some_user_4",
"uploads": 2,
"rank": 5
}
]
To add a new user to leaderboard we can have a POST and PUT methods and DELETE method for removing the user.
I would like to know, where I can get the number of uploads done by a username in a particular timeframe?
In this script the condition is hardcoded log_timestamp > "20171101000000" and log_timestamp < "20190801000000";
About the JSON format: I think more info will be required (uploaded/nearby/used), so I guess a second parameter is needed? Like http://example.com/api?duration=monthly&game=nearby
When a user first opens the achievements screen, I would suggest using POST to register this user's interest in being in the rankings. I don't think we need a DELETE method.
To get the number of uploads you can probably adapt this SQL script and use SQL's COUNT operation. Do you know how to run SQL on Tools from an API call?
About the JSON format: I think more info will be required (uploaded/nearby/used), so I guess a second parameter is needed? Like http://example.com/api?duration=monthly&game=nearby
Agreed!
When a user first opens the achievements screen, I would suggest using POST to register this user's interest in being in the rankings. I don't think we need a DELETE method.
Okay!
To get the number of uploads you can probably adapt this SQL script and use SQL's COUNT operation. Do you know how to run SQL on Tools from an API call?
@nicolas-raoul I know how to write SQL queries but I am not able to understand how the database is defined and is working for common misc APIs. Could you please share the resources where I can find the database schemas?
Do you have ssh access to tools? If yes, can you start a SQL client there on command line? If yes, with SHOW and DESCRIBE you will probably be able to find out the structure and get the information you want :-)
@nicolas-raoul I don't have access to the VM, how can I get the credentials?
Steps 1 to 3 here I think: https://tools.wmflabs.org/admin/
@nicolas-raoul Thanks
Is this the correct one? https://toolsadmin.wikimedia.org/tools/id/commons-android-app
I don't think I have access to this one!
Looks like it :-)
I have applied for the access!
@madhurgupta10 Let me know when you get your membership request approved. I will add you as a maintainer in https://toolsadmin.wikimedia.org/tools/id/commons-android-app.
Also, can you check if you are able to access this repo?
https://phabricator.wikimedia.org/source/tool-commons-android-app/
@madhurgupta10 Let me know when you get your membership request approved. I will add you as a maintainer in https://toolsadmin.wikimedia.org/tools/id/commons-android-app.
Also, can you check if you are able to access this repo?
https://phabricator.wikimedia.org/source/tool-commons-android-app/
@maskaravivek Thanks! Yes I can access this https://phabricator.wikimedia.org/source/tool-commons-android-app/
@nicolas-raoul @maskaravivek my request for access was approved, I tried to SSH using the following ssh -J madhurgupta10@primary.bastion.wmflabs.org madhurgupta10@commons-android-app.eqiad.wmflabs
but did not work.
What documentation/procedure did you follow?
What documentation/procedure did you follow?
https://wikitech.wikimedia.org/wiki/Help:Accessing_Cloud_VPS_instances
Could you please detail what you checked, following the "Troubleshooting" section?
did not work
What error message do you get?
@nicolas-raoul @maskaravivek
This is the procedure I followed, let me know if I a doing this correctly or not.
$ ssh-keygen -t rsa -b 4096 -C "[email]"
ssh -J madhurgupta10@primary.bastion.wmflabs.org madhurgupta10@commons-android-app.eqiad.wmflabs
This error is typical of SSH keys not being recognized.
You added the public key to toolsadmin, right?
@maskaravivek What exact commands do you use to connect?
If you have not found a solution, please connect to IRC and ask there: https://wikitech.wikimedia.org/wiki/Help:Accessing_Cloud_VPS_instances#Communication_and_support
If noone answers on IRC, please ask on the mailing list linked from the same section, giving as many details as possible :-)
@nicolas-raoul Thanks, I can access it now. I was missing the step ssh-add key
and using the wrong hostname, the correct one is tools-login.wmflabs.org
Edit: I think we can just use commonswiki
database
@nicolas-raoul @maskaravivek What is the hostname for our database?
select count(*) from logging_userindex where log_type="upload" and log_actor=(select actor_id from actor where actor_name="Madhurgupta10") and log_timestamp > "20200608000000" and log_timestamp < "20200609000000"
I can count the uploads using the following SQL Query :)
@nicolas-raoul @maskaravivek How can I connect my database with MySQL workbench? To write APIs I need the make an os.environ
file
Can't you use scripts such as the ones that are already in the repository?
By "MySQL workbench", do you mean the GUI tool? I don't think there is any way to connect directly, for obvious security reasons.
If you need to create a file, the ssh command line is far enough :-)
Can't you use scripts such as the ones that are already in the repository?
I am unable to run the script, It says 'nouser'
You are able to run the uploadsbyuser.py script from a web browser, right?
Why not copy this script and make it do what you want, for instance create tables or run SELECT queries?
You are able to run the uploadsbyuser.py script from a web browser, right?
Correct, I am unable to run this file because
if 'QUERY_STRING' in os.environ:
QS = os.environ['QUERY_STRING']
neither my local system nor the Cloud Instance has this QUERY_STRING
Why not copy this script and make it do what you want, for instance create tables or run SELECT queries?
That what I would like to do but I am unable to connect to the database using python script. If I run my SQL directly in the terminal it works, but not inside a python script. What I suspect it is due to some username or hostname issue.
Please run uploadsbyuser.py not from command line, but in a web browser. You can see the exact syntax in logcat, as the Android app calls it successfully.
@nicolas-raoul This one works on the broswer https://tools.wmflabs.org/urbanecmbot/commonsmisc/uploadsbyuser.py?user=Martin%20Urbanec
But it is already a deployed API, I want to test my code locally first before deploying it. What I understood is that when we add a .py file to this repo, it automatically connects to server right? But how can I test my code without adding it to the repo?
@madhurgupta10 The easiest way would be to create a separate branch and test it on the VM itself. I am not sure if it would be possible to set it up locally.
@maskaravivek @nicolas-raoul The API is now live at https://tools.wmflabs.org/commons-android-app/tool-commons-android-app/leaderboard.py?user=Madhurgupta10&duration=yearly&category=nearby
I will update the docs for all the APIs I made :)
All the code is available at https://phabricator.wikimedia.org/source/tool-commons-android-app/
With your permission, we can close this issue.
Summary: Designing and implementing the APIs for calculating and displaying ranks of the User (all-time, monthly, weekly).
[x] Discuss and Design the API
[x] Code the API in Python and Test it using Postman.
Would you like to work on the issue? Yes