class SearchRelation(): def __init__(self): self.relation_access = JikkyolizerAccess() def add_relation(self, group_or_item, relation_name): self.relation_access.dict_update('sox_jikkyolized', {group_or_item: relation_name}, { 'group_id': group_id, 'item_id': item_id }) def fetch_relation(self, relation_name, group_or_item, except_group, except_item, raw_value): rel_flag = 'No_speciality' if group_or_item == 'group': rels = self.relation_access.dict_select( 'sox_jikkyolized', {'group_relation': relation_name}) if group_or_item == 'item': rels = self.relation_access.dict_select( 'sox_jikkyolized', {'item_relation': relation_name}) rel_graph = [] smaller = 0 for rel in rels: if rel['group_id'] != except_group or rel['item_id'] != except_item: rel_es = self.relation_access.dict_select( 'sox_data_last', { 'group_id': rel['group_id'], 'item_id': rel['item_id'] }) for rel_e in rel_es: if rel['item_kind'] is not None: item_kind = rel['item_kind'] rel_graph.append(eval(item_kind)(rel_e['raw_value'])) e_value = eval(item_kind)(rel_e['raw_value']) if e_value < raw_value: smaller += 1 if item_kind == 'int' or item_kind == 'float': max_value = max(rel_graph) min_value = min(rel_graph) if raw_value > max_value: rel_flag = 'rel_max' elif raw_value < min_value: rel_flag = 'rel_min' elif (smaller / len(rel_graph)) < 0.1: rel_flag = 'rel_little' elif (smaller / len(rel_graph)) > 0.9: rel_flag = 'rel_much' return rel_flag
def main(from_java_string): fj_string = from_java_string group_id_start = len('group_id=') group_id_start += 1 group_id_end = fj_string.find(',') group_id = fj_string[group_id_start:group_id_end] item_id_start = fj_string.find('item_id') item_id_start += len('item_id') item_id_start += 1 item_id_end = fj_string.find(',') item_id = fj_string[item_id_start:item_id_end] #item_id = fj_string[item_id_start:-1] group_name_start = fj_string.find('group_name') group_name_start += len('group_name') group_name_start += 1 group_name = fj_string[group_name:-1] print(group_id + item_id + group_name, flush=True) #items = [] to_jikkyolizer_data = JikkyolizerAccess() #if item_id is None: #false if isinstance(item_id, str): dummy = 'aaa' else: dummy = 'ccc' #if group_id is None: #false if isinstance(group_id, str): dummy2 = 'bbb' else: dummy2 = 'ddd' try: to_jikkyolizer_data.dict_insert('sox_jikkyolized', { 'group_id': group_id, 'item_id': item_id, 'total_number': 0 }) except: #f.write('group_id=' + group_id + ', item_id=' +item_id + '\n') #f.flush() pass pre_ID = to_jikkyolizer_data.dict_select('sox_jikkyolized', { 'group_id': group_id, 'item_id': item_id }) voice_ID = '{0:07d}'.format(pre_ID[0]['ID']) pre_ID = to_jikkyolizer_data.dict_insert('sox_id_name_relation', { 'device_id': group_id, 'device_name': item_id }) MakeVoice.raw_vocalize(group_name + 'の' + item_id, 'group_item', 'id-' + voice_ID) return item_id, str(type(item_id))