Fix today active robots

This commit is contained in:
Reckless_Satoshi 2022-01-18 09:52:48 -08:00
parent ce9845cbc2
commit f010fe9bb0
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
4 changed files with 18 additions and 22 deletions

View File

@ -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:

View File

@ -330,7 +330,6 @@ class UserView(APIView):
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)
# Compute token entropy
@ -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,7 +356,6 @@ 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:
@ -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 = []

View File

@ -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 {
<ListItemText
primaryTypographyProps={{fontSize: '14px'}}
secondaryTypographyProps={{fontSize: '12px'}}
primary={this.state.num_active_robotsats}
secondary="Num Active RoboSats" />
primary={this.state.active_robots_today}
secondary="Today Active Robots" />
</ListItem>
</Grid>

View File

@ -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',