Implement read api in data.py - to connect influxdb, fetch NSSI performance reports... 15/15315/1
authorsunil.n <sunil.n@samsung.com>
Wed, 26 Nov 2025 08:10:37 +0000 (13:40 +0530)
committersunil.n <sunil.n@samsung.com>
Wed, 26 Nov 2025 08:10:37 +0000 (13:40 +0530)
Change-Id: Iadb5f359695d9809b68fee392e2868800112ac20
Signed-off-by: sunil.n <sunil.n@samsung.com>
sample-rapp-generator/rapp-slice-prb-prediction/README.md
sample-rapp-generator/rapp-slice-prb-prediction/src/data.py

index 2543946..f027fe2 100644 (file)
@@ -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:
index fc85456..652fe8c 100644 (file)
@@ -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