def nowdata(): type_id = int(request.form['type_id']) ids = request.form['steps'] ids = ids.split('H') num = PI(c_int(len(ids))) id_array = (c_int * len(ids))() try: for i in range(len(id_array)): id_array[i] = int(ids[i]) except: abort(404) type_array = (c_int * len(ids))() for i in range(len(type_array)): type_array[i] = type_id timestamps = (c_longlong * len(ids))() sers = (Mydata.Serializer * len(ids))() err = lib.ReadNewDatas(handle, id_array, type_array, timestamps, sers, num) if err and err != -65275: current_app.logger.error("获取标签点最新数据失败,%d", err) abort(404) typeinfo = (Mydata.TypeInfo * 1)() err = lib.MyDataGetTypeByID(handle, type_id, typeinfo) if err: current_app.logger.error("获取指定类型失败,%d", err) abort(404) readable_datas = Mydata.TransformReadableData(typeinfo[0], timestamps, sers, current_app.logger) if readable_datas is None: abort(404) return jsonify(readable_datas)
def index(): table_num = PI(c_int(0)) err = lib.MyDataGetTableNum(handle, table_num) if err: current_app.logger.error("获取表数量失败,%d", err) table_info = (Mydata.TableInfo * table_num.contents.value)() err = lib.MyDataGetTables(handle, table_info, table_num) if err: current_app.logger.error("获取表信息失败,%d", err) table_num = table_num.contents.value return render_template('index.html', table_num=table_num, table_info=table_info)
def show_datafiles(): num = PI(c_int()) err = lib.GetDataFileNums(handle, num) if err: current_app.logger.error("获取数据文件数量失败,%d", err) dfinfo = (Mydata.DataFileInfo * num.contents.value)() err = lib.GetDataFileInfos(handle, dfinfo, num) if err: current_app.logger.error("获取数据文件信息失败,%d", err) return render_template('datafiles.html', dfinfo=dfinfo, titlename='数据文件信息', num=num.contents.value)
def show_types(): num = PI(c_int(0)) err = lib.MyDataGetTypeNum(handle, num) if err: current_app.logger.error("获取类型数量失败,%d", err) typeinfo = (Mydata.TypeInfo * num.contents.value)() err = lib.MyDataGetTypes(handle, typeinfo, num) if err: current_app.logger.error("获取类型信息失败,%d", err) typestrs = Mydata.Typeid2Typestr(typeinfo) return render_template('types.html', typeinfo=typeinfo, titlename='类型信息', num=num.contents.value, typestrs=typestrs)
def point(): tid = int(request.form['tid']) point_name = request.form['point_name'] num = PI(c_int(0)) err = lib.MyDataSearchPointsNumByID(handle, tid, c_char_p(point_name.encode('utf-8')), num) if err: current_app.logger.error("获取标签点数量失败,%d", err) abort(404) pointinfo = (Mydata.PointInfo * num.contents.value)() err = lib.MyDataSearchPointsByID(handle, tid, c_char_p(point_name.encode('utf-8')), pointinfo, num) return jsonify({'point_infos': [info.to_json() for info in pointinfo]})
def get_tables(): table_num = PI(c_int(0)) err = lib.MyDataGetTableNum(handle, table_num) if err: current_app.logger.error("获取表数量失败,%d", err) table_info = (Mydata.TableInfo * table_num.contents.value)() err = lib.MyDataGetTables(handle, table_info, table_num) if err: current_app.logger.error("获取表信息失败,%d", err) tables = [] for info in table_info: tables.append({ "id": info.id, "type_id": info.type_id, "name": info.name.decode() }) return jsonify({"tables": tables})
def alldatas(): type_id = int(request.form['type_id']) point_id = int(request.form['point_id']) start_time = c_longlong(int(request.form['start_time'])) end_time = c_longlong(int(request.form['end_time'])) num = PI(c_int()) lib.MyDataGetErrDesc.restype = c_char_p err = lib.ReadDatasNum(handle, point_id, start_time, end_time, num) if err: current_app.logger.error("获取数据数量失败,%d", err) return jsonify({ 'retcode': -1, 'errmsg': '获取数据数量失败,' + lib.MyDataGetErrDesc(err).decode('gbk') }) timestamps = (c_longlong * num.contents.value)() sers = (Mydata.Serializer * num.contents.value)() err = lib.ReadDatas(handle, point_id, type_id, start_time, end_time, timestamps, sers, num) if err: current_app.logger.error("获取数据失败,%d", err) return jsonify({ 'retcode': -1, 'errmsg': '获取数据失败,' + lib.MyDataGetErrDesc(err).decode('gbk') }) typeinfo = (Mydata.TypeInfo * 1)() err = lib.MyDataGetTypeByID(handle, type_id, typeinfo) if err: current_app.logger.error("获取指定类型失败,%d", err) return jsonify({ 'retcode': -1, 'errmsg': '获取指定类型失败,' + lib.MyDataGetErrDesc(err).decode('gbk') }) readable_datas = Mydata.TransformReadableData(typeinfo[0], timestamps, sers, current_app.logger) if readable_datas is None: return jsonify({'retcode': -1, 'errmsg': '数据解析失败'}) return jsonify(readable_datas)