This commit is contained in:
hailin 2024-10-28 20:25:27 +08:00
parent 90913c98cd
commit 3cefa98c77
1 changed files with 21 additions and 25 deletions

46
app.py
View File

@ -81,12 +81,26 @@ def load_indices_from_es(key: str, index: str, buf: Dict[str, Any]) -> Any:
return None
def calculate_statistics():
total_emails = 0
cold_lead_count = 0
no_promotion_count = 0
# 遍历所有客户数据以计算统计信息
for customer in customer_data:
for domain, info in customer.items():
if 'email addresses' in info and isinstance(info['email addresses'], list):
for email in info['email addresses']:
total_emails += 1
# 判断 "cold lead" 类型
if email.get('category', '').lower() == "cold lead":
cold_lead_count += 1
# 判断是否有推广历史
promotion_history = email.get('promotion history', [])
if not promotion_history: # 如果推广历史为空或不存在
no_promotion_count += 1
@app.route('/')
def index():
# 默认展示第一个客户
return redirect(url_for('view_customer', index=0))
return total_emails, cold_lead_count, no_promotion_count
@app.route('/customer/<int:index>')
@ -109,29 +123,12 @@ def view_customer(index):
for email_idx, email in enumerate(info['email addresses']):
email['idx'] = email_idx # 给每个 email 项添加唯一的索引
# 统计数据的计算
total_emails = 0
cold_lead_count = 0
no_promotion_count = 0
# 遍历所有客户数据以计算统计信息
for customer in customer_data:
for domain, info in customer.items():
if 'email addresses' in info and isinstance(info['email addresses'], list):
for email in info['email addresses']:
total_emails += 1
# 判断 "cold lead" 类型
if email.get('category', '').lower() == "cold lead":
cold_lead_count += 1
# 判断是否有推广历史
promotion_history = email.get('promotion history', [])
if not promotion_history: # 如果推广历史为空或不存在
no_promotion_count += 1
is_first = index == 0
is_last = index == len(customer_data) - 1
# 将统计信息和原有数据一起传递到模板
# 计算统计数据
total_emails, cold_lead_count, no_promotion_count = calculate_statistics()
return render_template('edit_customers.html',
customer=customer,
index=index,
@ -144,7 +141,6 @@ def view_customer(index):
# @app.route('/customer/<int:index>')
# def view_customer(index):
# # 判断是否有数据