Compare commits

..

4 Commits

8 changed files with 42 additions and 15 deletions

17
Dockerfile Normal file
View File

@ -0,0 +1,17 @@
FROM python:3.12
# 设置工作目录
WORKDIR /app
# 将当前目录内容复制到位于容器的/app目录下
COPY . /app
# 安装依赖
RUN pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
RUN pip install --no-cache-dir -r requirements.txt
# 暴露容器的端口
EXPOSE 8000
# 在容器启动时运行app.py
CMD ["python", "main.py"]

View File

@ -1,6 +1,6 @@
[server]
listen = 0.0.0.0
port = 8080
port = 8000
debug = true
[database]

View File

@ -1,3 +1,4 @@
Flask == 3.1.0
pymysql == 1.1.1
confluent-kafka == 2.7.0
Flask
pymysql
confluent-kafka
kafka-python-ng

View File

@ -12,7 +12,7 @@ def readKafka():
messages = []
try:
# 读取消息最多读取10条消息
msg = consumer.poll(timeout_ms=500, max_records=50)
msg = consumer.poll(timeout_ms=1000, max_records=50)
for partition, msgs in msg.items():
for message in msgs:
messages.append(raw_Data_to_jsonstr(message.value.decode('utf-8')))
@ -44,7 +44,7 @@ def orders_count_by_name():
messages = []
try:
# 读取消息最多读取10条消息
msg = consumer.poll(timeout_ms=500, max_records=50)
msg = consumer.poll(timeout_ms=1000, max_records=50)
for partition, msgs in msg.items():
for message in msgs:
jsondata = json.loads(message.value.decode('utf-8'))
@ -66,7 +66,7 @@ def order_name_count():
messages = []
try:
# 读取消息最多读取10条消息
msg = consumer.poll(timeout_ms=500, max_records=50)
msg = consumer.poll(timeout_ms=1000, max_records=50)
for partition, msgs in msg.items():
for message in msgs:
jsondata = json.loads(message.value.decode('utf-8'))
@ -88,7 +88,7 @@ def summary():
messages = []
try:
# 读取消息最多读取10条消息
msg = consumer.poll(timeout_ms=500, max_records=50)
msg = consumer.poll(timeout_ms=1000, max_records=50)
for partition, msgs in msg.items():
for message in msgs:
jsondata = json.loads(message.value.decode('utf-8'))

View File

@ -80,7 +80,7 @@
}
// 每5秒更新一次图表数据
setInterval(fetchDataAndUpdateChart, 5000);
setInterval(fetchDataAndUpdateChart, 10000);
// 初始数据加载
fetchDataAndUpdateChart();

View File

@ -54,7 +54,7 @@
// 获取数据并更新图表
function fetchDataAndUpdateChart() {
fetch('/api/stream/ordernamecount') // 替换为你的实际API地址
fetch('/api/stream/ordernamecount')
.then(response => response.json())
.then(data => {
// 统计每个订单名称的数量
@ -82,7 +82,7 @@
}
// 每5秒更新一次数据
setInterval(fetchDataAndUpdateChart, 5000);
setInterval(fetchDataAndUpdateChart, 10000);
// 初始数据加载
fetchDataAndUpdateChart();

View File

@ -35,6 +35,11 @@
data: chartData,
options: {
responsive: true,
plugins: {
legend: {
display: true, // 显示图例
}
},
scales: {
x: {
type: 'category', // X轴使用类别型
@ -54,9 +59,11 @@
// 获取数据并更新图表
function fetchDataAndUpdateChart() {
fetch('/api/stream/ordersummary') // 替换为你的实际API地址
fetch('/api/stream/ordersummary')
.then(response => response.json())
.then(data => {
console.log('Received data:', data);
// 统计每个时间点的订单数量
let orderCounts = {};
data.forEach(order => {
@ -71,6 +78,8 @@
}
});
console.log('Order counts:', orderCounts);
// 更新图表数据
chartData.labels = Object.keys(orderCounts); // 设置X轴标签为时间
chartData.datasets[0].data = Object.values(orderCounts); // 设置Y轴数据为订单数量
@ -81,8 +90,8 @@
.catch(error => console.error('获取数据失败:', error));
}
// 每5秒更新一次数据
setInterval(fetchDataAndUpdateChart, 5000);
// 每10秒更新一次数据
setInterval(fetchDataAndUpdateChart, 10000);
// 初始数据加载
fetchDataAndUpdateChart();

View File

@ -91,7 +91,7 @@
}
// 每5秒更新一次数据
setInterval(fetchDataAndUpdateChart, 5000);
setInterval(fetchDataAndUpdateChart, 10000);
// 初始数据加载
fetchDataAndUpdateChart();