Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
flake fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmorina committed Dec 5, 2017
1 parent f679b35 commit f860301
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 33 deletions.
2 changes: 1 addition & 1 deletion crowdsourcing/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def filter_by_boomerang(self, worker, sort_by='-boomerang'):
up.handle requester_handle, p.published_at
FROM crowdsourcing_project p
INNER JOIN crowdsourcing_userprofile up on up.user_id = p.owner_id
INNER JOIN projects ON projects.project_id = p.id ORDER BY case when %(sort_by)s='-boomerang'
INNER JOIN projects ON projects.project_id = p.id ORDER BY case when %(sort_by)s='-boomerang'
then requester_rating when %(sort_by)s='-available_tasks' then available_tasks
when %(sort_by)s='-published_at' then 12 when %(sort_by)s='-price' then p.price
end desc nulls last, p.id desc;
Expand Down
3 changes: 0 additions & 3 deletions crowdsourcing/permissions/user.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from rest_framework import permissions
from csp import settings
from rest_framework.exceptions import PermissionDenied
from crowdsourcing.models import RegistrationWhitelist


class IsWorker(permissions.BasePermission):
Expand All @@ -16,8 +15,6 @@ def has_object_permission(self, request, view, object):

class CanCreateAccount(permissions.BasePermission):
def has_permission(self, request, view):
# user_email = request.data.get('email')
# users = RegistrationWhitelist.objects.filter(email=user_email).count()
if view.action == 'create' and not (request.user.is_staff or settings.REGISTRATION_ALLOWED):
raise PermissionDenied(detail='We are currently in closed beta. '
'If you\'d like an account, email [email protected] '
Expand Down
1 change: 0 additions & 1 deletion crowdsourcing/serializers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class Meta:
def get_sender_alias(self, obj):
return obj.sender.profile.handle


def get_posted_time(self, obj):
from crowdsourcing.utils import get_time_delta
delta = get_time_delta(obj.created_at)
Expand Down
13 changes: 6 additions & 7 deletions crowdsourcing/serializers/project.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import copy
import numpy as np
from decimal import Decimal

import numpy as np
from django.db import transaction
from crowdsourcing.utils import hash_task
from django.db.models import Q, F
from django.utils import timezone
from rest_framework import serializers
Expand All @@ -11,14 +11,14 @@
from crowdsourcing import models
from crowdsourcing.crypto import to_hash
from crowdsourcing.serializers.dynamic import DynamicFieldsModelSerializer
from crowdsourcing.serializers.file import BatchFileSerializer
from crowdsourcing.serializers.message import CommentSerializer
from crowdsourcing.serializers.task import TaskSerializer, TaskCommentSerializer
from crowdsourcing.serializers.template import TemplateSerializer, TemplateItemSerializer
from crowdsourcing.serializers.file import BatchFileSerializer
from crowdsourcing.tasks import update_project_boomerang
from crowdsourcing.utils import generate_random_id
from crowdsourcing.utils import hash_task
from crowdsourcing.validators.project import ProjectValidator
from mturk.tasks import mturk_update_status


class ProjectSerializer(DynamicFieldsModelSerializer):
Expand Down Expand Up @@ -106,9 +106,8 @@ def create(self, with_defaults=True, **kwargs):
template_items = template_initial['items'] if template_initial else []

template = {
"name": template_initial.get('name',
generate_random_id()) if template_initial
is not None else 't_' + generate_random_id(),
"name": template_initial.get('name', generate_random_id()
) if template_initial is not None else 't_' + generate_random_id(),
"items": template_items
}
if 'post_mturk' in self.validated_data:
Expand Down
2 changes: 1 addition & 1 deletion crowdsourcing/serializers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def create(self, **kwargs):
password=self.initial_data.get('password1'),
active=True,
approved=True)
except:
except Exception:
print("Failed to create Discourse user!")

return user
Expand Down
6 changes: 3 additions & 3 deletions crowdsourcing/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def expire_tasks():
INNER JOIN crowdsourcing_task t ON tw.task_id = t.id
INNER JOIN crowdsourcing_project p ON t.project_id = p.id
INNER JOIN crowdsourcing_taskworkersession sessions ON sessions.task_worker_id = tw.id
WHERE tw.status=%(in_progress)s
WHERE tw.status=%(in_progress)s
GROUP BY tw.id, p.id
HAVING sum(coalesce(sessions.ended_at, now()) - sessions.started_at) >
coalesce(p.timeout, INTERVAL '24 hour'))
Expand Down Expand Up @@ -137,7 +137,7 @@ def auto_approve_tasks():
INNER JOIN auth_user u_worker ON tw.worker_id = u_worker.id
WHERE tw.submitted_at + INTERVAL %(auto_approve_freq)s < NOW()
AND tw.status=%(submitted)s)
UPDATE crowdsourcing_taskworker tw_up SET status=%(accepted)s, approved_at = %(approved_at)s,
UPDATE crowdsourcing_taskworker tw_up SET status=%(accepted)s, approved_at = %(approved_at)s,
auto_approved=TRUE
FROM taskworkers
WHERE taskworkers.id=tw_up.id
Expand Down Expand Up @@ -448,7 +448,7 @@ def update_feed_boomerang():
WHERE p.status = 3 AND p.deleted_at IS NULL
GROUP BY p.id, p.name, owner_id, p.min_rating, p.group_id, p.price, aux_attributes) available
INNER JOIN auth_user u_workers ON TRUE
INNER JOIN crowdsourcing_userprofile p_workers ON p_workers.user_id = u_workers.id
INNER JOIN crowdsourcing_userprofile p_workers ON p_workers.user_id = u_workers.id
AND p_workers.is_worker IS TRUE
INNER JOIN get_worker_ratings(u_workers.id) worker_ratings
ON worker_ratings.requester_id = available.owner_id
Expand Down
2 changes: 1 addition & 1 deletion crowdsourcing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_pk(id_or_hash):
try:
project_id = int(id_or_hash)
return project_id, False
except:
except Exception:
return to_pk(id_or_hash), True


