def update_status_by_id(id, new_status): try: dialogs = (Dialogs.select(Dialogs.id).where(Dialogs.id==id)).execute() if len(list(dialogs)) == 1: Dialogs.update(status=new_status).where(Dialogs.id==id) return True else: raise Exception("没有这个ID") except Exception as e: error_logger.error("将新的Dialog数据写入的时候错误, %s, Traceback: %s",str(e) , traceback.format_exc(), extra={"host": 'localhost'}) return False
def update_dialog_with_manual_rating(dialog_id, manual_rating, manual_score): dialog = (Dialogs.select().where(Dialogs.id==dialog_id)).execute() if len(dialog) == 1: (Dialogs.update( is_manual_rated=True, manual_score = manual_score, manual_rating = json.dumps(manual_rating, ensure_ascii=False) ).where(Dialogs.id == dialog_id)).execute() return True else: raise Exception("Cannot find dialog with given id")
def update_status_by_session_id(session_id, new_status): try: print(session_id) dialogs = (Dialogs.select(Dialogs.id).where(Dialogs.session_id==session_id)).execute() print("Found " + str(len(list(dialogs))) + " Dialogs") if len(list(dialogs)) != 0: (Dialogs.update(status=new_status).where(Dialogs.session_id==session_id)).execute() return True else: raise Exception("没有这个SessionID") except Exception as e: error_logger.error("将新的Dialog数据写入的时候错误, %s, Traceback: %s",str(e) , traceback.format_exc(), extra={"host": 'localhost'}) return False
def add_s2t_result_to_dialog(id, transcripts, emotion, silence, interruption): try: dialogs = (Dialogs.select(Dialogs.id).where(Dialogs.id==id)).execute() if len(list(dialogs)) == 1: (Dialogs.update( transcripts=transcripts, emotion=emotion, silence=silence, interruption=interruption ).where(Dialogs.id==id)).execute() return True else: raise Exception("没有这个ID") except Exception as e: error_logger.error("将新的Dialog数据写入的时候错误, %s, Traceback: %s",str(e) , traceback.format_exc(), extra={"host": 'localhost'}) return False
def upload_audio_to_info(call_id, session_id): ''' @Description: 用户上传一个对应的语音文件到流水记录后,系统会根据用户提供的callid和session_id更新这条记录状态,通常是从0(Dialog收到流水信息,还没有收到语音文件)到1(Dialog收到语音信息) ''' try: fetch_query = (Dialogs.select(Dialogs.id).where((Dialogs.call_id==call_id) & (Dialogs.session_id==session_id))) fetch_query.execute() if len(fetch_query) == 1: target_id=fetch_query[0].id update_query = (Dialogs.update(status=1).where(Dialogs.id==target_id)) update_query.execute() return target_id else: raise Exception("无法根据call_id和session_id找到需要更新的record") except Exception as e: error_logger.error("无法更新 %s Dialog的状态, 原因:%s, TraceBack: %s",str(call_id), str(e), traceback.format_exc(), extra={"host": "localhost"}) return False