File size: 2,566 Bytes
226a637
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
import dask.dataframe as dd
from dotenv import load_dotenv
from itertools import combinations
from collections import defaultdict

# Load environment variables
load_dotenv()

# Configuration from environment variables
FILE_UPLOAD_LIMIT = int(os.getenv('FILE_UPLOAD_LIMIT', 200))
EXECUTION_TIME_LIMIT = int(os.getenv('EXECUTION_TIME_LIMIT', 300))
RESOURCE_LIMIT = int(os.getenv('RESOURCE_LIMIT', 1024))  # in MB
DATA_DIR = os.getenv('DATA_DIR', './data')
CONFIG_FLAG = os.getenv('CONFIG_FLAG', 'default')

# Main application logic
def main():
    st.title("CyberOps Dashboard")

    # Sidebar for user inputs
    st.sidebar.header("Options")

    # Option to select a CSV file
    uploaded_file = st.sidebar.file_uploader("Select a CSV file:", type=["csv"])

    if uploaded_file:
        @st.cache_data
        def load_csv(file):
            return pd.read_csv(file)

        @st.cache_data
        def load_dask_csv(file):
            return dd.read_csv(file)

        if os.path.getsize(uploaded_file) < RESOURCE_LIMIT * 1024 * 1024:
            df = load_csv(uploaded_file)
        else:
            df = load_dask_csv(uploaded_file)

        if not df.empty:
            st.write("Data Preview:")
            st.dataframe(df.compute() if isinstance(df, dd.DataFrame) else df)

            # Select columns for plotting
            x_column = st.sidebar.selectbox('Select X-axis:', df.columns)
            y_column = st.sidebar.selectbox('Select Y-axis:', df.columns)

            # Plotting
            fig, ax = plt.subplots()
            ax.plot(df[x_column], df[y_column], marker='o')
            ax.set_xlabel(x_column)
            ax.set_ylabel(y_column)
            ax.set_title(f"{y_column} vs {x_column}")
            st.pyplot(fig)

            # Combinatorial analysis
            col_combinations = st.sidebar.multiselect('Select columns for combinations:', df.columns)
            if col_combinations:
                st.write("Column Combinations:")
                comb = list(combinations(col_combinations, 2))
                st.write(comb)

            # Grouping and aggregation
            group_by_column = st.sidebar.selectbox('Select column to group by:', df.columns)
            if group_by_column:
                grouped_df = df.groupby(group_by_column).agg(list)
                st.write("Grouped Data:")
                st.dataframe(grouped_df.compute() if isinstance(grouped_df, dd.DataFrame) else grouped_df)

if __name__ == "__main__":
    main()