Expand Down
5 changes: 2 additions & 3 deletions crowdsourcing/viewsets/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from rest_framework.response import Response
from yapf.yapflib.yapf_api import FormatCode

from crowdsourcing.models import Category, Project, Task, TaskWorker, TaskWorkerResult
from crowdsourcing.models import Project, Task, TaskWorker, TaskWorkerResult
from crowdsourcing.permissions.project import IsProjectOwnerOrCollaborator, ProjectChangesAllowed
from crowdsourcing.serializers.project import *
from crowdsourcing.serializers.task import *
Expand Down Expand Up @@ -229,7 +229,6 @@ def calculate_total(instance):

@detail_route(methods=['POST'])
def publish(self, request, pk=None, *args, **kwargs):
num_rows = request.data.get('num_rows', 0)
project_id, is_hash = get_pk(pk)
filter_by = {}
if is_hash:
Expand Down Expand Up @@ -435,7 +434,7 @@ def requester_projects(self, request, *args, **kwargs):
INNER JOIN crowdsourcing_project p0 ON p0.id=p_max.id
GROUP BY p_max.id, p0.repetition) t
ON t.project_id = p.id
where p.deleted_at is NULL
where p.deleted_at is NULL
ORDER BY id DESC;
'''
projects = Project.objects.raw(query, params={'owner_id': request.user.id})
Expand Down
19 changes: 9 additions & 10 deletions crowdsourcing/viewsets/task.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import datetime
import json
from decimal import Decimal, ROUND_UP
from urlparse import urlsplit

import trueskill
from django.conf import settings
Expand Down Expand Up @@ -283,7 +282,7 @@ def list(self, request, *args, **kwargs):
"next": None,
"previous": None
})
except:
except Exception:
return Response([])

@detail_route(methods=['get'], url_path='assignment-results', permission_classes=[IsTaskOwner])
Expand Down Expand Up @@ -789,7 +788,7 @@ def list_other_submissions(self, request, pk, *args, **kwargs):
return Response(serializer.data)

@detail_route(methods=['post'])
def reject(self, request, *args, **kwargs):
def collective_reject(self, request, *args, **kwargs):
task_worker = self.get_object()
serializer = CollectiveRejectionSerializer(data=request.data)
if serializer.is_valid():
Expand Down Expand Up @@ -1025,13 +1024,13 @@ def post(self, request, *args, **kwargs):
if len(identifier_hash.decode(identifier)) == 0:
raise serializers.ValidationError(detail=daemo_error("Invalid identifier"))
task_worker_id, task_id, template_item_id = identifier_hash.decode(identifier)
template_item = models.TemplateItem.objects.get(id=template_item_id)
task = models.Task.objects.get(id=task_id)
source_url = None
if template_item.aux_attributes['src']:
source_url = urlsplit(template_item.aux_attributes['src'])
else:
source_url = urlsplit(task.data[template_item.aux_attributes['data_source']])
# template_item = models.TemplateItem.objects.get(id=template_item_id)
# task = models.Task.objects.get(id=task_id)
# source_url = None
# if template_item.aux_attributes['src']:
# source_url = urlsplit(template_item.aux_attributes['src'])
# else:
# source_url = urlsplit(task.data[template_item.aux_attributes['data_source']])
# if 'HTTP_REFERER' not in request.META.keys():
# return Response(data={"message": "Missing referer"}, status=status.HTTP_403_FORBIDDEN)
# referer_url = urlsplit(request.META['HTTP_REFERER'])
Expand Down
4 changes: 2 additions & 2 deletions mturk/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def _mturk_system_qualifications(qualification):
requirement = None
if item.expression['attribute'] == 'location':
op = OP_IN if item.expression['operator'] == 'in' else OP_NOT_IN
requirement = MultiLocaleRequirement(op, [l.strip() for l in item.expression['value'] if
l is not None and l != ''])
requirement = MultiLocaleRequirement(op, [val.strip() for val in item.expression['value'] if
val is not None and val != ''])
elif item.expression['attribute'] == 'approval_rate':
op = OP_GT if item.expression['operator'] == 'gt' else OP_LT
requirement = PercentAssignmentsApprovedRequirement(op, item.expression['value'])
Expand Down
2 changes: 1 addition & 1 deletion mturk/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def calculate_cumulative_ratings(owner_id, project_id):

try:
mat = IterativeSVD(verbose=False, init_fill_method="mean").complete(matrix)
except:
except Exception:
mat = SoftImpute(verbose=False, init_fill_method="mean").complete(matrix)

data['score'] = mat.mean(axis=ROW_WISE)
Expand Down

0 comments on commit f860301

Please sign in to comment.