コード例 #1
0
ファイル: defs.py プロジェクト: alexdrozdov/asrdbs
 def apply_on(self, rtme, other_rtme):
     rtme_form = rtme.get_form()
     other_form = other_rtme.get_form()
     res = parser.matcher.match(other_form, rtme_form)
     if res:
         rtme.add_link(
             [
                 ns(master=other_rtme, slave=rtme, details=res.to_dict()),
                 ns(master=other_rtme, slave=rtme, details=self.to_dict()),
             ]
         )
     return RtRule.res_matched if res else RtRule.res_failed
コード例 #2
0
ファイル: sentparser.py プロジェクト: alexdrozdov/asrdbs
 def __create_word_entry(self, word, position):
     res = []
     word = word.lower()
     info = self.__wdb.get_word_info(word)
     assert isinstance(info, list), u"No info avaible for {0}".format(word)
     for form in filter(
         lambda form: self.__validate_info(form),
         reduce(
             lambda x, y: x + y,
             map(
                 lambda i: i['form'],
                 info
             )
         )
     ):
         res.append(
             WordForm(
                 ns(
                     word=form['word'],
                     original_word=word,
                     info=eval(form['info']),
                     pos=position,
                     uniq=self.__form_uniq
                 )
             )
         )
         self.__form_uniq = str(uuid.uuid1())
     wf = WordForms(word, res, self.__group_uniq)
     self.__group_uniq = str(uuid.uuid1())
     return wf
コード例 #3
0
ファイル: defs.py プロジェクト: alexdrozdov/asrdbs
 def apply_on(self, rtme, aggregator_rtme):
     aggregator_rtme.attach_referer(rtme)
     rtme.add_link(
         [
             ns(master=aggregator_rtme, slave=rtme, details=self.to_dict()),
         ]
     )
     return RtRule.res_matched
コード例 #4
0
    def register_custom_commands(self) -> None:
        def update_max_lenght(lenght: Union[int, str]) -> None:
            if isinstance(lenght, str):
                lenght = len(lenght)
            if lenght > self._max_lenght:
                self._max_lenght = lenght

        tp_commands = []
        for raw in self.get_visible_commands():
            recmd = self._category_pattern.search(raw)
            cmd_func = self.cmd_func(raw)
            if recmd is not None:
                data = ns(**recmd.groupdict())
                key = data.category
                subcategory = data.subcategory
                if subcategory:
                    self.total.submodules.add(subcategory)
                    subcategory = self.module_delimeter.join(
                        subcategory.split("__"))
                    key += (self.module_delimeter + subcategory)
                if not self.modules.get(key):
                    self.modules[key] = []
                if key.lower().startswith("auxilary"):
                    self.total.auxilaries.add(raw)
                res_data = (data.command, raw)
                location_to = self.modules[key]
                if res_data not in location_to:
                    update_max_lenght(res_data[0])
                    location_to.append(res_data)
                    self.total.commands += 1
            elif not recmd and raw not in self.hidden_commands:
                alias = raw
                update_max_lenght(raw)
                if not hasattr(cmd_func, constants.USE_FOR):
                    self.g_commands.append(alias)
                self.total.commands += 1
            if hasattr(cmd_func, constants.USE_FOR):
                for module in cmd_func._USE_FOR:
                    module = self.module_delimeter.join(module)
                    if not self.modules.get(module):
                        self.modules[module] = []
                    self.modules[module].insert(
                        0, (raw if not recmd else data.command, raw))
            if hasattr(cmd_func, constants.ALIASES):
                alias = cmd_func._ALIASES
                update_max_lenght(alias)
                self._alias_commands[raw if not recmd else data.
                                     command] = alias

        self._max_lenght += 4
        self.total.modules = len(
            set(i.split(self.module_delimeter)[0] for i in self.modules))
        self.total.submodules = len(self.total.submodules)
        self.total.auxilaries = len(self.total.auxilaries)
        self._revalias_commands = dict(
            [v, k] for k, v in self._alias_commands.items())
コード例 #5
0
ファイル: send_messages.py プロジェクト: czue/mwachx
def appointment_reminders(date, hour, email_body, options, send=False):

    email_body.append("***** Appointment Reminders *****\n")
    # Find visits scheduled within delta_days and not attended early
    scheduled_date = date + datetime.timedelta(days=2)
    upcoming_visits = cont.Visit.objects.pending(scheduled=scheduled_date)\
        .to_send().select_related('participant')

    vals = ns(sent_to={},
              no_messages=[],
              control=0,
              duplicates=0,
              not_active=0,
              times={
                  8: 0,
                  13: 0,
                  20: 0
              },
              errors=[],
              exclude=[])

    for visit in upcoming_visits:
        if visit.participant.study_group == 'control':
            vals.control += 1
        elif visit.participant.id in vals.sent_to:
            vals.duplicates += 1
        elif not visit.participant.is_active:
            vals.not_active += 1
        else:
            vals.times[visit.participant.send_time] += 1
            if visit.participant.study_id in options.get('exclude', []):
                vals.exclude.append('{} (#{})'.format(
                    visit.participant.description(today=date),
                    visit.participant.study_id))
            elif hour == 0 or visit.participant.send_time == hour:
                try:
                    message = visit.send_visit_reminder(send=send)
                except requests.HTTPError as e:
                    vals.errors.append('{} (#{})'.format(
                        visit.participant.description(today=date),
                        visit.participant.study_id))
                else:
                    if message is None:
                        condition = visit.get_condition('pre')
                        vals.no_messages.append('{}-{}'.format(
                            visit.participant.description(), condition))
                    else:
                        vals.sent_to[visit.participant.id] = "{} (#{})".format(
                            message.description(), visit.participant.study_id)

    email_body.append(
        'Total: {0} Control: {1.control} Duplicate: {1.duplicates} Not-Active: {1.not_active}'
        .format(upcoming_visits.count(), vals))

    append_errors(email_body, vals)
