Skip to content

Commit

Permalink
Added highload.fun
Browse files Browse the repository at this point in the history
leetcode.com curl headers fix
Added virtual start
Account suggests
Standings edit
Codechef and Leetcode news
Added supervisorctl
  • Loading branch information
aropan committed May 1, 2024
1 parent c3d2b9e commit 146cd6f
Show file tree
Hide file tree
Showing 47 changed files with 892 additions and 183 deletions.
29 changes: 29 additions & 0 deletions legacy/module/highload.fun/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
require_once dirname(__FILE__) . '/../../config.php';

$data = curlexec($URL, null, array("json_output" => 1));
if ($data['result'] !== 'OK') {
trigger_error("Failed to fetch data, result = '${data['result']}', error = '${data['error']}'", E_USER_WARNING);
return;
}

foreach ($data['data'] as $_ => $contest) {
foreach ($contest['rounds'] as $_ => $round) {
$contests[] = array(
'start_time' => $round['round_from'],
'end_time' => $round['round_to'],
'title' => $contest['caption'] . '. ' . $round['caption'],
'url' => url_merge($HOST_URL, "/timed_competitions/${contest['id']}"),
'standings_url' => url_merge($HOST_URL, "/timed_competitions/${contest['id']}/leaderboard/${round['id']}/"),
'host' => $HOST,
'rid' => $RID,
'timezone' => $TIMEZONE,
'key' => $contest['id'] . '/' . $round['id'],
);
}
}

if ($RID === -1) {
print_r($contests);
}
?>
15 changes: 15 additions & 0 deletions src/clist/templatetags/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from django.apps import apps
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.contrib.humanize.templatetags.humanize import naturaltime
from django.db.models import Value
from django.template.base import Node
from django.template.defaultfilters import floatformat, slugify, stringfilter
Expand Down Expand Up @@ -297,6 +298,11 @@ def aslist(value):
return [value]


@register.filter
def asbool(value):
return bool(value)


@register.simple_tag
def calc_mod_penalty(info, contest, solving, penalty):
if not isinstance(penalty, (int, float)):
Expand Down Expand Up @@ -723,6 +729,8 @@ def to_escaped_json(data):

@register.filter
def chain(value, arg):
if arg is None:
return value
return itertools.chain(value, arg)


Expand Down Expand Up @@ -1402,3 +1410,10 @@ def search_linked_coder(request, account):
search = value

return search


@register.simple_tag(takes_context=True)
def time_ago(context, time):
title = format_time(timezone(time, context['timezone']), context['timeformat'])
value = naturaltime(timezone(time, context['timezone']))
return mark_safe(f'<span title="{title}" data-placement="top" data-toggle="tooltip">{value}</span>')
4 changes: 2 additions & 2 deletions src/clist/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
re_path(r'^$', views.main, name='main'),
re_path(r'^send-event-notification/$', views.send_event_notification, name='send_event_notification'),
re_path(r'^resources/$', views.resources, name='resources'),
re_path(r'^resources/account/rating/$', views.resources_account_rating, name='resources_account_rating'),
re_path(r'^resources/country/rating/$', views.resources_country_rating, name='resources_country_rating'),
re_path(r'^resources/account/ratings/$', views.resources_account_ratings, name='resources_account_ratings'),
re_path(r'^resources/country/ratings/$', views.resources_country_ratings, name='resources_country_ratings'),
re_path(r'^resources/dumpdata/$', views.resources_dumpdata, name='resources_dumpdata'),
re_path(r'^resource/(.*)/$', views.resource, name='resource'),
re_path(r'^get/events/$', views.get_events),
Expand Down
10 changes: 8 additions & 2 deletions src/clist/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def resources(request):

@page_templates((('resources_account_rating_paging.html', None),))
@context_pagination()
def resources_account_rating(request, template='resources_account_rating.html'):
def resources_account_ratings(request, template='resources_account_ratings.html'):
params = {}
accounts_filter = Q()

Expand Down Expand Up @@ -424,7 +424,7 @@ def resources_account_rating(request, template='resources_account_rating.html'):

@page_templates((('resources_country_rating_paging.html', None),))
@context_pagination()
def resources_country_rating(request, template='resources_country_rating.html'):
def resources_country_ratings(request, template='resources_country_ratings.html'):
params = {}
country_accounts = CountryAccount.objects.filter(rating__isnull=False).order_by('-rating')

Expand Down Expand Up @@ -546,6 +546,7 @@ def resource(request, host, template='resource.html', extra_context=None):
primary_country = None

params = {}
mute_country_rating = False

contests = resource.contest_set.all()

Expand Down Expand Up @@ -573,6 +574,7 @@ def resource(request, host, template='resource.html', extra_context=None):
delta_period = deltas_period.get(period, None)
if delta_period:
accounts = accounts.filter(last_activity__gte=now - delta_period)
mute_country_rating = True

