Update monetization/revenue_tracker.py
Browse files
monetization/revenue_tracker.py
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# revenue_tracker.py - Tracks clicks and affiliate earnings from robot apps
|
| 2 |
+
|
| 3 |
+
import logging
|
| 4 |
+
from collections import defaultdict
|
| 5 |
+
|
| 6 |
+
logging.basicConfig(level=logging.INFO)
|
| 7 |
+
|
| 8 |
+
# Simulated database: user_id -> list of (app_title, clicks, revenue)
|
| 9 |
+
USER_REVENUE = defaultdict(list)
|
| 10 |
+
|
| 11 |
+
class RevenueTracker:
|
| 12 |
+
def __init__(self):
|
| 13 |
+
self.revenue_data = USER_REVENUE
|
| 14 |
+
|
| 15 |
+
def log_affiliate_click(self, user_id: str, app_title: str, earning: float = 0.30):
|
| 16 |
+
found = False
|
| 17 |
+
for app in self.revenue_data[user_id]:
|
| 18 |
+
if app[0] == app_title:
|
| 19 |
+
app[1] += 1
|
| 20 |
+
app[2] += earning
|
| 21 |
+
found = True
|
| 22 |
+
break
|
| 23 |
+
if not found:
|
| 24 |
+
self.revenue_data[user_id].append([app_title, 1, earning])
|
| 25 |
+
logging.info(f"[💰] Click tracked: {user_id} - {app_title} +${earning:.2f}")
|
| 26 |
+
|
| 27 |
+
def get_user_earnings(self, user_id: str):
|
| 28 |
+
return [
|
| 29 |
+
{"title": a[0], "clicks": a[1], "revenue": a[2]}
|
| 30 |
+
for a in self.revenue_data.get(user_id, [])
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
# Example usage
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
tracker = RevenueTracker()
|
| 36 |
+
tracker.log_affiliate_click("user_001", "WaveBot")
|
| 37 |
+
tracker.log_affiliate_click("user_001", "WaveBot")
|
| 38 |
+
tracker.log_affiliate_click("user_001", "EduHelper", 0.45)
|
| 39 |
+
print(tracker.get_user_earnings("user_001"))
|