将 native/api/ 改名为 native/wndb/,避免与 Web API 层命名冲突
This commit is contained in:
@@ -149,7 +149,7 @@
|
|||||||
|-------|------------|---------------|-----------------|
|
|-------|------------|---------------|-----------------|
|
||||||
| **APIs** | § 1 QSG | § 2 SDG | `app/api/v1/` |
|
| **APIs** | § 1 QSG | § 2 SDG | `app/api/v1/` |
|
||||||
| **Database** | § 2 QSG | § 3 SDG | `app/infra/db/` |
|
| **Database** | § 2 QSG | § 3 SDG | `app/infra/db/` |
|
||||||
| **Native Code** | § 4 QSG | § 4 SDG | `app/native/api/` |
|
| **Native Code** | § 4 QSG | § 4 SDG | `app/native/wndb/` |
|
||||||
| **Auth** | § 3 QSG | § 5 SDG | `app/auth/` |
|
| **Auth** | § 3 QSG | § 5 SDG | `app/auth/` |
|
||||||
| **Config** | § 6 QSG | § 6 SDG | `app/core/config.py` |
|
| **Config** | § 6 QSG | § 6 SDG | `app/core/config.py` |
|
||||||
| **Testing** | § 7 QSG | § 7 SDG | `tests/` |
|
| **Testing** | § 7 QSG | § 7 SDG | `tests/` |
|
||||||
@@ -202,7 +202,7 @@ TJWaterServerBinary/
|
|||||||
5. **Permission Decorators**: See `app/auth/permissions.py` - RBAC
|
5. **Permission Decorators**: See `app/auth/permissions.py` - RBAC
|
||||||
6. **Config Management**: See `app/core/config.py` (82 lines) - Pydantic Settings
|
6. **Config Management**: See `app/core/config.py` (82 lines) - Pydantic Settings
|
||||||
7. **Database Pooling**: See `app/infra/db/postgresql/database.py` - async pools
|
7. **Database Pooling**: See `app/infra/db/postgresql/database.py` - async pools
|
||||||
8. **Native Integration**: See `app/native/api/__init__.py` - 100+ wrapped functions
|
8. **Native Integration**: See `app/native/wndb/__init__.py` - 100+ wrapped functions
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ async def get_reports(user: UserInDB = Depends(require_viewer)):
|
|||||||
## 4️⃣ Call Native (Binary) Code
|
## 4️⃣ Call Native (Binary) Code
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from app.native.api import get_all_junctions, add_junction, set_junction
|
from app.native.wndb import get_all_junctions, add_junction, set_junction
|
||||||
|
|
||||||
# Read network elements
|
# Read network elements
|
||||||
junctions = get_all_junctions()
|
junctions = get_all_junctions()
|
||||||
@@ -96,7 +96,7 @@ add_junction({"id": "J1", "x": 0.0, "y": 0.0, "demand": 100.0})
|
|||||||
set_junction("J1", {"demand": 150.0})
|
set_junction("J1", {"demand": 150.0})
|
||||||
|
|
||||||
# Get constants
|
# Get constants
|
||||||
from app.native.api import PIPE_STATUS_OPEN, OPTION_UNITS_LPS
|
from app.native.wndb import PIPE_STATUS_OPEN, OPTION_UNITS_LPS
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -174,7 +174,7 @@ pytest tests/unit/test_my_feature.py::test_my_function -v
|
|||||||
| `app/domain/` | Models/Schemas | Data structures |
|
| `app/domain/` | Models/Schemas | Data structures |
|
||||||
| `app/infra/db/` | DB access | Queries, repositories |
|
| `app/infra/db/` | DB access | Queries, repositories |
|
||||||
| `app/services/` | Business logic | Complex operations |
|
| `app/services/` | Business logic | Complex operations |
|
||||||
| `app/native/api/` | Binary functions | Network simulation |
|
| `app/native/wndb/` | Binary functions | Network simulation |
|
||||||
| `app/core/` | Core utilities | Config, security, encryption |
|
| `app/core/` | Core utilities | Config, security, encryption |
|
||||||
| `tests/` | Tests | Unit & integration tests |
|
| `tests/` | Tests | Unit & integration tests |
|
||||||
|
|
||||||
@@ -203,7 +203,7 @@ from app.core.encryption import get_encryptor
|
|||||||
from app.core.config import settings
|
from app.core.config import settings
|
||||||
|
|
||||||
# Native API
|
# Native API
|
||||||
from app.native.api import get_all_junctions, add_junction, open_project
|
from app.native.wndb import get_all_junctions, add_junction, open_project
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ TJWater integrates compiled C/Go binaries for water network simulation:
|
|||||||
```
|
```
|
||||||
Python (FastAPI)
|
Python (FastAPI)
|
||||||
↓
|
↓
|
||||||
app/native/api/
|
app/native/wndb/
|
||||||
├── project.py (list, create, delete, open projects)
|
├── project.py (list, create, delete, open projects)
|
||||||
├── s2_junctions.py (CRUD for junctions)
|
├── s2_junctions.py (CRUD for junctions)
|
||||||
├── s5_pipes.py (CRUD for pipes)
|
├── s5_pipes.py (CRUD for pipes)
|
||||||
@@ -290,7 +290,7 @@ app/native/api_encap/ (Low-level binary wrappers)
|
|||||||
|
|
||||||
#### 1. Native API Initialization
|
#### 1. Native API Initialization
|
||||||
```python
|
```python
|
||||||
# app/native/api/__init__.py
|
# app/native/wndb/__init__.py
|
||||||
from app.native.api_encap.api import (
|
from app.native.api_encap.api import (
|
||||||
ChangeSet, # Change tracking
|
ChangeSet, # Change tracking
|
||||||
API_ADD, API_UPDATE, API_DELETE, # Operations
|
API_ADD, API_UPDATE, API_DELETE, # Operations
|
||||||
@@ -302,7 +302,7 @@ from app.native.api_encap.api import (
|
|||||||
#### 2. Example: Project Management
|
#### 2. Example: Project Management
|
||||||
```python
|
```python
|
||||||
# app/services/tjnetwork.py
|
# app/services/tjnetwork.py
|
||||||
from app.native.api import list_project, open_project, close_project
|
from app.native.wndb import list_project, open_project, close_project
|
||||||
|
|
||||||
def list_project() -> list[str]:
|
def list_project() -> list[str]:
|
||||||
"""List all project databases"""
|
"""List all project databases"""
|
||||||
@@ -334,7 +334,7 @@ def update_junction(name: str, demand: float):
|
|||||||
#### 4. Network CRUD Operations
|
#### 4. Network CRUD Operations
|
||||||
```python
|
```python
|
||||||
# All operations follow this pattern:
|
# All operations follow this pattern:
|
||||||
from app.native.api import get_all_junctions, add_junction, set_junction
|
from app.native.wndb import get_all_junctions, add_junction, set_junction
|
||||||
|
|
||||||
# Read
|
# Read
|
||||||
junctions = get_all_junctions() # Returns list of dicts
|
junctions = get_all_junctions() # Returns list of dicts
|
||||||
@@ -357,7 +357,7 @@ app/api/v1/endpoints/simulation.py
|
|||||||
↓
|
↓
|
||||||
app/services/simulation.py (business logic)
|
app/services/simulation.py (business logic)
|
||||||
↓
|
↓
|
||||||
app/native/api/ (calls binary functions)
|
app/native/wndb/ (calls binary functions)
|
||||||
├── open_project("szh")
|
├── open_project("szh")
|
||||||
├── set_option("QUALITY", "CHEMICAL")
|
├── set_option("QUALITY", "CHEMICAL")
|
||||||
├── run_simulation()
|
├── run_simulation()
|
||||||
@@ -372,7 +372,7 @@ Response to client
|
|||||||
Native module exports constants for enumerations:
|
Native module exports constants for enumerations:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from app.native.api import (
|
from app.native.wndb import (
|
||||||
OPTION_UNITS_LPS, # Flow units
|
OPTION_UNITS_LPS, # Flow units
|
||||||
OPTION_PRESSURE_KPA, # Pressure units
|
OPTION_PRESSURE_KPA, # Pressure units
|
||||||
OPTION_QUALITY_CHEMICAL, # Quality type
|
OPTION_QUALITY_CHEMICAL, # Quality type
|
||||||
@@ -1004,7 +1004,7 @@ services:
|
|||||||
| **Repository** | `app/infra/repositories/` | Data access layer | psycopg cursor |
|
| **Repository** | `app/infra/repositories/` | Data access layer | psycopg cursor |
|
||||||
| **Domain** | `app/domain/` | Models & schemas | Pydantic, Enum |
|
| **Domain** | `app/domain/` | Models & schemas | Pydantic, Enum |
|
||||||
| **Services** | `app/services/` | Business logic | Python, native APIs |
|
| **Services** | `app/services/` | Business logic | Python, native APIs |
|
||||||
| **Native API** | `app/native/api/` | Binary integration | ctypes/cffi, .so/.dll |
|
| **Native API** | `app/native/wndb/` | Binary integration | ctypes/cffi, .so/.dll |
|
||||||
| **Config** | `app/core/config.py` | Settings management | Pydantic Settings |
|
| **Config** | `app/core/config.py` | Settings management | Pydantic Settings |
|
||||||
| **Security** | `app/core/security.py` | Encryption, hashing | cryptography, passlib |
|
| **Security** | `app/core/security.py` | Encryption, hashing | cryptography, passlib |
|
||||||
| **Audit** | `app/infra/audit/` | Operation logging | Middleware, Repository |
|
| **Audit** | `app/infra/audit/` | Operation logging | Middleware, Repository |
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from app.services.tjnetwork import *
|
from app.services.tjnetwork import *
|
||||||
from app.native.api.s36_wda_cal import *
|
from app.native.wndb.s36_wda_cal import *
|
||||||
# from get_real_status import *
|
# from get_real_status import *
|
||||||
from datetime import datetime,timedelta
|
from datetime import datetime,timedelta
|
||||||
from math import modf
|
from math import modf
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import psycopg
|
|||||||
|
|
||||||
import app.algorithms.api_ex.kmeans_sensor as kmeans_sensor
|
import app.algorithms.api_ex.kmeans_sensor as kmeans_sensor
|
||||||
import app.algorithms.api_ex.sensitivity as sensitivity
|
import app.algorithms.api_ex.sensitivity as sensitivity
|
||||||
from app.native.api.postgresql_info import get_pgconn_string
|
from app.native.wndb.postgresql_info import get_pgconn_string
|
||||||
from app.services.tjnetwork import dump_inp
|
from app.services.tjnetwork import dump_inp
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from app.algorithms.api_ex.run_simulation import (
|
|||||||
run_simulation_ex,
|
run_simulation_ex,
|
||||||
from_clock_to_seconds_2,
|
from_clock_to_seconds_2,
|
||||||
)
|
)
|
||||||
from app.native.api.project import copy_project
|
from app.native.wndb.project import copy_project
|
||||||
from app.services.epanet.epanet import Output
|
from app.services.epanet.epanet import Output
|
||||||
from app.services.scheme_management import store_scheme_info
|
from app.services.scheme_management import store_scheme_info
|
||||||
from app.services.tjnetwork import *
|
from app.services.tjnetwork import *
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from typing import List, Any
|
from typing import List, Any
|
||||||
from fastapi import APIRouter, Request, HTTPException
|
from fastapi import APIRouter, Request, HTTPException
|
||||||
from app.native.api import ChangeSet
|
from app.native.wndb import ChangeSet
|
||||||
from app.services.tjnetwork import (
|
from app.services.tjnetwork import (
|
||||||
get_all_extension_data_keys,
|
get_all_extension_data_keys,
|
||||||
get_all_extension_data,
|
get_all_extension_data,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from fastapi import APIRouter, Request, HTTPException
|
|||||||
from fastapi.responses import PlainTextResponse
|
from fastapi.responses import PlainTextResponse
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
import app.services.project_info as project_info
|
import app.services.project_info as project_info
|
||||||
from app.native.api import ChangeSet
|
from app.native.wndb import ChangeSet
|
||||||
from app.infra.db.postgresql.database import get_database_instance as get_pg_db
|
from app.infra.db.postgresql.database import get_database_instance as get_pg_db
|
||||||
from app.infra.db.timescaledb.database import get_database_instance as get_ts_db
|
from app.infra.db.timescaledb.database import get_database_instance as get_ts_db
|
||||||
from app.services.tjnetwork import (
|
from app.services.tjnetwork import (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
from fastapi import APIRouter, Request
|
from fastapi import APIRouter, Request
|
||||||
from app.native.api import ChangeSet
|
from app.native.wndb import ChangeSet
|
||||||
from app.services.tjnetwork import (
|
from app.services.tjnetwork import (
|
||||||
get_scada_info,
|
get_scada_info,
|
||||||
get_all_scada_info,
|
get_all_scada_info,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from fastapi import APIRouter, Request
|
from fastapi import APIRouter, Request
|
||||||
from app.native.api import ChangeSet
|
from app.native.wndb import ChangeSet
|
||||||
from app.services.tjnetwork import (
|
from app.services.tjnetwork import (
|
||||||
get_current_operation,
|
get_current_operation,
|
||||||
execute_undo,
|
execute_undo,
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import pytz
|
|||||||
import app.infra.db.influxdb.info as influxdb_info
|
import app.infra.db.influxdb.info as influxdb_info
|
||||||
import app.services.project_info as project_info
|
import app.services.project_info as project_info
|
||||||
import app.services.time_api as time_api
|
import app.services.time_api as time_api
|
||||||
from app.native.api.postgresql_info import get_pgconn_string
|
from app.native.wndb.postgresql_info import get_pgconn_string
|
||||||
|
|
||||||
# influxdb数据库连接信息
|
# influxdb数据库连接信息
|
||||||
url = influxdb_info.url
|
url = influxdb_info.url
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from contextlib import asynccontextmanager
|
|||||||
from typing import AsyncGenerator, Dict, Optional
|
from typing import AsyncGenerator, Dict, Optional
|
||||||
import psycopg_pool
|
import psycopg_pool
|
||||||
from psycopg.rows import dict_row
|
from psycopg.rows import dict_row
|
||||||
import app.native.api.postgresql_info as postgresql_info
|
import app.native.wndb.postgresql_info as postgresql_info
|
||||||
|
|
||||||
# Configure logging
|
# Configure logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import time
|
|||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from fastapi.logger import logger
|
from fastapi.logger import logger
|
||||||
import app.native.api.postgresql_info as postgresql_info
|
import app.native.wndb.postgresql_info as postgresql_info
|
||||||
import psycopg
|
import psycopg
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import logging
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
sys.path.append("..")
|
sys.path.append("..")
|
||||||
from app.native.api import project
|
from app.native.wndb import project
|
||||||
from app.native.api import inp_out
|
from app.native.wndb import inp_out
|
||||||
|
|
||||||
|
|
||||||
def _verify_platform():
|
def _verify_platform():
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import psycopg
|
|||||||
from psycopg import sql
|
from psycopg import sql
|
||||||
|
|
||||||
import app.services.project_info as project_info
|
import app.services.project_info as project_info
|
||||||
from app.native.api.postgresql_info import get_pgconn_string
|
from app.native.wndb.postgresql_info import get_pgconn_string
|
||||||
from app.services.tjnetwork import read_inp
|
from app.services.tjnetwork import read_inp
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import pandas as pd
|
|||||||
import psycopg
|
import psycopg
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
|
|
||||||
from app.native.api.postgresql_info import get_pgconn_string
|
from app.native.wndb.postgresql_info import get_pgconn_string
|
||||||
|
|
||||||
|
|
||||||
# 2025/03/23
|
# 2025/03/23
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from app.services.tjnetwork import *
|
from app.services.tjnetwork import *
|
||||||
from app.native.api.s36_wda_cal import *
|
from app.native.wndb.s36_wda_cal import *
|
||||||
|
|
||||||
# from get_real_status import *
|
# from get_real_status import *
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
@@ -20,7 +20,7 @@ import logging
|
|||||||
import app.services.globals as globals
|
import app.services.globals as globals
|
||||||
import uuid
|
import uuid
|
||||||
import app.services.project_info as project_info
|
import app.services.project_info as project_info
|
||||||
from app.native.api.postgresql_info import get_pgconn_string
|
from app.native.wndb.postgresql_info import get_pgconn_string
|
||||||
from app.infra.db.timescaledb.internal_queries import (
|
from app.infra.db.timescaledb.internal_queries import (
|
||||||
InternalQueries as TimescaleInternalQueries,
|
InternalQueries as TimescaleInternalQueries,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from math import pi
|
|||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
from app.algorithms.api_ex.run_simulation import run_simulation_ex
|
from app.algorithms.api_ex.run_simulation import run_simulation_ex
|
||||||
from app.native.api.project import copy_project
|
from app.native.wndb.project import copy_project
|
||||||
from app.services.epanet.epanet import Output
|
from app.services.epanet.epanet import Output
|
||||||
from app.services.tjnetwork import *
|
from app.services.tjnetwork import *
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
import app.native.api as api
|
import app.native.wndb as api
|
||||||
import app.services.epanet as epanet
|
import app.services.epanet as epanet
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
from app.services.tjnetwork import *
|
from app.services.tjnetwork import *
|
||||||
from app.native.api.project import copy_project
|
from app.native.wndb.project import copy_project
|
||||||
from app.algorithms.api_ex.run_simulation import run_simulation_ex, from_clock_to_seconds_2
|
from app.algorithms.api_ex.run_simulation import run_simulation_ex, from_clock_to_seconds_2
|
||||||
from math import sqrt, pi
|
from math import sqrt, pi
|
||||||
from app.services.epanet.epanet import Output
|
from app.services.epanet.epanet import Output
|
||||||
@@ -22,7 +22,7 @@ import app.algorithms.api_ex.kmeans_sensor as kmeans_sensor
|
|||||||
import app.algorithms.api_ex.flow_data_clean as flow_data_clean
|
import app.algorithms.api_ex.flow_data_clean as flow_data_clean
|
||||||
import app.algorithms.api_ex.pressure_data_clean as pressure_data_clean
|
import app.algorithms.api_ex.pressure_data_clean as pressure_data_clean
|
||||||
import app.algorithms.api_ex.sensitivity as sensitivity
|
import app.algorithms.api_ex.sensitivity as sensitivity
|
||||||
from app.native.api.postgresql_info import get_pgconn_string
|
from app.native.wndb.postgresql_info import get_pgconn_string
|
||||||
|
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user