File size: 1,175 Bytes
81a794d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# DEBUG ONLY
import time
import random
from tqdm import tqdm

from backend.section_infer_helper.base_helper import BaseHelper
from backend.utils.data_process import split_to_file_diff, split_to_section

class RandomHelper(BaseHelper):
    
    PREDEF_MODEL = ["Random"]
    
    MODELS_SUPPORTED_LANGUAGES = {
        "Random": ["C", "C++", "Java", "Python"]
    }
    
    
    def load_model(self, model_name):
        pass
    
    
    def infer(self, diff_code):
        file_diff_list = split_to_file_diff(diff_code, BaseHelper._get_lang_ext(self.MODELS_SUPPORTED_LANGUAGES["Random"]))
        results = {}
        for file_a, _, file_diff in tqdm(file_diff_list, desc="Inferencing", unit="file", total=len(file_diff_list)):
            time.sleep(0.1)
            sections = split_to_section(file_diff)
            file = file_a.removeprefix("a/")
            results[file] = []
            for section in sections:
                results[file].append({
                    "section": section,
                    "predict": random.choice([0, 1]),
                    "conf": random.random()
                })
        return results


random_helper = RandomHelper()