From b61029caf8cab95e151337bd3d991ef3f5dcb58b Mon Sep 17 00:00:00 2001 From: "sunil.n" Date: Wed, 26 Nov 2025 13:40:37 +0530 Subject: [PATCH] Implement read api in data.py - to connect influxdb, fetch NSSI performance reports for predictions Change-Id: Iadb5f359695d9809b68fee392e2868800112ac20 Signed-off-by: sunil.n --- .../rapp-slice-prb-prediction/README.md | 25 ++++++++++++++++++++++ .../rapp-slice-prb-prediction/src/data.py | 19 +++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/sample-rapp-generator/rapp-slice-prb-prediction/README.md b/sample-rapp-generator/rapp-slice-prb-prediction/README.md index 2543946..f027fe2 100644 --- a/sample-rapp-generator/rapp-slice-prb-prediction/README.md +++ b/sample-rapp-generator/rapp-slice-prb-prediction/README.md @@ -240,6 +240,31 @@ else: - Implements automatic retry delay to handle temporary network issues - Logs InfluxDB version information for debugging compatibility issues +#### Data Query Methods + +##### read_data() +The `read_data()` method enables fetching performance monitoring data from InfluxDB using Flux query language. This method constructs dynamic queries based on configuration parameters and retrieves time-series data for PRB prediction analysis. + +**Usage Example:** +```python +# Initialize database and connect +db = DATABASE() +if db.connect(): + # Fetch performance data + data = db.read_data() + # Process the retrieved data for model training or prediction + print(f"Retrieved {len(data)} records") +else: + logger.error("Cannot fetch data - database connection failed") +``` + +**Expected Data Structure:** +The method returns a pandas DataFrame with the following structure: +- `_time`: Timestamp of the measurement +- `{tag_slice_type}`: Slice type (eMBB, URLLC, mMTC) +- `{tag_nssi_id}`: Network Slice Subnet Instance identifier +- KPI fields as configured in `field_names` (PRB usage, data volume, RRC connections) + #### Integration with RAPP Architecture The DATABASE class serves as the foundation for all data operations in the RAPP: diff --git a/sample-rapp-generator/rapp-slice-prb-prediction/src/data.py b/sample-rapp-generator/rapp-slice-prb-prediction/src/data.py index fc85456..652fe8c 100644 --- a/sample-rapp-generator/rapp-slice-prb-prediction/src/data.py +++ b/sample-rapp-generator/rapp-slice-prb-prediction/src/data.py @@ -80,4 +80,21 @@ class DATABASE(object): except (RequestException, ConnectionError): logger.error("Failed to establish a new connection with InflulxDB, Please check your url/hostname") - time.sleep(120) \ No newline at end of file + time.sleep(120) + + def read_data(self): + # Fetch Data from InfluxDB + fields_filter = " or ".join([f'r["_field"] == "{f}"' for f in self.field_names]) + query = f''' + from(bucket: "{self.bucket}") + |> range(start: {self.time_range}) + |> filter(fn: (r) => r["_measurement"] == "{self.measurements}") + |> filter(fn: (r) => {fields_filter}) + |> tail(n:{self.window_size}) + |> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value") + |> keep(columns: ["_time", "{self.tag_slice_type}", "{self.tag_nssi_id}", "{'","'.join(self.field_names)}"]) + |> sort(columns: ["_time"]) + ''' + + result = self.query(query) + return result \ No newline at end of file -- 2.16.6