Files
InterferenceETL/README.md
T

10 KiB

InterferenceETL

InterferenceETL follows the newest interference KPI time group in the configured file source. It reads seven ZIP/XLSX source types, converts each Sheet0 to CSV, and creates one merged high-interference summary. It runs as a hosted app in Metrix App Hosting with an admin page at /admin.

Source file names are identified by one of the seven fixed prefixes plus a final _YYYYMMDDHHMMHHMM.zip; text between the prefix and time is unrestricted. Only the first YYYYMMDDHHMM start time is used for grouping. Start times are rounded down to natural 15-minute boundaries, so 12:00 through 12:14 belong to 12:00. This also works unchanged when all providers switch together to hourly or daily delivery.

Every run follows only the group containing the newest source start time. It never falls back or backfills an older group. If any source type is missing, the run reports status=waiting with the missing types and ends successfully. When one source has multiple files in the group, its latest start time wins.

Output

Each run writes one window directory:

output/20260731100000/
├── converted/
│   ├── 5G下FDD干扰监控_2026073110001100.csv
│   ├── 5G干扰监控_2026073110001100.csv
│   └── ... seven source CSV files
├── interference_summary_20260731100000.csv
└── manifest.json

For every processed group, the run also reads the latest filename-dated XLSX from each configured CellData directory. It builds CellData CGI as 460-00-{eNB/gNB}-{CI} and adds coordinates plus direction angle to matching interference rows. Unmatched rows keep empty coordinates and use 0 for azimuth.

In each CellData directory, only XLSX files ending with a valid YYYYMMDD.xlsx date are considered, and the latest date is selected. CellData column 方向角 maps to summary/database column azimuth; an empty source value becomes 0. Parsing these workbooks is the slow part of a run, so the parsed result of each workbook is kept in /data/cache/cell-data/, named after the SHA-256 of the workbook bytes. A workbook is parsed again whenever its content changes; entries that the latest run did not use are removed.

The summary columns are:

metric_time,network_type,cgi,cell_name,interference_dbm,prev_interference_dbm,longitude,latitude,azimuth,nearby_count,nearby_26g,nearby_700m,nearby_tdd,nearby_fdd,prev_nearby_count,prev_nearby_26g,prev_nearby_700m,prev_nearby_tdd,prev_nearby_fdd

All selected workbook rows must belong to the selected natural 15-minute group. Every summary row receives the same normalized metric_time; a row outside the group fails the run before database or history output.

network_type is derived from the seven source types: 5G干扰监控 is 2.6G, 700M干扰监控 is 700M, SDR_TDD干扰监控 and 反开RD干扰监控 are TDD, and SDR_FDD干扰监控, 5G下FDD干扰监控, and 700M下FDD干扰监控 are FDD. The summary and database keep only high-interference rows. Thresholds keep the original directory grouping and are independent of the network_type label: the two 5G... sources use >= -107 dBm, and the other five sources use >= -110 dBm. Converted source CSV files remain full source conversions.

nearby_count is the number of other high-interference cells from the same selected time group within 1 km, across all network types. The cell itself is excluded, the 1 km boundary is included, and rows without coordinates use 0. Candidate cells are found through a 1 km spatial grid index and confirmed with exact Haversine distance.

nearby_26g, nearby_700m, nearby_tdd, and nearby_fdd split the same neighbors by the neighbor's network_type. Each field defaults to 0, and the four values always add up to nearby_count.

When multiple retained source rows have the same CGI, the summary keeps the row with the numerically largest interference value. Equal values keep the first row encountered. Deduplication happens before nearby-cell counting and database insertion; converted source CSVs remain complete.

prev_interference_dbm, prev_nearby_count, and the four prev_nearby_26g/700m/tdd/fdd fields come from the previously retained database time, matched by CGI before the current batch replaces old rows. They represent the same cell's previous-period interference value and nearby high-interference counts. On the first run, or when a CGI did not exist in the previous period, these fields are empty in CSV/history output and NULL in MySQL.

A run never modifies or deletes source ZIP or CellData files. Before downloading source ZIP files or CellData, it compares the normalized target time with the database. A target already present, or older than the database, is not processed again.