default_variables = resource.info.get('default_variables', {})
range_filter_values = {}
Expand All @@ -590,6 +592,7 @@ def resource(request, host, template='resource.html', extra_context=None):
if value is not None:
params[field] = value
accounts = accounts.filter(**{operator: value})
mute_country_rating = True

if not request.as_coder:
update_coder_range_filter(coder, range_filter_values, resource.host)
Expand Down Expand Up @@ -679,6 +682,7 @@ def resource(request, host, template='resource.html', extra_context=None):
},
'contest_key': None,
'has_country': has_country,
'mute_country_rating': mute_country_rating,
'periods': periods,
'params': params,
'first_per_page': 10,
Expand Down Expand Up @@ -1009,6 +1013,8 @@ def problems(request, template='problems.html'):
mapping={
'name': {'fields': ['name__iregex']},
'key': {'fields': ['key__iexact']},
'index': {'fields': ['index']},
'short': {'fields': ['short']},
'contest': {'fields': ['contest__title__iregex'], 'exists': 'contests'},
'resource': {'fields': ['resource__host__iregex']},
'tag': {'fields': ['problemtag__name'], 'exists': 'tags'},
Expand Down
4 changes: 2 additions & 2 deletions src/pyclist/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def group_and_calculate_times(queries):
query_sql = re.sub(r'\b\d+\b', '%d', query_sql) # replace number
query_sql = re.sub(r'\'.+?\'', '%s', query_sql) # replace string
query_sql = re.sub(r'\bs\d+_x\d+\b', '%s', query_sql) # replace savepoint
query_sql = re.sub(r'\b%d\b(, %d\b)+', '%ds', query_sql) # replace many numbers
query_sql = re.sub(r'\b%s\b(, %s\b)+', '%ss', query_sql) # replace many strings
query_sql = re.sub(r'%d\b(, %d\b)+', '%ds', query_sql) # replace many numbers
query_sql = re.sub(r'%s\b(, %s\b)+', '%ss', query_sql) # replace many strings
grouped.setdefault(query_sql, []).append(query)
total_times = []
for key, queries in grouped.items():
Expand Down
2 changes: 2 additions & 0 deletions src/pyclist/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,8 @@ def show_toolbar_callback(request):
'dev': '<i class="fa-regular fa-clone"></i>',
'medal_scores': '<i class="fa-fw fas fa-chart-line"></i>',
'merged_standings': '<i class="fa-solid fa-object-group"></i>',
'finish': '<i class="fa-solid fa-flag-checkered"></i>',
'virtual_start': '<i class="fa-solid fa-stopwatch"></i>',

'google': {'icon': '<i class="fab fa-google"></i>', 'title': None},
'facebook': {'icon': '<i class="fab fa-facebook"></i>', 'title': None},
Expand Down
1 change: 1 addition & 0 deletions src/ranking/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class ModuleAdmin(BaseModelAdmin):
@admin_register(VirtualStart)
class VirtualStartAdmin(BaseModelAdmin):
list_display = ['id', 'coder', 'entity', 'start_time']
date_hierarchy = 'created'
search_fields = ['coder__username']


Expand Down
4 changes: 2 additions & 2 deletions src/ranking/management/commands/parse_statistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,9 +1152,9 @@ def update_after_update_or_create(statistic, created, addition, try_calculate_ti
v_result = v.get('result', '')
if isinstance(v_result, str) and '?' in v_result:
calculate_time = True
p = p_problems.get(k, {})
if 'time' in v:
if 'time' in v or 'result' not in v:
continue
p = p_problems.get(k, {})
has_change = v.get('result') != p.get('result')
if (not has_change or contest.end_time < now) and 'time' in p:
v['time'] = p['time']
Expand Down
16 changes: 8 additions & 8 deletions src/ranking/management/modules/codeforces.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from clist.templatetags.extras import as_number, is_solved
from ranking.management.modules import conf
from ranking.management.modules.common import LOG, REQ, BaseModule, FailOnGetResponse, parsed_table, utc_now, UNCHANGED
from ranking.management.modules.common import LOG, REQ, UNCHANGED, BaseModule, FailOnGetResponse, parsed_table, utc_now
from ranking.management.modules.excepts import ExceptionParseStandings, InitModuleException
from ranking.utils import create_upsolving_statistic
from utils.aes import AESModeOfOperation
Expand Down Expand Up @@ -211,7 +211,7 @@ def get_standings_from_html(self):
return standings

@staticmethod
def process_submission(submission, result, upsolve, contest, binary):
def process_submission(submission, result, upsolve, contest, with_binary=False):
contest_url = contest.url.replace('contests', 'contest')

info = {
Expand Down Expand Up @@ -251,10 +251,10 @@ def process_submission(submission, result, upsolve, contest, binary):
p['submission_id'] > info['submission_id'] and is_accepted
):
p.update(info)
if binary:
p['binary'] = binary
if with_binary:
p['binary'] = is_accepted
if update_result:
p['result'] = '+' if is_accepted else '-1'
p['result'] = '+' if is_accepted else '-'
info['updated'] = True
r = as_number(p.get('result'), force=True)
p['partial'] = not is_accepted and p.get('partial', True) and r and r > 0
Expand Down Expand Up @@ -542,7 +542,7 @@ def parse_points_info(points_info):
):
upsolve = True

info = Statistic.process_submission(submission, result, upsolve, contest=self, binary=False)
info = Statistic.process_submission(submission, result, upsolve, contest=self)

has_accepted |= info['is_accepted']
if contest_type == 'IOI' and info['is_accepted']:
Expand All @@ -556,7 +556,7 @@ def parse_points_info(points_info):

def to_score(x):
return (
(1 if x.startswith('+') or not x.startswith('?') and float(x) > 0 else 0)
(1 if x.startswith('+') or not x.startswith('-') and not x.startswith('?') and float(x) > 0 else 0)
if isinstance(x, str) else x
)

Expand Down Expand Up @@ -772,7 +772,7 @@ def update_submissions(account, resource):

result = {account.key: deepcopy(addition)}
submission_info = Statistic.process_submission(submission, result,
upsolve=True, contest=contest, binary=True)
upsolve=True, contest=contest, with_binary=True)
if not submission_info.get('updated'):
continue

