start project
This commit is contained in:
0
tapdata/__init__.py
Normal file
0
tapdata/__init__.py
Normal file
BIN
tapdata/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
tapdata/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
tapdata/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
tapdata/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
tapdata/__pycache__/admin.cpython-310.pyc
Normal file
BIN
tapdata/__pycache__/admin.cpython-310.pyc
Normal file
Binary file not shown.
BIN
tapdata/__pycache__/admin.cpython-311.pyc
Normal file
BIN
tapdata/__pycache__/admin.cpython-311.pyc
Normal file
Binary file not shown.
BIN
tapdata/__pycache__/apps.cpython-310.pyc
Normal file
BIN
tapdata/__pycache__/apps.cpython-310.pyc
Normal file
Binary file not shown.
BIN
tapdata/__pycache__/apps.cpython-311.pyc
Normal file
BIN
tapdata/__pycache__/apps.cpython-311.pyc
Normal file
Binary file not shown.
BIN
tapdata/__pycache__/models.cpython-310.pyc
Normal file
BIN
tapdata/__pycache__/models.cpython-310.pyc
Normal file
Binary file not shown.
BIN
tapdata/__pycache__/models.cpython-311.pyc
Normal file
BIN
tapdata/__pycache__/models.cpython-311.pyc
Normal file
Binary file not shown.
BIN
tapdata/__pycache__/serializers.cpython-310.pyc
Normal file
BIN
tapdata/__pycache__/serializers.cpython-310.pyc
Normal file
Binary file not shown.
BIN
tapdata/__pycache__/serializers.cpython-311.pyc
Normal file
BIN
tapdata/__pycache__/serializers.cpython-311.pyc
Normal file
Binary file not shown.
BIN
tapdata/__pycache__/views.cpython-310.pyc
Normal file
BIN
tapdata/__pycache__/views.cpython-310.pyc
Normal file
Binary file not shown.
BIN
tapdata/__pycache__/views.cpython-311.pyc
Normal file
BIN
tapdata/__pycache__/views.cpython-311.pyc
Normal file
Binary file not shown.
13
tapdata/admin.py
Normal file
13
tapdata/admin.py
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
from django.contrib import admin
|
||||
from .models import Farming, Prizes
|
||||
|
||||
admin.site.register(Farming)
|
||||
admin.site.register(Prizes)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
6
tapdata/apps.py
Normal file
6
tapdata/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class TapdataConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'tapdata'
|
50
tapdata/migrations/0001_initial.py
Normal file
50
tapdata/migrations/0001_initial.py
Normal file
@@ -0,0 +1,50 @@
|
||||
# Generated by Django 5.0.6 on 2024-08-26 11:44
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Prizes',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('prize_type', models.CharField(choices=[('CN', 'Coins'), ('AL', 'Acceleration'), ('AC', 'Auto_collection')], max_length=250, verbose_name='Тип приза')),
|
||||
('time', models.IntegerField(blank=True, null=True, verbose_name='Время награды в днях')),
|
||||
('coins', models.BigIntegerField(blank=True, null=True, verbose_name='Количество MCDK (Необязательно)')),
|
||||
('percent', models.IntegerField(blank=True, null=True, verbose_name='Процент (Необязательно)')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Приз',
|
||||
'verbose_name_plural': 'Призы',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Farming',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('coins_per_min', models.BigIntegerField(blank=True, default=1, verbose_name='Монет за мин')),
|
||||
('coins', models.BigIntegerField(blank=True, default=0, verbose_name='Количество MCDK')),
|
||||
('start_time', models.DateTimeField(blank=True, null=True, verbose_name='Время и дата начала фарминга')),
|
||||
('percent', models.IntegerField(default=0, verbose_name='Дополнительные проценты фарминга')),
|
||||
('is_auto_collection_active', models.BooleanField(default=False, verbose_name='Автосбор активен')),
|
||||
('auto_collection_end_time', models.DateTimeField(blank=True, null=True, verbose_name='Время окончания автосбора')),
|
||||
('bonus_multiplier', models.FloatField(blank=True, default=1.0, verbose_name='Множитель скорости фарминга')),
|
||||
('bonus_end_time', models.DateTimeField(blank=True, null=True, verbose_name='Время окончания бонуса')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Данные фарминга',
|
||||
'verbose_name_plural': 'Данные фармингов',
|
||||
},
|
||||
),
|
||||
]
|
0
tapdata/migrations/__init__.py
Normal file
0
tapdata/migrations/__init__.py
Normal file
BIN
tapdata/migrations/__pycache__/0001_initial.cpython-310.pyc
Normal file
BIN
tapdata/migrations/__pycache__/0001_initial.cpython-310.pyc
Normal file
Binary file not shown.
BIN
tapdata/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
BIN
tapdata/migrations/__pycache__/0001_initial.cpython-311.pyc
Normal file
Binary file not shown.
BIN
tapdata/migrations/__pycache__/__init__.cpython-310.pyc
Normal file
BIN
tapdata/migrations/__pycache__/__init__.cpython-310.pyc
Normal file
Binary file not shown.
BIN
tapdata/migrations/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
tapdata/migrations/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
73
tapdata/models.py
Normal file
73
tapdata/models.py
Normal file
@@ -0,0 +1,73 @@
|
||||
from django.db import models
|
||||
from users.models import User
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
class Farming(models.Model):
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
coins_per_min = models.BigIntegerField('Монет за мин', default=1, blank=True)
|
||||
coins = models.BigIntegerField('Количество MCDK', default=0, blank=True)
|
||||
start_time = models.DateTimeField('Время и дата начала фарминга', null=True, blank=True)
|
||||
percent = models.IntegerField("Дополнительные проценты фарминга", default=0)
|
||||
is_auto_collection_active = models.BooleanField('Автосбор активен', default=False)
|
||||
auto_collection_end_time = models.DateTimeField('Время окончания автосбора', null=True, blank=True)
|
||||
bonus_multiplier = models.FloatField('Множитель скорости фарминга', default=1.0, blank=True)
|
||||
bonus_end_time = models.DateTimeField('Время окончания бонуса', null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.user.username} имеет {self.coins} MCDK'
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Данные фарминга'
|
||||
verbose_name_plural = 'Данные фармингов'
|
||||
|
||||
def apply_auto_collection(self, duration_days):
|
||||
self.is_auto_collection_active = True
|
||||
self.auto_collection_end_time = timezone.now() + timedelta(days=duration_days)
|
||||
self.save()
|
||||
|
||||
def apply_bonus_multiplier(self, percent, duration_days):
|
||||
self.bonus_multiplier = 1 + (percent / 100)
|
||||
self.bonus_end_time = timezone.now() + timedelta(days=duration_days)
|
||||
self.save()
|
||||
|
||||
def update_farming(self):
|
||||
current_time = timezone.now()
|
||||
|
||||
# Обновление авто-сбора
|
||||
if self.is_auto_collection_active and self.auto_collection_end_time < current_time:
|
||||
self.is_auto_collection_active = False
|
||||
self.auto_collection_end_time = None
|
||||
self.save()
|
||||
|
||||
# Обновление бонусного множителя
|
||||
if self.bonus_multiplier > 1.0 and self.bonus_end_time < current_time:
|
||||
self.bonus_multiplier = 1.0
|
||||
self.bonus_end_time = None
|
||||
self.save()
|
||||
|
||||
# Обновление монет с учетом бонусного множителя
|
||||
self.coins += self.coins_per_min * self.bonus_multiplier
|
||||
self.save()
|
||||
|
||||
# Призы с колеса фортуны
|
||||
class Prizes(models.Model):
|
||||
class PrizeTypeEnum(models.TextChoices):
|
||||
COINS = 'CN', _('Coins')
|
||||
ACCELERATION = 'AL', _('Acceleration')
|
||||
AUTO_COLLECTION = 'AC', _('Auto_collection')
|
||||
|
||||
prize_type = models.CharField('Тип приза', choices=PrizeTypeEnum.choices, max_length=250)
|
||||
time = models.IntegerField('Время награды в днях', null=True, blank=True)
|
||||
coins = models.BigIntegerField('Количество MCDK (Необязательно)', null=True, blank=True)
|
||||
percent = models.IntegerField('Процент (Необязательно)', null=True, blank=True)
|
||||
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f'Тип приза - {self.prize_type}'
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'Приз'
|
||||
verbose_name_plural = 'Призы'
|
14
tapdata/serializers.py
Normal file
14
tapdata/serializers.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from rest_framework import serializers
|
||||
from .models import Farming, Prizes
|
||||
|
||||
class FarmingSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Farming
|
||||
fields = '__all__'
|
||||
|
||||
class PrizesSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Prizes
|
||||
fields = '__all__'
|
||||
|
||||
|
3
tapdata/tests.py
Normal file
3
tapdata/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
14
tapdata/views.py
Normal file
14
tapdata/views.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from rest_framework import viewsets
|
||||
from .models import Farming, Prizes
|
||||
from .serializers import FarmingSerializer, PrizesSerializer
|
||||
|
||||
|
||||
|
||||
class FarmingViewSet(viewsets.ModelViewSet):
|
||||
queryset = Farming.objects.all()
|
||||
serializer_class = FarmingSerializer
|
||||
|
||||
class PrizesViewSet(viewsets.ModelViewSet):
|
||||
queryset = Prizes.objects.all()
|
||||
serializer_class = PrizesSerializer
|
||||
|
Reference in New Issue
Block a user