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)
|
||||
elseif cmd.type == 'contest_setup' then
|
||||
local setup = require('cp.setup')
|
||||
if setup.set_platform(cmd.platform) then
|
||||
setup.setup_contest(cmd.platform, cmd.contest, nil)
|
||||
end
|
||||
setup.setup_contest(cmd.platform, cmd.contest, nil)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,16 +7,6 @@ local scraper = require('cp.scraper')
|
|||
local state = require('cp.state')
|
||||
|
||||
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
|
||||
---@field input string
|
||||
|
|
@ -35,9 +25,10 @@ end
|
|||
|
||||
---@param platform string
|
||||
---@param contest_id string
|
||||
---@param problem_id string|nil
|
||||
---@param language? string|nil
|
||||
---@param problem_id? string
|
||||
---@param language? string
|
||||
function M.setup_contest(platform, contest_id, problem_id, language)
|
||||
state.set_platform(platform)
|
||||
state.set_contest_id(contest_id)
|
||||
cache.load()
|
||||
|
||||
|
|
|
|||
|
|
@ -132,12 +132,17 @@ def parse_category_problems(category_id: str, html: str) -> list[ProblemSummary]
|
|||
return []
|
||||
|
||||
|
||||
def parse_limits(html: str) -> tuple[int, int]:
|
||||
def _extract_problem_info(html: str) -> tuple[int, int, bool]:
|
||||
tm = TIME_RE.search(html)
|
||||
mm = MEM_RE.search(html)
|
||||
t = int(round(float(tm.group(1)) * 1000)) if tm 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:
|
||||
|
|
@ -220,10 +225,10 @@ class CSESScraper(BaseScraper):
|
|||
try:
|
||||
html = await fetch_text(client, task_path(pid))
|
||||
tests = parse_tests(html)
|
||||
timeout_ms, memory_mb = parse_limits(html)
|
||||
timeout_ms, memory_mb, interactive = _extract_problem_info(html)
|
||||
except Exception:
|
||||
tests = []
|
||||
timeout_ms, memory_mb = 0, 0
|
||||
timeout_ms, memory_mb, interactive = 0, 0, False
|
||||
return {
|
||||
"problem_id": pid,
|
||||
"tests": [
|
||||
|
|
@ -231,7 +236,7 @@ class CSESScraper(BaseScraper):
|
|||
],
|
||||
"timeout_ms": timeout_ms,
|
||||
"memory_mb": memory_mb,
|
||||
"interactive": False,
|
||||
"interactive": interactive,
|
||||
}
|
||||
|
||||
tasks = [run_one(p.id) for p in problems]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue