Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefix all constants with DMOJ_ #930

Merged
merged 1 commit into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions dmoj/throttle_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@


def new_email():
cache.add('error_email_throttle', 0, getattr(settings, 'EMAIL_THROTTLING', DEFAULT_THROTTLE)[1])
cache.add('error_email_throttle', 0, getattr(settings, 'DMOJ_EMAIL_THROTTLING', DEFAULT_THROTTLE)[1])
return cache.incr('error_email_throttle')


class ThrottledEmailHandler(AdminEmailHandler):
def __init__(self, *args, **kwargs):
super(ThrottledEmailHandler, self).__init__(*args, **kwargs)

self.throttle = getattr(settings, 'EMAIL_THROTTLING', DEFAULT_THROTTLE)[0]
self.throttle = getattr(settings, 'DMOJ_EMAIL_THROTTLING', DEFAULT_THROTTLE)[0]

def emit(self, record):
try:
Expand Down
2 changes: 1 addition & 1 deletion judge/admin/contest.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def rejudge_view(self, request, contest_id, problem_id):

queryset = ContestSubmission.objects.filter(problem_id=problem_id).select_related('submission')
if not request.user.has_perm('judge.rejudge_submission_lot') and \
len(queryset) > getattr(settings, 'REJUDGE_SUBMISSION_LIMIT', 10):
len(queryset) > getattr(settings, 'DMOJ_SUBMISSIONS_REJUDGE_LIMIT', 10):
self.message_user(request, ugettext('You do not have the permission to rejudge THAT many submissions.'),
level=messages.ERROR)
return
Expand Down
2 changes: 1 addition & 1 deletion judge/admin/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def judge(self, request, queryset):
return
queryset = queryset.order_by('id')
if not request.user.has_perm('judge.rejudge_submission_lot') and \
queryset.count() > getattr(settings, 'REJUDGE_SUBMISSION_LIMIT', 10):
queryset.count() > getattr(settings, 'DMOJ_SUBMISSIONS_REJUDGE_LIMIT', 10):
self.message_user(request, ugettext('You do not have the permission to rejudge THAT many submissions.'),
level=messages.ERROR)
return
Expand Down
2 changes: 1 addition & 1 deletion judge/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,6 @@ def get_context_data(self, **kwargs):
context['is_new_user'] = (not self.request.user.is_staff and
not profile.submission_set.filter(points=F('problem__points')).exists())
context['comment_list'] = queryset
context['vote_hide_threshold'] = getattr(settings, 'COMMENT_VOTE_HIDE_THRESHOLD', -5)
context['vote_hide_threshold'] = getattr(settings, 'DMOJ_COMMENT_VOTE_HIDE_THRESHOLD', -5)

return context
2 changes: 1 addition & 1 deletion judge/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Meta:

def clean(self):
organizations = self.cleaned_data.get('organizations') or []
max_orgs = getattr(settings, 'MAX_USER_ORGANIZATION_COUNT', 3)
max_orgs = getattr(settings, 'DMOJ_USER_MAX_ORGANIZATION_COUNT', 3)

if sum(org.is_open for org in organizations) > max_orgs:
raise ValidationError(_('You may not be part of more than {count} public organizations.').format(count=max_orgs))
Expand Down
8 changes: 5 additions & 3 deletions judge/migrations/0055_add_performance_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
def gen_pp(apps, schema_editor):
Profile = apps.get_model('judge', 'Profile')
Problem = apps.get_model('judge', 'Problem')
table = (lambda x: [pow(x, i) for i in xrange(100)])(getattr(settings, 'PP_STEP', 0.95))
bonus_function = getattr(settings, 'PP_BONUS_FUNCTION', lambda n: 300 * (1 - 0.997 ** n))
_pp_step = getattr(settings, 'DMOJ_PP_STEP', 0.95)
table = [pow(_pp_step, i) for i in xrange(getattr(settings, 'DMOJ_PP_ENTRIES', 100))]
bonus_function = getattr(settings, 'DMOJ_PP_BONUS_FUNCTION', lambda n: 300 * (1 - 0.997 ** n))
for row in Profile.objects.all():
data = (Problem.objects.filter(submission__user=row, submission__points__isnull=False, is_public=True)
.annotate(max_points=Max('submission__points')).order_by('-max_points')
.values_list('max_points', flat=True))
extradata = Problem.objects.filter(submission__user=row, submission__result='AC', is_public=True).values('id').distinct().count()
extradata = Problem.objects.filter(submission__user=row, submission__result='AC', is_public=True) \
.values('id').distinct().count()
size = min(len(data), len(table))
row.performance_points = sum(map(mul, table[:size], data[:size])) + bonus_function(extradata)
row.save()
Expand Down
16 changes: 10 additions & 6 deletions judge/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,17 @@ def organization(self):
def username(self):
return self.user.username

