Beispiel #1
0
 def __init__(self,
              coordinate=None,
              width=None,
              height=None,
              spatial_unit_map=None):
     if spatial_unit_map is None and coordinate is None and width is None and height is None:
         raise NullArgument(
             'must provide a coordinate or a spatial_unit_map')
     if spatial_unit_map is not None:
         self._coordinate = BasicCoordinate(
             spatial_unit_map['coordinateValues'])
         self._width = spatial_unit_map['width']
         self._height = spatial_unit_map['height']
     else:
         if not isinstance(coordinate, abc_mapping_primitives.Coordinate):
             raise InvalidArgument('coordinate must be a Coordinate')
         if height is None:
             raise NullArgument('height must be provided with a coordinate')
         if width is None:
             raise NullArgument('width must be provided with a coordinate')
         if not (isinstance(height, int) or isinstance(height, float)):
             raise InvalidArgument('height must be an int or float')
         if not (isinstance(width, int) or isinstance(width, float)):
             raise InvalidArgument('width must be an int or float')
         if width <= 0 or height <= 0:
             raise InvalidArgument(
                 'width and height must be positive values')
         self._coordinate = coordinate
         self._width = width
         self._height = height
Beispiel #2
0
 def create_o3d_asset(self,
                      manip=None,
                      small_ov_set=None,
                      large_ov_set=None,
                      display_name='',
                      description=''):
     """stub"""
     if manip and not isinstance(manip, ABCDataInputStream):
         raise InvalidArgument('Manipulatable object must be an ' +
                               'osid.transport.DataInputStream object')
     if small_ov_set and not isinstance(small_ov_set, ABCDataInputStream):
         raise InvalidArgument('Small OV Set object must be an ' +
                               'osid.transport.DataInputStream object')
     if large_ov_set and not isinstance(large_ov_set, ABCDataInputStream):
         raise InvalidArgument('Large OV Set object must be an ' +
                               'osid.transport.DataInputStream object')
     asset_id, asset_content_id = self.create_asset(asset_type=O3D_ASSET_TYPE,
                                                    display_name=display_name,
                                                    description=description)
     if manip is not None:
         self.add_content_to_asset(asset_id=asset_id,
                                   asset_data=manip,
                                   asset_content_type=MANIP_ASSET_CONTENT_TYPE,
                                   asset_label='3d manipulatable')
     if small_ov_set is not None:
         self.add_content_to_asset(asset_id=asset_id,
                                   asset_data=small_ov_set,
                                   asset_content_type=OV_SET_SMALL_ASSET_CONTENT_TYPE,
                                   asset_label='small orthoviewset')
     if large_ov_set is not None:
         self.add_content_to_asset(asset_id=asset_id,
                                   asset_data=large_ov_set,
                                   asset_content_type=OV_SET_LARGE_ASSET_CONTENT_TYPE,
                                   asset_label='large orthoviewset')
     return asset_id
Beispiel #3
0
 def get_spatial_unit(self, spatial_unit_map):
     record_type = Type(idstr=spatial_unit_map['recordTypes'][0])
     if (record_type.get_authority() != 'ODL.MIT.EDU'
             or record_type.get_identifier_namespace() !=
             'osid.mapping.SpatialUnit'):
         raise InvalidArgument()
     if record_type.get_identifier() == 'rectangle':
         return RectangularSpatialUnit(spatial_unit_map=spatial_unit_map)
     raise InvalidArgument()
Beispiel #4
0
 def set_difficulty(self, difficulty):
     """stub"""
     if not is_string(difficulty):
         raise InvalidArgument('difficulty value must be a string')
     if difficulty.lower() not in ['low', 'medium', 'hard']:
         raise InvalidArgument(
             'difficulty value must be low, medium, or hard')
     self.my_osid_object_form._my_map['texts']['difficulty'][
         'text'] = difficulty
Beispiel #5
0
 def set_max_attempts(self, value):
     """stub"""
     if value is None:
         raise InvalidArgument('value must be an integer')
     if value is not None and not isinstance(value, int):
         raise InvalidArgument('value is not an integer')
     if not self.my_osid_object_form._is_valid_integer(value,
                                                       self.get_max_attempts_metadata()):
         raise InvalidArgument('value must be an integer')
     self.my_osid_object_form._my_map['maxAttempts'] = value
