fix(scrapers): cses interactive problems
This commit is contained in:
parent
78c4cc779e
commit
d4df57bd05
3 changed files with 14 additions and 20 deletions
|
|
@ -153,9 +153,7 @@ function M.handle_command(opts)
|
||||||
cache_commands.handle_cache_command(cmd)
|
cache_commands.handle_cache_command(cmd)
|
||||||
elseif cmd.type == 'contest_setup' then
|
elseif cmd.type == 'contest_setup' then
|
||||||
local setup = require('cp.setup')
|
local setup = require('cp.setup')
|
||||||
if setup.set_platform(cmd.platform) then
|
|
||||||
setup.setup_contest(cmd.platform, cmd.contest, nil)
|
setup.setup_contest(cmd.platform, cmd.contest, nil)
|
||||||
end
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -7,16 +7,6 @@ local scraper = require('cp.scraper')
|
||||||
local state = require('cp.state')
|
local state = require('cp.state')
|
||||||
|
|
||||||
local constants = require('cp.constants')
|
local constants = require('cp.constants')
|
||||||
local platforms = constants.PLATFORMS
|
|
||||||
|
|
||||||
function M.set_platform(platform)
|
|
||||||
if not vim.tbl_contains(platforms, platform) then
|
|
||||||
logger.log(("Unknown platform '%s'"):format(platform), vim.log.levels.ERROR)
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
state.set_platform(platform)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
---@class TestCaseLite
|
---@class TestCaseLite
|
||||||
---@field input string
|
---@field input string
|
||||||
|
|
@ -35,9 +25,10 @@ end
|
||||||
|
|
||||||
---@param platform string
|
---@param platform string
|
||||||
---@param contest_id string
|
---@param contest_id string
|
||||||
---@param problem_id string|nil
|
---@param problem_id? string
|
||||||
---@param language? string|nil
|
---@param language? string
|
||||||
function M.setup_contest(platform, contest_id, problem_id, language)
|
function M.setup_contest(platform, contest_id, problem_id, language)
|
||||||
|
state.set_platform(platform)
|
||||||
state.set_contest_id(contest_id)
|
state.set_contest_id(contest_id)
|
||||||
cache.load()
|
cache.load()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -132,12 +132,17 @@ def parse_category_problems(category_id: str, html: str) -> list[ProblemSummary]
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def parse_limits(html: str) -> tuple[int, int]:
|
def _extract_problem_info(html: str) -> tuple[int, int, bool]:
|
||||||
tm = TIME_RE.search(html)
|
tm = TIME_RE.search(html)
|
||||||
mm = MEM_RE.search(html)
|
mm = MEM_RE.search(html)
|
||||||
t = int(round(float(tm.group(1)) * 1000)) if tm else 0
|
t = int(round(float(tm.group(1)) * 1000)) if tm else 0
|
||||||
m = int(mm.group(1)) if mm else 0
|
m = int(mm.group(1)) if mm else 0
|
||||||
return t, m
|
md = MD_BLOCK_RE.search(html)
|
||||||
|
interactive = False
|
||||||
|
if md:
|
||||||
|
body = md.group(1)
|
||||||
|
interactive = "This is an interactive problem." in body
|
||||||
|
return t, m, interactive
|
||||||
|
|
||||||
|
|
||||||
def parse_title(html: str) -> str:
|
def parse_title(html: str) -> str:
|
||||||
|
|
@ -220,10 +225,10 @@ class CSESScraper(BaseScraper):
|
||||||
try:
|
try:
|
||||||
html = await fetch_text(client, task_path(pid))
|
html = await fetch_text(client, task_path(pid))
|
||||||
tests = parse_tests(html)
|
tests = parse_tests(html)
|
||||||
timeout_ms, memory_mb = parse_limits(html)
|
timeout_ms, memory_mb, interactive = _extract_problem_info(html)
|
||||||
except Exception:
|
except Exception:
|
||||||
tests = []
|
tests = []
|
||||||
timeout_ms, memory_mb = 0, 0
|
timeout_ms, memory_mb, interactive = 0, 0, False
|
||||||
return {
|
return {
|
||||||
"problem_id": pid,
|
"problem_id": pid,
|
||||||
"tests": [
|
"tests": [
|
||||||
|
|
@ -231,7 +236,7 @@ class CSESScraper(BaseScraper):
|
||||||
],
|
],
|
||||||
"timeout_ms": timeout_ms,
|
"timeout_ms": timeout_ms,
|
||||||
"memory_mb": memory_mb,
|
"memory_mb": memory_mb,
|
||||||
"interactive": False,
|
"interactive": interactive,
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks = [run_one(p.id) for p in problems]
|
tasks = [run_one(p.id) for p in problems]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue