-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
71 lines (56 loc) · 2.78 KB
/
bot.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import random
from dataclasses import dataclass
from tulipService import Bot
from tulipService.model.variableModel import VariableModel
@dataclass
class BotInputSchema:
companycode: VariableModel = None
companyCodeSampleCount: VariableModel = None
manualEntitiesCompanyCode: VariableModel = None
@dataclass
class BotOutputSchema:
def __init__(self):
self.manualEntitiesCompanyCodeList = VariableModel()
self.nonManualEntitiesCompanyCodeList = VariableModel()
self.manualFlag = VariableModel()
self.nonManualFlag = VariableModel()
class BotLogic(Bot):
def __init__(self) -> None:
super().__init__()
try:
self.outputs = BotOutputSchema()
self.input = self.bot_input.get_proposedBotInputs(BotInputs=BotInputSchema)
self.company_codes = self.input.companycode.value
self.company_code_sample_count = int(self.input.companyCodeSampleCount.value)
self.manual_entities_company_code = self.input.manualEntitiesCompanyCode.value
except Exception as error:
self.log.error(f"Error initializing BotLogic: {error}")
raise error
def main(self):
"""Bot Logic code"""
try:
self.log.info("Randomly select a specified number of company codes")
# Step 1: Randomly select a specified number of company codes
selected_company_codes = random.sample(self.company_codes, self.company_code_sample_count)
# Step 2: Validate the selected company codes against the list of manual entity company codes
self.log.info("Validate the selected company codes against the list of manual entity company codes")
manual_entities_list = []
non_manual_entities_list = []
for code in selected_company_codes:
if code in self.manual_entities_company_code:
manual_entities_list.append(code)
else:
non_manual_entities_list.append(code)
self.log.info("manual and non-manual entities list created")
self.outputs.manualEntitiesCompanyCodeList.value = manual_entities_list
self.outputs.nonManualEntitiesCompanyCodeList.value = non_manual_entities_list
manual_flag = bool(manual_entities_list)
non_manual_flag = bool(non_manual_entities_list)
self.outputs.manualFlag.value = manual_flag
self.outputs.nonManualFlag.value = non_manual_flag
self.bot_output.success("SUCCESS")
except Exception as e:
self.log.error(f"Error in main execution: {e}")
self.bot_output.error(e)
finally:
self.log.info("Bot execution completed.")