Beispiel #6
0
 def set_max_string_length(self, length=None):
     """stub"""
     if self.get_max_string_length_metadata().is_read_only():
         raise NoAccess()
     if length is not None and not self.my_osid_object_form._is_valid_cardinal(
             length,
             self.get_max_string_length_metadata()):
         raise InvalidArgument()
     if self._min_string_length is not None and length < self._min_string_length + 1:
         raise InvalidArgument()
     self.my_osid_object_form._my_map['maxStringLength'] = length
     self._max_string_length = length
Beispiel #7
0
 def set_ovs_view(self, asset_data, view_name):
     """
     view_name should be frontView, sideView, or topView
     """
     if not isinstance(asset_data, DataInputStream):
         raise InvalidArgument('view file must be an ' +
                               'osid.transport.DataInputStream object')
     if view_name not in ['frontView', 'sideView', 'topView']:
         raise InvalidArgument('View name must be frontView, sideView, or topView.')
     self.clear_file(view_name)
     self.add_file(asset_data,
                   label=view_name,
                   asset_type=OV_ASSET_TYPE,
                   asset_content_type=OV_ASSET_CONTENT_TYPE)
Beispiel #8
0
 def __init__(self, components=None):
     if components is None:
         self._components = []
     elif isinstance(components, list):
         self._components = components
     else:
         raise InvalidArgument()
Beispiel #9
0
 def set_item_bank_id(self, bank_id):
     """the assessment bank in which to search for items, such as related to an objective"""
     if self.get_item_bank_id_metadata().is_read_only():
         raise NoAccess()
     if not self.my_osid_object_form._is_valid_id(bank_id):
         raise InvalidArgument()
     self.my_osid_object_form._my_map['itemBankId'] = str(bank_id)
Beispiel #10
0
 def set_manip_id(self, o3d_asset_id):
     """stub"""
     if not isinstance(o3d_asset_id, ABCId):
         raise InvalidArgument('Argument must be a valid Id')
     self.add_asset(o3d_asset_id,
                    label='manip',
                    asset_content_type=MANIP_ASSET_CONTENT_TYPE)
Beispiel #11
0
 def _float_list(self, value_list, dimensions=None):
     if not isinstance(value_list, list):
         raise InvalidArgument(
             'arguments must be list of floating point or integer values')
     if dimensions is not None and len(value_list) != dimensions:
         raise InvalidArgument(
             'dimensions of uncertainty must match dimensions of values')
     return_list = list()
     for value in value_list:
         if isinstance(value, float) or isinstance(value, int):
             return_list.append(float(value))
         else:
             raise InvalidArgument(
                 'arguments must be list of floating point or integer values'
             )
     return return_list
Beispiel #12
0
    def edit_choice(self, new_choice, choice_id, inline_region):
        """edit an existing choice, to keep the ID the same"""
        if inline_region not in self.my_osid_object_form._my_map['choices']:
            raise IllegalState('that inline region does not exist')
        if not isinstance(new_choice, DisplayText):
            raise InvalidArgument('new choice is not a DisplayText object')
        choices = [c for c in self.my_osid_object_form._my_map['choices'][inline_region] if c['id'] == choice_id]
        if len(choices) == 0:
            raise InvalidArgument('invalid choice_id for that region')

        for current_choice in self.my_osid_object_form._my_map['choices'][inline_region]:
            if choice_id == current_choice['id']:
                index = self.get_index_of_language_type('texts',
                                                        new_choice.language_type,
                                                        dictionary=current_choice)

                current_choice['texts'][index] = self._dict_display_text(new_choice)
Beispiel #13
0
 def set_waypoint_quota(self, waypoint_quota):
     """how many waypoint questions need to be answered correctly"""
     if self.get_waypoint_quota_metadata().is_read_only():
         raise NoAccess()
     if not self.my_osid_object_form._is_valid_cardinal(
             waypoint_quota, self.get_waypoint_quota_metadata()):
         raise InvalidArgument()
     self.my_osid_object_form._my_map['waypointQuota'] = waypoint_quota
Beispiel #14
0
 def set_allow_repeat_items(self, allow_repeat_items):
     """determines if repeat items will be shown, or if the scaffold iteration will simply stop"""
     if self.get_allow_repeat_items_metadata().is_read_only():
         raise NoAccess()
     if not self.my_osid_object_form._is_valid_boolean(allow_repeat_items):
         raise InvalidArgument()
     self.my_osid_object_form._my_map[
         'allowRepeatItems'] = allow_repeat_items