コード例 #6
0
def regularly_scheduled_messages(participants,
                                 hour,
                                 date,
                                 email_body,
                                 options,
                                 send=False):
    """ Send regularly scheduled messages to participants based on day of week and time of day
        :day(int): day of week to select participants for
        :hour(int): hour of day (0 for all)
        :email_body(array): array of strings for email body
    """

    # counter variables for email output
    vals = ns(times={
        8: 0,
        13: 0,
        20: 0
    },
              control=0,
              no_messages=[],
              sent_to=[],
              errors=[],
              exclude=[])

    for p in participants:
        if p.study_group == 'control':
            # Don't do anything with controls
            vals.control += 1
        else:
            vals.times[p.send_time] += 1
            if p.study_id in options.get('exclude', []):
                vals.exclude.append('{} (#{})'.format(
                    p.description(today=date), p.study_id))
            elif hour == 0 or hour == p.send_time:
                try:
                    message = p.send_automated_message(today=date, send=send)
                except HTTPError as e:
                    vals.errors.append('{} (#{})'.format(
                        p.description(today=date), p.study_id))
                else:
                    if message is None:
                        vals.no_messages.append('{} (#{})'.format(
                            p.description(today=date), p.study_id))
                    else:
                        vals.sent_to.append("{} (#{}) {}".format(
                            message.description(), p.study_id, p.send_time))

    email_body.append(
        "Total: {0}   8h: {1.times[8]} 13h: {1.times[13]} 20h: {1.times[20]}".
        format(participants.count(), vals))

    append_errors(email_body, vals, options['verbosity'])
コード例 #7
0
ファイル: send_messages.py プロジェクト: czue/mwachx
def missed_visit_reminders(hour, email_body, options, send=False):

    email_body.append("***** Missed Visit Reminders *****\n")
    missed_visits = cont.Visit.objects.get_missed_visits().to_send()

    vals = ns(sent_to=[],
              no_messages=[],
              control=0,
              not_active=0,
              times={
                  8: 0,
                  13: 0,
                  20: 0
              },
              exclude=[],
              errors=[])

    for visit in missed_visits:
        if visit.participant.study_group == 'control':
            vals.control += 1
        elif not visit.participant.is_active:
            vals.not_active += 1
        elif visit.participant.study_id in options.get('exclude', []):
            vals.exclude.append('{} (#{})'.format(
                visit.participant.description(today=date),
                visit.participant.study_id))
        else:
            vals.times[visit.participant.send_time] += 1
            if hour == 0 or visit.participant.send_time == hour:
                try:
                    message = visit.send_missed_visit_reminder(send=send)
                except requests.HTTPError as e:
                    vals.errors.append('{} (#{})'.format(
                        visit.participant.description(today=date),
                        visit.participant.study_id))
                else:
                    if message is None:
                        condition = visit.get_condition('missed')
                        vals.no_messages.append('{}-{}'.format(
                            visit.participant.description(), condition))
                    else:
                        vals.sent_to.append("{} (#{})".format(
                            message.description(), visit.participant.study_id))

    email_body.append(
        'Total: {0} Control: {1.control} Not-Active: {1.not_active}'.format(
            missed_visits.count(), vals, len(vals.sent_to)))
    append_errors(email_body, vals)
コード例 #8
0
ファイル: send_messages.py プロジェクト: czue/mwachx
def weekly_messages(day, hour, date, email_body, options, send=False):
    ''' Send weeky messages to participants based on day of week and time of day
        :param day(int): day of week to select participants for
        :param hour(int): hour of day (0 for all)
        :email_body(array): array of strings for email body
    '''

    email_body.append("***** Weekly Messages ******\n")

    participants = cont.Contact.objects.active_users().filter(send_day=day)

    vals = ns(times={
        8: 0,
        13: 0,
        20: 0
    },
              control=0,
              no_messages=[],
              sent_to=[],
              errors=[],
              exclude=[])

    for p in participants:
        if p.study_group == 'control':
            vals.control += 1
        else:
            vals.times[p.send_time] += 1
            if p.study_id in options.get('exclude', []):
                vals.exclude.append('{} (#{})'.format(
                    p.description(today=date), p.study_id))
            elif hour == 0 or hour == p.send_time:
                try:
                    message = p.send_automated_message(today=date, send=send)
                except HTTPError as e:
                    vals.errors.append('{} (#{})'.format(
                        p.description(today=date), p.study_id))
                else:
                    if message is None:
                        vals.no_messages.append('{} (#{})'.format(
                            p.description(today=date), p.study_id))
                    else:
                        vals.sent_to.append("{} (#{}) {}".format(
                            message.description(), p.study_id, p.send_time))

    email_body.append("Total: {0} Control: {1}".format(participants.count(),
                                                       vals.control))

    append_errors(email_body, vals)
コード例 #9
0
ファイル: preprocessor.py プロジェクト: alexdrozdov/asrdbs
 def preprocess(self, spec):
     ctx = PreprocessorContext(spec.get_name())
     self.__validate_spec(ctx, spec.get_spec())
     return ns(
         dependencies=list(ctx.get_dependencies())
     )