refactor: Remove dead SEO/GBP audit code from app.py
Removed 280 lines of dead code after moving to blueprint. app.py: 11,774 → 11,494 lines (-280) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
1384c7f090
commit
52ffdafd00
282
app.py
282
app.py
@ -2481,289 +2481,9 @@ def api_seo_audit_trigger():
|
||||
|
||||
|
||||
# ============================================================
|
||||
# SEO ADMIN DASHBOARD - MOVED TO: blueprints/admin/routes_audits.py
|
||||
# SEO & GBP AUDIT DASHBOARDS - MOVED TO: blueprints/admin/routes_audits.py
|
||||
# ============================================================
|
||||
|
||||
# @app.route('/admin/seo') # MOVED TO admin.admin_seo
|
||||
# @login_required
|
||||
def _old_admin_seo():
|
||||
"""
|
||||
Admin dashboard for SEO metrics overview.
|
||||
|
||||
Displays:
|
||||
- Summary stats (score distribution, average score)
|
||||
- Sortable table of all companies with SEO scores
|
||||
- Color-coded score badges (green 90-100, yellow 50-89, red 0-49)
|
||||
- Filtering by category, score range, and search text
|
||||
- Last audit date with staleness indicator
|
||||
- Actions: view profile, trigger single company audit
|
||||
|
||||
Query Parameters:
|
||||
- company: Slug of company to highlight/filter (optional)
|
||||
"""
|
||||
if not current_user.is_admin:
|
||||
flash('Brak uprawnień do tej strony.', 'error')
|
||||
return redirect(url_for('dashboard'))
|
||||
|
||||
# Get optional company filter from URL
|
||||
filter_company_slug = request.args.get('company', '')
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
from sqlalchemy import func
|
||||
|
||||
# Get all active companies with their latest SEO analysis data
|
||||
# Using outerjoin to include companies without SEO data
|
||||
companies_query = db.query(
|
||||
Company.id,
|
||||
Company.name,
|
||||
Company.slug,
|
||||
Company.website,
|
||||
Category.name.label('category_name'),
|
||||
CompanyWebsiteAnalysis.pagespeed_seo_score,
|
||||
CompanyWebsiteAnalysis.pagespeed_performance_score,
|
||||
CompanyWebsiteAnalysis.pagespeed_accessibility_score,
|
||||
CompanyWebsiteAnalysis.pagespeed_best_practices_score,
|
||||
CompanyWebsiteAnalysis.seo_audited_at
|
||||
).outerjoin(
|
||||
Category,
|
||||
Company.category_id == Category.id
|
||||
).outerjoin(
|
||||
CompanyWebsiteAnalysis,
|
||||
Company.id == CompanyWebsiteAnalysis.company_id
|
||||
).filter(
|
||||
Company.status == 'active'
|
||||
).order_by(
|
||||
Company.name
|
||||
).all()
|
||||
|
||||
# Build companies list with named attributes for template
|
||||
companies = []
|
||||
for row in companies_query:
|
||||
companies.append({
|
||||
'id': row.id,
|
||||
'name': row.name,
|
||||
'slug': row.slug,
|
||||
'website': row.website,
|
||||
'category': row.category_name,
|
||||
'seo_score': row.pagespeed_seo_score,
|
||||
'performance_score': row.pagespeed_performance_score,
|
||||
'accessibility_score': row.pagespeed_accessibility_score,
|
||||
'best_practices_score': row.pagespeed_best_practices_score,
|
||||
'seo_audited_at': row.seo_audited_at
|
||||
})
|
||||
|
||||
# Calculate statistics
|
||||
audited_companies = [c for c in companies if c['seo_score'] is not None]
|
||||
not_audited = [c for c in companies if c['seo_score'] is None]
|
||||
|
||||
good_count = len([c for c in audited_companies if c['seo_score'] >= 90])
|
||||
medium_count = len([c for c in audited_companies if 50 <= c['seo_score'] < 90])
|
||||
poor_count = len([c for c in audited_companies if c['seo_score'] < 50])
|
||||
not_audited_count = len(not_audited)
|
||||
|
||||
# Calculate average score (only for audited companies)
|
||||
if audited_companies:
|
||||
avg_score = round(sum(c['seo_score'] for c in audited_companies) / len(audited_companies))
|
||||
else:
|
||||
avg_score = None
|
||||
|
||||
stats = {
|
||||
'good_count': good_count,
|
||||
'medium_count': medium_count,
|
||||
'poor_count': poor_count,
|
||||
'not_audited_count': not_audited_count,
|
||||
'avg_score': avg_score
|
||||
}
|
||||
|
||||
# Get unique categories for filter dropdown
|
||||
categories = sorted(set(c['category'] for c in companies if c['category']))
|
||||
|
||||
# Convert companies list to objects with attribute access for template
|
||||
class CompanyRow:
|
||||
def __init__(self, data):
|
||||
for key, value in data.items():
|
||||
setattr(self, key, value)
|
||||
|
||||
companies_objects = [CompanyRow(c) for c in companies]
|
||||
|
||||
return render_template('admin_seo_dashboard.html',
|
||||
companies=companies_objects,
|
||||
stats=stats,
|
||||
categories=categories,
|
||||
now=datetime.now(),
|
||||
filter_company=filter_company_slug
|
||||
)
|
||||
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
# ============================================================
|
||||
# GBP AUDIT ADMIN DASHBOARD - MOVED TO: blueprints/admin/routes_audits.py
|
||||
# ============================================================
|
||||
|
||||
# @app.route('/admin/gbp-audit') # MOVED TO admin.admin_gbp_audit
|
||||
# @login_required
|
||||
def _old_admin_gbp_audit():
|
||||
"""
|
||||
Admin dashboard for GBP (Google Business Profile) audit overview.
|
||||
|
||||
Displays:
|
||||
- Summary stats (completeness score distribution, field coverage)
|
||||
- Sortable table of all companies with GBP audit data
|
||||
- Review metrics (avg rating, review counts)
|
||||
- Photo statistics
|
||||
"""
|
||||
if not current_user.is_admin:
|
||||
flash('Brak uprawnień do tej strony.', 'error')
|
||||
return redirect(url_for('dashboard'))
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
from sqlalchemy import func, distinct
|
||||
from database import GBPAudit, Category
|
||||
|
||||
# Subquery to get latest audit for each company
|
||||
latest_audit_subq = db.query(
|
||||
GBPAudit.company_id,
|
||||
func.max(GBPAudit.audit_date).label('max_date')
|
||||
).group_by(GBPAudit.company_id).subquery()
|
||||
|
||||
# Get all companies with their latest GBP audit data
|
||||
companies_query = db.query(
|
||||
Company.id,
|
||||
Company.name,
|
||||
Company.slug,
|
||||
Company.website,
|
||||
Category.name.label('category_name'),
|
||||
GBPAudit.completeness_score,
|
||||
GBPAudit.average_rating,
|
||||
GBPAudit.review_count,
|
||||
GBPAudit.photo_count,
|
||||
GBPAudit.has_name,
|
||||
GBPAudit.has_address,
|
||||
GBPAudit.has_phone,
|
||||
GBPAudit.has_website,
|
||||
GBPAudit.has_hours,
|
||||
GBPAudit.has_categories,
|
||||
GBPAudit.has_photos,
|
||||
GBPAudit.has_description,
|
||||
GBPAudit.has_services,
|
||||
GBPAudit.has_reviews,
|
||||
GBPAudit.audit_date
|
||||
).outerjoin(
|
||||
Category,
|
||||
Company.category_id == Category.id
|
||||
).outerjoin(
|
||||
latest_audit_subq,
|
||||
Company.id == latest_audit_subq.c.company_id
|
||||
).outerjoin(
|
||||
GBPAudit,
|
||||
(Company.id == GBPAudit.company_id) &
|
||||
(GBPAudit.audit_date == latest_audit_subq.c.max_date)
|
||||
).filter(
|
||||
Company.status == 'active'
|
||||
).order_by(Company.name).all()
|
||||
|
||||
# Build companies list
|
||||
companies = []
|
||||
for row in companies_query:
|
||||
companies.append({
|
||||
'id': row.id,
|
||||
'name': row.name,
|
||||
'slug': row.slug,
|
||||
'website': row.website,
|
||||
'category': row.category_name,
|
||||
'completeness_score': row.completeness_score,
|
||||
'average_rating': float(row.average_rating) if row.average_rating else None,
|
||||
'review_count': row.review_count or 0,
|
||||
'photo_count': row.photo_count or 0,
|
||||
'has_name': row.has_name,
|
||||
'has_address': row.has_address,
|
||||
'has_phone': row.has_phone,
|
||||
'has_website': row.has_website,
|
||||
'has_hours': row.has_hours,
|
||||
'has_categories': row.has_categories,
|
||||
'has_photos': row.has_photos,
|
||||
'has_description': row.has_description,
|
||||
'has_services': row.has_services,
|
||||
'has_reviews': row.has_reviews,
|
||||
'audit_date': row.audit_date
|
||||
})
|
||||
|
||||
# Calculate statistics
|
||||
total_companies = len(companies)
|
||||
audited = [c for c in companies if c['completeness_score'] is not None]
|
||||
not_audited = [c for c in companies if c['completeness_score'] is None]
|
||||
|
||||
# Score distribution
|
||||
excellent_count = len([c for c in audited if c['completeness_score'] >= 90])
|
||||
good_count = len([c for c in audited if 70 <= c['completeness_score'] < 90])
|
||||
poor_count = len([c for c in audited if c['completeness_score'] < 70])
|
||||
not_audited_count = len(not_audited)
|
||||
|
||||
# Average completeness
|
||||
avg_completeness = round(sum(c['completeness_score'] for c in audited) / len(audited)) if audited else None
|
||||
|
||||
# Average rating (only for companies with reviews)
|
||||
companies_with_rating = [c for c in audited if c['average_rating']]
|
||||
avg_rating = round(sum(c['average_rating'] for c in companies_with_rating) / len(companies_with_rating), 1) if companies_with_rating else None
|
||||
|
||||
# Total reviews
|
||||
total_reviews = sum(c['review_count'] for c in companies)
|
||||
|
||||
# Field coverage stats (percentage of audited companies with each field)
|
||||
if audited:
|
||||
field_coverage = {
|
||||
'name': round(len([c for c in audited if c['has_name']]) / len(audited) * 100),
|
||||
'address': round(len([c for c in audited if c['has_address']]) / len(audited) * 100),
|
||||
'phone': round(len([c for c in audited if c['has_phone']]) / len(audited) * 100),
|
||||
'website': round(len([c for c in audited if c['has_website']]) / len(audited) * 100),
|
||||
'hours': round(len([c for c in audited if c['has_hours']]) / len(audited) * 100),
|
||||
'categories': round(len([c for c in audited if c['has_categories']]) / len(audited) * 100),
|
||||
'photos': round(len([c for c in audited if c['has_photos']]) / len(audited) * 100),
|
||||
'description': round(len([c for c in audited if c['has_description']]) / len(audited) * 100),
|
||||
'services': round(len([c for c in audited if c['has_services']]) / len(audited) * 100),
|
||||
'reviews': round(len([c for c in audited if c['has_reviews']]) / len(audited) * 100),
|
||||
}
|
||||
else:
|
||||
field_coverage = {k: 0 for k in ['name', 'address', 'phone', 'website', 'hours', 'categories', 'photos', 'description', 'services', 'reviews']}
|
||||
|
||||
stats = {
|
||||
'total_companies': total_companies,
|
||||
'audited_count': len(audited),
|
||||
'excellent_count': excellent_count,
|
||||
'good_count': good_count,
|
||||
'poor_count': poor_count,
|
||||
'not_audited_count': not_audited_count,
|
||||
'avg_completeness': avg_completeness,
|
||||
'avg_rating': avg_rating,
|
||||
'total_reviews': total_reviews,
|
||||
'field_coverage': field_coverage
|
||||
}
|
||||
|
||||
# Get unique categories
|
||||
categories = sorted(set(c['category'] for c in companies if c['category']))
|
||||
|
||||
# Convert to objects for template
|
||||
class CompanyRow:
|
||||
def __init__(self, data):
|
||||
for key, value in data.items():
|
||||
setattr(self, key, value)
|
||||
|
||||
companies_objects = [CompanyRow(c) for c in companies]
|
||||
|
||||
return render_template('admin/gbp_audit_dashboard.html',
|
||||
companies=companies_objects,
|
||||
stats=stats,
|
||||
categories=categories,
|
||||
now=datetime.now()
|
||||
)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
# ============================================================
|
||||
# GBP (GOOGLE BUSINESS PROFILE) AUDIT API
|
||||
# ============================================================
|
||||
|
||||
Loading…
Reference in New Issue
Block a user