Expand Down
6 changes: 4 additions & 2 deletions src/ranking/management/modules/huawei.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#!/usr/bin/env python

from ranking.management.modules.common import BaseModule
from urllib.parse import urlparse

from ranking.management.modules import open_kattis
from ranking.management.modules.common import BaseModule


class Statistic(BaseModule):

def __new__(cls, **kwargs):
contest = kwargs.get('contest')
if contest:
if 'kattis.com' in contest.url:
if urlparse(contest.url).netloc.endswith('.kattis.com'):
return open_kattis.Statistic(**kwargs)
return super().__new__(cls)
16 changes: 15 additions & 1 deletion src/ranking/management/modules/leetcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,21 @@ def _get(self, *args, req=None, **kwargs):

headers = kwargs.setdefault('headers', {})
headers['User-Agent'] = 'Mediapartners-Google'
headers['Referrer-Policy'] = 'strict-origin-when-cross-origin'
headers['Accept-Encoding'] = 'gzip, deflate, br'

for key, value in (
('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8'),
('Accept-Language', 'en-US,en;q=0.5'),
('Connection', 'keep-alive'),
('DNT', '1'),
('Upgrade-Insecure-Requests', '1'),
('Sec-Fetch-Dest', 'document'),
('Sec-Fetch-Mode', 'navigate'),
('Sec-Fetch-Site', 'cross-site'),
('Pragma', 'no-cache'),
('Cache-Control', 'no-cache'),
):
headers.setdefault(key, value)

kwargs['with_curl'] = req.proxer is None and 'post' not in kwargs
kwargs['with_referer'] = False
Expand Down
18 changes: 18 additions & 0 deletions src/ranking/migrations/0125_virtualstart_finish_time.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/ranking/migrations/0126_virtualstart_addition.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/ranking/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,9 @@ class VirtualStart(BaseModel):
entity = GenericForeignKey('content_type', 'object_id')

start_time = models.DateTimeField()
finish_time = models.DateTimeField(default=None, null=True, blank=True)

addition = models.JSONField(default=dict, blank=True)

class Meta:
unique_together = ('coder', 'content_type', 'object_id')
Expand All @@ -1194,3 +1197,17 @@ def contests_filter(coder):
has_virtual_start = VirtualStart.filter_by_content_type(Contest).filter(coder=coder, object_id=OuterRef('id'))
has_verdict = coder.verdicts.filter(problem__contests=OuterRef('pk'))
return Exists(has_virtual_start) | Exists(has_verdict)

def is_active(self):
return self.finish_time is None or self.finish_time > timezone.now()

def statistics(self):
return [{
'id': f'virtualstart{self.pk}',
'contest_id': self.object_id if self.content_type.model == 'contest' else None,
'place': self.addition.get('place'),
'solving': self.addition.get('solving'),
'addition': self.addition,
'virtual_start': True,
'virtual_start_pk': self.pk,
}]
2 changes: 1 addition & 1 deletion src/ranking/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
re_path(r'^solutions/(?P<sid>[0-9]+)/(?P<problem_key>.*)/$', views.solutions, name='solution'),
re_path(r'^versus/$', views.make_versus, name='make_versus'),
re_path(r'^versus/(.+/vs/.+)/$', views.versus, name='versus'),
re_path(r'^virtual-start/$', views.virtual_start, name='virtual-start'),
re_path(r'^virtual-start/$', views.virtual_start, name='virtual_start'),
]
Loading

0 comments on commit 146cd6f

Please sign in to comment.