Release 0.0.6
[ric-app/qp.git] / insert.py
1 # ==================================================================================
2 #  Copyright (c) 2020 HCL Technologies Limited.
3 #
4 #  Licensed under the Apache License, Version 2.0 (the "License");
5 #  you may not use this file except in compliance with the License.
6 #  You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #  Unless required by applicable law or agreed to in writing, software
11 #  distributed under the License is distributed on an "AS IS" BASIS,
12 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #  See the License for the specific language governing permissions and
14 #  limitations under the License.
15 # ==================================================================================
16
17 """
18 This Module is temporary for pushing data into influxdb before dpeloyment of QP xApp. It will depreciated in future, when data will be coming through KPIMON
19 """
20
21 import datetime
22 import time
23 import pandas as pd
24 from src.database import DATABASE
25 from configparser import ConfigParser
26
27
28 class INSERTDATA(DATABASE):
29
30     def __init__(self):
31         super().__init__()
32         self.connect()
33
34     def createdb(self, dbname):
35         print("Create database: " + dbname)
36         self.client.create_database(dbname)
37         self.client.switch_database(dbname)
38
39     def dropdb(self, dbname):
40         print("DROP database: " + dbname)
41         self.client.drop_database(dbname)
42
43     def dropmeas(self, measname):
44         print("DROP MEASUREMENT: " + measname)
45         self.client.query('DROP MEASUREMENT '+measname)
46
47     def assign_timestamp(self, df):
48         steps = df['measTimeStampRf'].unique()
49         for timestamp in steps:
50             d = df[df['measTimeStampRf'] == timestamp]
51             d.index = pd.date_range(start=datetime.datetime.now(), freq='1ms', periods=len(d))
52             self.client.write_points(d, self.cellmeas)
53             time.sleep(0.4)
54
55
56 def populatedb():
57     # inintiate connection and create database UEDATA
58     db = INSERTDATA()
59     df = pd.read_csv('src/cells.csv')
60     print("Writinig data into influxDB")
61     while True:
62         db.assign_timestamp(df)
63
64
65 if __name__ == "__main__":
66     populatedb()