def test_getting_unique_users(self) -> None:
        users = [User(), User(), User()]
        users_dist = [3, 0, 20]
        code_info_list = []
        # Create code_info_list with users distribution
        for i, dist in enumerate(users_dist):
            for j in range(dist):
                code_info_list.append(CodeInfo(users[i]))
        assert len(code_info_list) == sum(users_dist)

        sg = SolutionGraph(CURRENT_TASK)
        vertex = Vertex(sg)
        for code_info in code_info_list:
            vertex.add_code_info(code_info)

        # In result set will be only two users form three because the second one has 0 code_info
        assert vertex.get_unique_users() == {users[0], users[2]}
 def test_adding_code_info(self) -> None:
     sg = SolutionGraph(CURRENT_TASK)
     vertex = Vertex(sg)
     code_info_list_len = 100
     code_info_list = [CodeInfo(User()) for _ in range(code_info_list_len)]
     for code_info in code_info_list:
         vertex.add_code_info(code_info)
     assert vertex.code_info_list == code_info_list
Example #3
0
 def create_user_trees(
         self,
         source_code: str,
         profile: Profile,
         rate: Optional[float] = None) -> Tuple[AnonTree, ast.AST]:
     code_info = CodeInfo(User(profile))
     code = Code.from_source(source_code, rate=rate, task=self._graph.task)
     anon_tree = AnonTree(code.anon_tree, code.rate,
                          self.get_file_path(f'{TREE_TYPE.ANON.value}'),
                          code_info)
     anon_tree.find_medians()
     return anon_tree, code.canon_tree
Example #4
0
def get_solution_graph(task: TASK, to_plot_graph: bool = True, test_prefix: str = 'num_diffs') -> SolutionGraph:
    sources, goals = __get_sources_and_goals(task)
    sg = SolutionGraph(task)
    code_info = CodeInfo(User())
    for goal in goals:
        goal_code = __get_code_by_source(goal, is_goal=True)
        codes = [__get_code_by_source(s) for s in sources] + [goal_code]
        chain = [(code, code_info) for code in codes]
        sg.add_code_info_chain(chain)
    if to_plot_graph:
        path = __plot_graph(task, sg, test_prefix)
        log.info(f'Graph path for solution space for task {task.value} is {path}')
    return sg
Example #5
0
import logging
from typing import List, Tuple, Callable

import pytest

from src.test.test_config import to_skip, TEST_LEVEL
from src.main.solution_space.serialized_code import Code
from src.main.util.consts import LOGGER_NAME, TEST_RESULT
from src.main.util.helper_classes.id_counter import IdCounter
from src.main.solution_space.data_classes import CodeInfo, User
from src.main.solution_space.solution_space_handler import __remove_loops


log = logging.getLogger(LOGGER_NAME)

user = User()
code_info = CodeInfo(user)

source_1 = ''
source_2 = 'a = int(input())'
source_3 = 'a = int(input())\nb = int(input())'
source_4 = 'a = int(input())\nb = int(input())\nc = int(input())'
source_5 = 'a = int(input())\nb = int(input())\nc = int(input())\nprint(a * c + " " + b * c)'

sources = [source_1, source_2, source_3, source_4, source_5]


def get_code_chain_from_sources(start_index: int = 0, end_index: int = len(sources)) -> List[Tuple[Code, CodeInfo]]:
    IdCounter.reset_all()
    return [(Code.from_source(source, TEST_RESULT.CORRECT_CODE.value), code_info)
            for source in sources[start_index: end_index]]
Example #6
0
def get_code_info_chain(sources: List[str]) -> List[Tuple[Code, CodeInfo]]:
    user = User()
    return [(Code.from_source(s,
                              TEST_RESULT.CORRECT_CODE.value), CodeInfo(user))
            for s in sources]
Example #7
0
def __get_user(solutions: pd.DataFrame) -> User:
    return User(__get_profile(solutions))