def CopySampleToBP(BPName, TextRowsSample, TabInfo, SampleCode): conn = get_db() db = conn.cursor() buf_types = [] # dlya strok for tabinf in TabInfo[1:]: buf_types.append(tabinf[1]) if (request.form.get('IdInFile') == 'on'): StrNames = ','.join(Str[0] for Str in TabInfo) else: StrNames = ','.join(Str[0] for Str in TabInfo[1:]) # начиная с 1 элемента for Str in TextRowsSample: #for i,Str in enumerate(TextStr): StrParam= re.split("[,; ]+", Str.replace('\n', '')) #Buf=', '.join('?' for s in StrParam) Buf='' for j,str_type in enumerate(StrParam): if buf_types[j] == 'varchar(255)': Buf += '\'{}\', '.format(str_type) else: Buf += '{}, '.format(str_type) Buf = Buf[0:len(Buf)-2] if SampleCode == 'train': db.execute("INSERT INTO {0} ({1}) VALUES ({2},\'{3}\','good')".format(BPName, StrNames, Buf, SampleCode)) else: db.execute("INSERT INTO {0} ({1}) VALUES ({2},\'{3}\','')".format(BPName, StrNames, Buf, SampleCode)) print(Buf) conn.commit()
def registration(): conn = get_db() cur = conn.cursor() user_name = request.values.get('login') user_pass = request.values.get('pass') secret_word = request.values.get('secretWord') try: if len(user_name) > 32: abort(404) cur.execute( "SELECT COUNT(1) FROM users WHERE user_name = \'{}\';".format( user_name)) if cur.fetchone()[0]: #raise ServerError('Имя пользователя уже занято') abort(404) user_pass_b = user_pass.encode('utf-8') # perevodim v bayts password_form_hash = md5(user_pass_b).hexdigest() print(password_form_hash) print( 'INSERT INTO users SET user_name = \'{0}\', user_pass = \'{1}\', user_rights = \'user\', user_secret_word=\'{2}\';' .format(user_name, password_form_hash, secret_word)) cur.execute( 'INSERT INTO users SET user_name = \'{0}\', user_pass = \'{1}\', user_rights = \'user\', user_secret_word=\'{2}\';' .format(user_name, password_form_hash, secret_word)) conn.commit() #print(url_for('login')) #return redirect(url_for('login')) except: abort(404) redirect(url_for('Registration.login')) return 'OK'
def CopyDataToDescriptionTable(DescriptionBPName, StrDescNames ,StrParamNames, StrDescriptions, StrTypes, StrUnits, StrRangeFrom, StrRangeTo, StrWeights, ColCount, DescrTabInfTypes): #cur=get_db() conn=get_db() cur=conn.cursor() ParamNames_mas = StrParamNames[2:].split(', ') Descriptions_mas = StrDescriptions[2:].split(', ') Types_mas = StrTypes[2:].split(', ') Units_mas = StrUnits[2:].split(', ') RangeFrom_mas = StrRangeFrom[2:].split(', ') RangeTo_mas = StrRangeTo[2:].split(', ') Weights_mas = StrWeights[2:].split(', ') # flash(StrDescNames) for i in range(0,ColCount-1): mas_param = ParamNames_mas[i] + ', ' + Descriptions_mas[i]+ ', ' + Types_mas[i]+', ' + Units_mas[i]+', ' + RangeFrom_mas[i]+', ' + RangeTo_mas[i]+', ' + Weights_mas[i] mas_param_spl = mas_param.split(', ') DescrTabInfTypesNew = DescrTabInfTypes[1:] Buf='' #print(DescrTabInfTypesNew) #print(mas_param_spl) for j in range(0,len(mas_param_spl)-1): if DescrTabInfTypesNew[j] == 'text': Buf += "\'{}\', ".format(mas_param_spl[j]) else: Buf += '{}, ' .format(mas_param_spl[j]) Buf += mas_param_spl[len(mas_param_spl)-1] # flash(mas_param) cur.execute('INSERT INTO {0} ({1}) VALUES ({2})'.format(DescriptionBPName, StrDescNames, Buf)) #db.commit() conn.commit() return
def ExpHandLoad(): db = get_db() mistake_message = '' if 'create_ontology_mistake' in session: mistake_message = escape(session['create_ontology_mistake']).capitalize() session.pop('create_ontology_mistake', None) return render_template('ExpHandLoad.html', mistake_message = mistake_message)
def ExportToFile(TabName): db = get_db() cur = db.cursor() BPName = request.form['HiddenTableChoice'] tfile = tempfile.TemporaryFile() FileName = BPName #print(request.form['ExportToFile']) if request.form['ExportToFile'] == 'Экспорт БП': cur.execute("SELECT COUNT(*) FROM {0}".format(BPName)) TotalCount, Id, CountStr = cur.fetchone()[0], 1, 5000 while (Id <= TotalCount): cur.execute("SELECT * FROM {0} WHERE id>={1} AND id<{2}".format( BPName, Id, (Id + CountStr))) TabData = cur.fetchall() for Str in TabData: buf = ','.join(str(Col) for Col in Str) + '\n' tfile.write(buf.encode("utf-8")) Id += CountStr elif request.form['ExportToFile'] == 'Экспорт тестовой выборки': TestSample = request.form['HiddenTestSample'] cur.execute('SELECT * FROM {0} WHERE id IN ({1})'.format( BPName, TestSample)) TabData = cur.fetchall() for Str in TabData: buf = ','.join(str(Col) for Col in Str) + '\n' tfile.write(buf.encode("utf-8")) FileName += 'TestSample' elif request.form['ExportToFile'] == 'Экспорт обучающей выборки': TestSample = request.form['HiddenTestSample'] cur.execute("SELECT COUNT(*) FROM {0}".format(BPName)) TotalCount, Id, CountStr = cur.fetchone()[0], 1, 5000 while (Id <= TotalCount): cur.execute( "SELECT * FROM {0} WHERE id>={1} AND id<{2} AND id NOT IN ({3})" .format(BPName, Id, (Id + CountStr), TestSample)) TabData = cur.fetchall() for Str in TabData: buf = ','.join(str(Col) for Col in Str) + '\n' tfile.write(buf.encode("utf-8")) Id += CountStr FileName += 'TrainSample' tfile.seek(0) return send_file(tfile, attachment_filename="{0}.csv".format(FileName), as_attachment=True, mimetype='text/csv')
def MainPage(): db = get_db() if 'username' not in session: return redirect(url_for('Registration.login')) print(session) username_session = escape(session['username']).capitalize() print(username_session) return render_template('MainPage.html')
def EditBP(): db = get_db() cur = db.cursor() cur.execute( "SELECT table_name FROM information_schema.tables where table_schema='table_storage'\ and table_name NOT LIKE '%Description' and table_name NOT LIKE 'users'") TabList = [Tab[0] for Tab in cur.fetchall()] return render_template('EditBP.html', TabList=TabList)
def get_db(dict_cursor=True): mysqldb = db.get_db() # if not in a request we won't be connected if not mysqldb: mysqldb = db.connect() # return a DictCursor if dict_cursor: return mysqldb.cursor(MySQLdb.cursors.DictCursor) else: return mysqldb.cursor()
def DeleteBP(TabNames): print("kek") db = get_db() cur = db.cursor() BPChoice = json.loads(request.values.get('BPChoice')) for BPName in BPChoice: cur.execute("DROP TABLE {0}".format(BPName)) cur.execute("DROP TABLE {0}".format(BPName + 'Description')) db.commit() return 'OK'
def LookBPRequest(TabName): db = get_db() cur = db.cursor() BPName = request.args.get('TableChoice') Id = int(request.args.get('Id'), 10) if (Id == -1): cur.execute("SELECT COUNT(*) FROM {0}".format(BPName)) TotalCount = cur.fetchone()[0] to_json = {'TotalCount': TotalCount} else: CountStr = int(request.args.get('CountStr'), 10) cur.execute("SELECT COUNT(*) FROM {0} WHERE id>={1} AND id<{2}".format( BPName, Id, (Id + CountStr))) CurCount = cur.fetchone()[0] cur.execute('DESCRIBE {0}'.format(BPName)) col_names = '' Info = cur.fetchall() for info in Info: col_names += info[0] + ',' if (col_names != ''): col_names = col_names[:-1] col_names = col_names.replace(',sampleCode,qualityCode', '') print("SELECT {0} FROM {1} WHERE id>={2} AND id<{3}".format( col_names, BPName, Id, (Id + CountStr))) cur.execute("SELECT {0} FROM {1} WHERE id>={2} AND id<{3}".format( col_names, BPName, Id, (Id + CountStr))) TabData = cur.fetchall() to_json = {'Id': Id, 'CurCount': CurCount, 'TabData': TabData} if (Id == 0): cur.execute('DESCRIBE {0}'.format(BPName)) TabInfo = cur.fetchall() TabInfo = ModifyTabInfo( TabInfo ) #Если это убрать, то поледние 2 колонки отображаются нормально cur.execute('DESCRIBE {0}'.format(BPName + 'Description')) DescrTabInfo = cur.fetchall() cur.execute("SELECT * FROM {0}".format(BPName + 'Description')) DescrTabData = cur.fetchall() to_json = { 'Id': Id, 'CurCount': CurCount, 'TabData': TabData, 'TabInfo': TabInfo, 'DescrTabData': DescrTabData, 'DescrTabInfo': DescrTabInfo } return json.dumps(to_json)
def RenameBP(TabNames): db = get_db() cur = db.cursor() cur.execute( "SELECT table_name FROM information_schema.tables where table_schema='table_storage'\ and table_name NOT LIKE '%Description'") OldBPNames = [BP[0] for BP in cur.fetchall()] NewBPNames = json.loads(request.values.get('NewBPNames')) for OldBPName, key in zip(OldBPNames, range(0, len(NewBPNames))): try: cur.execute('ALTER TABLE {0} RENAME TO {1}'.format( OldBPName, NewBPNames.get(str(key)))) cur.execute( 'ALTER TABLE {0}Description RENAME TO {1}Description'.format( OldBPName, NewBPNames.get(str(key)))) except mysql.OperationalError: pass return 'OK'
def loginRequest(): conn = get_db() cur = conn.cursor() user_name = request.values.get('login') user_pass = request.values.get('pass') secret_word = request.values.get('secretWord') print(len(secret_word)) if 'username' in session: return redirect(url_for('MainPage.MainPage')) error = None try: cur.execute( 'SELECT COUNT(1) FROM users WHERE user_name = \'{}\';'.format( user_name)) if not cur.fetchone()[0]: abort(404) if len(secret_word) == 0: cur.execute( 'SELECT user_pass FROM users WHERE user_name = \'{}\' limit 1;' .format(user_name)) print('golubi letyat2') hash_pass = cur.fetchone()[0] print(hash_pass) user_pass_b = user_pass.encode('utf-8') if md5(user_pass_b).hexdigest() == hash_pass: #session['logged_in'] = True session['username'] = user_name return redirect(url_for('MainPage.MainPage')) abort(404) else: cur.execute( 'SELECT user_secret_word FROM users WHERE user_name = \'{}\' limit 1;' .format(user_name)) secret_word_from_query = cur.fetchall()[0] if secret_word_from_query == secret_word: session['username'] = user_name #session['logged_in'] = True return redirect(url_for('MainPage.MainPage')) abort(404) except: abort(404) return 'OK'
def OptimizationBP(): print('Optimization') conn = get_db() cur = conn.cursor() BPName = request.values.get('TableChoice') OptArr = json.loads(request.values.get('JsonObj')) #print(BPName) cur.execute('SELECT * FROM {0} ORDER BY id ASC'.format(BPName)) TabData = cur.fetchall() cur.execute('SELECT * FROM {0}Description ORDER BY id ASC'.format(BPName)) DescrTabData = cur.fetchall() Weight = [Str[7] for Str in DescrTabData] if OptArr['OptAlgol'] == 'Classification': print('classification enter') OptTabData = Classification2(TabData[:], OptArr['ClassMetric'], Weight, float(OptArr['ClassSimilarity'])) elif OptArr['OptAlgol'] == 'KMeans': print('kmeans enter') OptTabData = KMeans2(TabData, int(OptArr['KMClusterCount'], 10), OptArr['KMMetric'], Weight, OptArr['KMPrimaryCenter']) elif OptArr['OptAlgol'] == 'TimurAlgorithm': OptTabData = TimurAlgorithm2(TabData[:]) ''' if len(OptTabData)!=0: for Str in TabData: if (len(OptTabData)==0 or Str[0]!=OptTabData[0][0]): db.execute('DELETE FROM {0} WHERE id={1}'.format(BPName, Str[0])) else: OptTabData.pop(0) ''' if len(OptTabData) != 0: #print(','.join(str(Str[0]) for Str in OptTabData)) cur.execute('DELETE FROM {0} WHERE id NOT IN ({1})'.format( BPName, ','.join(str(Str[0]) for Str in OptTabData))) conn.commit() return 'Success'
def EditBPRequest(TabName): db = get_db() cur = db.cursor() BPName = request.values.get('TableChoice') cur.execute('DESCRIBE {0}'.format(BPName)) TabInfo = cur.fetchall() buf_types = [] #dlya strok for tabinf in TabInfo[1:]: buf_types.append(tabinf[1]) Operation = request.values.get('Operation') if (Operation == 'Delete'): Data = json.loads(request.values.get('JsonObj')) for Id in Data: cur.execute('DELETE FROM {0} WHERE id={1}'.format(BPName, Id)) to_json = {'Status': 'OK!'} elif Operation == 'DeleteAll': cur.execute('DELETE FROM {0}'.format(BPName)) to_json = {'Status': 'OK!'} elif Operation == 'Insert': CountStr = int(request.values.get('Count'), 10) RowId = [] for i in range(0, CountStr): cur.execute('INSERT INTO {0} () VALUES()'.format(BPName)) cur.execute('SELECT last_insert_id()') RowId.append(cur.fetchone()[0]) to_json = {'LastInsertRowId': RowId} elif Operation == 'Update': Data = json.loads(request.values.get('JsonObj')) cur.execute('UPDATE {0} SET {1}="{2}" WHERE id={3}'.format( BPName, Data['ColName'], Data['Value'], Data['Id'])) to_json = {'Status': 'OK!'} elif Operation == 'RenameColumn': Data = json.loads(request.values.get('JsonObj')) #db.execute('ALTER TABLE {0} RENAME COLUMN {1} TO {2}'.format(BPName, Data['ColName'], Data['Value'])) to_json = {'Status': 'OK!'} elif Operation == 'Load From File': file = request.files['ImportBPFile'] LastId = -1 cur.execute("SELECT COUNT(*) FROM {0}".format(BPName)) TotalCountBeforeInsert = cur.fetchone()[0] for line in file: line = re.sub("[\n\r]", "", line.decode('UTF-8')) data = re.split("[(,\s)(;\s),;\s]", line) #Buf=','.join('?' for d in data) Buf = '' for j, data_type in enumerate(data): if buf_types[j] == 'varchar(255)': Buf += '\'{}\', '.format(data_type) else: Buf += '{}, '.format(data_type) Buf = Buf[0:len(Buf) - 2] cur.execute('INSERT INTO {0} VALUES(null, {1})'.format( BPName, Buf)) if LastId == -1: #cur.execute("SELECT LAST_INSERT_ROWID()") cur.execute("SELECT last_insert_id()") LastId = cur.fetchone()[0] cur.execute("SELECT COUNT(*) FROM {0}".format(BPName)) TotalCountAfterInsert = cur.fetchone()[0] to_json = { 'TCBI': TotalCountBeforeInsert, 'TCAI': TotalCountAfterInsert, 'LastId': LastId } conn.commit() return json.dumps(to_json)
def AcceptAndCreateScheme(): # создание таблицы в бп ColCount=int(request.form['ColCount'], 10) # преобразовать в int в десятичной системе global BPName, TabInfo, TabData global DescriptionBPName, DescriptionTabInfo, TabDescrData BPName=request.form['BPName'] OntologyBPName = BPName + 'Ontology.owl' DescriptionBPName = BPName + 'Description' StrNames = '' StrDescNames = '' StrParamNames = '' StrDescriptions = '' StrTypes = '' StrRangeFrom = '' StrRangeTo = '' StrWeights = '' StrUnits = '' TextFile = '' Description_Str_Names = '' conn = get_db() cur = conn.cursor() for i in range(0,ColCount): StrNames = StrNames+', '+request.form['ColName'+str(i)]+' '+request.form['ColType'+str(i)] # str - переводит строку в id StrNames = StrNames + ', sampleCode VARCHAR(10), qualityCode VARCHAR(10)' Description_Str_Names = ', '+ 'Параметр' + ' ' + 'text' + ', ' + 'Описание' + ' ' + 'text' + ', '+ 'Тип' + ' ' + 'text' + ', ' + 'Единицы_измерения' + ' ' + 'text' + ', ' + 'Диапазон_от' + ' ' + 'real' + ', ' + 'Диапазон_до' + ' ' + 'real' + ', ' + 'Вес' + ' ' + 'real' for i in range(0,ColCount-1): StrParamNames = StrParamNames + ', ' + request.form['ColName' + str(i)] StrDescriptions = StrDescriptions + ', ' + request.form['DescriptionName'+str(i)] StrTypes = StrTypes + ', ' + request.form['ColType' + str(i)] StrUnits = StrUnits + ', ' + request.form['ColUnit' + str(i)] #todo StrRangeFrom = StrRangeFrom + ', ' + request.form['RangeFrom' + str(i)] StrRangeTo = StrRangeTo + ', ' + request.form['RangeTo' + str(i)] StrWeights = StrWeights + ', ' + request.form['ColWeights' + str(i)] StrDescNames = 'Параметр' + ', ' + 'Описание' + ', ' + 'Тип' + ', ' + 'Единицы_измерения' + ', ' + 'Диапазон_от' + ', ' + 'Диапазон_до' + ', ' + 'Вес' ontology_file = request.files['OntologyFile'] if ontology_file.filename != '': ontology_file.save(os.path.join(current_app.root_path, current_app.config['UPLOAD_FOLDER'], OntologyBPName)) old_path = "file://" + os.path.join(current_app.root_path, current_app.config['UPLOAD_FOLDER'], OntologyBPName) ontology_path = old_path.replace(os.sep, '/') world2 = World() onto = world2.get_ontology(ontology_path).load() situation_params = getNodeKidsList(onto.situation) # т.к. в текущей ситуации нет ответа, а в параметрах при создании таблицы (БП) есть + 1 if len(situation_params) + 1 == ColCount: # т.к. в текущей ситуации нет ответа, а в параметрах при создании таблицы (БП) не сравниваем его for i in range(0,ColCount - 1): if request.form['ColName'+str(i)] not in situation_params: session['create_ontology_mistake'] = 'Ошибка создания БП. Загруженная модель БП не совпадает с введенными параметрами.' return redirect(url_for('ExpHandLoad.ExpHandLoad')) else: session['create_ontology_mistake'] = 'Ошибка создания БП. Загруженная модель БП не совпадает с введенными параметрами.' return redirect(url_for('ExpHandLoad.ExpHandLoad')) cur.execute('CREATE TABLE {0} (id integer primary key AUTO_INCREMENT{1})'.format(BPName, StrNames)) cur.execute('CREATE TABLE {0} (id integer primary key AUTO_INCREMENT{1})'.format(DescriptionBPName, Description_Str_Names)) cur.close() conn1 = get_db() cur_1 = conn1.cursor() conn2 = get_db() cur_2 = conn2.cursor() cur_1.execute('DESCRIBE {0}'.format(BPName)) cur_2.execute('DESCRIBE {0}'.format(DescriptionBPName)) TabInfo = cur_1.fetchall() DescriptionTabInfo = cur_2.fetchall() uploaded_files = '' if request.form.get('BPFile[]')!='' and request.form.get('CopyDataToBP')=='on': uploaded_files = request.files.getlist("BPFile[]") #CopyDataToBP(BPName, TextFile, TabInfo, request.files['BPFile']) # io.TextIOWrapper(request.files['BPFile']) if len(uploaded_files) == 1: print('CopyDataToBP1File!1') trainSize = request.form['TrainSizeInput'] TextFile = io.TextIOWrapper(uploaded_files[0]) CopyDataToBP1File(BPName, TextFile, TabInfo, trainSize) elif len(uploaded_files) == 2: print('CopyDataToBP1File!2') if uploaded_files[0].name.endswith('Train.csv') or uploaded_files[0].name.endswith('Train.txt'): TrainSample = io.TextIOWrapper(uploaded_files[0]).readlines() TestSample = io.TextIOWrapper(uploaded_files[1]).readlines() else: TestSample = io.TextIOWrapper(uploaded_files[0]).readlines() TrainSample = io.TextIOWrapper(uploaded_files[1]).readlines() CopySampleToBP(BPName, TrainSample, TabInfo, 'train') CopySampleToBP(BPName, TestSample, TabInfo, 'test') print('CopyDataToBP1File!3') cur_2.execute("show columns from {0}".format(DescriptionBPName)) descr_values = [Row[1] for Row in cur_2.fetchall()] CopyDataToDescriptionTable(DescriptionBPName, StrDescNames, StrParamNames, StrDescriptions, StrTypes, StrUnits, StrRangeFrom, StrRangeTo, StrWeights, ColCount, descr_values) cur_1.execute('SELECT * FROM {0} ORDER BY id ASC'.format(BPName)) cur_2.execute('SELECT * FROM {0} ORDER BY id ASC'.format(DescriptionBPName)) TabData=cur_1.fetchall() TabDescrData = cur_2.fetchall() db = get_db() cur = db.cursor() cur.execute("SELECT table_name FROM information_schema.tables where table_schema='table_storage'\ and table_name NOT LIKE '%Description' and table_name NOT LIKE 'users'") TabList = [Tab[0] for Tab in cur.fetchall()] return render_template('EditBP.html', TabList=TabList)
def create_cursor(): db = get_db() return db.cursor()
def add_good_bad_precedents_to_table(): db = get_db() cur = db.cursor() current_BP_name = request.args['current_BP_name'] table_columns_description_tuples = get_data_from_base( cur, "DESCRIBE {0}".format(current_BP_name)) parametrs_and_answer_names_string = get_parametrs_and_answer_names_string( table_columns_description_tuples) parametrs_answer_names_sampleCode_qualCode_string = parametrs_and_answer_names_string + ', sampleCode' + ', qualityCode' parametrs_answer_names_qualCode_string = parametrs_and_answer_names_string + ', qualityCode' mode_of_add_auto_or_hand = request.args['add_radio_btn'] good_bad_precedents_matrix = get_data_from_base( cur, "SELECT {0} FROM {1} WHERE {2} = 'good' or {2} = 'bad'".format( parametrs_and_answer_names_string, current_BP_name, 'qualityCode')) if (mode_of_add_auto_or_hand == 'auto_add'): unique_cases_matrix = [] for case, qual_code in zip(global_cases_matrix_with_answers_list, global_good_bad_list): if (case not in unique_cases_matrix): unique_cases_matrix.append(case) case_is_already_in_good_bad_base = False for good_bad_case in good_bad_precedents_matrix: if (make_list_from_tuple(good_bad_case) == case): case_is_already_in_good_bad_base = True if (not (case_is_already_in_good_bad_base)): case_string = ", ".join("'{0}'".format(str( elem)) if isinstance(elem, str) else str(elem) for elem in case) if qual_code == 'good': print( "INSERT INTO {0}({1}) VALUES({2}, '{3}', '{4}')". format( current_BP_name, parametrs_answer_names_sampleCode_qualCode_string, case_string, 'train', qual_code)) cur.execute( "INSERT INTO {0}({1}) VALUES({2}, '{3}', '{4}')". format( current_BP_name, parametrs_answer_names_sampleCode_qualCode_string, case_string, 'train', qual_code)) else: print("INSERT INTO {0}({1}) VALUES({2}, '{3}')".format( current_BP_name, parametrs_answer_names_qualCode_string, case_string, qual_code)) cur.execute( "INSERT INTO {0}({1}) VALUES({2}, '{3}')".format( current_BP_name, parametrs_answer_names_qualCode_string, case_string, qual_code)) db.commit() return 'success' elif (mode_of_add_auto_or_hand == 'hand_add'): good_cases_string = list(request.args['good_cases_input']) unique_cases_matrix = [] for case, qual_code, good_case_code in zip( global_cases_matrix_with_answers_list, global_good_bad_list, good_cases_string): if (case not in unique_cases_matrix): unique_cases_matrix.append(case) case_is_already_in_good_bad_base = False for good_bad_case in good_bad_precedents_matrix: if (make_list_from_tuple(good_bad_case) == case): case_is_already_in_good_bad_base = True if (not (case_is_already_in_good_bad_base) and (good_case_code == '1')): case_string = ", ".join("'{0}'".format(str( elem)) if isinstance(elem, str) else str(elem) for elem in case) if qual_code == 'good': cur.execute( "INSERT INTO {0}({1}) VALUES({2}, '{3}', '{4}')". format( current_BP_name, parametrs_answer_names_sampleCode_qualCode_string, case_string, 'train', qual_code)) else: cur.execute( "INSERT INTO {0}({1}) VALUES({2}, '{3}')".format( current_BP_name, parametrs_answer_names_qualCode_string, case_string, qual_code)) db.commit() return 'success' else: return 'failed'