Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d7b2d0e
files to be reviewed
yashasingh Oct 3, 2017
5ad9407
task 2 for review
yashasingh Oct 5, 2017
cc7ea89
Incomplete file deleted
yashasingh Oct 6, 2017
8133e9a
changes complete
yashasingh Oct 6, 2017
6dd4900
conflict resolved
yashasingh Oct 6, 2017
ef6bda9
conflict resolved
yashasingh Oct 6, 2017
8c861d6
review changes implemented
yashasingh Oct 6, 2017
7bbf540
Sanitized database query
yashasingh Oct 6, 2017
db47853
bug fixes done
yashasingh Oct 6, 2017
97357e5
minor bugs fixed
yashasingh Oct 6, 2017
3553348
minor bugs fixed
yashasingh Oct 6, 2017
863165f
minor fixes
yashasingh Oct 6, 2017
2f5e74d
issues fixed
yashasingh Oct 8, 2017
efcde18
issues fixed
yashasingh Oct 8, 2017
a613a35
issues fixed
yashasingh Oct 8, 2017
f5c41a7
issues resolved
yashasingh Oct 8, 2017
8969f0c
percentile issue resolved
yashasingh Oct 9, 2017
fee5636
merged code
yashasingh Oct 9, 2017
c9e8057
conflict resolved
yashasingh Oct 9, 2017
7659411
minor fixes
yashasingh Oct 9, 2017
66399e5
code cleaned
yashasingh Oct 9, 2017
1581136
merged task1
yashasingh Oct 9, 2017
8df73a2
Merge branch 'devtask2' into complete
yashasingh Oct 9, 2017
ed0cb90
minor fixes
yashasingh Oct 9, 2017
4c4a59f
code made deployable
yashasingh Oct 9, 2017
a7fea46
UI updated
yashasingh Oct 11, 2017
f3d082f
minor fixes
yashasingh Oct 11, 2017
f166090
code updated
yashasingh Oct 11, 2017
0edfcac
pyc files ignored
yashasingh Oct 12, 2017
355f556
merged master
yashasingh Oct 12, 2017
6e607d7
Merge branch 'complete' of https://github.com/yashasingh/Review into …
yashasingh Oct 12, 2017
acb8ea9
percentile formula updated
yashasingh Oct 14, 2017
8bda4b9
percentile updated
yashasingh Oct 14, 2017
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
12 changes: 12 additions & 0 deletions App/templates/App/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Home Page</title>
</head>
<body>
<center>
<a href="{% url 'Microtask1:main' %}">Microtask1</a> <br>
<a href="{% url 'Microtask1:main2' %}">Microtask2</a> <br>
</center>
</body>
</html>
38 changes: 38 additions & 0 deletions App/templates/App/task2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<title>User Percentile</title>
</head>
<body>
<center>
<h2>Tool to display user Percentile and Rank in Georgian wiki</h2>
<p>Enter initial letter of username in capital</p> <br>
<form method="post">
{% csrf_token %}
Enter username: <input type="text" name="username">
<br>
<br>
<button type='submit'> Submit </button>
<a href="https://stats.wikimedia.org/EN/TablesWikipediaKA.htm">Click to see the list of users</a>
</form>
</center>
<br>
<br>
<br>

{% if false_query %}
<h2>No user found</h2> <br>
{% endif %}

{% if name %}
Name = {{name}} <br>
Useredits = {{edits}} <br>
Total_edits = {{total_edits}} <br>
Rank = {{rank}} <br>
Total_users = {{total_users}} <br>
Percentile = {{Percentile}} <br>
User rating = {{user_rating}} <br>
{% endif %}

</body>
</html>
48 changes: 48 additions & 0 deletions App/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from django.http import HttpResponse
from django.shortcuts import render
import math
import json
import requests
import toolforge

def main2(request):
if(request.method=='POST'):
flag = 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but if you want a nicer approach, you can wrap everything in a try...catch and throw an exception when the user is not found etc.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

usr = request.POST['username']
a = 1 if re.match("^[a-zA-Z0-9_ ]*$", s) else 0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would leave users with a non-ASCII username stranded. You should accept anything that's a valid MediaWiki username and escape it. Usually in SQL that means using parametrized queries. (Also, where does the s come from?)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if(!a):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look like valid Python. (Now that I look at it, all your ifs are in C-style. In Python you can just wrote if reqest.method=='POST' without the braces.)

Also, what's the point of the variable? You can always just inline it.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

flag=0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not much point in setting this as you are exiting the function anyway.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return(render(request, 'Microtask1/task2.html',{"false_query":1}))
SqlQuery1 = "SELECT user_editcount FROM user WHERE user_name='" + usr + "';"
SqlQuery2 = "SELECT ss_total_edits FROM site_stats"
#SqlQuery3 = "select rank from (select user_name, @curRank := @curRank + 1 as rank from user p, ( select @curRank := 0 ) q order by user_editcount DESC) q where user_name='"+usr+"';"
SqlQuery3 = "SELECT 1+(SELECT count(*) from user a WHERE a.user_editcount > b.user_editcount) as RNK FROM user b WHERE user_name='"+usr+"';"
SqlQuery4 = "select count(*) from user;"
conn = toolforge.connect('kawiki_p')
with conn.cursor() as curr:
s1 = curr.execute(SqlQuery1)
useredits_tup = curr.fetchall()
s2 = curr.execute(SqlQuery2)
totaledits_tup =curr.fetchall()
s3 = curr.execute(SqlQuery3)
userrank_tup = curr.fetchall()
s4 = curr.execute(SqlQuery4)
totalusers_tup = curr.fetchall()

conn.close()
try:
useredits = useredits_tup[0][0]
totaledits = totaledits_tup[0][0]
userrank = userrank_tup[0][0]
totalusers = totalusers_tup[0][0]
except:
flag = 0

if(flag):
percentile = 100-((userrank*100)/(totalusers+1))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the logic here. In practice this will be the same as 100 - rating (since totalusers is large so adding one doesn't matter). In theory, the +1 seems wrong. The percentile is the smallest number N for which the user is included in the top N% of users - you order the users by editcount, split the list into 100 equal chunks, if the user is in the chunk with the largest editcount, they are in the first percentile, the next chunk is the second etc. So the top 1% is the users with rank 1..(totalusers/100), top 2% is (totalusers/100)..(2*totalusers/100) etc. So percentile is same as what you call rating here (or 100 minus that if you prefer - either could be called a percentile).

Copy link
Copy Markdown
Owner Author

@yashasingh yashasingh Oct 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was calculating percentile on the basis no of editcounts , so the user with highest editcounts gets 99 percentile (since 99% of users lie below him) and not the basis of userrank. In which case, the percentile of the user with highest no of editcounts would we 1, so he would be in top 1 percentile.
I'll have updated it according to userrank.

rating = math.ceil((userrank/totalusers)*100)
userrating = "User lies in top "+str(rating) + "%"
return(render(request, 'Microtask1/task2.html',{'edits':useredits, 'name':usr, 'total_edits':totaledits, 'rank':userrank, 'total_users':totalusers, 'Percentile':percentile, 'user_rating':userrating}))
return(render(request, 'Microtask1/task2.html',{"false_query":1}))
else:
return(render(request, 'Microtask1/task2.html',{}))