初始渲染页面
This commit is contained in:
33
db_utils.py
Normal file
33
db_utils.py
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding:utf-8 -*-
|
||||
from loguru import logger
|
||||
from sqlalchemy import Column, Integer, String, create_engine
|
||||
from sqlalchemy.orm import declarative_base, sessionmaker
|
||||
|
||||
from bak.evolve_config2 import train_data
|
||||
from bak.init_data import BatchDataBase
|
||||
|
||||
Base = declarative_base()
|
||||
# 创建 SQLite 数据库引擎
|
||||
engine = create_engine('sqlite:///data.db', echo=False)
|
||||
|
||||
|
||||
class BatchData(Base):
|
||||
__tablename__ = 'batch_data'
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
year = Column(Integer)
|
||||
census_batch = Column(String) # 普查批次
|
||||
id_code = Column(String)
|
||||
precision = Column(String) # 精度
|
||||
is_train = Column(Integer)
|
||||
is_validation = Column(Integer)
|
||||
ann_file = Column(String)
|
||||
img_prefix = Column(String)
|
||||
filter_empty_gt = Column(Integer)
|
||||
update_cache = Column(Integer)
|
||||
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
Session = sessionmaker(bind=engine, )
|
||||
session = Session()
|
||||
27
flush.py
27
flush.py
@@ -1,36 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding:utf-8 -*-
|
||||
from loguru import logger
|
||||
from sqlalchemy import Column, Integer, String, create_engine
|
||||
from sqlalchemy.orm import declarative_base, sessionmaker
|
||||
|
||||
from bak.evolve_config2 import train_data
|
||||
from bak.init_data import BatchDataBase
|
||||
from db_utils import BatchData, session
|
||||
|
||||
Base = declarative_base()
|
||||
# 创建 SQLite 数据库引擎
|
||||
engine = create_engine('sqlite:///data.db', echo=False)
|
||||
|
||||
|
||||
class BatchData(Base):
|
||||
__tablename__ = 'batch_data'
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
year = Column(Integer)
|
||||
census_batch = Column(String) # 普查批次
|
||||
id_code = Column(String)
|
||||
precision = Column(String) # 精度
|
||||
is_train = Column(Integer)
|
||||
is_validation = Column(Integer)
|
||||
ann_file = Column(String)
|
||||
img_prefix = Column(String)
|
||||
filter_empty_gt = Column(Integer)
|
||||
update_cache = Column(Integer)
|
||||
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
Session = sessionmaker(bind=engine, )
|
||||
session = Session()
|
||||
logger.debug(f"{len(train_data)=}")
|
||||
|
||||
census_batches = []
|
||||
|
||||
27
main.py
27
main.py
@@ -1,22 +1,13 @@
|
||||
# streamlit_app.py
|
||||
|
||||
import pandas as pd
|
||||
import streamlit as st
|
||||
|
||||
# Create the SQL connection to pets_db as specified in your secrets file.
|
||||
conn = st.connection('data_db', type='sql')
|
||||
from bak.init_data import BatchDataRead
|
||||
from db_utils import BatchData, session
|
||||
|
||||
# Insert some data with conn.session.
|
||||
with conn.session as s:
|
||||
s.execute('CREATE TABLE IF NOT EXISTS pet_owners (person TEXT, pet TEXT);')
|
||||
s.execute('DELETE FROM pet_owners;')
|
||||
pet_owners = {'jerry': 'fish', 'barbara': 'cat', 'alex': 'puppy'}
|
||||
for k in pet_owners:
|
||||
s.execute(
|
||||
'INSERT INTO pet_owners (person, pet) VALUES (:owner, :pet);',
|
||||
params=dict(owner=k, pet=pet_owners[k])
|
||||
)
|
||||
s.commit()
|
||||
|
||||
# Query and display the data you inserted
|
||||
pet_owners = conn.query('select * from pet_owners')
|
||||
st.dataframe(pet_owners)
|
||||
df = pd.DataFrame(
|
||||
data=(BatchDataRead.from_orm(db_obj).dict()
|
||||
for db_obj in session.query(BatchData).all())
|
||||
)
|
||||
#
|
||||
st.dataframe(df, use_container_width=True)
|
||||
|
||||
@@ -2,3 +2,4 @@ sqlalchemy~=1.4
|
||||
streamlit~=1.29
|
||||
pydantic~=1.0
|
||||
loguru~=0.7
|
||||
pandas~=2.2.1
|
||||
Reference in New Issue
Block a user