248 lines
10 KiB
Python
248 lines
10 KiB
Python
import json
|
|
import mysql.connector
|
|
import mysql.connector
|
|
from work_util import params
|
|
from datetime import datetime
|
|
|
|
def fetch_data(sql):
|
|
# 连接到数据库
|
|
param = params.ModelParams()
|
|
config = param.config
|
|
connection = mysql.connector.connect(**config)
|
|
try:
|
|
with connection.cursor(dictionary=True) as cursor:
|
|
# 查询数据
|
|
cursor.execute(sql)
|
|
return cursor.fetchall()
|
|
finally:
|
|
connection.close()
|
|
|
|
def fetch_data_with_param(sql,type):
|
|
# 连接到数据库
|
|
param = params.ModelParams()
|
|
config = param.config
|
|
connection = mysql.connector.connect(**config)
|
|
try:
|
|
with connection.cursor(dictionary=True) as cursor:
|
|
# 查询数据
|
|
cursor.execute(sql,type)
|
|
return cursor.fetchall()
|
|
finally:
|
|
connection.close()
|
|
|
|
|
|
def generate_json_data_source(data):
|
|
result = []
|
|
# 组织数据
|
|
for application in set(item['application_name'] for item in data):
|
|
app_data = {'name': application, 'list': []}
|
|
param = params.ModelParams()
|
|
task_types_order = param.task_types_order
|
|
for task_type in task_types_order:
|
|
task_data = {'name_col': task_type, 'list': []}
|
|
for item in data:
|
|
if item['task_type'] == task_type:
|
|
time_str = item['time'].strftime('%Y-%m-%d %H:%M:%S') if isinstance(item['time'], (datetime,)) else str(item['time'])
|
|
task_data['list'].append({
|
|
'id': item['id'],
|
|
'name': item['sample_name'],
|
|
'img': item['img_url'],
|
|
'time': time_str, # 使用转换后的字符串
|
|
'download': item['download_url']
|
|
})
|
|
app_data['list'].append(task_data)
|
|
result.append(app_data)
|
|
jiaoxue_data = {"name":"教学案例数据","list":[{"name_col":"chapter1","list":[]},{"name_col":"chapter2","list":[]},{"name_col":"chapter3","list":[]}]}
|
|
result.append(jiaoxue_data)
|
|
return {'result': result}
|
|
|
|
# 获取应用界面信息
|
|
def generate_json_app_source(data):
|
|
result = []
|
|
# 组织数据
|
|
for application in set(item['application_name'] for item in data):
|
|
app_data = {'name': application, 'list': []}
|
|
param = params.ModelParams()
|
|
task_types_order = param.task_types_order
|
|
for task_type in task_types_order:
|
|
task_data = {'name_col': task_type, 'list': []}
|
|
for item in data:
|
|
if item['task_type'] == task_type:
|
|
time_str = item['time'].strftime('%Y-%m-%d %H:%M:%S') if isinstance(item['time'], (datetime,)) else str(item['time'])
|
|
task_data['list'].append({
|
|
'id': item['id'],
|
|
'name': item['sample_name'],
|
|
'img': item['img_url'],
|
|
'time': time_str # 使用转换后的字符串
|
|
})
|
|
app_data['list'].append(task_data)
|
|
result.append(app_data)
|
|
return {'result': result}
|
|
|
|
# 获取应用界面信息
|
|
def generate_json_meijitancailiao_source(data):
|
|
result = []
|
|
# 组织数据
|
|
for application in set(item['application_name'] for item in data):
|
|
app_data = {'name': application, 'list': []}
|
|
task_types_order = ["煤基活性碳孔道结构预测","煤基碳材料电容领域应用","煤基活性碳模拟器"]
|
|
for task_type in task_types_order:
|
|
task_data = {'name_col': task_type, 'list': []}
|
|
for item in data:
|
|
if item['task_type'] == task_type:
|
|
time_str = item['time'].strftime('%Y-%m-%d %H:%M:%S') if isinstance(item['time'], (datetime,)) else str(item['time'])
|
|
task_data['list'].append({
|
|
'id': item['id'],
|
|
'name': item['sample_name'],
|
|
'img': item['img_url'],
|
|
'time': time_str # 使用转换后的字符串
|
|
})
|
|
app_data['list'].append(task_data)
|
|
result.append(app_data)
|
|
return {'result': result}
|
|
|
|
# 获取应用界面信息
|
|
def generate_json_meirejie_source(data):
|
|
result = []
|
|
# 组织数据
|
|
for application in set(item['application_name'] for item in data):
|
|
app_data = {'name': application, 'list': []}
|
|
task_types_order = ["煤热解产物预测"]
|
|
for task_type in task_types_order:
|
|
task_data = {'name_col': task_type, 'list': []}
|
|
for item in data:
|
|
if item['task_type'] == task_type:
|
|
time_str = item['time'].strftime('%Y-%m-%d %H:%M:%S') if isinstance(item['time'], (datetime,)) else str(item['time'])
|
|
task_data['list'].append({
|
|
'id': item['id'],
|
|
'name': item['sample_name'],
|
|
'img': item['img_url'],
|
|
'time': time_str # 使用转换后的字符串
|
|
})
|
|
app_data['list'].append(task_data)
|
|
result.append(app_data)
|
|
return {'result': result}
|
|
|
|
# 图片
|
|
def allowed_file(filename: str) -> bool:
|
|
"""检查图片扩展名是否被允许"""
|
|
param = params.ModelParams()
|
|
return any(filename.endswith(ext) for ext in param.ALLOWED_EXTENSIONS)
|
|
|
|
|
|
|
|
####################SAM###################################
|
|
|
|
|
|
# data_info ={
|
|
# "result": [
|
|
# {
|
|
# "name":"应用数据",
|
|
# "list":
|
|
# [
|
|
# {
|
|
# "name_col": "回归预测任务",
|
|
# "list" : [
|
|
# {
|
|
# "name": "煤基功能碳材料样例数据",
|
|
# "img": "http://124.16.151.196:13432/files/imgs/data/meijitancailiao.png",
|
|
# "time": "2025-04-28",
|
|
# "download":"http://124.16.151.196:13432/files/datas/meijitancailiao.zip"
|
|
# },
|
|
# {
|
|
# "name": "煤热解样例数据",
|
|
# "img": "http://124.16.151.196:13432/files/imgs/data/meirejie.png",
|
|
# "time": "2025-04-28",
|
|
# "download":"http://124.16.151.196:13432/files/datas/meirejie.zip"
|
|
# }
|
|
# ]},
|
|
# {
|
|
# "name_col": "时序预测任务",
|
|
# "list" : [
|
|
# {
|
|
# "name": "光伏出力预测样例数据",
|
|
# "img": "http://124.16.151.196:13432/files/imgs/data/pv_forecast.png",
|
|
# "time": "2025-04-28",
|
|
# "download":"http://124.16.151.196:13432/files/datas/pv_forecast.zip"
|
|
# },
|
|
# {
|
|
# "name": "生物制甲烷产量预测样例数据",
|
|
# "img": "http://124.16.151.196:13432/files/imgs/data/jiwanyuce.png",
|
|
# "time": "2025-04-28",
|
|
# "download":"http://124.16.151.196:13432/files/datas/jiwanyuce.zip"
|
|
# },
|
|
# {
|
|
# "name": "风力发电预测样例数据",
|
|
# "img": "http://124.16.151.196:13432/files/imgs/data/wind_power_forecasting.png",
|
|
# "time": "2025-04-28",
|
|
# "download":"http://124.16.151.196:13432/files/datas/wind_power_forecasting.zip"
|
|
# }
|
|
# ]},
|
|
|
|
# {
|
|
# "name_col": "计算机视觉任务",
|
|
# "list" : [
|
|
# {
|
|
# "name": "光伏识别样例数据",
|
|
# "img": "http://124.16.151.196:13432/files/imgs/data/pv.png",
|
|
# "time": "2025-04-28",
|
|
# "download":"http://124.16.151.196:13432/files/datas/pv.zip"
|
|
# },
|
|
# {
|
|
# "name": "屋顶识别样例数据",
|
|
# "img": "http://124.16.151.196:13432/files/imgs/data/roof.png",
|
|
# "time": "2025-04-28",
|
|
# "download":"http://124.16.151.196:13432/files/datas/roof.zip"
|
|
# },
|
|
# {
|
|
# "name": "屋顶光伏识别样例数据",
|
|
# "img": "http://124.16.151.196:13432/files/imgs/data/roofpv.png",
|
|
# "time": "2025-04-28",
|
|
# "download":"http://124.16.151.196:13432/files/datas/roofpv.zip"
|
|
# },
|
|
# {
|
|
# "name": "地貌语义识别样例数据",
|
|
# "img": "http://124.16.151.196:13432/files/imgs/data/dimaoshibie.png",
|
|
# "time": "2025-04-28",
|
|
# "download":"http://124.16.151.196:13432/files/datas/dimaoshibie.zip"
|
|
# },
|
|
# ]},
|
|
|
|
# {
|
|
# "name_col": "强化学习任务",
|
|
# "list" : [
|
|
# ]},
|
|
# {
|
|
# "name_col": "自然语言处理任务",
|
|
# "list" : [
|
|
# ]},
|
|
# {
|
|
# "name_col": "算法标注工具",
|
|
# "list" : [
|
|
# {
|
|
# "name": "SAM样例数据集",
|
|
# "img": "http://124.16.151.196:13432/files/imgs/data/sam.png",
|
|
# "time": "2025-04-28",
|
|
# "download":"http://124.16.151.196:13432/files/datas/sam.zip"
|
|
# }
|
|
# ]}
|
|
# ]
|
|
# },
|
|
# {
|
|
# "name": "教学案例数据",
|
|
# "list" : [
|
|
# {"name_col": "chapter1",
|
|
# "list" : []
|
|
# },
|
|
# {"name_col": "chapter2",
|
|
# "list" : []
|
|
# },
|
|
# {"name_col": "chapter3",
|
|
# "list" : []
|
|
# },
|
|
# ]
|
|
# }
|
|
# ]
|
|
# }
|
|
|
|
# name_list = ["应用数据","'教学案例数据'"] |