def do_insert(self, **kwargs): """ Add a record to the RAMSTKRequirement table. :return: (_error_code, _msg); the error code and associated message. :rtype: (int, str) """ _requirement = RAMSTKRequirement() _requirement.revision_id = kwargs['revision_id'] _requirement.parent_id = kwargs['parent_id'] _error_code, _msg = RAMSTKDataModel.do_insert(self, entities=[ _requirement, ]) if _error_code == 0: self.tree.create_node(_requirement.requirement_code, _requirement.requirement_id, parent=_requirement.parent_id, data=_requirement) # pylint: disable=attribute-defined-outside-init # It is defined in RAMSTKDataModel.__init__ self.last_id = _requirement.requirement_id return _error_code, _msg
def do_insert(self, **kwargs): """ Add a record to the RAMSTKSimilarItem table. :return: (_error_code, _msg); the error code and associated message. :rtype: (int, str) """ _similar_item = RAMSTKSimilarItem() _similar_item.revision_id = kwargs['revision_id'] _similar_item.hardware_id = kwargs['hardware_id'] _similar_item.parent_id = kwargs['parent_id'] _error_code, _msg = RAMSTKDataModel.do_insert(self, entities=[ _similar_item, ]) self.tree.create_node('SimilarItem ID: {0:d}'.format( _similar_item.hardware_id), _similar_item.hardware_id, parent=_similar_item.parent_id, data=_similar_item) self.last_id = max(self.last_id, _similar_item.hardware_id) return _error_code, _msg
def do_insert(self, **kwargs): """ Add a record to the RAMSTKStakeholder table. :param int revision_id: the Revision ID to add the Failure Definition against. :return: (_error_code, _msg); the error code and associated message. :rtype: (int, str) """ _revision_id = kwargs['revision_id'] _stakeholder = RAMSTKStakeholder() _stakeholder.revision_id = _revision_id _error_code, _msg = RAMSTKDataModel.do_insert(self, entities=[ _stakeholder, ]) if _error_code == 0: self.tree.create_node(_stakeholder.description, _stakeholder.stakeholder_id, parent=0, data=_stakeholder) # pylint: disable=attribute-defined-outside-init # It is defined in RAMSTKDataModel.__init__ self.last_id = max(self.last_id, _stakeholder.stakeholder_id) return _error_code, _msg
def do_insert(self, **kwargs): """ Add a record to the RAMSTKAllocation table. :return: (_error_code, _msg); the error code and associated message. :rtype: (int, str) """ _allocation = RAMSTKAllocation() _allocation.revision_id = kwargs['revision_id'] _allocation.hardware_id = kwargs['hardware_id'] _allocation.parent_id = kwargs['parent_id'] _error_code, _msg = RAMSTKDataModel.do_insert(self, entities=[ _allocation, ]) if _error_code == 0: try: self.tree.create_node('Allocation ID: {0:d}'.format( _allocation.hardware_id), _allocation.hardware_id, parent=_allocation.parent_id, data=_allocation) self.last_id = max(self.last_id, _allocation.hardware_id) except DuplicatedNodeIdError: _error_code = 1 _msg = ('RAMSTK ERROR: Node ID {0:s} already exists in the ' 'Allocation tree for Hardware ID {1:s}').format( str(_allocation.hardware_id), str(_allocation.parent_id)) return _error_code, _msg
def do_insert(self, **kwargs): """ Add a record to the RAMSTKFunction table. :return: (_error_code, _msg); the error code and associated message. :rtype: (int, str) """ _function = RAMSTKFunction() _function.revision_id = kwargs['revision_id'] _function.parent_id = kwargs['parent_id'] _error_code, _msg = RAMSTKDataModel.do_insert(self, entities=[ _function, ]) if _error_code == 0: self.tree.create_node(_function.name, _function.function_id, parent=_function.parent_id, data=_function) # pylint: disable=attribute-defined-outside-init # It is defined in RAMSTKDataModel.__init__ self.last_id = _function.function_id # If we're not running a test, let anyone who cares know a new # Function was inserted. if not self._test: pub.sendMessage('inserted_function', tree=self.tree) return _error_code, _msg
def do_insert(self, **kwargs): # pylint: disable=unused-argument """ Add a record to the RAMSTKTestMethod table. :return: (_error_code, _msg); the error code and associated message. :rtype: (int, str) """ _testmethod = RAMSTKTestMethod() _testmethod.load_id = kwargs['load_id'] _error_code, _msg = RAMSTKDataModel.do_insert( self, entities=[ _testmethod, ]) if _error_code == 0: self.tree.create_node( _testmethod.description, _testmethod.test_id, parent=0, data=_testmethod) # pylint: disable=attribute-defined-outside-init # It is defined in RAMSTKDataModel.__init__ self.last_id = max(self.last_id, _testmethod.test_id) return _error_code, _msg
def do_insert(self, **kwargs): # pylint: disable=unused-argument """ Add a record to the RAMSTKValidation table. :return: (_error_code, _msg); the error code and associated message. :rtype: (int, str) """ _validation = RAMSTKValidation() _validation.revision_id = kwargs['revision_id'] _error_code, _msg = RAMSTKDataModel.do_insert( self, entities=[ _validation, ]) if _error_code == 0: self.tree.create_node( _validation.description, _validation.validation_id, parent=0, data=_validation) # pylint: disable=attribute-defined-outside-init # It is defined in RAMSTKDataModel.__init__ self.last_id = _validation.validation_id return _error_code, _msg
def do_insert(self, **kwargs): """ Add a record to the RAMSTKEnvironment table in the RAMSTK Program database. :return: (_error_code, _msg); the error code and associated message. :rtype: (int, str) """ _phase_id = kwargs['phase_id'] _environment = RAMSTKEnvironment() _environment.phase_id = _phase_id _error_code, _msg = RAMSTKDataModel.do_insert(self, entities=[ _environment, ]) if _error_code == 0: self.tree.create_node(_environment.name, _environment.environment_id, parent=0, data=_environment) # pylint: disable=attribute-defined-outside-init # It is defined in RAMSTKDataModel.__init__ self.last_id = _environment.environment_id return _error_code, _msg
def do_insert(self, **kwargs): """ Add a record to the RAMSTKMissionPhase table in the RAMSTK Program database. :param int mission_id: the Mission ID to add the Mission Phase to. :return: (_error_code, _msg); the error code and associated message. :rtype: (int, str) """ _mission_id = kwargs['mission_id'] _phase = RAMSTKMissionPhase() _phase.mission_id = _mission_id _error_code, _msg = RAMSTKDataModel.do_insert(self, entities=[ _phase, ]) if _error_code == 0: self.tree.create_node(_phase.name, _phase.phase_id, parent=0, data=_phase) # pylint: disable=attribute-defined-outside-init # It is defined in RAMSTKDataModel.__init__ self.last_id = _phase.phase_id return _error_code, _msg
def do_insert(self, **kwargs): """ Add a record to the RAMSTKAction table. :return: (_error_code, _msg); the error code and associated message. :rtype: (int, str) """ _action = RAMSTKAction() _action.cause_id = kwargs['cause_id'] _error_code, _msg = RAMSTKDataModel.do_insert( self, entities=[ _action, ]) if _error_code == 0: self.tree.create_node( _action.action_status, _action.action_id, parent=0, data=_action) # pylint: disable=attribute-defined-outside-init # It is defined in RAMSTKDataModel.__init__ self.last_id = max(self.last_id, _action.action_id) return _error_code, _msg
def do_insert(self, **kwargs): """ Add a record to the RAMSTKMechanism table. :return: (_error_code, _msg); the error code and associated message. :rtype: (int, str) """ _mechanism = RAMSTKMechanism() _mechanism.mode_id = kwargs['mode_id'] _error_code, _msg = RAMSTKDataModel.do_insert( self, entities=[ _mechanism, ]) if _error_code == 0: self.tree.create_node( _mechanism.description, _mechanism.mechanism_id, parent=0, data=_mechanism) # pylint: disable=attribute-defined-outside-init # It is defined in RAMSTKDataModel.__init__ self.last_id = max(self.last_id, _mechanism.mechanism_id) return _error_code, _msg
def do_insert(self, **kwargs): """ Insert a new entity to the RAMSTK db with values from external file. :param str module: the name of the RAMSTK module to import. :return: (_revision_id, _count, _error_code, _msg; the Revision ID the import is associated with, the total number of entities added, the error code and associated message from the RAMSTK Program DAO. :rtype: (int, int, int, str) """ _module = kwargs['module'] _revision_id = 1 _entities = [] for _idx, _row in self._input_data.iterrows(): if _module == 'Function': _entity = self._do_insert_function(_row) _entities.append(_entity) _revision_id = _entity.revision_id elif _module == 'Requirement': _entity = self._do_insert_requirement(_row) _entities.append(_entity) _revision_id = _entity.revision_id elif _module == 'Hardware': _entity = self._do_insert_hardware(_row) _entities.append(_entity) _revision_id = _entity.revision_id _entity = self._do_insert_allocation(_row) _entities.append(_entity) _entity = self._do_insert_similar_item(_row) _entities.append(_entity) _entity = self._do_insert_design_electric(_row) _entities.append(_entity) _entity = self._do_insert_mil_hdbk_f(_row) _entities.append(_entity) _entity = self._do_insert_design_mechanic(_row) _entities.append(_entity) _entity = self._do_insert_nswc(_row) _entities.append(_entity) _entity = self._do_insert_reliability(_row) _entities.append(_entity) elif _module == 'Validation': _entity = self._do_insert_validation(_row) _entities.append(_entity) _revision_id = _entity.revision_id _error_code, _msg = RAMSTKDataModel.do_insert(self, entities=_entities) if _error_code == 0: _count = len(_entities) else: _count = 0 return _revision_id, _count, _error_code, _msg
def do_insert(self, **kwargs): """ Add a record to the RAMSTKHazardAnalysis table. :return: (_error_code, _msg); the error code and associated message. :rtype: (int, str) """ _hazard_analysis = RAMSTKHazardAnalysis() _hazard_analysis.revision_id = kwargs['revision_id'] _hazard_analysis.hardware_id = kwargs['hardware_id'] _error_code, _msg = RAMSTKDataModel.do_insert( self, entities=[ _hazard_analysis, ]) _id = '{0:d}.{1:d}'.format(_hazard_analysis.hardware_id, _hazard_analysis.hazard_id) try: self.tree.create_node( _hazard_analysis.potential_hazard, _id, parent=_hazard_analysis.hardware_id, data=_hazard_analysis) except tree.NodeIDAbsentError: self.tree.create_node( _hazard_analysis.potential_hazard, _hazard_analysis.hardware_id, parent=0, data=None) self.tree.create_node( _hazard_analysis.potential_hazard, _id, parent=_hazard_analysis.hardware_id, data=_hazard_analysis) self.last_id = max(self.last_id, _hazard_analysis.hazard_id) return _error_code, _msg
def do_insert(self, **kwargs): """ Add a record to the RAMSTKFailureDefinition table. :return: (_error_code, _msg); the error code and associated message. :rtype: (int, str) """ _revision_id = kwargs['revision_id'] _definition = RAMSTKFailureDefinition() _definition.revision_id = _revision_id _error_code, _msg = RAMSTKDataModel.do_insert(self, entities=[ _definition, ]) if _error_code == 0: self.tree.create_node(_definition.definition, _definition.definition_id, parent=0, data=_definition) self.last_id = _definition.definition_id return _error_code, _msg
def do_select_all(self, **kwargs): """ Retrieve all the Validations from the RAMSTK Program database. This method retrieves all the records from the RAMSTKValidation table in the connected RAMSTK Program database. It then add each to the Validation data model treelib.Tree(). :return: tree; the Tree() of RAMSTKValidation data models. :rtype: :class:`treelib.Tree` """ _revision_id = kwargs['revision_id'] _session = RAMSTKDataModel.do_select_all(self) for _validation in _session.query(RAMSTKValidation).filter( RAMSTKValidation.revision_id == _revision_id).all(): # We get and then set the attributes to replace any None values # (NULL fields in the database) with their default value. _attributes = _validation.get_attributes() _validation.set_attributes(_attributes) self.tree.create_node( _validation.description, _validation.validation_id, parent=0, data=_validation) # pylint: disable=attribute-defined-outside-init # It is defined in RAMSTKDataModel.__init__ self.last_id = max(self.last_id, _validation.validation_id) # Now select all the status updates. _today = False for _status in _session.query(RAMSTKProgramStatus).filter( RAMSTKProgramStatus.revision_id == _revision_id).all(): _attributes = _status.get_attributes() _status.set_attributes(_attributes) try: self.status_tree.create_node( _status.date_status, date_to_ordinal(_status.date_status), parent=0, data=_status) except tree.DuplicatedNodeIdError: pass if _status.date_status == date.today(): _today = True if not _today: _status = RAMSTKProgramStatus() _status.revision_id = _revision_id _status.date_status = date.today() _error_code, _msg = RAMSTKDataModel.do_insert( self, entities=[ _status, ]) if _error_code == 0: self.status_tree.create_node( _status.date_status, date_to_ordinal(_status.date_status), parent=0, data=_status) _session.close() return self.tree
def do_insert(self, **kwargs): """ Add an entity to the Usage Profile and RAMSTK Program database.. :param int entity_id: the RAMSTK Program database Revision ID, Mission ID, Mission Phase ID to add the entity to. :param int parent_id: the Node ID of the parent node in the treelib Tree(). :param str level: the type of entity to add to the Usage Profile. Levels are: * mission * phase * environment :return: (_error_code, _msg); the error code and associated message. :rtype: (int, str) """ _tag = 'Tag' _node_id = -1 _entity_id = kwargs['entity_id'] _parent_id = kwargs['parent_id'] _level = kwargs['level'] if _level == 'mission': _entity = RAMSTKMission() _entity.revision_id = _entity_id elif _level == 'phase': _entity = RAMSTKMissionPhase() _entity.mission_id = _entity_id elif _level == 'environment': _entity = RAMSTKEnvironment() _entity.phase_id = _entity_id else: _entity = None _error_code, _msg = RAMSTKDataModel.do_insert(self, entities=[ _entity, ]) if _level == 'mission': _tag = _entity.description _node_id = _entity.mission_id elif _level == 'phase': _tag = _entity.name _node_id = int(str(_parent_id) + str(_entity.phase_id)) elif _level == 'environment': _tag = _entity.name _node_id = int(str(_parent_id) + str(_entity.environment_id)) if _error_code == 0: self.tree.create_node(_tag, _node_id, parent=_parent_id, data=_entity) else: _error_code = 2105 _msg = 'RAMSTK ERROR: Attempted to add an item to the Usage ' \ 'Profile with an undefined indenture level. Level {0:s} ' \ 'was requested. Must be one of mission, phase, or ' \ 'environment.'.format(_level) return _error_code, _msg