File size: 8,455 Bytes
af2bcb1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
from typing import Dict, List
from config import RECOMMENDATIONS_RULES

def generate_recommendations(analysis_results: Dict) -> List[Dict]:
    """
    Generate actionable recommendations based on analysis results
    
    Args:
        analysis_results: Dictionary with analysis results from AI
        
    Returns:
        List of recommendation dictionaries
    """
    recommendations = []
    
    if not analysis_results:
        return recommendations
    
    # Product not found recommendations
    if not analysis_results.get('product_found', False):
        recommendations.append({
            'type': 'critical',
            'priority': 1,
            'title': '🚨 Produkt nie znaleziony',
            'description': 'Produkt nie jest widoczny na półce lub jest niedostępny.',
            'action': 'Uzupełnij asortyment lub sprawdź lokalizację produktu',
            'estimated_impact': '+100% dostępności',
            'time_to_fix': '5-15 minut',
            'difficulty': 'Łatwe'
        })
        return recommendations
    
    # Position recommendations
    shelf_position = analysis_results.get('shelf_position', '').lower()
    if shelf_position in ['bottom', 'dół', 'dolna']:
        recommendations.append({
            'type': 'position',
            'priority': 2,
            'title': '📈 Przenieś na poziom oczu',
            'description': 'Produkt znajduje się na dolnej półce, co znacznie zmniejsza widoczność.',
            'action': 'Przenieś produkty na poziom oczu (120-160cm)',
            'estimated_impact': '+30% sprzedaży',
            'time_to_fix': '2-3 minuty',
            'difficulty': 'Łatwe'
        })
    elif shelf_position in ['top', 'góra', 'górna']:
        recommendations.append({
            'type': 'position',
            'priority': 3,
            'title': '👁️ Popraw widoczność',
            'description': 'Produkt na górnej półce - rozważ przeniesienie lub dodatkowe oznakowanie.',
            'action': 'Przenieś na środkową półkę lub dodaj shelf talker',
            'estimated_impact': '+20% widoczności',
            'time_to_fix': '2-3 minuty',
            'difficulty': 'Łatwe'
        })
    
    # Facing count recommendations
    facing_count = analysis_results.get('facing_count', 0)
    if facing_count == 1:
        recommendations.append({
            'type': 'quantity',
            'priority': 3,
            'title': '➕ Zwiększ liczbę facings',
            'description': 'Tylko jeden facing - zwiększenie do 2-3 poprawia widoczność.',
            'action': 'Dodaj 1-2 dodatkowe facings',
            'estimated_impact': '+15% widoczności',
            'time_to_fix': '1-2 minuty',
            'difficulty': 'Bardzo łatwe'
        })
    elif facing_count == 0:
        recommendations.append({
            'type': 'quantity',
            'priority': 1,
            'title': '🔄 Uzupełnij produkty',
            'description': 'Brak produktów na półce.',
            'action': 'Uzupełnij asortyment z magazynu',
            'estimated_impact': '+100% dostępności',
            'time_to_fix': '5-10 minut',
            'difficulty': 'Łatwe'
        })
    
    # Price visibility recommendations
    if not analysis_results.get('price_visible', False):
        recommendations.append({
            'type': 'pricing',
            'priority': 2,
            'title': '💰 Dodaj widoczną cenę',
            'description': 'Brak widocznej ceny może zniechęcać klientów.',
            'action': 'Dodaj lub popraw czytelność cenówki',
            'estimated_impact': '+10% konwersji',
            'time_to_fix': '1-2 minuty',
            'difficulty': 'Bardzo łatwe'
        })
    
    # Product condition recommendations
    condition = analysis_results.get('product_condition', '').lower()
    if condition in ['dusty', 'zakurzony']:
        recommendations.append({
            'type': 'condition',
            'priority': 4,
            'title': '🧹 Wyczyść produkty',
            'description': 'Produkty wyglądają na zakurzone, co wpływa na postrzeganie jakości.',
            'action': 'Wyczyść produkty i opakowania',
            'estimated_impact': '+5% percepcji jakości',
            'time_to_fix': '2-3 minuty',
            'difficulty': 'Bardzo łatwe'
        })
    elif condition in ['damaged', 'uszkodzony']:
        recommendations.append({
            'type': 'condition',
            'priority': 1,
            'title': '⚠️ Wymień uszkodzone produkty',
            'description': 'Uszkodzone produkty negatywnie wpływają na wizerunek marki.',
            'action': 'Usuń uszkodzone produkty i zastąp nowymi',
            'estimated_impact': '+15% percepcji marki',
            'time_to_fix': '3-5 minut',
            'difficulty': 'Łatwe'
        })
    
    # Competition recommendations
    competitors = analysis_results.get('competitors_nearby', [])
    if len(competitors) > 3:
        recommendations.append({
            'type': 'competition',
            'priority': 3,
            'title': '🎯 Zwiększ wyróżnienie',
            'description': f'Silna konkurencja w pobliżu ({len(competitors)} produktów konkurencyjnych).',
            'action': 'Dodaj materiały POS lub zwiększ liczbę facings',
            'estimated_impact': '+20% uwagi klientów',
            'time_to_fix': '5-10 minut',
            'difficulty': 'Średnie'
        })
    
    # Shelf share recommendations
    shelf_share = analysis_results.get('shelf_share', 0)
    if shelf_share < 10:
        recommendations.append({
            'type': 'share',
            'priority': 2,
            'title': '📊 Zwiększ udział w półce',
            'description': f'Niski udział w półce ({shelf_share}%). Rozważ negocjacje z menedżerem kategorii.',
            'action': 'Zwiększ liczbę facings lub wynegocjuj lepszą przestrzeń',
            'estimated_impact': '+25% widoczności',
            'time_to_fix': '10-30 minut',
            'difficulty': 'Trudne'
        })
    
    # Overall score recommendations
    overall_score = analysis_results.get('overall_score', 5)
    if overall_score < 4:
        recommendations.append({
            'type': 'general',
            'priority': 1,
            'title': '🚀 Kompleksowa poprawa',
            'description': 'Niska ogólna ocena ekspozycji wymaga kompleksowej poprawy.',
            'action': 'Zastosuj wszystkie powyższe rekomendacje w kolejności priorytetów',
            'estimated_impact': '+50% ogólnej efektywności',
            'time_to_fix': '15-30 minut',
            'difficulty': 'Średnie'
        })
    
    # Sort recommendations by priority
    recommendations.sort(key=lambda x: x['priority'])
    
    return recommendations

