1 # ==================================================================================
2 # Copyright (c) 2020 AT&T Intellectual Property.
3 # Copyright (c) 2020 HCL Technologies Limited.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ==================================================================================
17 from influxdb import DataFrameClient
22 class NoDataError(Exception):
26 class DATABASE(object):
28 def __init__(self, dbname, user='root', password='root', host='r4-influxdb.ricplt', port='8086'):
29 self.client = DataFrameClient(host, port, user, password, dbname)
32 def read_data(self, meas='ueMeasReport', limit=100000, cellid=False, ueid=False):
33 query = """select * from """ + meas
36 query += " where nrCellIdentity= '" + cellid + "'"
39 query += """ where "ue-id" = \'{}\'""".format(ueid)
40 query += " ORDER BY DESC LIMIT " + str(limit)
41 result = self.client.query(query)
44 # print("Querying data : " + meas + " : size - " + str(len(result[meas])))
45 self.data = result[meas]
46 self.data['measTimeStampRf'] = self.data.index
52 print('Data not found for ' + meas + ' CellID : '+cellid)
54 print('Data not found for ' + meas + ' UEID : '+ueid)
56 print('Data not found for ' + meas)
59 def write_prediction(self, df, meas_name='QP'):
60 df.index = pd.date_range(start=datetime.datetime.now(), freq='10ms', periods=len(df))
61 self.client.write_points(df, meas_name)
67 self.ue = pd.DataFrame([[1002, "c2/B13", 8, 69, 65, 113, 0.1, 0.1, "Waiting passenger 9", -882, -959, pd.to_datetime("2021-05-12T07:43:51.652")]], columns=["du-id", "nbCellIdentity", "prb_usage", "rsrp", "rsrq", "rssinr", "throughput", "targetTput", "ue-id", "x", "y", "measTimeStampRf"])
68 self.cell = pd.read_csv('qp/dummy.csv')
71 def read_data(self, meas='ueMeasReport', limit=100000, cellid=False, ueid=False):
73 self.data = self.ue.head(limit)
75 self.data = self.cell.head(limit)
77 def write_prediction(self, df, meas_name='QP'):