Skip to content
Open
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
112 changes: 112 additions & 0 deletions App/templates/App/task4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{% load static %}
<!DOCTYPE html>
<html>
<head>
<title>
Microtask 4
</title>
<link type="text/css" rel="stylesheet" href="https://tools-static.wmflabs.org/cdnjs/ajax/libs/materialize/0.100.2/css/materialize.css" ></link>
<link type="text/css" rel="stylesheet" href={% static "style.css" %} ></link>
</head>
<body>
<div class="row">
<nav>
<div class="nav-wrapper pd-left-20">
<a href="{% url 'App:get_recent_english_edits' %}" class="brand-logo">Microtask 4: Edit analysis</a>
<ul id="nav-mobile" class="right hide-on-med-and-down">
<li><a href="{% url 'App:get_recent_english_edits' %}">Microtask1</a></li>
<li><a href="{% url 'App:get_the_user_percentile' %}">Microtask2</a></li>
<li><a href="{% url 'App:index' %}">Home</a></li>
</ul>
</div>
</nav>
</div>
<center><h4>Tool to analyse quality of last 5 edits made by user</h4></center>
<div class="row">
<form class="col s12" method="post">
{% csrf_token %}
<div class="row">
<div class="input-field col s6 m6 offset-m3">
<input id="username" name="username" type="text">
<label for="username">Username</label>
</div>
</div>
<div class="row">
<div class="col s6 m6 offset-m3">
<button class="btn waves-effect waves-light blue-color" type="submit" name="action">Search
</button>
</div>
</div>
</form>
</div>

{% if error %}
<div class="row">
<div class="col s12 m6 offset-m3">
<div class="card blue lighten-2">
<div class="card-content white-text">
{{error}}
</div>
</div>
</div>
</div>
{% endif %}

<div class="row">
<div class="col s12 m6 offset-m3">
<div class="card blue lighten-2">
<div class="card-content white-text">
<span class="card-title"> About analysis parameters </span>
<p>
<ul>
<li><b>Edit Quality</b>
<li>Goodfaith: predicts whether an edit was saved in good-faith </li>
<li>Damaging: predicts whether or not an edit causes damage </li>
<li>Reverted: predicts whether an edit will eventually be reverted </li>
</li><br>
<li><b>Article Quality</b>
<li>Draft Qulity: predicts if the article will need to be speedy deleted (spam, vandalism, attack, or OK) </li>
<li>Assessment scale: predicts the (Wikipedia 1.0-like) assessment class of an article or draft</li>
</li>
</ul>
</p>
</div>
</div>
</div>
</div>

<!-- loop -->
{% for x in articles %}

<div class="row">
<div class="col s12 m6 offset-m3">
<div class="card blue lighten-2">
<div class="card-content white-text">
<span class="card-title"> User : {{x.user}}</span>
<ul>
<li>Title = {{x.title}} </li>
<li>Comment = {{x.comment}} </li>
<li>Timestamp = {{x.timestamp}} </li>
<li>revisionID = {{x.revid}} </li>
<li><a href="https://en.wikipedia.org/w/index.php?title=User:{{x.user}}&amp;diff=prev&amp;oldid={{x.revid}}">
Click here to check the difference.</a><br><br>
</li>
<li><b>Edit Quality</b>
<li>Goodfaith = {{x.goodfaith}}</li>
<li>Damaging = {{x.damaging}}</li>
<li>Reverted = {{x.reverted}}</li>
</li><br>
<li><b>Article Quality</b>
<li>Draft Quality = {{x.draftquality}}</li>
<li>Assessment Rating = {{x.quality}}</li>
</li>
</ul>
</div>
</div>
</div>
</div>

{% endfor %}

</body>
</html>
70 changes: 70 additions & 0 deletions App/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import json
import requests
import urllib.parse

from django.http import HttpResponse
from django.shortcuts import render


def user_revisions_analysis(request):
"""
Display analysis of last 5 edits made by user.
"""
if request.method=='POST':
# Here, we get the username
username = request.POST['username']
# if username is submitted blank
if not username:
return render(request, "App/task4.html", {"error": "Please enter a username"})
# if username is not blank
details = list()
parameters = {'action':'query',
'format':'json',
'list':'usercontribs',
'uclimit':'5',
'ucuser':username}
url_base = 'https://en.wikipedia.org/w/api.php?'
# Recieved data in json-format
response = requests.get(url_base, params = parameters)
if response.status_code == 200:
try:
# Edit data extracted
edits_data = json.loads(response.text)
if 'error' in edits_data:
raise Error(edits_data['error']['info'])
contributions = [i for i in edits_data['query']['usercontribs']]
# if user has no edits
if len(contributions) == 0:
raise Error("0 edits found for username {}".format(username))
for articles in contributions:
url_ores = "https://ores.wikimedia.org/v3/scores/enwiki/{}".format(str(articles['revid']))
# recieve ORES response
response2 = requests.get(url_ores)
if response2.status_code != 200:
raise Error("ORES failed to return response")
# if successfull response from ORES
data = json.loads(response2.text)
analysis = data['enwiki']['scores'][str(articles['revid'])]
predictions = {'goodfaith': analysis['goodfaith']['score']['prediction'],
'reverted': analysis['reverted']['score']['prediction'],
'damaging': analysis['damaging']['score']['prediction'],
'draftquality': analysis['draftquality']['score']['prediction'],
'quality': analysis['wp10']['score']['prediction'],
'title': articles['title'],
'comment': articles['comment'],
'timestamp': articles['timestamp'],
'revid': articles['revid'],
'user': articles['user']}
details.append(predictions)
except Exception as err:
return(render(request,
'App/task4.html',
{'error': err}))
context = {'articles': details}
return render(request, 'App/task4.html', context)
else:
return render(request,
'App/index.html',
{"error": 'Exit code {}'.format(str(response.status_code))})
else:
return render(request,'App/task4.html',{})