Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Nov 11, 2023
1 parent a0c9f4b commit 29dd4a2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
18 changes: 8 additions & 10 deletions app/service/analyzer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,31 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from app.utils import utils
from app.commons.log_preparation import LogPreparation
from app.commons.log_merger import LogMerger
from app.boosting_decision_making import weighted_similarity_calculator
from app.commons import namespace_finder
import logging
import re

from app.boosting_decision_making import weighted_similarity_calculator
from app.commons.log_merger import LogMerger
from app.commons.log_preparation import LogPreparation
from app.utils import utils

logger = logging.getLogger("analyzerApp.analyzerService")


class AnalyzerService:

def __init__(self, model_chooser, app_config=None, search_cfg=None):
self.app_config = app_config or {}
def __init__(self, model_chooser, search_cfg=None):
self.search_cfg = search_cfg or {}
self.log_preparation = LogPreparation()
self.log_merger = LogMerger()
self.namespace_finder = namespace_finder.NamespaceFinder(app_config)
self.model_chooser = model_chooser
self.weighted_log_similarity_calculator = None
if self.search_cfg["SimilarityWeightsFolder"].strip():
self.weighted_log_similarity_calculator = weighted_similarity_calculator.\
self.weighted_log_similarity_calculator = weighted_similarity_calculator. \
WeightedSimilarityCalculator(folder=self.search_cfg["SimilarityWeightsFolder"])

def find_min_should_match_threshold(self, analyzer_config):
return analyzer_config.minShouldMatch if analyzer_config.minShouldMatch > 0 else\
return analyzer_config.minShouldMatch if analyzer_config.minShouldMatch > 0 else \
int(re.search(r"\d+", self.search_cfg["MinShouldMatch"]).group(0))

def add_constraints_for_launches_into_query(self, query, launch):
Expand Down
5 changes: 4 additions & 1 deletion app/service/auto_analyzer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from app.service.analyzer_service import AnalyzerService
from app.amqp.amqp import AmqpClient
from app.commons.similarity_calculator import SimilarityCalculator
from app.commons.namespace_finder import NamespaceFinder
import json
import logging
from time import time, sleep
Expand All @@ -33,12 +34,14 @@
class AutoAnalyzerService(AnalyzerService):

es_client: EsClient
namespace_finder: NamespaceFinder

def __init__(self, model_chooser, app_config=None, search_cfg=None, es_client: EsClient = None):
self.app_config = app_config or {}
self.search_cfg = search_cfg or {}
super().__init__(model_chooser, app_config=self.app_config, search_cfg=self.search_cfg)
super().__init__(model_chooser, search_cfg=self.search_cfg)
self.es_client = es_client or EsClient(app_config=self.app_config, search_cfg=self.search_cfg)
self.namespace_finder = NamespaceFinder(app_config)

def get_config_for_boosting(self, analyzer_config):
min_should_match = self.find_min_should_match_threshold(analyzer_config) / 100
Expand Down
5 changes: 4 additions & 1 deletion app/service/suggest_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from app.commons import similarity_calculator
from app.commons.esclient import EsClient
from app.commons.launch_objects import SuggestAnalysisResult
from app.commons.namespace_finder import NamespaceFinder
from app.service.analyzer_service import AnalyzerService
from app.utils import utils, text_processing

Expand All @@ -41,15 +42,17 @@ class SuggestService(AnalyzerService):
"""The service serves suggestion lists in Make Decision modal."""

es_client: EsClient
namespace_finder: NamespaceFinder

def __init__(self, model_chooser, app_config=None, search_cfg=None, es_client: EsClient = None):
self.app_config = app_config or {}
self.search_cfg = search_cfg or {}
super().__init__(model_chooser, app_config=self.app_config, search_cfg=self.search_cfg)
super().__init__(model_chooser, search_cfg=self.search_cfg)
self.es_client = es_client or EsClient(app_config=self.app_config, search_cfg=self.search_cfg)
self.suggest_threshold = 0.4
self.rp_suggest_index_template = "rp_suggestions_info"
self.rp_suggest_metrics_index_template = "rp_suggestions_info_metrics"
self.namespace_finder = NamespaceFinder(app_config)

def get_config_for_boosting_suggests(self, analyzerConfig):
return {
Expand Down

0 comments on commit 29dd4a2

Please sign in to comment.