Beispiel #15
0
 def edit_feedback(self, new_feedback):
     if self.get_feedbacks_metadata().is_read_only():
         raise NoAccess()
     if not isinstance(new_feedback, DisplayText):
         raise InvalidArgument('new feedback is not a DisplayText object')
     index = self.get_index_of_language_type('feedbacks',
                                             new_feedback.language_type)
     self.my_osid_object_form._my_map['feedbacks'][
         index] = self._dict_display_text(new_feedback)
Beispiel #16
0
 def set_first_angle_projection(self, value=None):
     """stub"""
     if value is None:
         raise NullArgument()
     if self.get_first_angle_projection_metadata().is_read_only():
         raise NoAccess()
     if not self.my_osid_object_form._is_valid_boolean(value):
         raise InvalidArgument()
     self.my_osid_object_form._my_map['firstAngle'] = value
Beispiel #17
0
 def set_manip(self, manipulatable):
     """stub"""
     if not isinstance(manipulatable, DataInputStream):
         raise InvalidArgument('Manipulatable object be an ' +
                               'osid.transport.DataInputStream object')
     self.add_file(manipulatable,
                   label='manip',
                   asset_type=MANIP_ASSET_TYPE,
                   asset_content_type=MANIP_ASSET_CONTENT_TYPE)
Beispiel #18
0
 def set_max_waypoint_items(self, max_waypoint_items):
     """This determines how many waypoint items will be seen for a scaffolded wrong answer"""
     if self.get_max_waypoint_items_metadata().is_read_only():
         raise NoAccess()
     if not self.my_osid_object_form._is_valid_cardinal(
             max_waypoint_items, self.get_max_waypoint_items_metadata()):
         raise InvalidArgument()
     self.my_osid_object_form._my_map[
         'maxWaypointItems'] = max_waypoint_items
Beispiel #19
0
 def set_published(self, value=None):
     """stub"""
     if value is None:
         raise NullArgument()
     if self.get_published_metadata().is_read_only():
         raise NoAccess()
     if not self.my_osid_object_form._is_valid_boolean(value):
         raise InvalidArgument()
     self.my_osid_object_form._my_map['published'] = value
Beispiel #20
0
 def set_end_timestamp(self, end_timestamp=None):
     """stub"""
     if end_timestamp is None:
         raise NullArgument()
     if self.get_end_timestamp_metadata().is_read_only():
         raise NoAccess()
     if not self.my_osid_object_form._is_valid_integer(
             end_timestamp,
             self.get_end_timestamp_metadata()):
         raise InvalidArgument()
     self.my_osid_object_form._my_map['endTimestamp'] = end_timestamp
Beispiel #21
0
 def add_choice(self, text, name='', identifier=None):
     """stub"""
     if not utilities.is_string(text):
         raise InvalidArgument('text is not a string')
     choice_display_text = self._choice_text_metadata[
         'default_string_values'][0]
     choice_display_text['text'] = text
     if identifier is None:
         identifier = str(ObjectId())
     choice = {'id': identifier, 'text': text, 'name': name}
     self.my_osid_object_form._my_map['choices'].append(choice)
     return choice
Beispiel #22
0
    def edit_choice(self, new_choice, choice_id):
        if self.get_choices_metadata().is_read_only():
            raise NoAccess()
        if not isinstance(new_choice, DisplayText):
            raise InvalidArgument('new choice is not a DisplayText object')
        choices = [
            c for c in self.my_osid_object_form._my_map['choices']
            if c['id'] == choice_id
        ]
        if len(choices) == 0:
            raise InvalidArgument('invalid choice_id')

        for current_choice in self.my_osid_object_form._my_map['choices']:
            if choice_id == current_choice['id']:
                index = self.get_index_of_language_type(
                    'texts',
                    new_choice.language_type,
                    dictionary=current_choice)

                current_choice['texts'][index] = self._dict_display_text(
                    new_choice)
Beispiel #23
0
 def set_solution(self, text):
     """stub"""
     if not self.my_osid_object_form._is_valid_string(
             text, self.get_solution_metadata()):
         raise InvalidArgument('text')
     if is_string(text):
         self.my_osid_object_form._my_map['solution'] = {
             'text': text,
             'languageTypeId': str(DEFAULT_LANGUAGE_TYPE),
             'scriptTypeId': str(DEFAULT_SCRIPT_TYPE),
             'formatTypeId': str(DEFAULT_FORMAT_TYPE)
         }
     else:
         self.my_osid_object_form._my_map['solution'] = text
