From e46b3b03fbe1f274f4df427e59868de75151efb6 Mon Sep 17 00:00:00 2001 From: morelucks Date: Wed, 22 Apr 2026 19:20:33 +0100 Subject: [PATCH] feat: implement subscription price optimization engine closes #210 --- app/screens/PricingOptimizationScreen.tsx | 336 ++++ backend/ml/pricingModel.py | 106 ++ backend/services/index.ts | 1 + backend/services/pricingService.ts | 94 ++ package-lock.json | 1685 ++------------------- src/navigation/AppNavigator.tsx | 21 +- src/navigation/types.ts | 2 + 7 files changed, 679 insertions(+), 1566 deletions(-) create mode 100644 app/screens/PricingOptimizationScreen.tsx create mode 100644 backend/ml/pricingModel.py create mode 100644 backend/services/pricingService.ts diff --git a/app/screens/PricingOptimizationScreen.tsx b/app/screens/PricingOptimizationScreen.tsx new file mode 100644 index 0000000..f815cf3 --- /dev/null +++ b/app/screens/PricingOptimizationScreen.tsx @@ -0,0 +1,336 @@ +import React, { useState, useEffect } from 'react'; +import { + View, + Text, + StyleSheet, + ScrollView, + TouchableOpacity, + ActivityIndicator, +} from 'react-native'; +import { colors, spacing } from '../../src/utils/constants'; +import { Card } from '../../src/components/common/Card'; +import { Button } from '../../src/components/common/Button'; +import { + PricingService, + PriceRecommendation, + ABTestScenario, +} from '../../backend/services/pricingService'; + +const PricingOptimizationScreen = () => { + const [loading, setLoading] = useState(true); + const [recommendation, setRecommendation] = useState(null); + const [abTests, setAbTests] = useState([]); + const [activeTest, setActiveTest] = useState(null); + + useEffect(() => { + fetchData(); + }, []); + + const fetchData = async () => { + setLoading(true); + try { + const rec = await PricingService.calculateOptimalPrice('sub_123', { + current_price: 14.99, + competitor_avg: 12.99, + current_demand: 1.2, + usage_data: { + retention_rate: 0.85, + sessions_per_week: 10, + }, + }); + const tests = await PricingService.getPriceRecommendations('plan_gold'); + setRecommendation(rec); + setAbTests(tests); + } catch (error) { + console.error(error); + } finally { + setLoading(false); + } + }; + + const renderMetric = (label: string, value: string | number, subtext?: string) => ( + + {label} + {value} + {subtext && {subtext}} + + ); + + if (loading) { + return ( + + + + ); + } + + return ( + + + Pricing Optimization + AI-Powered Revenue Maximization + + + + Optimal Price Recommendation + + $14.99 + + ${recommendation?.optimalPrice} + + + + {recommendation?.recommendation} Recommendation + + + + + {renderMetric('Demand Factor', `${recommendation?.factors.demandImpact}x`, 'High Demand')} + {renderMetric( + 'Comp. Avg', + `$${recommendation?.factors.competitorBenchmark}`, + 'Market Bench' + )} + {renderMetric('WTP Est.', `$${recommendation?.factors.willingnessToPay}`, 'User Value')} + + + + + A/B Testing Strategies + {abTests.map((test, index) => ( + setActiveTest(test.tier)}> + + {test.tier} + ${test.price} + + {test.reasoning} + {activeTest === test.tier && ( + + ACTIVE TEST + + )} + + ))} + + + + Demand Forecast + + + {[40, 60, 45, 90, 75, 80, 95].map((h, i) => ( + + ))} + + + {['M', 'T', 'W', 'T', 'F', 'S', 'S'].map((l, i) => ( + + {l} + + ))} + + + + +