mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-18 20:21:35 +00:00
Fix today active robots
This commit is contained in:
parent
ce9845cbc2
commit
f010fe9bb0
@ -11,12 +11,12 @@ def users_cleansing():
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
# Users who's last login has not been in the last 12 hours
|
# Users who's last login has not been in the last 6 hours
|
||||||
active_time_range = (timezone.now() - timedelta(hours=12), timezone.now())
|
active_time_range = (timezone.now() - timedelta(hours=6), timezone.now())
|
||||||
queryset = User.objects.filter(~Q(last_login__range=active_time_range))
|
queryset = User.objects.filter(~Q(last_login__range=active_time_range))
|
||||||
queryset = queryset.filter(is_staff=False) # Do not delete staff users
|
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 = []
|
deleted_users = []
|
||||||
for user in queryset:
|
for user in queryset:
|
||||||
if not user.profile.total_contracts == 0:
|
if not user.profile.total_contracts == 0:
|
||||||
|
14
api/views.py
14
api/views.py
@ -330,7 +330,6 @@ class UserView(APIView):
|
|||||||
context['bad_request'] = f'You are already logged in as {request.user}'
|
context['bad_request'] = f'You are already logged in as {request.user}'
|
||||||
return Response(context, status.HTTP_400_BAD_REQUEST)
|
return Response(context, status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
token = request.GET.get(self.lookup_url_kwarg)
|
token = request.GET.get(self.lookup_url_kwarg)
|
||||||
|
|
||||||
# Compute token entropy
|
# Compute token entropy
|
||||||
@ -345,10 +344,10 @@ class UserView(APIView):
|
|||||||
context['bad_request'] = 'The token does not have enough entropy'
|
context['bad_request'] = 'The token does not have enough entropy'
|
||||||
return Response(context, status=status.HTTP_400_BAD_REQUEST)
|
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()
|
hash = hashlib.sha256(str.encode(token)).hexdigest()
|
||||||
|
|
||||||
# Generate nickname
|
# Generate nickname deterministically
|
||||||
nickname = self.NickGen.short_from_SHA256(hash, max_length=18)[0]
|
nickname = self.NickGen.short_from_SHA256(hash, max_length=18)[0]
|
||||||
context['nickname'] = nickname
|
context['nickname'] = nickname
|
||||||
|
|
||||||
@ -357,13 +356,12 @@ class UserView(APIView):
|
|||||||
rh.assemble(roboset='set1', bgset='any')# for backgrounds ON
|
rh.assemble(roboset='set1', bgset='any')# for backgrounds ON
|
||||||
|
|
||||||
# Does not replace image if existing (avoid re-avatar in case of nick collusion)
|
# Does not replace image if existing (avoid re-avatar in case of nick collusion)
|
||||||
|
|
||||||
image_path = avatar_path.joinpath(nickname+".png")
|
image_path = avatar_path.joinpath(nickname+".png")
|
||||||
if not image_path.exists():
|
if not image_path.exists():
|
||||||
with open(image_path, "wb") as f:
|
with open(image_path, "wb") as f:
|
||||||
rh.img.save(f, format="png")
|
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:
|
if len(User.objects.filter(username=nickname)) == 0:
|
||||||
User.objects.create_user(username=nickname, password=token, is_staff=False)
|
User.objects.create_user(username=nickname, password=token, is_staff=False)
|
||||||
user = authenticate(request, username=nickname, password=token)
|
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))
|
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)
|
# Number of active users (logged in in last 30 minutes)
|
||||||
active_user_time_range = (timezone.now() - timedelta(minutes=120), timezone.now())
|
today = datetime.today()
|
||||||
context['num_active_robotsats'] = len(User.objects.filter(last_login__range=active_user_time_range))
|
context['active_robots_today'] = len(User.objects.filter(last_login__day=today.day))
|
||||||
|
|
||||||
# Compute average premium and volume of today
|
# Compute average premium and volume of today
|
||||||
today = datetime.today()
|
|
||||||
|
|
||||||
queryset = MarketTick.objects.filter(timestamp__day=today.day)
|
queryset = MarketTick.objects.filter(timestamp__day=today.day)
|
||||||
if not len(queryset) == 0:
|
if not len(queryset) == 0:
|
||||||
weighted_premiums = []
|
weighted_premiums = []
|
||||||
|
@ -21,12 +21,12 @@ export default class BottomBar extends Component {
|
|||||||
this.state = {
|
this.state = {
|
||||||
openStatsForNerds: false,
|
openStatsForNerds: false,
|
||||||
openCommuniy: false,
|
openCommuniy: false,
|
||||||
num_public_buy_orders: null,
|
num_public_buy_orders: 0,
|
||||||
num_active_robotsats: null,
|
num_public_sell_orders: 0,
|
||||||
num_public_sell_orders: null,
|
active_robots_today: 0,
|
||||||
fee: null,
|
fee: 0,
|
||||||
today_avg_nonkyc_btc_premium: null,
|
today_avg_nonkyc_btc_premium: 0,
|
||||||
today_total_volume: null,
|
today_total_volume: 0,
|
||||||
};
|
};
|
||||||
this.getInfo();
|
this.getInfo();
|
||||||
}
|
}
|
||||||
@ -200,8 +200,8 @@ export default class BottomBar extends Component {
|
|||||||
<ListItemText
|
<ListItemText
|
||||||
primaryTypographyProps={{fontSize: '14px'}}
|
primaryTypographyProps={{fontSize: '14px'}}
|
||||||
secondaryTypographyProps={{fontSize: '12px'}}
|
secondaryTypographyProps={{fontSize: '12px'}}
|
||||||
primary={this.state.num_active_robotsats}
|
primary={this.state.active_robots_today}
|
||||||
secondary="Num Active RoboSats" />
|
secondary="Today Active Robots" />
|
||||||
</ListItem>
|
</ListItem>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
@ -31,9 +31,9 @@ app.conf.beat_scheduler = 'django_celery_beat.schedulers:DatabaseScheduler'
|
|||||||
|
|
||||||
# Configure the periodic tasks
|
# Configure the periodic tasks
|
||||||
app.conf.beat_schedule = {
|
app.conf.beat_schedule = {
|
||||||
'users-cleansing': { # Cleans abandoned users every 6 hours
|
'users-cleansing': { # Cleans abandoned users every hour
|
||||||
'task': 'users_cleansing',
|
'task': 'users_cleansing',
|
||||||
'schedule': timedelta(hours=6),
|
'schedule': timedelta(hours=1),
|
||||||
},
|
},
|
||||||
'cache-market-prices': { # Cache market prices every minutes for now.
|
'cache-market-prices': { # Cache market prices every minutes for now.
|
||||||
'task': 'cache_external_market_prices',
|
'task': 'cache_external_market_prices',
|
||||||
|
Loading…
Reference in New Issue
Block a user