Esempio n. 1
0
    def clean(self):

        for k in ['name', 'app_sequence', 'num_demo_participants']:
            if k not in self:
                msg = f'Session config is missing "{k}"'
                raise SessionConfigError(msg)

        validate_alphanumeric(
            self['name'], identifier_description='settings.SESSION_CONFIGS name'
        )

        app_sequence = self['app_sequence']
        if len(app_sequence) != len(set(app_sequence)):
            msg = (
                'settings.SESSION_CONFIGS: '
                'app_sequence of "{}" '
                'must not contain duplicate elements. '
                'If you want multiple rounds, '
                'you should set Constants.num_rounds.'
            )
            raise SessionConfigError(msg.format(self['name']))

        if len(app_sequence) == 0:
            raise SessionConfigError(
                'settings.SESSION_CONFIGS: app_sequence cannot be empty.'
            )

        self.setdefault('display_name', self['name'])
        self.setdefault('doc', '')

        self['participation_fee'] = RealWorldCurrency(self['participation_fee'])
Esempio n. 2
0
 def get_participant_labels(self):
     labels = Path(
         self.participant_label_file).read_text(encoding='utf8').split()
     for label in labels:
         validate_alphanumeric(label,
                               identifier_description='participant label')
     # eliminate duplicates
     return list(dict.fromkeys(labels))
Esempio n. 3
0
 def get_participant_labels(self):
     lines = (Path(self.participant_label_file).read_text(
         encoding='utf8').splitlines())
     labels = []
     for line in lines:
         label = line.strip()
         if label:
             validate_alphanumeric(
                 label, identifier_description='participant label')
             labels.append(label)
     # eliminate duplicates
     return list(dict.fromkeys(labels))
Esempio n. 4
0
 def __init__(
     self,
     name,
     display_name,
 ):
     self.name = validate_alphanumeric(
         name, identifier_description='settings.ROOMS room name')
     self.display_name = display_name
Esempio n. 5
0
 def __init__(self,
              name,
              display_name,
              use_secure_urls=False,
              participant_label_file=None):
     self.name = validate_alphanumeric(
         name, identifier_description='settings.ROOMS room name')
     if use_secure_urls and not participant_label_file:
         raise ValueError(
             'Room "{}": you must either set "participant_label_file", '
             'or set "use_secure_urls": False'.format(name))
     self.participant_label_file = participant_label_file
     self.display_name = display_name
     # secure URLs are complicated, don't use them by default
     self.use_secure_urls = use_secure_urls