| | |
| | | # 约束 |
| | | - 应用过程标识:应用过程标识就是APID,一般会在名称后的括号中列出来; |
| | | - code:指令代号,没有就空着; |
| | | - name:指令名称,根据表格内容提取,注意名称需要提取完整,如果有多列则合并用-分割; |
| | | - 应用数据区:提取表格中的应用数据区内容。 |
| | | # 输出例子: |
| | | [{ |
| | |
| | | {"start": "起始字段code", "end": "结束字段code", "formula": "计算公式"} |
| | | - start:起始字段code,长度包括起始字段,字段描述中说明了起始字段, |
| | | - end:结束字段code,长度包括结束字段,字段描述中说明了结束字段, |
| | | - formula:计算公式,如果没有计算相关描述则表示不需要计算公式。 |
| | | - formula:计算公式,如果没有长度特殊计算相关描述则使用BYTES。 |
| | | 计算公式定义: |
| | | - BYTES:按字节计算; |
| | | - BYTES:按字节计算,字节数; |
| | | - N-x:总字节数减x,例如总字节数减1的公式为N-1。 |
| | | |
| | | # 字段类型分析方法 |
| | |
| | | - length 自动转换为bit长度,必须是数值、null或范围定义,不能为0; |
| | | - value 根据字段描述提取字段值,字段值一般为数值类型,需要根据字段类型来分析,如果是length类型value的值为范围定义; |
| | | - enums 枚举类型的字段必须要有enums,根据字段描述提取,枚举元素的数据结构为{"n":"","v":"","c":""}; |
| | | - length类型的范围定义中的start和end必须是生成结果中的字段code; |
| | | - length类型字段的范围定义中的start和end必须是生成结果中的字段code,长度包括start和end,必须使用长度描述中的字段; |
| | | - 输出数据结构为数组,数组元素为字段信息; |
| | | - 输出内容必须为严格的json,不能输出除json以外的任何内容。 |
| | | |
| | |
| | | "code": "para2", |
| | | "length": 8, |
| | | "type": "length", |
| | | "value": {"start": "para1", "end": "data", "formula": "BYTES"} |
| | | "value": {"start": "data", "end": "data", "formula": "BYTES"} |
| | | }, |
| | | { |
| | | "name": "数据", |
New file |
| | |
| | | # -*- coding: utf-8 -*- |
| | | # |
| | | # @author: |
| | | # @date: |
| | | # @version: |
| | | # @description: |
| | | |
| | | from fastapi import FastAPI, UploadFile |
| | | import asyncio |
| | | import os |
| | | from knowledgebase import utils |
| | | from knowledgebase.log import Log |
| | | |
| | | UPLOAD_FILE_PATH = "upload_files" |
| | | if not utils.file_exists(UPLOAD_FILE_PATH): |
| | | os.mkdir(UPLOAD_FILE_PATH) |
| | | |
| | | app = FastAPI(swagger_ui_parameters={"syntaxHighlight": False}) |
| | | |
| | | |
| | | @app.get("/") |
| | | async def read_root(): |
| | | return {"Hello": "World"} |
| | | |
| | | |
| | | # 上传文件,保存文件到本地,返回md5 |
| | | @app.post("/UploadFile/") |
| | | async def upload_file(file: UploadFile): |
| | | data = await file.read() |
| | | md5 = await utils.get_md5_async(data) |
| | | ext = os.path.splitext(file.filename)[1] |
| | | save_path = f'./upload_files/{md5}{ext}' |
| | | Log.info(f'上传文件:{file.filename},md5: {md5}') |
| | | |
| | | await utils.save_to_file_async(data, save_path) |
| | | return {"md5": md5} |
| | |
| | | 保存缓存。 |
| | | """ |
| | | text = json.dumps(self.cache) |
| | | utils.save_to_file(text, self.cache_file) |
| | | utils.save_text_to_file(text, self.cache_file) |
| | | |
| | | def run(self, in_text: str) -> list[str]: |
| | | """ |
| | |
| | | import os |
| | | import json |
| | | import re |
| | | import asyncio |
| | | |
| | | |
| | | def get_bit_mask(start, end): |
| | |
| | | |
| | | return md5_digest |
| | | |
| | | |
| | | def generate_bytes_md5(input_bytes): |
| | | # 创建一个 md5 哈希对象 |
| | | md5_hash = hashlib.md5() |
| | |
| | | |
| | | return md5_digest |
| | | |
| | | |
| | | async def get_md5_async(file: bytes): |
| | | md5 = await asyncio.to_thread(generate_bytes_md5, file) |
| | | return md5 |
| | | |
| | | |
| | | async def save_to_file_async(data: bytes, file_path: str): |
| | | await asyncio.to_thread(save_bytes_to_file, data, file_path) |
| | | |
| | | |
| | | def file_exists(cache_file: str): |
| | | return os.path.exists(cache_file) |
| | | |
| | | |
| | | def read_from_file(cache_file: str) -> str: |
| | | with open(cache_file, 'r', encoding='utf-8') as f: |
| | | def read_from_file(file: str) -> str: |
| | | with open(file, 'r', encoding='utf-8') as f: |
| | | text = f.read() |
| | | return text |
| | | |
| | | |
| | | def save_to_file(text, cache_file): |
| | | with open(cache_file, 'w', encoding='utf-8') as f: |
| | | def save_text_to_file(text: str, file: str): |
| | | with open(file, 'w', encoding='utf-8') as f: |
| | | f.write(text) |
| | | |
| | | |
| | | def save_bytes_to_file(bytes_data: bytes, file: str): |
| | | with open(file, 'wb') as f: |
| | | f.write(bytes_data) |
| | | |
| | | |
| | | def replace_tpl_paras(tpl_text: str, data: dict): |
| | | for key, val in data.items(): |
| | | if not isinstance(val, str): |