Beispiel #24
0
 def __init__(self,
              hexstr=None,
              values=None,
              uncertainty_minus=None,
              uncertainty_plus=None):
     if values is not None:
         if not isinstance(values, list) or len(values) != 3:
             raise InvalidArgument()
         self._values = values
     elif hexstr is not None:
         if not is_string(hexstr) or len(hexstr) != 6:
             raise InvalidArgument()
         try:
             self._values = [
                 int(hexstr[:-4], 16),
                 int(hexstr[2:-2], 16),
                 int(hexstr[4:], 16)
             ]
         except:
             raise InvalidArgument(hexstr)
     else:
         raise NullArgument()
     self._uncertainty_minus = uncertainty_minus
     self._uncertainty_plus = uncertainty_plus
Beispiel #25
0
    def set_item_ids(self, item_ids):
        '''the target Item

        This can only be set if there is no learning objective set

        '''
        if self.get_item_ids_metadata().is_read_only():
            raise NoAccess()
        for item_id in item_ids:
            if not self.my_osid_object_form._is_valid_id(item_id):
                raise InvalidArgument()
        if self.my_osid_object_form._my_map['learningObjectiveIds'][0]:
            raise IllegalState()
        self.my_osid_object_form._my_map['itemIds'] = [
            str(i) for i in item_ids
        ]
Beispiel #26
0
    def remove_choice_language(self, language_type, choice_id, inline_region):
        """stub"""
        if len(self.my_osid_object_form._my_map['choices'][inline_region]) == 0:
            raise IllegalState('there are currently no choices defined for this region')
        if self.get_choices_metadata().is_read_only():
            raise NoAccess()

        choices = [c for c in self.my_osid_object_form._my_map['choices'][inline_region] if c['id'] == choice_id]
        if len(choices) == 0:
            raise InvalidArgument('invalid choice_id')

        for current_choice in self.my_osid_object_form._my_map['choices'][inline_region]:
            if choice_id == current_choice['id']:
                self.remove_field_by_language('texts',
                                              language_type,
                                              current_choice)
Beispiel #27
0
    def remove_choice_language(self, language_type, choice_id):
        if self.get_choices_metadata().is_read_only():
            raise NoAccess()

        choices = [
            c for c in self.my_osid_object_form._my_map['choices']
            if c['id'] == choice_id
        ]
        if len(choices) == 0:
            raise InvalidArgument('invalid choice_id')

        for current_choice in self.my_osid_object_form._my_map['choices']:
            if choice_id == current_choice['id']:
                self.remove_field_by_language('texts',
                                              language_type,
                                              dictionary=current_choice)
Beispiel #28
0
    def set_learning_objective_ids(self, learning_objective_ids):
        """the learning objective to find related items for

        This can only be set if there are no items specifically set

        """
        if self.get_learning_objective_ids_metadata().is_read_only():
            raise NoAccess()
        for learning_objective_id in learning_objective_ids:
            if not self.my_osid_object_form._is_valid_id(
                    learning_objective_id):
                raise InvalidArgument()
        if self.my_osid_object_form._my_map['itemIds'][0]:
            raise IllegalState()
        self.my_osid_object_form._my_map['learningObjectiveIds'] = [
            str(lo) for lo in learning_objective_ids
        ]
Beispiel #29
0
 def set_ortho_view_set(self, front_view, side_view, top_view):
     """stub"""
     if (not isinstance(front_view, DataInputStream) or
             not isinstance(top_view, DataInputStream) or
             not isinstance(side_view, DataInputStream)):
         raise InvalidArgument('views must be osid.transport.DataInputStream objects')
     self.add_file(front_view,
                   label='frontView',
                   asset_type=OV_ASSET_TYPE,
                   asset_content_type=OV_ASSET_CONTENT_TYPE)
     self.add_file(side_view,
                   label='sideView',
                   asset_type=OV_ASSET_TYPE,
                   asset_content_type=OV_ASSET_CONTENT_TYPE)
     self.add_file(top_view,
                   label='topView',
                   asset_type=OV_ASSET_TYPE,
                   asset_content_type=OV_ASSET_CONTENT_TYPE)
Beispiel #30
0
 def __init__(self,
              display_text_map=None,
              text=None,
              language_type=None,
              script_type=None,
              format_type=None):
     if display_text_map is not None:
         if not isinstance(display_text_map, dict):
             raise InvalidArgument('display_text_map must be a dict')
         self._unfold_map(display_text_map)
     elif (text is not None and language_type is not None
           and script_type is not None and format_type is not None):
         self._text = text
         self._language_type = language_type
         self._script_type = script_type
         self._format_type = format_type
     else:
         raise NullArgument()