def calculate_points(self, table=(lambda x: [pow(x, i) for i in xrange(100)])(getattr(settings, 'PP_STEP', 0.95))):
_pp_step = getattr(settings, 'DMOJ_PP_STEP', 0.95)
_pp_table = [pow(_pp_step, i) for i in xrange(getattr(settings, 'DMOJ_PP_ENTRIES', 100))]
def calculate_points(self, table=_pp_table):
from judge.models import Problem
data = (Problem.objects.filter(submission__user=self, submission__points__isnull=False, is_public=True, is_organization_private=False)
.annotate(max_points=Max('submission__points')).order_by('-max_points')
.values_list('max_points', flat=True).filter(max_points__gt=0))
extradata = Problem.objects.filter(submission__user=self, submission__result='AC', is_public=True).values('id').distinct().count()
bonus_function = getattr(settings, 'PP_BONUS_FUNCTION', lambda n: 300 * (1 - 0.997 ** n))
data = (Problem.objects.filter(submission__user=self, submission__points__isnull=False, is_public=True,
is_organization_private=False)
.annotate(max_points=Max('submission__points')).order_by('-max_points')
.values_list('max_points', flat=True).filter(max_points__gt=0))
extradata = Problem.objects.filter(submission__user=self, submission__result='AC', is_public=True) \
.values('id').distinct().count()
bonus_function = getattr(settings, 'DMOJ_PP_BONUS_FUNCTION', lambda n: 300 * (1 - 0.997 ** n))
points = sum(data)
problems = len(data)
entries = min(len(data), len(table))
Expand Down
4 changes: 2 additions & 2 deletions judge/pdf_problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
PUPPETEER_MODULE = getattr(settings, 'PUPPETEER_MODULE', '/usr/lib/node_modules/puppeteer')
HAS_PUPPETEER = os.access(NODE_PATH, os.X_OK) and os.path.isdir(PUPPETEER_MODULE)

HAS_PDF = (os.path.isdir(getattr(settings, 'PROBLEM_PDF_CACHE', '')) and
HAS_PDF = (os.path.isdir(getattr(settings, 'DMOJ_PDF_PROBLEM_CACHE', '')) and
(HAS_PHANTOMJS or HAS_SLIMERJS or HAS_PUPPETEER))

EXIFTOOL = getattr(settings, 'EXIFTOOL', '/usr/bin/exiftool')
Expand All @@ -33,7 +33,7 @@ class BasePdfMaker(object):
title = None

def __init__(self, dir=None, clean_up=True):
self.dir = dir or os.path.join(getattr(settings, 'PROBLEM_PDF_TEMP_DIR', tempfile.gettempdir()),
self.dir = dir or os.path.join(getattr(settings, 'DMOJ_PDF_PROBLEM_TEMP_DIR', tempfile.gettempdir()),
str(uuid.uuid1()))
self.proc = None
self.log = None
Expand Down
6 changes: 3 additions & 3 deletions judge/performance_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
from judge.models import Submission
from judge.timezone import from_database_time

PP_STEP = getattr(settings, 'PP_STEP', 0.95)
PP_ENTRIES = getattr(settings, 'PP_ENTRIES', 100)
PP_STEP = getattr(settings, 'DMOJ_PP_STEP', 0.95)
PP_ENTRIES = getattr(settings, 'DMOJ_PP_ENTRIES', 100)
PP_WEIGHT_TABLE = [pow(PP_STEP, i) for i in xrange(PP_ENTRIES)]

PPBreakdown = namedtuple('PPBreakdown', 'points weight scaled_points problem_name problem_code '
'sub_id sub_date sub_points sub_total sub_result_class '
'sub_short_status sub_long_status sub_lang')


def get_pp_breakdown(user, start=0, end=100):
def get_pp_breakdown(user, start=0, end=PP_ENTRIES):
with connection.cursor() as cursor:
cursor.execute('''
SELECT max_points_table.problem_code,
Expand Down
8 changes: 4 additions & 4 deletions judge/utils/camo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def update_tree(self, doc):
obj.set('data', self.rewrite_url(obj.get('data')))


if getattr(settings, 'CAMO_URL', None) and getattr(settings, 'CAMO_KEY', None):
client = CamoClient(settings.CAMO_URL, key=settings.CAMO_KEY,
excluded=getattr(settings, 'CAMO_EXCLUDE', ()),
https=getattr(settings, 'CAMO_HTTPS', False))
if getattr(settings, 'DMOJ_CAMO_URL', None) and getattr(settings, 'DMOJ_CAMO_KEY', None):
client = CamoClient(settings.DMOJ_CAMO_URL, key=settings.DMOJ_CAMO_KEY,
excluded=getattr(settings, 'DMOJ_CAMO_EXCLUDE', ()),
https=getattr(settings, 'DMOJ_CAMO_HTTPS', False))
else:
client = None
2 changes: 1 addition & 1 deletion judge/utils/problem_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def split_path_first(path):

class ProblemDataStorage(FileSystemStorage):
def __init__(self):
super(ProblemDataStorage, self).__init__(getattr(settings, 'PROBLEM_DATA_ROOT', None))
super(ProblemDataStorage, self).__init__(getattr(settings, 'DMOJ_PROBLEM_DATA_ROOT', None))

def url(self, name):
path = split_path_first(name)
Expand Down
2 changes: 1 addition & 1 deletion judge/views/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def handle(self, request, org, profile):
if not org.is_open:
return generic_message(request, _('Joining organization'), _('This organization is not open.'))

max_orgs = getattr(settings, 'MAX_USER_ORGANIZATION_COUNT', 3)
max_orgs = getattr(settings, 'DMOJ_USER_MAX_ORGANIZATION_COUNT', 3)
if profile.organizations.filter(is_open=True).count() >= max_orgs:
return generic_message(request, _('Joining organization'), _('You may not be part of more than {count} public organizations.').format(count=max_orgs))

Expand Down