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 # ==================================================================================
19 This module is temporary which aims to populate cell data into influxDB. This will be depreciated once KPIMON push cell info. into influxDB.
23 from influxdb import DataFrameClient
30 host = 'r4-influxdb.ricplt'
31 self.client = DataFrameClient(host, '8086', 'root', 'root')
32 self.switchdb('UEData')
35 def switchdb(self, dbname):
36 print("Switch database: " + dbname)
37 self.client.switch_database(dbname)
39 def dropmeas(self, measname):
40 print("DROP MEASUREMENT: " + measname)
41 self.client.query('DROP MEASUREMENT '+measname)
45 for col in df.columns:
46 if isinstance(df.iloc[0][col], list):
48 d = df[col].apply(pd.Series)
50 df = df.drop(col, axis=1)
55 df.index = range(len(df))
56 cols = [col for col in df.columns if isinstance(df.iloc[0][col], dict) or isinstance(df.iloc[0][col], list)]
60 d = explode(pd.DataFrame(df[col], columns=[col]))
61 d = d.dropna(axis=1, how='all')
62 df = pd.concat([df, d], axis=1)
63 df = df.drop(col, axis=1).dropna()
64 return jsonToTable(df)
68 df.index = pd.date_range(start=datetime.datetime.now(), freq='10ms', periods=len(df))
69 df['measTimeStampRf'] = df['measTimeStampRf'].apply(lambda x: str(x))
74 df = pd.read_json('qp/cell.json.gz', lines=True)
75 df = df[['cellMeasReport']].dropna()
79 db.client.write_points(df, 'liveCell', batch_size=500, protocol='line')