def calculate_total_impact(recommendations: List[Dict]) -> Dict:
    """
    Calculate estimated total impact of all recommendations
    
    Args:
        recommendations: List of recommendation dictionaries
        
    Returns:
        Dictionary with total impact estimates
    """
    total_time = 0
    impact_categories = {
        'sprzedaż': [],
        'widoczność': [],
        'dostępność': [],
        'jakość': []
    }
    
    for rec in recommendations:
        # Extract time (assuming format like "2-3 minuty")
        time_str = rec.get('time_to_fix', '0')
        try:
            # Extract first number from time string
            time_parts = time_str.split('-')
            if time_parts:
                total_time += int(''.join(filter(str.isdigit, time_parts[0])))
        except:
            total_time += 5  # Default 5 minutes
        
        # Categorize impact
        impact = rec.get('estimated_impact', '')
        if 'sprzedaż' in impact.lower():
            impact_categories['sprzedaż'].append(impact)
        elif 'widoczność' in impact.lower():
            impact_categories['widoczność'].append(impact)
        elif 'dostępność' in impact.lower():
            impact_categories['dostępność'].append(impact)
        elif any(word in impact.lower() for word in ['jakość', 'percepcj']):
            impact_categories['jakość'].append(impact)
    
    return {
        'total_time_minutes': total_time,
        'impact_categories': impact_categories,
        'total_recommendations': len(recommendations),
        'high_priority_count': len([r for r in recommendations if r['priority'] <= 2])
    }