add better eco ratings
Android Release Build / build-android (push) Successful in 13m35s

This commit is contained in:
Frederik Spirgi
2026-10-26 11:42:28 +01:00
parent f12a9d47b6
commit 1d32aeaf29
9 changed files with 255 additions and 35 deletions
+48 -5
View File
@@ -69,24 +69,42 @@ export default function ProductDetailScreen({
<Text style={styles.meta}>
{product.category || 'Produkt'} · {formatPrice(pricedProduct.price, currency)}
</Text>
<Text style={styles.source}>{sourceLabel(product.dataSource)}</Text>
<Text style={styles.source}>{sourceLabel(product.dataSource)}{product.cacheStale ? ' · Veraltete Daten' : ''}</Text>
{['cache', 'open-food-facts'].includes(product.dataSource) ? <Text style={styles.meta}>Produktdaten geprüft: {formatCheckedDate(product.fetchedAt)}</Text> : null}
</View>
<ProductScoreBadge status={rating.overallStatus} score={rating.overallScore} />
</View>
<View style={[styles.recommendation, styles[`${rating.overallStatus}Recommendation`]]}>
<Text style={[styles.recommendationTitle, styles[`${rating.overallStatus}Text`]]}>{recommendation}</Text>
<Text style={styles.recommendationCopy}>
{rating.allergenReviewRequired
? 'Allergenangaben fehlen oder sind nicht bestätigt. Prüfe vor dem Kauf die Verpackung.'
{rating.hasBlockedAllergen
? rating.categoryScores.allergies.message
: rating.allergenReviewRequired
? rating.allergenReviewMessage
: rating.staleDataReviewRequired
? 'Gespeicherte Produktdaten sind veraltet. Prüfe vor dem Kauf die Verpackung.'
: rating.overallStatus === 'unknown'
? 'Für eine Empfehlung fehlen belastbare Produktangaben.'
: rating.limitedByMissingData
? 'Nur ein Teil der Kriterien ist belegt. Die Empfehlung ist deshalb auf „Prüfen“ begrenzt.'
: 'Tippe unten auf ein Kriterium, um die Bewertung nachzuvollziehen.'}
</Text>
<Text style={styles.recommendationCopy}>Bewertbare Daten: {rating.dataCoverage}% der für dein Profil anwendbaren Kriterien (gewichtet).</Text>
</View>
</View>
{rating.mainFactors.length > 0 || rating.scoreLimitReasons.length > 0 ? (
<View style={styles.dataPanel}>
<Text style={styles.factorTitle}>Wichtigste Einflüsse auf die App-Bewertung</Text>
{rating.scoreLimitReasons.map((reason) => <Text key={reason} style={styles.dataText}>{reason}</Text>)}
{rating.mainFactors.map((factor) => (
<Text key={factor.category} style={styles.dataText}>
{factor.label}: {factor.score}/100 · {factor.message}
</Text>
))}
</View>
) : null}
{!hasProductPrice ? (
<View style={styles.pricePanel}>
<Text style={styles.priceTitle}>Ladenpreis ergänzen</Text>
@@ -168,14 +186,22 @@ export default function ProductDetailScreen({
</>
) : <Text style={styles.dataText}>CO₂-Fussabdruck: Nicht verfügbar.</Text>}
<Text style={styles.dataText}>Green-Score (Open Food Facts): {product.sustainability?.ecoScore || 'Nicht verfügbar'}</Text>
<Text style={styles.dataText}>Zutatenherkunft: {ingredientOriginLabel(product)}</Text>
{(product.sustainability?.sellingCountries || []).length > 0 ? (
<Text style={styles.dataText}>Verkaufsländer: {product.sustainability.sellingCountries.map(formatCountryTag).join(', ')}</Text>
) : null}
</View>
<SectionTitle>Produktdaten</SectionTitle>
<View style={styles.dataPanel}>
<Text style={styles.dataText}>Barcode: {product.barcode}</Text>
<Text style={styles.dataText}>Zutaten: {(product.ingredients || []).join(', ') || 'Keine Angaben'}</Text>
<Text style={styles.dataText}>Allergene: {(product.allergens || []).join(', ') || 'Keine Angaben'}</Text>
<Text style={styles.dataText}>Nutri-Score: {product.nutrition?.nutriScore || 'Keine Angabe'}</Text>
<Text style={styles.dataText}>Angegebene Allergene: {(product.allergens || []).join(', ') || 'Keine Angaben'}</Text>
<Text style={styles.dataText}>Mögliche Allergenspuren: {(product.allergenTraces || []).join(', ') || 'Keine Angaben'}</Text>
<Text style={styles.dataText}>
Nutri-Score: {rating.categoryScores.nutrition.nutriScore || 'Keine Angabe'}
{rating.categoryScores.nutrition.nutriScoreSource === 'calculated' ? ' (von der App berechnet)' : rating.categoryScores.nutrition.nutriScore ? ' (Open Food Facts)' : ''}
</Text>
</View>
</ScreenContainer>
@@ -203,6 +229,22 @@ function sourceLabel(source) {
return labels[source] || 'Quelle: unbekannt';
}
function formatCheckedDate(value) {
const date = new Date(value);
return Number.isNaN(date.getTime()) ? 'unbekannt' : date.toLocaleDateString('de-CH');
}
function ingredientOriginLabel(product) {
const sustainability = product.sustainability || {};
if (['cache', 'open-food-facts'].includes(product.dataSource)
&& sustainability.originSource !== 'ingredient-origin') return 'Nicht verfügbar';
return sustainability.originCountry || 'Nicht verfügbar';
}
function formatCountryTag(tag) {
return tag.replace(/^[a-z]{2}:/, '').replace(/-/g, ' ');
}
function formatImpact(value, maximumFractionDigits = 2) {
return new Intl.NumberFormat('de-CH', { maximumFractionDigits, minimumFractionDigits: value < 0.01 ? 3 : 0 }).format(value);
}
@@ -222,6 +264,7 @@ function matchLabel(method) {
}
const styles = StyleSheet.create({
factorTitle: { color: colors.text, fontSize: 16, fontWeight: '800' },
productPanel: {
backgroundColor: colors.surface,
borderColor: colors.border,