def diff(): if request.method == 'POST': request_data = request.get_json() if not isinstance(request_data, dict) or 'ids' not in request_data.keys(): return 'error' ids = request_data['ids'] if not isinstance(ids, list) or len(ids) > len(app.tables) or len(ids) is not 2: return 'error' start = request_data['start'] if 'start' in request_data.keys() else 0 num = request_data['num'] if 'num' in request_data.keys() else 10 ids = sorted(ids, key=lambda x: int(x)) if 'diff' not in app.current_result.keys() or app.current_result['diff']['ids'] != ids: result_all, column_list = get_diff_data(ids) app.current_result['diff'] = { 'ids': ids, 'result': (result_all, column_list) } else: result_all, column_list = app.current_result['diff']['result'] total = len(result_all) end = start + num if start + num < total else total response_data = dict() response_data['total'] = total response_data['next_start'] = end response_data['column_list'] = column_list response_data['data'] = result_all[start:end].to_dict('records') return json.dumps(response_data) return 'error'
def funnel(): if request.method == 'POST': request_data = request.get_json() if not isinstance(request_data, dict) or 'condition' not in request_data.keys(): return 'error' condition = request_data['condition'] if not isinstance(condition, list) or len(condition) > len(app.tables): return 'error' start = request_data['start'] if 'start' in request_data.keys() else 0 num = request_data['num'] if 'num' in request_data.keys() else 10 condition = sorted(condition, key=lambda x: x['id']) if 'funnel' not in app.current_result.keys() or app.current_result['funnel']['condition'] != condition: result_all, column_list = get_funnel_data(condition) app.current_result['funnel'] = { 'condition': condition, 'result': (result_all, column_list) } else: result_all, column_list = app.current_result['funnel']['result'] total = result_all.index.size end = start + num if start + num < total else total result = slice_df(result_all, start, end) response_data = dict() response_data['total'] = total response_data['next_start'] = end response_data['column_list'] = column_list response_data['data'] = result.to_dict('records') return json.dumps(response_data)
def get_column_list(): if request.method == 'POST': table_id = int(request.form['id']) tables = app.tables if table_id >= len(tables): return 'error' table = tables[table_id] column_list = table.get_column_list() return json.dumps(column_list) return 'error'
def load_data(): if request.method == 'POST': path = request.form['path'] try: table = Table(path) except: message = '请选择标准Excel文件' return json.dumps({'message': message, 'error': True}) status = table.check_columns() if status['error']: return status app.tables += [table] table_id = len(app.tables) - 1 return json.dumps({ "error": False, "id": table_id, "column_list": table.get_column_list() }) return 'error'
def load_data(): if request.method == 'POST': path = request.form['path'] table = Table(path) app.tables += [table] table_id = len(app.tables) - 1 return json.dumps({ "id": table_id, "column_list": table.get_column_list() }) return 'error'
def toComment(topic_id, content, ua, authorization): comment = GetComment(content) signal.alarm(10) print("Post:" + content) print("AI Response:" + comment) try: comment = input( "Do you agree with the response? Enter an alternative response or Do nothing and the response will be posted in 10 seconds:" ) except InputTimeoutError: print('\n Agree') text = "AI Response(Final):" + comment + "\n\n" print('\033[33;1m' + text + '\033[0m') signal.alarm(0) url = Community_toComment_Url postdata = { "content": comment, "referenced_id": -1, "diff_data": 1, "is_watermark": True, "topic_id": topic_id } para = json.dumps(postdata) req = urllib.request.Request(url, para.encode(encoding='UTF8')) req.add_header("User-Agent", ua) req.add_header("Authorization", authorization) req.add_header("Content-Type", "application/json;charset=UTF-8") data = urllib.request.urlopen(req).read().decode("utf-8") print(data) return comment
def start_process(): mongo_url = app.config['MONGODB_URL'] process = MongoClient.getProcesses(mongo_url) print("process ", process) if process is not None: MongoClient.updateProcesses(process.get("_id"), mongo_url, "2") Process.start_process(str(process.get("_id")), process.get("linksList"), mongo_url) MongoClient.updateProcesses(process.get("_id"), mongo_url, "0") data = {} data['urlList'] = process.get("linksList") data['process_id'] = str(process.get("_id")) json_data = json.dumps(data) print("urlList", json_data) headers = {'Content-Type': 'application/json'} requests.post(url='http://35.237.239.190:8080/api/index/create', headers=headers, data=json_data) print("post sent")
def get_table_rates(): if request.method == 'POST': table_id = int(request.form['id']) result = get_all_rate(table_id) return json.dumps(result) return 'error'