The database table contains normalized metric_time DATETIME, network_type VARCHAR(16), interference_dbm DECIMAL(10,3), nullable prev_interference_dbm DECIMAL(10,3), nullable longitude and latitude, azimuth DECIMAL(6,2) NOT NULL DEFAULT 0, the five NOT NULL DEFAULT 0 INT count columns (nearby_count, nearby_26g, nearby_700m, nearby_tdd, nearby_fdd), and the five nullable INT previous-period count columns (prev_nearby_count, prev_nearby_26g, prev_nearby_700m, prev_nearby_tdd, prev_nearby_fdd). A successful transaction replaces the target batch and deletes every other database time, so the table retains only the latest processed group. The previous-period values are read before this replacement transaction. The database and table are created automatically when they do not exist.

After the database succeeds, the same nineteen result columns are uploaded as GBK CSV to the history directory:

/网优日常优化数据文档/(勿删)干扰定时小时指标/干扰历史数据/YYYY-MM-DD/干扰数据处理结果_YYYYMMDDHHMMSS.csv

The filename time comes from normalized metric_time, never the server clock. If the database already contains the target time but its history CSV is missing or empty, the run exports that time from the database and repairs the history file without reprocessing source data.

History retention reads the directory and file names, not file modification times. It keeps the latest 7 calendar days by default and deletes older date directories and result files from the file source. It runs after a new group has been stored; a failure there is written to the run log and does not fail the run. Set the retention days to 0 to keep everything.

Only the history CSV uses GBK without a UTF-8 BOM. Source non-breaking spaces (U+00A0) are normalized to ordinary spaces in this history file because GBK cannot encode them; other unsupported characters still fail visibly. The seven local converted CSV files and local merged summary remain UTF-8 with BOM, and manifest.json remains UTF-8 JSON.

CGI is generated with fixed rules:

  • NR (5G干扰监控, 700M干扰监控): {gNBplmn}-{gNBId}-{cellId}.
  • 4G (the other five source types): 460-00-{eNodeBID}-{小区ID}, using each source schema's actual equivalent column names.

Metrix hosted app

InterferenceETL runs as one long-lived container in Metrix App Hosting. A FastAPI + NiceGUI admin page at /admin (Metrix account, app admin role only) edits every setting, shows the live log, keeps the run history and browses the summary table with server-side paging (GET /api/data?page=&page_size=20|50|100&network=&q=&sort=). The app has no user page: its manifest declares user_auth: none, so the hosting list shows only the admin entry and Metrix admits app admins only on every path.

The schedule runs inside the same container with APScheduler (fixed interval in minutes or a 5-field cron expression, timezone Asia/Shanghai). Each run is a child Python process inside that container, so no extra containers are started; one run at a time, with a per-run timeout.

Settings live on the app data volume and are edited only through the admin page:

  • Source storage: Metrix storage API, or direct FTP / SFTP (host, port, account, FTP encoding and passive mode).
  • Database: Metrix database connection API, or direct MySQL (host, port, account). Database and table names are configurable.
  • Metrix API address and token are required only when either side uses the Metrix API.
  • Source root, history CSV directory (optional), CellData directories, lookback days and retention.

Passwords and tokens are written to /data/settings.json (mode 0600) and never returned to the browser; a blank field keeps the saved value. Run records are in /data/runs.db, run logs in /data/logs/, local outputs in /data/output/ (newest 48 kept by default), parsed CellData in /data/cache/cell-data/.

The page content is sent over a live connection (WebSocket, with HTTP long-polling as the fallback). While that connection is being set up the page shows a connecting notice. If it stays there, something between the browser and Metrix is blocking the connection, for example a capture proxy set as the system proxy.

Build the app bundle on a machine with docker, then upload it in App Hosting:

python scripts\package_metrix.py

The bundle dist/metrix/interference-etl-<version>.zip contains metrix-app.json, icon.svg and image.tar built from deploy/Dockerfile. --pip-index and --python-image override the package index and base image. The schedule starts paused; enable it from the overview page after the connection test passes.

Local development

python -m pip install -r requirements-app.txt
python -m unittest discover -s tests -v
$env:METRIX_APP_DATA_DIR = "Temp\appdata"; $env:ETL_DEV_ADMIN = "1"; $env:PORT = "18090"
python -m etl_app.server

ETL_DEV_ADMIN=1 grants admin access only when no Metrix proxy token is configured.

To process a local copy of the source tree into CSV files without a database:

python main.py --source-dir C:\path\to\exported-tree --output-dir output

Use --window 2026073110001100 to select the natural 15-minute group containing that source start time. Without it, the newest observed source start time determines the group. Incomplete groups wait and never fall back.