Skip to content

Commit

Permalink
add database management page, user don't need to upload config file a…
Browse files Browse the repository at this point in the history
…ny more
  • Loading branch information
ChickenSellerRED committed Jan 31, 2024
1 parent 8a3a6f8 commit db5787d
Show file tree
Hide file tree
Showing 6 changed files with 336 additions and 181 deletions.
45 changes: 22 additions & 23 deletions conf/config.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
database_number: 1

database1:
nickname: 'Google cloud'
dbms: 'postgresql'
host: '35.235.95.37' # '35.235.95.37' # Replace with your DB host
port: 5439 # 5439 # Replace with your DB port
user: 'jize'# 'jize' # Replace with your DB username

mapping:
columns:
user_id: 'user_id'
timestamp: 'timestamp'
value: 'value'
timestamp: timestamp
user_id: user_id
value: value
tables:
geo:
- locations
time_series:
- heart_rates
- calories
- mets
- distances
- steps
- sleep
- weight
user_table:
name: 'geomts_users'
columns:
user_id: String(50)
device: String(50)
location: String(50)
time_series:
- heart_rates
- calories
- mets
- distances
- steps
- sleep
- weight
geo:
- locations
user_id: String(50)
name: geomts_users
database1:
nickname: 'local'
dbms: 'postgresql'
host: 'db'
port: 5432
user: 'admin'
password: 'admin'
23 changes: 23 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
database_number: 0
mapping:
columns:
timestamp: timestamp
user_id: user_id
value: value
tables:
geo:
- locations
time_series:
- heart_rates
- calories
- mets
- distances
- steps
- sleep
- weight
user_table:
columns:
device: String(50)
location: String(50)
user_id: String(50)
name: geomts_users
8 changes: 7 additions & 1 deletion script/import_hub_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ def generate_mets_by_calories(df):
return df

def import_page():
st.subheader("Database Manage")
if st.button("Edit Database Settings"):
st.session_state["page"] = "setting"
st.experimental_rerun()


"""Main function for the streamlit app"""
# Load the config
config = load_config(config_file=CONFIG_FILE)
Expand Down Expand Up @@ -141,7 +147,7 @@ def import_page():
if uploaded_file and not is_subjects_populated:
st.success("File uploaded!")
df = pd.read_csv(uploaded_file)
df = generate_mets_by_calories(df)
# df = generate_mets_by_calories(df)
st.write("Columns in your CSV:")
st.write(df.columns)

Expand Down
2 changes: 2 additions & 0 deletions script/nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@


def createNav():
st.sidebar.title("W4H Integrated Toolkit")
# Using object notation
isLogin = st.session_state.get("login-state",False)
loginPage = st.sidebar.button('Log Out' if isLogin else 'Log In',use_container_width=True,type="primary")


st.sidebar.divider()
st.sidebar.caption("Import Historical Data / Instantiate a New W4H DB Instance")
importPage = st.sidebar.button("ImportHub",use_container_width=True,type="secondary")
Expand Down
3 changes: 3 additions & 0 deletions script/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def load_config(config_file: str) -> dict:
return yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
def save_config(config_file,config):
with open(config_file, 'w') as file:
yaml.dump(config, file)

def getServerIdByNickname(config_file: str='conf/config.yaml', nickname='local db'):
config = load_config(config_file)
Expand Down
Loading

0 comments on commit db5787d

Please sign in to comment.