Skip to content

Commit

Permalink
Add workflow for flake8. Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
KuzenkovAG committed Jun 30, 2023
1 parent a14edb0 commit a7218fb
Show file tree
Hide file tree
Showing 28 changed files with 132 additions and 86 deletions.
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Main Workflow
on:
push:
branches:
- main
jobs:
backend_linters:
name: Check Linters
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8==6.0.0 flake8-isort==6.0.0
- name: Test with flake8
run: python -m flake8 hmom3/
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ resurses_test/
.env

db.sqlite3

to_do
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# hmom3 Online game

[![Flake8](https://img.shields.io/github/actions/workflow/status/KuzenkovAG/hmom3/ci.yml)](https://github.com/KuzenkovAG/hmom3/actions/workflows/ci.yml)
![Top language](https://img.shields.io/github/languages/top/KuzenkovAG/hmom3?style=flat-square&logo=appveyor)
![Languages count](https://img.shields.io/github/languages/count/KuzenkovAG/hmom3?style=flat-square&logo=appveyor)
![Commit activity](https://img.shields.io/github/commit-activity/m/KuzenkovAG/hmom3?style=flat-square&logo=appveyor)
Expand Down
6 changes: 2 additions & 4 deletions hmom3/apps/about/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,5 @@
app_name = 'about'

urlpatterns = [
path('',
views.AboutView.as_view(),
name='index'),
]
path('', views.AboutView.as_view(), name='index'),
]
4 changes: 2 additions & 2 deletions hmom3/apps/core/balance/calculate_coefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ def calculate_coef(point1, point2):
"""Calculate coefficients a and b of f(x) = a*x**2 + b*x."""
x1, y1 = point1
x2, y2 = point2
a = (y2 - x2*y1/x1) / (x2**2 - x1*x2)
b = y1/x1 - x1*a
a = (y2 - x2 * y1 / x1) / (x2**2 - x1 * x2)
b = y1 / x1 - x1 * a
return a, b


Expand Down
9 changes: 4 additions & 5 deletions hmom3/apps/core/balance/duration_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from django.conf import settings


BUILD_TIME_COEF = settings.BUILD_TIME_COEF
SEARCH_TIME_COEF = settings.SEARCH_TIME_COEF
RES_TIME_COEF = settings.RES_TIME_COEF
Expand Down Expand Up @@ -46,16 +45,16 @@ def get_research_time(level, tech=1, time=None):
def get_gold_amount(level, tech=1, res=None):
"""Gold amount depend on level."""
result = (
(1 / math.e ** (level - ZERO_EXPONENT) + GOLD_TIME_COEF) *
level ** GOLD_EXPONENT_COEF
(1 / math.e**(level - ZERO_EXPONENT) + GOLD_TIME_COEF)
* level**GOLD_EXPONENT_COEF
) * res / tech
return int(result)


def get_resources_amount(level, tech=1, res=None):
"""Wood or stone amount depend on level."""
result = (
(1 / math.e ** (level - ZERO_EXPONENT) + RES_TIME_COEF) *
level ** RES_EXPONENT_COEF
(1 / math.e**(level - ZERO_EXPONENT) + RES_TIME_COEF)
* level ** RES_EXPONENT_COEF
) * res / tech
return int(result)
1 change: 0 additions & 1 deletion hmom3/apps/core/balance/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from django.conf import settings


DEF_GOLD_INCOME = settings.DEF_GOLD_INCOME
ROUND_COEF = 100

Expand Down
2 changes: 1 addition & 1 deletion hmom3/apps/core/templatetags/user_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def is_even(number):
@register.filter(name='split_half')
def split_half(number):
"""Split number in half."""
return int(number/2)
return int(number / 2)


@register.simple_tag
Expand Down
2 changes: 1 addition & 1 deletion hmom3/apps/market/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.urls import path
from django.contrib.auth.decorators import login_required
from django.urls import path

from . import views

Expand Down
2 changes: 1 addition & 1 deletion hmom3/apps/market/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.conf import settings
from django.contrib.auth import get_user_model
from django.shortcuts import get_object_or_404, redirect
from django.views.generic import RedirectView, FormView
from django.urls import reverse_lazy
from django.views.generic import FormView

from ..towns import utils
from .forms import TradeForm
Expand Down
12 changes: 7 additions & 5 deletions hmom3/apps/stats/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from django.urls import path
from django.contrib.auth.decorators import login_required
from django.urls import path

from . import views

app_name = 'stats'

urlpatterns = [
path('',
login_required(views.StatisticView.as_view()),
name='index'),
]
path(
'',
login_required(views.StatisticView.as_view()),
name='index'
),
]
5 changes: 1 addition & 4 deletions hmom3/apps/towns/action/building_level_up.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from django.shortcuts import get_object_or_404

from ...core.balance.resources import (
get_resource_income,
get_resource_limit,
)
from ...core.balance.resources import get_resource_income, get_resource_limit
from ..models import Resource


Expand Down
25 changes: 17 additions & 8 deletions hmom3/apps/towns/management/commands/patch_resources.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import csv

from django.conf import settings
from django.core.management.base import BaseCommand

from ....towns import models
from ....core.balance.resources import get_resource_income, get_resource_limit
from ....towns import models

DEF_GOLD_INCOME = settings.DEF_GOLD_INCOME
DEF_WOOD_INCOME = settings.DEF_WOOD_INCOME
Expand All @@ -21,20 +19,31 @@ def handle(self, *args, **options):
resources = models.Resource.objects.all()

for resource in resources:
sild = models.UserBuilding.objects.filter(user=resource.user.id).filter(building__type__name='sild')
hall = models.UserBuilding.objects.filter(user=resource.user.id).filter(building__type__name='hall')
sild = models.UserBuilding.objects.filter(
user=resource.user.id).filter(building__type__name='sild')
hall = models.UserBuilding.objects.filter(
user=resource.user.id).filter(building__type__name='hall')

if sild.exists() and sild[0].level != 0:
resource.gold_limit = get_resource_limit(sild[0].level, resource='gold')
resource.wood_limit = get_resource_limit(sild[0].level, resource='wood')
resource.gold_limit = get_resource_limit(
sild[0].level,
resource='gold'
)
resource.wood_limit = get_resource_limit(
sild[0].level,
resource='wood'
)
resource.stone_limit = resource.wood_limit
else:
resource.gold_limit = DEF_GOLD_LIMIT
resource.wood_limit = DEF_WOOD_LIMIT
resource.stone_limit = DEF_STONE_LIMIT

if hall.exists() and hall[0].level != 0:
resource.gold_income = get_resource_income(hall[0].level, resource='gold')
resource.gold_income = get_resource_income(
hall[0].level,
resource='gold'
)
else:
resource.gold_income = DEF_GOLD_INCOME
resource.wood_income = DEF_WOOD_INCOME
Expand Down
6 changes: 3 additions & 3 deletions hmom3/apps/towns/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.db import models
from django.contrib.auth import get_user_model
from django.utils import timezone
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models
from django.urls import reverse
from django.utils import timezone

from ..core.balance.duration_cost import get_building_time

Expand Down
4 changes: 2 additions & 2 deletions hmom3/apps/towns/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.urls import path
from django.contrib.auth.decorators import login_required
from django.urls import path

from . import views

Expand All @@ -21,4 +21,4 @@
path('army/',
login_required(views.ArmyView.as_view()),
name='army'),
]
]
22 changes: 13 additions & 9 deletions hmom3/apps/towns/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
from django.shortcuts import get_object_or_404
from django.utils import timezone

from ..core.balance import duration_cost
from . import models
from .action import building_level_up
from ..core.balance.duration_cost import (
get_building_time,
get_gold_amount,
get_resources_amount
)

ACTION_ON_LEVEL_UP = {
'hall': building_level_up.create_hall,
Expand All @@ -34,11 +30,19 @@ def _level_up(instance):
base_gold = instance.building.type.base_gold
base_wood = instance.building.type.base_wood
base_stone = instance.building.type.base_stone
instance.building_time = get_building_time(
instance.building_time = duration_cost.get_building_time(
level=instance.level, time=build_time)
instance.gold = get_gold_amount(level=instance.level, res=base_gold)
instance.wood = get_resources_amount(level=instance.level, res=base_wood)
instance.stone = get_resources_amount(level=instance.level, res=base_stone)
instance.gold = duration_cost.get_gold_amount(
level=instance.level,
res=base_gold
)
instance.wood = duration_cost.get_resources_amount(
level=instance.level,
res=base_wood
)
instance.stone = duration_cost.get_resources_amount(
level=instance.level, res=base_stone
)
instance.save()


Expand Down
12 changes: 6 additions & 6 deletions hmom3/apps/towns/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from django.urls import reverse_lazy
from django.views.generic import RedirectView

from .models import UserBuilding, BuildingInProcess
from . import utils
from ..core.views import ViewWithContext
from . import utils
from .models import BuildingInProcess, UserBuilding


class TownView(ViewWithContext):
Expand Down Expand Up @@ -56,10 +56,10 @@ def get(self, request, *args, **kwargs):
# check requirements
if building.level > 0 or not building.user_building.all():
resource = utils.get_and_update_resources(user)
resource_condition = (
building.gold <= resource.gold_amount and
building.wood <= resource.wood_amount and
building.stone <= resource.stone_amount
resource_condition = ((
building.gold <= resource.gold_amount) and (
building.wood <= resource.wood_amount) and (
building.stone <= resource.stone_amount)
)
if resource_condition:
resource.gold_amount -= building.gold
Expand Down
2 changes: 1 addition & 1 deletion hmom3/apps/users/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import Group

User = get_user_model()
admin.site.unregister(Group)
Expand Down
3 changes: 2 additions & 1 deletion hmom3/apps/users/management/commands/create-superuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def handle(self, *args, **options):

if not password or not username or not email:
raise CommandError(
"--email --username and --password are required options")
"--email --username and --password are required options"
)

user_data = {
'username': username,
Expand Down
2 changes: 1 addition & 1 deletion hmom3/apps/users/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.db import models


class User(AbstractUser):
Expand Down
4 changes: 2 additions & 2 deletions hmom3/apps/users/signals.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.dispatch import receiver
from django.db.models.signals import post_save
from django.contrib.auth import get_user_model
from django.db.models.signals import post_save
from django.dispatch import receiver

from ..users import utils

Expand Down
39 changes: 21 additions & 18 deletions hmom3/apps/users/urls.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
from django.contrib.auth.views import LoginView, LogoutView
from django.urls import path, reverse_lazy
from django.contrib.auth.views import (
LoginView,
LogoutView,
)

from . import views
from ..core.decorators import for_not_authorized
from . import views

app_name = 'users'

urlpatterns = [
path('signup/',
for_not_authorized(views.UserCreationView.as_view()),
name='signup'),
path('',
for_not_authorized(LoginView.as_view(
path(
'signup/',
for_not_authorized(views.UserCreationView.as_view()),
name='signup'
),
path(
'',
for_not_authorized(LoginView.as_view(
template_name='users/login.html',
)),
name='login'),
path('logout/',
LogoutView.as_view(
template_name='users/logout.html',
next_page=reverse_lazy('users:login')
),
name='logout'),
)),
name='login'
),
path(
'logout/',
LogoutView.as_view(
template_name='users/logout.html',
next_page=reverse_lazy('users:login')
),
name='logout'
),
]
8 changes: 4 additions & 4 deletions hmom3/apps/users/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def create_requirements(user):

for requirement in requirements:
obj2 = models.UserBuildingRequirement(
building=obj,
requirement=requirement.requirement,
level=requirement.level,
)
building=obj,
requirement=requirement.requirement,
level=requirement.level,
)
requirment_objects.append(obj2)

models.UserBuildingRequirement.objects.bulk_create(requirment_objects)
Expand Down
Loading

0 comments on commit a7218fb

Please sign in to comment.