Many Changes
This commit is contained in:
+43
-15
@@ -8,7 +8,7 @@ from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
|
||||
def get_filtered_server(customer_id, service_id, service_status):
|
||||
def get_filtered_server(customer_ids, service_id, service_status, os_type, reporting):
|
||||
mydb = mysql.connector.connect(
|
||||
host=os.getenv("MYSQL_HOST"),
|
||||
user=os.getenv("MYSQL_USER"),
|
||||
@@ -18,23 +18,30 @@ def get_filtered_server(customer_id, service_id, service_status):
|
||||
|
||||
# Prepare the base query
|
||||
query = f"""
|
||||
select s.hostname,s.privat_ipaddress,s.public_ipaddress, s.ram, s.createdate, s.disabledate,s.customer_ID,s.server_ID,hc.name,hc.core
|
||||
select s.hostname, s.privat_ipaddress, s.public_ipaddress, s.ram, s.createdate, s.disabledate, s.os, s.customer_ID, s.server_ID, hc.name, hc.core
|
||||
from Kunden.server s
|
||||
join Kunden.`hardware.cpu` hc ON hc.cpu_ID = s.cpu_ID
|
||||
WHERE 1=1
|
||||
"""
|
||||
if customer_id:
|
||||
query += f"AND s.customer_ID = {customer_id}"
|
||||
|
||||
# If multiple customers are selected, use the IN clause
|
||||
if customer_ids:
|
||||
customer_ids_str = ', '.join([str(id) for id in customer_ids])
|
||||
query += f" AND s.customer_ID IN ({customer_ids_str})"
|
||||
|
||||
if service_id:
|
||||
query += f" AND s.service_ID = {service_id}"
|
||||
if service_status:
|
||||
query += f" AND s.status = {service_status}"
|
||||
if os_type:
|
||||
query += f" AND s.os = '{os_type}'"
|
||||
if reporting == "True":
|
||||
query += f" AND licensekey IS NOT NULL"
|
||||
|
||||
users = pd.read_sql_query(query, mydb)
|
||||
mydb.close()
|
||||
return users
|
||||
|
||||
|
||||
def get_initial_data():
|
||||
mydb = mysql.connector.connect(
|
||||
host=os.getenv("MYSQL_HOST"),
|
||||
@@ -60,7 +67,6 @@ def get_initial_data():
|
||||
mydb.close()
|
||||
return service_ids, customers
|
||||
|
||||
|
||||
def server_filter():
|
||||
st.title("Server Filter :mag_right:")
|
||||
# Get initial data for widgets
|
||||
@@ -68,15 +74,17 @@ def server_filter():
|
||||
# Combine service_ID and name for display
|
||||
service_options = initial_service_ids.apply(lambda row: f"{row['service_ID']} - {row['name']}", axis=1)
|
||||
|
||||
# Add selection widget for customer ID
|
||||
selected_customer = st.selectbox(
|
||||
'Select Customer',
|
||||
["All"] + customers.apply(lambda row: f"{row['customer_ID']} - {row['companyname']} - {row['customer']}",
|
||||
axis=1).tolist()
|
||||
# Create a dictionary for customer selection
|
||||
customer_dict = {f"{row['companyname']} - {row['customer']}": row['customer_ID'] for _, row in customers.iterrows()}
|
||||
|
||||
# Use multiselect for multiple customer selection
|
||||
selected_customers = st.multiselect(
|
||||
'Select Customer(s)',
|
||||
list(customer_dict.keys()) # Display only companyname and customer
|
||||
)
|
||||
|
||||
# Extract customer_ID from selected option
|
||||
selected_customer_id = None if selected_customer == "All" else int(selected_customer.split(' - ')[0])
|
||||
# Get the corresponding customer IDs
|
||||
selected_customer_ids = [customer_dict[customer] for customer in selected_customers]
|
||||
|
||||
# Add selection widget for service ID
|
||||
selected_service = st.selectbox(
|
||||
@@ -96,13 +104,33 @@ def server_filter():
|
||||
# Extract status from selected option
|
||||
service_status = None if selected_status == "All" else int(selected_status.split(' - ')[0])
|
||||
|
||||
# Add SPLA server selection
|
||||
reporting_box = st.selectbox(
|
||||
'Select SPLA Server',
|
||||
["Nein", "Ja"]
|
||||
)
|
||||
|
||||
# Extract reporting status
|
||||
reporting = None if reporting_box == "Nein" else "True"
|
||||
|
||||
# Add OS type selection
|
||||
os_box = st.selectbox(
|
||||
'Select OS Type',
|
||||
["All", "Linux", "Windows"]
|
||||
)
|
||||
|
||||
# Extract OS type
|
||||
os_type = None if os_box == "All" else os_box
|
||||
|
||||
# Add a button to apply filters
|
||||
if st.button('Apply Filters'):
|
||||
# Fetch filtered data from the database
|
||||
filtered_data = get_filtered_server(selected_customer_id, selected_service_id, service_status)
|
||||
|
||||
filtered_data = get_filtered_server(selected_customer_ids, selected_service_id, service_status, os_type, reporting)
|
||||
# Display the filtered data
|
||||
if not filtered_data.empty:
|
||||
st.dataframe(filtered_data)
|
||||
st.text(f"CPU SUMME = {sum(filtered_data['core'])}" )
|
||||
st.text(f"Berechung der Core-Pakete: Anzahl der Cores({filtered_data['core'].count()}) * Core-Pakete aus SPLA (8) / 2")
|
||||
st.text(f"Reporting Core-Pakete = {(filtered_data['core'].count())*8/2}".split('.')[0])
|
||||
else:
|
||||
st.write("No data available for the selected filters.")
|
||||
Reference in New Issue
Block a user