mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-01 19:28:00 +00:00
kpi_csv_sq.py : make class based
csv_sqlite.py : naming changes Signed-off-by: Chuck SmileyRekiere <chuck.smileyrekiere@candelatech.com>
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
'''
|
||||
File: will search sub diretories for kpi.csv and place the data into an sqlite database
|
||||
|
||||
File: will search path recursivly for kpi.csv and place into sqlite database
|
||||
Usage: csv_sqlite.py --path <path to directories to traverse> --database <name of database>
|
||||
'''
|
||||
|
||||
@@ -19,39 +17,28 @@ class csv_to_sqlite():
|
||||
def __init__(self,
|
||||
_path = '.',
|
||||
_file = 'kpi.csv',
|
||||
_database = 'test_db'):
|
||||
_database = 'qa_db',
|
||||
_table = 'qa_table'):
|
||||
self.path = _path
|
||||
self.file = _file
|
||||
self.database = _database
|
||||
self.table = _table
|
||||
|
||||
# information on sqlite database
|
||||
# https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_sql.html
|
||||
def store(self):
|
||||
print(self.path)
|
||||
path = Path(self.path)
|
||||
print(path)
|
||||
#path = Path('./test_data3')
|
||||
#path = Path('test_data3')
|
||||
#print(path)
|
||||
#quit(1)
|
||||
|
||||
kpi_list = list(path.glob('**/{}'.format(self.file)))
|
||||
#kpi_list = list(path.glob('**/kpi.csv'))
|
||||
print(kpi_list)
|
||||
print("lenth kpi_list {}".format(len(kpi_list)))
|
||||
|
||||
df = pd.DataFrame()
|
||||
|
||||
for kpi in kpi_list:
|
||||
# load data
|
||||
append_df = pd.read_csv(kpi, sep='\t')
|
||||
df = df.append(append_df, ignore_index=True)
|
||||
|
||||
# information on sqlite database
|
||||
# https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_sql.html
|
||||
|
||||
print(self.database)
|
||||
conn = sqlite3.connect(self.database)
|
||||
#data may be appended setting if_exists='append'
|
||||
df.to_sql("dp_table",conn,if_exists='replace')
|
||||
df.to_sql(self.table,conn,if_exists='replace')
|
||||
conn.close()
|
||||
|
||||
def main():
|
||||
@@ -63,7 +50,6 @@ def main():
|
||||
read kpi.csv into sqlit database
|
||||
|
||||
''',
|
||||
|
||||
description='''\
|
||||
File: will search path recursivly for kpi.csv and place into sqlite database
|
||||
Usage: csv_sqlite.py --path <path to directories to traverse> --database <name of database>
|
||||
@@ -71,18 +57,21 @@ Usage: csv_sqlite.py --path <path to directories to traverse> --database <name o
|
||||
''')
|
||||
parser.add_argument('--path', help='--path ./top directory path to kpi',required=True)
|
||||
parser.add_argument('--file', help='--file kpi.csv',default='kpi.csv')
|
||||
parser.add_argument('--database', help='--database qa_test_db',default='qa_test_db')
|
||||
parser.add_argument('--database', help='--database qa_db',default='qa_db')
|
||||
parser.add_argument('--table', help='--table qa_table',default='qa_table')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
__path = args.path
|
||||
__file = args.file
|
||||
__database = args.database
|
||||
__table = args.table
|
||||
|
||||
csv_sqlite = csv_to_sqlite(
|
||||
_path = __path,
|
||||
_file = __file,
|
||||
_database = __database)
|
||||
_database = __database,
|
||||
_table= __table)
|
||||
|
||||
csv_sqlite.store()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user