上传文件至「/」
This commit is contained in:
@@ -1,21 +1,29 @@
|
||||
from house_service import *
|
||||
|
||||
def print_menu():
|
||||
print("\n===== 房屋出租系统 V3.0 =====")
|
||||
print("\n===== 房屋出租系统 V5.0 =====")
|
||||
print("1. 新增房源")
|
||||
print("2. 删除房源")
|
||||
print("3. 修改房源")
|
||||
print("4. 查询房源")
|
||||
print("5. 查看/管理操作记录")
|
||||
print("6. 查看/管理浏览历史")
|
||||
# V3.0 新增菜单
|
||||
print("7. 地址字符串解析测试")
|
||||
print("8. 按区域关键词模糊查询")
|
||||
print("9. 初始化小区邻接矩阵")
|
||||
print("10. 更新小区间距离")
|
||||
print("11. 退出系统")
|
||||
print("11. 房源二叉树范围查询(租金/面积)")
|
||||
print("12. 房源冒泡排序(租金/面积)")
|
||||
print("13. 房源快速排序(租金/面积)")
|
||||
#V5.0 新增菜单
|
||||
print("14. 可视化小区距离图(邻接矩阵)")
|
||||
print("15. 计算小区间最短路径(Dijkstra)")
|
||||
print("16. 基于最短路径推荐房源")
|
||||
print("17. 退出系统")
|
||||
print("============================")
|
||||
|
||||
|
||||
# V2原有操作记录子菜单
|
||||
def op_record_menu():
|
||||
while True:
|
||||
print("\n----- 操作记录管理 -----")
|
||||
@@ -25,7 +33,7 @@ def op_record_menu():
|
||||
print("4. 返回")
|
||||
c = input("请选择:")
|
||||
if c == "1":
|
||||
lst = get_recent_records("operation",10)
|
||||
lst = get_recent_records("operation", 10)
|
||||
print(lst if lst else "暂无记录")
|
||||
elif c == "2":
|
||||
print(pop_operation_stack() or "暂无记录")
|
||||
@@ -37,6 +45,7 @@ def op_record_menu():
|
||||
print("输入有误")
|
||||
|
||||
|
||||
# V2浏览历史子菜单
|
||||
def browse_history_menu():
|
||||
while True:
|
||||
print("\n----- 浏览历史管理 -----")
|
||||
@@ -46,11 +55,11 @@ def browse_history_menu():
|
||||
print("4. 返回")
|
||||
c = input("请选择:")
|
||||
if c == "1":
|
||||
id_list = get_recent_records("browse",10)
|
||||
id_list = get_recent_records("browse", 10)
|
||||
if not id_list:
|
||||
print("暂无浏览历史")
|
||||
continue
|
||||
for idx,hid in enumerate(id_list,1):
|
||||
for idx, hid in enumerate(id_list, 1):
|
||||
info = query_house("id", hid)
|
||||
if info:
|
||||
h = info[0]
|
||||
@@ -71,12 +80,12 @@ def browse_history_menu():
|
||||
else:
|
||||
print("输入有误")
|
||||
|
||||
|
||||
def main():
|
||||
while True:
|
||||
print_menu()
|
||||
choice = input("请输入功能编号:")
|
||||
|
||||
# ========== V1 原有功能==========
|
||||
if choice == "1":
|
||||
addr = input("输入房源地址:")
|
||||
try:
|
||||
@@ -86,14 +95,14 @@ def main():
|
||||
print("租金面积必须是数字!")
|
||||
continue
|
||||
htype = input("输入户型:")
|
||||
if add_house(addr,price,area,htype):
|
||||
if add_house(addr, price, area, htype):
|
||||
new_id = get_next_house_id() - 1
|
||||
push_operation_stack(f"新增房源ID:{new_id} 地址:{addr}")
|
||||
|
||||
elif choice == "2":
|
||||
try:
|
||||
hid = int(input("输入要删除房源ID:"))
|
||||
res = query_house("id",hid)
|
||||
res = query_house("id", hid)
|
||||
addr = res[0]["address"] if res else "未知地址"
|
||||
if delete_house(hid):
|
||||
push_operation_stack(f"删除房源ID:{hid} 地址:{addr}")
|
||||
@@ -123,7 +132,7 @@ def main():
|
||||
elif choice == "4":
|
||||
print("1-ID 2-地址 3-租金 4-户型")
|
||||
sel = input("选择查询类型:")
|
||||
map_dic = {"1":"id","2":"address","3":"price","4":"house_type"}
|
||||
map_dic = {"1": "id", "2": "address", "3": "price", "4": "house_type"}
|
||||
if sel not in map_dic:
|
||||
print("选择无效")
|
||||
continue
|
||||
@@ -137,20 +146,19 @@ def main():
|
||||
if map_dic[sel] == "id":
|
||||
push_browse_stack(h["id"])
|
||||
|
||||
# ========== V2 原有功能 ==========
|
||||
elif choice == "5":
|
||||
op_record_menu()
|
||||
elif choice == "6":
|
||||
browse_history_menu()
|
||||
|
||||
#3.0
|
||||
# ========== V3 原有功能==========
|
||||
elif choice == "7":
|
||||
# 测试地址字符串解析
|
||||
full_addr = input("输入完整地址(如:四川省德阳市什邡市XX小区):")
|
||||
res = parse_address_string(full_addr)
|
||||
print("解析结果:", res)
|
||||
|
||||
elif choice == "8":
|
||||
# 按区域关键词模糊查询
|
||||
keyword = input("输入区域关键词(如:什邡、德阳):")
|
||||
res_list = fuzzy_query_by_district(keyword)
|
||||
if not res_list:
|
||||
@@ -160,13 +168,11 @@ def main():
|
||||
print(f"ID:{h['id']} 地址:{h['address']}")
|
||||
|
||||
elif choice == "9":
|
||||
# 初始化小区邻接矩阵
|
||||
community_input = input("输入所有小区名称,用英文逗号分隔:")
|
||||
community_list = community_input.split(",")
|
||||
init_community_matrix(community_list)
|
||||
|
||||
elif choice == "10":
|
||||
# 更新两个小区距离
|
||||
c1 = input("输入小区A名称:")
|
||||
c2 = input("输入小区B名称:")
|
||||
try:
|
||||
@@ -175,11 +181,107 @@ def main():
|
||||
except:
|
||||
print("距离必须是数字")
|
||||
|
||||
# ========== V4 原有功能==========
|
||||
elif choice == "11":
|
||||
print("请选择查询维度:1-租金 2-面积")
|
||||
dim_choice = input("输入维度编号:")
|
||||
key_field = "price" if dim_choice == "1" else "area"
|
||||
field_name = "租金" if dim_choice == "1" else "面积"
|
||||
|
||||
try:
|
||||
min_val = float(input(f"输入{field_name}最小值:"))
|
||||
max_val = float(input(f"输入{field_name}最大值:"))
|
||||
except:
|
||||
print("数值必须是数字!")
|
||||
continue
|
||||
|
||||
all_houses = read_houses()
|
||||
if not all_houses:
|
||||
print("暂无房源数据!")
|
||||
continue
|
||||
bst_root = build_house_bst(all_houses, key_field)
|
||||
result = search_bst_range(bst_root, min_val, max_val, key_field)
|
||||
if not result:
|
||||
print(f"未找到{field_name}在{min_val}-{max_val}之间的房源")
|
||||
else:
|
||||
print(f"\n{field_name}在{min_val}-{max_val}之间的房源:")
|
||||
for h in result:
|
||||
print(f"ID:{h['id']} 地址:{h['address']} {field_name}:{h[key_field]}")
|
||||
|
||||
elif choice == "12":
|
||||
print("请选择排序维度:1-租金 2-面积")
|
||||
dim_choice = input("输入维度编号:")
|
||||
sort_field = "price" if dim_choice == "1" else "area"
|
||||
field_name = "租金" if dim_choice == "1" else "面积"
|
||||
|
||||
print("请选择排序方式:1-升序 2-降序")
|
||||
sort_way = input("输入方式编号:")
|
||||
reverse = (sort_way == "2")
|
||||
|
||||
all_houses = read_houses()
|
||||
if not all_houses:
|
||||
print("暂无房源数据!")
|
||||
continue
|
||||
sorted_houses = bubble_sort_houses(all_houses, sort_field, reverse)
|
||||
print(f"\n按{field_name}{'降序' if reverse else '升序'}排序结果(冒泡排序):")
|
||||
for h in sorted_houses:
|
||||
print(f"ID:{h['id']} 地址:{h['address']} {field_name}:{h[sort_field]}")
|
||||
|
||||
elif choice == "13":
|
||||
print("请选择排序维度:1-租金 2-面积")
|
||||
dim_choice = input("输入维度编号:")
|
||||
sort_field = "price" if dim_choice == "1" else "area"
|
||||
field_name = "租金" if dim_choice == "1" else "面积"
|
||||
|
||||
print("请选择排序方式:1-升序 2-降序")
|
||||
sort_way = input("输入方式编号:")
|
||||
reverse = (sort_way == "2")
|
||||
|
||||
all_houses = read_houses()
|
||||
if not all_houses:
|
||||
print("暂无房源数据!")
|
||||
continue
|
||||
sorted_houses = quick_sort_houses(all_houses, sort_field, reverse)
|
||||
print(f"\n按{field_name}{'降序' if reverse else '升序'}排序结果(快速排序):")
|
||||
for h in sorted_houses:
|
||||
print(f"ID:{h['id']} 地址:{h['address']} {field_name}:{h[sort_field]}")
|
||||
|
||||
# ========== V5 新增功能分支 ==========
|
||||
elif choice == "14":
|
||||
# 可视化小区图
|
||||
print_community_graph()
|
||||
|
||||
elif choice == "15":
|
||||
# 计算最短路径
|
||||
start_comm = input("输入起始小区名称:")
|
||||
end_comm = input("输入目标小区名称:")
|
||||
shortest_dist, shortest_path = dijkstra_shortest_path(start_comm, end_comm)
|
||||
if shortest_dist is not None:
|
||||
print(f"\n{start_comm} 到 {end_comm} 的最短距离:{shortest_dist:.1f}")
|
||||
print(f"最短路径:{' -> '.join(shortest_path)}")
|
||||
|
||||
elif choice == "16":
|
||||
# 基于路径推荐房源
|
||||
target_comm = input("输入目标小区名称:")
|
||||
try:
|
||||
max_dist = float(input("输入最大推荐距离:"))
|
||||
except:
|
||||
print("距离必须是数字!")
|
||||
continue
|
||||
recommend_list = recommend_houses_by_path(target_comm, max_dist)
|
||||
if not recommend_list:
|
||||
print(f"未找到{target_comm}周边{max_dist}范围内的房源")
|
||||
else:
|
||||
print(f"\n{target_comm}周边{max_dist}范围内的推荐房源:")
|
||||
for h in recommend_list:
|
||||
print(f"ID:{h['id']} 地址:{h['address']} 租金:{h['price']} 面积:{h['area']}")
|
||||
|
||||
elif choice == "17":
|
||||
print("系统退出成功!")
|
||||
break
|
||||
else:
|
||||
print("请输入有效编号")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user