diff --git a/api/tasks.py b/api/tasks.py index 9f1aaaa8..82da436a 100644 --- a/api/tasks.py +++ b/api/tasks.py @@ -11,12 +11,12 @@ def users_cleansing(): from datetime import timedelta from django.utils import timezone - # Users who's last login has not been in the last 12 hours - active_time_range = (timezone.now() - timedelta(hours=12), timezone.now()) + # Users who's last login has not been in the last 6 hours + active_time_range = (timezone.now() - timedelta(hours=6), timezone.now()) queryset = User.objects.filter(~Q(last_login__range=active_time_range)) queryset = queryset.filter(is_staff=False) # Do not delete staff users - # And do not have an active trade or any pass finished trade. + # And do not have an active trade or any past contract. deleted_users = [] for user in queryset: if not user.profile.total_contracts == 0: diff --git a/api/views.py b/api/views.py index 3683fe7c..d1fb2427 100644 --- a/api/views.py +++ b/api/views.py @@ -329,7 +329,6 @@ class UserView(APIView): if request.user.last_login < timezone.now() - timedelta(minutes=5): context['bad_request'] = f'You are already logged in as {request.user}' return Response(context, status.HTTP_400_BAD_REQUEST) - token = request.GET.get(self.lookup_url_kwarg) @@ -345,10 +344,10 @@ class UserView(APIView): context['bad_request'] = 'The token does not have enough entropy' return Response(context, status=status.HTTP_400_BAD_REQUEST) - # Hashes the token, only 1 iteration. Maybe more is better. + # Hash the token, only 1 iteration. hash = hashlib.sha256(str.encode(token)).hexdigest() - # Generate nickname + # Generate nickname deterministically nickname = self.NickGen.short_from_SHA256(hash, max_length=18)[0] context['nickname'] = nickname @@ -357,13 +356,12 @@ class UserView(APIView): rh.assemble(roboset='set1', bgset='any')# for backgrounds ON # Does not replace image if existing (avoid re-avatar in case of nick collusion) - image_path = avatar_path.joinpath(nickname+".png") if not image_path.exists(): with open(image_path, "wb") as f: rh.img.save(f, format="png") - # Create new credentials and log in if nickname is new + # Create new credentials and login if nickname is new if len(User.objects.filter(username=nickname)) == 0: User.objects.create_user(username=nickname, password=token, is_staff=False) user = authenticate(request, username=nickname, password=token) @@ -451,12 +449,10 @@ class InfoView(ListAPIView): context['num_public_sell_orders'] = len(Order.objects.filter(type=Order.Types.SELL, status=Order.Status.PUB)) # Number of active users (logged in in last 30 minutes) - active_user_time_range = (timezone.now() - timedelta(minutes=120), timezone.now()) - context['num_active_robotsats'] = len(User.objects.filter(last_login__range=active_user_time_range)) + today = datetime.today() + context['active_robots_today'] = len(User.objects.filter(last_login__day=today.day)) # Compute average premium and volume of today - today = datetime.today() - queryset = MarketTick.objects.filter(timestamp__day=today.day) if not len(queryset) == 0: weighted_premiums = [] diff --git a/frontend/src/components/BottomBar.js b/frontend/src/components/BottomBar.js index 5516ee36..df924fa6 100644 --- a/frontend/src/components/BottomBar.js +++ b/frontend/src/components/BottomBar.js @@ -21,12 +21,12 @@ export default class BottomBar extends Component { this.state = { openStatsForNerds: false, openCommuniy: false, - num_public_buy_orders: null, - num_active_robotsats: null, - num_public_sell_orders: null, - fee: null, - today_avg_nonkyc_btc_premium: null, - today_total_volume: null, + num_public_buy_orders: 0, + num_public_sell_orders: 0, + active_robots_today: 0, + fee: 0, + today_avg_nonkyc_btc_premium: 0, + today_total_volume: 0, }; this.getInfo(); } @@ -200,8 +200,8 @@ export default class BottomBar extends Component { + primary={this.state.active_robots_today} + secondary="Today Active Robots" /> diff --git a/robosats/celery/__init__.py b/robosats/celery/__init__.py index 0d1999d2..a176b226 100644 --- a/robosats/celery/__init__.py +++ b/robosats/celery/__init__.py @@ -31,9 +31,9 @@ app.conf.beat_scheduler = 'django_celery_beat.schedulers:DatabaseScheduler' # Configure the periodic tasks app.conf.beat_schedule = { - 'users-cleansing': { # Cleans abandoned users every 6 hours + 'users-cleansing': { # Cleans abandoned users every hour 'task': 'users_cleansing', - 'schedule': timedelta(hours=6), + 'schedule': timedelta(hours=1), }, 'cache-market-prices': { # Cache market prices every minutes for now. 'task': 'cache_external_market_prices',