# Path: termicoder/models/Problem.py
# class Problem(ABC):
#     @abstractmethod
#     def __init__(self, data):
#         self.name = None
#         self.status = None
#         self.submissions_count = 0
#         self.data = data
#         self.code = None
#         self.html = None
#         self.testcases = None
#         self.contest_code = None
#         self.judge_name = None
#         self.timelimit = 3.0  # in seconds
# 
#     # used by list
#     @abstractmethod
#     def __str__(self):
#         pass
# 
# Path: termicoder/utils/logging.py

# 
# Path: termicoder/judges/codechef/utils/testcases.py
# def extract(html):
#     logger.debug("extract is being called")
#     soup = BeautifulSoup(html, "html.parser")
#     testcases = []
#     pre_tag_elements = soup.find_all('pre')
#     try:
#         io = _extract_io(pre_tag_elements)
#         logger.debug(io)
#     except BaseException:
#         logger.error("Extraction of testcase for the problem failed")
#         return []
# 
#     if(len(pre_tag_elements) >= 1):
#         for i in range(len(io[0])):
#             inp = io[0][i]
#             ans = io[1][i]
#             testcases.append(Testcase(inp=inp, ans=ans, code=i))
#             logger.debug("inp\n" + inp + "\n\n")
#             logger.debug("ans\n" + ans + "\n\n")
#         return testcases
#     else:
#         logger.error("Extraction of testcase for the problem failed")


from termicoder.models import Problem
from termicoder.utils.logging import logger
from collections import namedtuple
from ..utils.testcases import extract
from tomd import Tomd
import markdown
import os
import mdv
        if(data is not None):
            self._initialize()

    def _initialize(self):
        concerned_data = self.data['result']['data']['content']
        problem_content = namedtuple(
            "problem", concerned_data.keys())(*concerned_data.values())
        self.name = problem_content.problemName
        self.submissions_count = problem_content.successfulSubmissions
        self.code = problem_content.problemCode
        self.text = problem_content.body
        self.html = self._get_html(problem_content.body)
        self.testcases = self._extract_testcases(self.html)
        self.timelimit = float(problem_content.maxTimeLimit)
        if(self.timelimit == 0):
            self.timelimit = 3.0

    def _get_html(self, body):
        newbody = body.replace('<br>', '\n')
        newbody = newbody.replace('<br />', '\n')
        self.text = newbody
        mdProcessor = markdown.Markdown()
        myHtmlFragment = str(mdProcessor.convert(newbody))
        myHtmlFragment = myHtmlFragment.replace('<code>', '<pre>')
        myHtmlFragment = myHtmlFragment.replace('</code>', '</pre>')
        logger.debug(myHtmlFragment)
        javascript = open(
            os.path.join((os.path.dirname(__file__)), "script.js")).read()
        return ("<script>%s</script>" % javascript) + myHtmlFragment


# Path: termicoder/models/Problem.py
# class Problem(ABC):
#     @abstractmethod
#     def __init__(self, data):
#         self.name = None
#         self.status = None
#         self.submissions_count = 0
#         self.data = data
#         self.code = None
#         self.html = None
#         self.testcases = None
#         self.contest_code = None
#         self.judge_name = None
#         self.timelimit = 3.0  # in seconds
# 
#     # used by list
#     @abstractmethod
#     def __str__(self):
#         pass
# 
# Path: termicoder/utils/logging.py

# 
# Path: termicoder/judges/codechef/utils/testcases.py
# def extract(html):
#     logger.debug("extract is being called")
#     soup = BeautifulSoup(html, "html.parser")
#     testcases = []
#     pre_tag_elements = soup.find_all('pre')
#     try:
#         io = _extract_io(pre_tag_elements)
#         logger.debug(io)
#     except BaseException:
#         logger.error("Extraction of testcase for the problem failed")
#         return []
# 
#     if(len(pre_tag_elements) >= 1):
#         for i in range(len(io[0])):
#             inp = io[0][i]
#             ans = io[1][i]
#             testcases.append(Testcase(inp=inp, ans=ans, code=i))
#             logger.debug("inp\n" + inp + "\n\n")
#             logger.debug("ans\n" + ans + "\n\n")
#         return testcases
#     else:
#         logger.error("Extraction of testcase for the problem failed")


# Path: termicoder/judges/codechef/models/Problem.py
from termicoder.models import Problem
from termicoder.utils.logging import logger
from collections import namedtuple
from ..utils.testcases import extract
from tomd import Tomd
import markdown
import os
import mdv

        if(data is not None):
            self._initialize()

    def _initialize(self):
        concerned_data = self.data['result']['data']['content']
        problem_content = namedtuple(
            "problem", concerned_data.keys())(*concerned_data.values())
        self.name = problem_content.problemName
        self.submissions_count = problem_content.successfulSubmissions
        self.code = problem_content.problemCode
        self.text = problem_content.body
        self.html = self._get_html(problem_content.body)
        self.testcases = self._extract_testcases(self.html)
        self.timelimit = float(problem_content.maxTimeLimit)
        if(self.timelimit == 0):
            self.timelimit = 3.0

    def _get_html(self, body):
        newbody = body.replace('<br>', '\n')
        newbody = newbody.replace('<br />', '\n')
        self.text = newbody
        mdProcessor = markdown.Markdown()
        myHtmlFragment = str(mdProcessor.convert(newbody))
        myHtmlFragment = myHtmlFragment.replace('<code>', '<pre>')
        myHtmlFragment = myHtmlFragment.replace('</code>', '</pre>')
        logger.debug(myHtmlFragment)
        javascript = open(
            os.path.join((os.path.dirname(__file__)), "script.js")).read()
        return ("<script>%s</script>" % javascript) + myHtmlFragment


    def _extract_testcases(self, html):