def findPlanetAtmosphChemistry(session, planet): """ @param session: current workable session @type session: sc_session @param planet: planet which radius we are finding @type planet: sc_global_addr @return: chemistry of the planet @rtype: tuple(property_name, [tuple(substance_name, percent),...],unit_name) """ atmosphereKey = space_keynodes.SpaceRelation.atmosphere chemistryKey = space_keynodes.SpaceRelation.chemistry prop_name = str(sc_utils.cp1251ToUtf8(session.get_idtf(atmosphereKey))) prop_name = prop_name.replace('*', '') result = None addr1 = sc_utils.searchOneShotBinPairAttrFromNode(session, planet, atmosphereKey, sc.SC_N_CONST) if addr1 is not None: addr2 = sc_utils.searchOneShotBinPairAttrFromNode( session, addr1, chemistryKey, sc.SC_N_CONST) chemistry = findAllPlanetProperties(session, addr2) items = [] unit_name = "" for chem in chemistry: if chem is not None: name, value, unit_name = chem item = (name, value) items.append(item) result = (prop_name, items, unit_name) return result
def findPlanetAtmosphChemistry(session, planet): """ @param session: current workable session @type session: sc_session @param planet: planet which radius we are finding @type planet: sc_global_addr @return: chemistry of the planet @rtype: tuple(property_name, [tuple(substance_name, percent),...],unit_name) """ atmosphereKey = space_keynodes.SpaceRelation.atmosphere chemistryKey = space_keynodes.SpaceRelation.chemistry prop_name = str(sc_utils.cp1251ToUtf8(session.get_idtf(atmosphereKey))) prop_name = prop_name.replace('*', '') result=None addr1 = sc_utils.searchOneShotBinPairAttrFromNode(session, planet, atmosphereKey, sc.SC_N_CONST) if addr1 is not None: addr2 = sc_utils.searchOneShotBinPairAttrFromNode(session, addr1, chemistryKey, sc.SC_N_CONST) chemistry = findAllPlanetProperties(session, addr2) items = [] unit_name = "" for chem in chemistry: if chem is not None: name, value, unit_name = chem item = (name, value) items.append(item) result = (prop_name, items, unit_name) return result
def findPlanetProperty(session, planet, property, unit_attr): """ @param session: current workable session @type session: sc_session @param planet: planet which property we are finding @type planet: sc_global_addr @param property: property keynode @type property: sc_global_addr @param unit_attr: property unit attribute keynode @type unit_attr: sc_global_addr @return: property value of the planet @rtype: str """ identficationKey = keynodes.common.nrel_identification dec_system = space_keynodes.DefaultAttr.dec_system addr1 = sc_utils.searchOneShotBinPairAttrFromNode(session, planet, property, sc.SC_N_CONST) if addr1 is not None: addr2 = searchOneShotPosArcAttrFrom(session, addr1, unit_attr) addr3 = sc_utils.searchOneShotBinPairAttrToNode( session, addr2, identficationKey, sc.SC_N_CONST) addr4 = searchPosArcAttrFrom(session, addr3, dec_system) for addr in addr4: content = session.get_content_str(addr) if content is not None: return sc_utils.cp1251ToUtf8(str(content)) return None
def findPlanetProperty(session, planet, property, unit_attr): """ @param session: current workable session @type session: sc_session @param planet: planet which property we are finding @type planet: sc_global_addr @param property: property keynode @type property: sc_global_addr @param unit_attr: property unit attribute keynode @type unit_attr: sc_global_addr @return: property value of the planet @rtype: str """ identficationKey = keynodes.common.nrel_identification dec_system = space_keynodes.DefaultAttr.dec_system addr1 = sc_utils.searchOneShotBinPairAttrFromNode(session, planet, property, sc.SC_N_CONST) if addr1 is not None: addr2 = searchOneShotPosArcAttrFrom(session, addr1, unit_attr) addr3 = sc_utils.searchOneShotBinPairAttrToNode(session, addr2, identficationKey, sc.SC_N_CONST) addr4 = searchPosArcAttrFrom(session, addr3, dec_system) for addr in addr4: content = session.get_content_str(addr) if content is not None: return sc_utils.cp1251ToUtf8(str(content)) return None
def user_output_answer(_params, _segment): # trying to find question node session = core.Kernel.session() # getting answer sheaf node answer_sheaf = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.questions.nrel_answer, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if answer_sheaf is None: raise Exception("Can't find answer sheaf node") answer_sheaf = answer_sheaf[2] # go to begin of pair question_node = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, answer_sheaf, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, keynodes.n_1), True, 5) if question_node is None: raise Exception("Can't find question node") question_node = question_node[2] if question_node is None: return # get author and check if it's a user authors_set = sc_utils.searchOneShotBinPairAttrFromNode(session, question_node, keynodes.common.nrel_authors, sc_core.pm.SC_CONST) if authors_set is None: return is_user = False it = session.create_iterator(session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, authors_set, sc_core.pm.SC_A_CONST | sc_core.pm.SC_POS, sc_core.pm.SC_N_CONST), True) while not it.is_over(): author = it.value(2) if sc_utils.checkIncToSets(session, author, [keynodes.ui.user], sc_core.pm.SC_CONST): is_user = True it.next() if not is_user: return # get answer node answer_node = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, answer_sheaf, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, keynodes.n_2), True, 5) if answer_node is None: return answer_node = answer_node[2] # get output windows output_set = sc_utils.searchOneShotBinPairAttrToNode(session, question_node, keynodes.ui.nrel_set_of_output_windows, sc_core.pm.SC_CONST) if output_set is None: return it = session.create_iterator(session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, output_set, sc_core.pm.SC_A_CONST | sc_core.pm.SC_POS, sc_core.pm.SC_N_CONST), True) while not it.is_over(): try: core.Kernel.getSingleton().translateFromSc(answer_node, it.value(2)) except: import sys, traceback print "Error:", sys.exc_info()[0] traceback.print_exc(file=sys.stdout) it.next()
def user_output_answer(_params, _segment): # trying to find question node session = core.Kernel.session() # getting answer sheaf node answer_sheaf = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.questions.nrel_answer, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if answer_sheaf is None: raise Exception("Can't find answer sheaf node") answer_sheaf = answer_sheaf[2] # go to begin of pair question_node = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, answer_sheaf, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, keynodes.n_1), True, 5) if question_node is None: raise Exception("Can't find question node") question_node = question_node[2] if question_node is None: return # get author and check if it's a user authors_set = sc_utils.searchOneShotBinPairAttrFromNode( session, question_node, keynodes.common.nrel_authors, sc_core.pm.SC_CONST) if authors_set is None: return is_user = False it = session.create_iterator( session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, authors_set, sc_core.pm.SC_A_CONST | sc_core.pm.SC_POS, sc_core.pm.SC_N_CONST), True) while not it.is_over(): author = it.value(2) if sc_utils.checkIncToSets(session, author, [keynodes.ui.user], sc_core.pm.SC_CONST): is_user = True it.next() if not is_user: return # get answer node answer_node = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, answer_sheaf, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, keynodes.n_2), True, 5) if answer_node is None: return answer_node = answer_node[2] # get output windows output_set = sc_utils.searchOneShotBinPairAttrToNode( session, question_node, keynodes.ui.nrel_set_of_output_windows, sc_core.pm.SC_CONST) if output_set is None: return it = session.create_iterator( session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, output_set, sc_core.pm.SC_A_CONST | sc_core.pm.SC_POS, sc_core.pm.SC_N_CONST), True) while not it.is_over(): try: core.Kernel.getSingleton().translateFromSc(answer_node, it.value(2)) except: import sys, traceback print "Error:", sys.exc_info()[0] traceback.print_exc(file=sys.stdout) it.next()