-
Notifications
You must be signed in to change notification settings - Fork 4
/
ETABS_driftTable.py
103 lines (78 loc) · 3.48 KB
/
ETABS_driftTable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 11 11:28:16 2020
@author: Andrew-V.Young
"""
import sys
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton, QLabel, QTextEdit, QFileDialog, QApplication
import pandas as pd
from openpyxl import load_workbook
def reformat_drift_table(inFileName = 'Book1.xlsx'):
# function to reformat story drift spreadsheet created by etabs
ofile = pd.read_excel(inFileName, header = 1)
# remove first and third row which are etabs titles
delete_rows = [0, 2]
rmvTitleRows = ofile.drop(delete_rows)
# insert initial excel row number
excelRow = rmvTitleRows.apply(lambda row: row.name + len(delete_rows) + 1, axis = 1)
rmvTitleRows.insert(0,'Initial Row', excelRow, True)
# filter for only rows that contain drift combos
driftRows = rmvTitleRows.loc[rmvTitleRows['Load Case/Combo'].str.contains('drift', case = False)]
# calculate story drift DCR
maxDrift = 0.01
dcrSeries = driftRows.apply(lambda row: row.Drift/maxDrift, axis = 1)
# insert DCR column and sort largest to smallest
driftRows.insert(len(driftRows.columns), 'DCR', dcrSeries, True)
dfSort = driftRows.sort_values(by=['DCR'], ascending = False)
# print(dfSort.head())
book = load_workbook(inFileName) # new data entry without deleting existing
# add sorted data to new sheet
with pd.ExcelWriter(inFileName, engine = 'openpyxl') as writer:
writer.book = book
dfSort.to_excel(writer, sheet_name = 'Drift Sorted')
writer.save()
writer.close()
return 'reformatting complete'
class get_file_dialog(QWidget):
def __init__(self, parent=None):
super(get_file_dialog, self).__init__(parent)
self.initUI()
def initUI(self):
# add window title and prompt label text
self.setWindowTitle("Story Drift Reformatting Tool")
layout = QVBoxLayout()
self.le = QLabel("Select Story Drift File To Reformat")
layout.addWidget(self.le)
# add button to open file name, connect to open file function
self.btn = QPushButton("Choose File")
self.btn.clicked.connect(lambda: self.getfile())
layout.addWidget(self.btn)
# add text box to use as status notification, enter initial text
self.statustext = QTextEdit()
self.statustext.setText('Please use button above to choose a file')
layout.addWidget(self.statustext)
self.setLayout(layout)
def getfile(self):
# function that pulls up get open file name window and re-formats selected file
dlg = QFileDialog()
dlg.setFileMode(QFileDialog.AnyFile)
dlg.setNameFilter("Excel files (*.xlsx)")
# open window and extract file name from outputs
fileName, others = dlg.getOpenFileName(self, "Choose File")
# run reformatting if file chosen, otherwise no action
if fileName:
mess1 = "Selected File: \n %s \n\n" % fileName
file_format = reformat_drift_table(fileName)
self.statustext.setText(mess1 + file_format)
else:
not_opened = "No file was opened"
self.statustext.setText(not_opened)
# set up main application with get_file_dialog widget
def main():
app = QApplication(sys.argv)
ex = get_file_dialog()
ex.show()
sys.exit(app.exec_())
# run widget
if __name__ == '__main__':
main()