Skip to content

Commit bd56f85

Browse files
committed
Microtask 4
1 parent 30b27c9 commit bd56f85

2 files changed

Lines changed: 191 additions & 0 deletions

File tree

App/templates/App/task4.html

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{% load static %}
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<title>
6+
Microtask 4
7+
</title>
8+
<link type="text/css" rel="stylesheet" href="https://tools-static.wmflabs.org/cdnjs/ajax/libs/materialize/0.100.2/css/materialize.css" ></link>
9+
<link type="text/css" rel="stylesheet" href={% static "style.css" %} ></link>
10+
</head>
11+
<body>
12+
<div class="row">
13+
<nav>
14+
<div class="nav-wrapper pd-left-20">
15+
<a href="{% url 'App:get_recent_english_edits' %}" class="brand-logo">Microtask 4: Edit analysis</a>
16+
<ul id="nav-mobile" class="right hide-on-med-and-down">
17+
<li><a href="{% url 'App:get_recent_english_edits' %}">Microtask1</a></li>
18+
<li><a href="{% url 'App:get_the_user_percentile' %}">Microtask2</a></li>
19+
<li><a href="{% url 'App:index' %}">Home</a></li>
20+
</ul>
21+
</div>
22+
</nav>
23+
</div>
24+
<center><h4>Tool to analyse quality of last 5 edits made by user</h4></center>
25+
<div class="row">
26+
<form class="col s12" method="post">
27+
{% csrf_token %}
28+
<div class="row">
29+
<div class="input-field col s6 m6 offset-m3">
30+
<input id="username" name="username" type="text">
31+
<label for="username">Username</label>
32+
</div>
33+
</div>
34+
<div class="row">
35+
<div class="col s6 m6 offset-m3">
36+
<button class="btn waves-effect waves-light blue-color" type="submit" name="action">Search
37+
</button>
38+
</div>
39+
</div>
40+
</form>
41+
</div>
42+
43+
{% if error %}
44+
<div class="row">
45+
<div class="col s12 m6 offset-m3">
46+
<div class="card blue lighten-2">
47+
<div class="card-content white-text">
48+
{{error}}
49+
</div>
50+
</div>
51+
</div>
52+
</div>
53+
{% endif %}
54+
55+
<div class="row">
56+
<div class="col s12 m6 offset-m3">
57+
<div class="card blue lighten-2">
58+
<div class="card-content white-text">
59+
<span class="card-title"> About analysis parameters </span>
60+
<p>
61+
<ul>
62+
<li><b>Edit Quality</b>
63+
<li>Goodfaith: predicts whether an edit was saved in good-faith </li>
64+
<li>Damaging: predicts whether or not an edit causes damage </li>
65+
<li>Reverted: predicts whether an edit will eventually be reverted </li>
66+
</li><br>
67+
<li><b>Article Quality</b>
68+
<li>Draft Qulity: predicts if the article will need to be speedy deleted (spam, vandalism, attack, or OK) </li>
69+
<li>Assessment scale: predicts the (Wikipedia 1.0-like) assessment class of an article or draft</li>
70+
</li>
71+
</ul>
72+
</p>
73+
</div>
74+
</div>
75+
</div>
76+
</div>
77+
78+
<!-- loop -->
79+
{% for x in articles %}
80+
81+
<div class="row">
82+
<div class="col s12 m6 offset-m3">
83+
<div class="card blue lighten-2">
84+
<div class="card-content white-text">
85+
<span class="card-title"> User : {{x.user}}</span>
86+
<ul>
87+
<li>Title = {{x.title}} </li>
88+
<li>Comment = {{x.comment}} </li>
89+
<li>Timestamp = {{x.timestamp}} </li>
90+
<li>revisionID = {{x.revid}} </li>
91+
<li><a href="https://en.wikipedia.org/w/index.php?title=User:{{x.user}}&amp;diff=prev&amp;oldid={{x.revid}}">
92+
Click here to check the difference.</a><br><br>
93+
</li>
94+
<li><b>Edit Quality</b>
95+
<li>Goodfaith = {{x.goodfaith}}</li>
96+
<li>Damaging = {{x.damaging}}</li>
97+
<li>Reverted = {{x.reverted}}</li>
98+
</li><br>
99+
<li><b>Article Quality</b>
100+
<li>Draft Quality = {{x.draftquality}}</li>
101+
<li>Assessment Rating = {{x.quality}}</li>
102+
</li>
103+
</ul>
104+
</div>
105+
</div>
106+
</div>
107+
</div>
108+
109+
{% endfor %}
110+
111+
</body>
112+
</html>

App/views.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import json
2+
import requests
3+
import urllib.parse
4+
5+
from django.http import HttpResponse
6+
from django.shortcuts import render
7+
8+
9+
def user_revisions_analysis(request):
10+
"""
11+
Display analysis of last 5 edits made by user.
12+
"""
13+
if request.method=='POST':
14+
# Here, we get the username
15+
username = request.POST['username']
16+
# if username is submitted blank
17+
if not username:
18+
return render(request, "App/task4.html", {"error": "Please enter a username"})
19+
20+
# if username is not blank
21+
details = list()
22+
parameters = {'action':'query',
23+
'format':'json',
24+
'list':'usercontribs',
25+
'uclimit':'5',
26+
'ucuser':username}
27+
url_parameters = urllib.parse.urlencode(parameters)
28+
url1 = 'https://en.wikipedia.org/w/api.php?{}'.format(url_parameters)
29+
30+
# Recieved data in json-format
31+
response = requests.get(url1)
32+
33+
if response.status_code == 200:
34+
lst = json.loads(response.text)
35+
try:
36+
# if username contains invalid value
37+
if lst['error']:
38+
return render(request,
39+
'App/task4.html',
40+
{"error":lst['error']['info']}
41+
)
42+
except:
43+
# Edit data extracted
44+
edits_data = json.loads(response.text)
45+
contributions = [i for i in edits_data['query']['usercontribs']]
46+
# if user has no edits
47+
if len(contributions) == 0:
48+
return render(request,
49+
'App/task4.html',
50+
{"error": "0 edits found for username {}".format(username)})
51+
52+
for articles in contributions:
53+
url2 = "https://ores.wikimedia.org/v3/scores/enwiki/" + str(articles['revid'])
54+
# recieve ORES response
55+
response2 = requests.get(url2)
56+
if response2.status_code != 200:
57+
return render(request,
58+
'App/tesk4.html',
59+
{"error": "ORES failed to return response"})
60+
61+
# if successfull response from ORES
62+
data = json.loads(response2.text)
63+
analysis = data['enwiki']['scores'][str(articles['revid'])]
64+
predictions = {'goodfaith': analysis['goodfaith']['score']['prediction'],
65+
'reverted': analysis['reverted']['score']['prediction'],
66+
'damaging': analysis['damaging']['score']['prediction'],
67+
'draftquality': analysis['draftquality']['score']['prediction'],
68+
'quality': analysis['wp10']['score']['prediction'],
69+
'title': articles['title'],
70+
'comment': articles['comment'],
71+
'timestamp': articles['timestamp'],
72+
'revid': articles['revid'],
73+
'user': articles['user']}
74+
details.append(predictions)
75+
context = {'articles': details}
76+
return render(request,'App/task4.html',context)
77+
78+
else:
79+
return render(request,'App/task4.html',{})

0 commit comments

Comments
 (0)