<commit_before>from sris import db, models
from messenger import Messenger
from service import SMSService


class Manager:
    """
    The middle-man of interaction between messenger and the SMS service.
    """
    def __init__(self):
        self.config = self.__load_config_file()
        self.messenger = Messenger(self.config)
        self.sms_service = SMSService()

    def send_initial_sms(self):
        """
        Sends an 'initial' SMS to new patients of the client.
        """
        # New patients are those that have recently been added
        # to the clients database, which the service does not know.
        for number in self.__new_patients():
            message = self.messenger.initial_message()
            self.sms_service.send(number, message)
            self.__create_new_patient(number)
            self.__save_message(number, message, 'sent')

    def respond(self, patient_response):
        """
        Respond to new SMS when it is received.

        Args:
            patient_message (dict): Contains the number, and message sent to
            the service by a patient.
        """
        number = patient_response['number']
        patient_message = patient_response['message']
        # Generate a response based on the sentiment of the patient's message.
        message = self.messenger.respond(number, patient_message)
        self.__save_message(number, patient_message, 'received')
        self.__save_message(number, message, 'sent')<commit_msg>Make it more obvious that patients need to be created.<commit_after>from sris import db, models
from messenger import Messenger
from service import SMSService


class Manager:
    """
    The middle-man of interaction between messenger and the SMS service.
    """
    def __init__(self):
        self.config = self.__load_config_file()
        self.messenger = Messenger(self.config)
        self.sms_service = SMSService()

    def send_initial_sms(self):
        """
        Sends an 'initial' SMS to new patients of the client.

        Note: this is REQUIRED otherwise 'respond' & other services do not
        function as database errors are thrown (understandably).
        """
        # New patients are those that have recently been added
        # to the clients database, which the service does not know.
        for number in self.__new_patients():
            message = self.messenger.initial_message()
            self.sms_service.send(number, message)
            self.__create_new_patient(number)
            self.__save_message(number, message, 'sent')

    def respond(self, patient_response):
        """
        Respond to new SMS when it is received.

        Args:
            patient_message (dict): Contains the number, and message sent to
            the service by a patient.
        """
        number = patient_response['number']
        patient_message = patient_response['message']
        # Generate a response based on the sentiment of the patient's message.
        message = self.messenger.respond(number, patient_message)
        self.__save_message(number, patient_message, 'received')
        self.__save_message(number, message, 'sent')
{'fraction_non_alphanumeric': 0.07833228048010107, 'fraction_numerical': 0.0, 'mean_word_length': 2.5947786606129397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5126353', 'n_tokens_mistral': 823, 'n_tokens_neox': 779, 'n_words': 277}