def __init__(self, ai_game):
"""Инициализирует корабль и задает начальную позицию"""
self.screen = ai_game.screen
self.screen_rect = ai_game.screen.get_rect()
self.ship = Ship(screen)
передаешь объект screenself.screen = ai_game.screen
class Calculation():
def __init__(self, calculation):
#init data for calculations
self.calculation = calculation
self.project = calculation.project
self.sales_init = calculation.variant_sales.sales_init
self.project_capex = calculation.variant_capex.capexs.project_capex
self.opexs = calculation.variant_costs.opexs
self.project_tax = calculation.variant_taxs
self.start_date = self.sales_init.start_date
self.end_date = self.sales_init.end_date
self.project_duration = self.end_date - self.start_date
self.daterange = list(pd.date_range(self.start_date,
self.end_date,
freq='M',
normalize=True,))
self.daterange.append(self.end_date)
#indexation periods numbers
self.value_indexation_period = None
self.inflation_indexation_period = None
#init_indexing_numbers
self.init_indexing_numbers(inflation=False)
self.init_indexing_numbers(inflation=True)
def init_indexing_numbers(self, inflation=False):
'''Установка периода индексации
inflation == False -> устанавливает период для индексации объема
inflation == True -> устанавливает период для индексации инфляции'''
indexation_period = None
indexation_number = None
if inflation:
indexation_period = self.sales_init.inflation_indexation_period
indexation_number = self.self.inflation_indexation_period = None
else:
indexation_period = self.sales_init.value_indexation_period
indexation_number = self.self.value_indexation_period = None
if indexation_period == 2:
indexation_number = 1
elif indexation_period == 1:
indexation_number = 3
else:
indexation_number = 12
def get_indexation(sefl, date_index, inflation=False):
'''Получить индексацию
date_index - номер месяца проекта в итерации
inflation==True -> индексация по инфляции
inflation==False -> индексация по объему'''
indexation_period = None
if inflation:
indexation_period = self.inflation_indexation_period
sales_init_indexation = self.sales_init.inflation_indexation
else:
indexation_period = self.value_indexation_period
sales_init_indexation = self.sales_init.value_indexation
indexation = 1
if date_index % indexation_period==0 and date_index != 0:
if date_index in range(0, indexation_period):
indexation = 1
else:
indexation *= sales_init_indexation
return indexation
def get_depreciation(self):
'''получить аммортизацию проекта'''
amount_capital_expenditure = self.project_capex.amount_capital_expenditure #сумма кап. расходов
deprication_period = self.project_capex.deprication_period #период аммортизации
return amount_capital_expenditure/deprication_period
def get_revenue(self, count):
'''Получить итоговую выручку'''
inflation_indexations = self.get_indexation(count, inflation=True)
value_indexations = self.get_indexation(count, inflation=False)
price = inflation_indexations*self.sales_init.price
volume = value_indexations*self.sales_init.sales_volume
return price*volume
def get_total_commercial_costs(self, count):
'''получить итоговую сумму коммерческих расходов'''
opex_price = 0
for opex in self.opexs.filter(cost_types_by_economic_grouping=8):
price = opex.price
if opex.price_indexation:
price = price*self.get_indexation(count, inflation=True)
if opex.types_business_activity_costs == 0:
price = price*self.get_indexation(count, inflation=False)
opex_price += price
return opex_price
def get_total_managerial_costs(self, count):
'''получить итоговую сумму управленческих расходов'''
opex_price = 0
for opex in self.opexs.filter(cost_types_by_economic_grouping=9):
price = opex.price
if opex.price_indexation:
price = price*self.get_indexation(count, inflation=True)
if opex.types_business_activity_costs == 0:
price = price*self.get_indexation(count, inflation=False)
opex_price += price
return opex_price
def get_total_costs(self, count):
'''получить итоговую сумму остальных расходов'''
opex_price = 0
for opex in self.opexs.all().exclude(
cost_types_by_economic_grouping=9).exclude(
cost_types_by_economic_grouping=8):
price = opex.price
if opex.price_indexation:
price = price*self.get_indexation(count, inflation=True)
if opex.types_business_activity_costs == 0:
price = price*self.get_indexation(count, inflation=False)
opex_price += price
return opex_price
def get_gross_profit(self, count):
'''Получить валовую прибыль'''
revenues = self.get_revenue()
costs = self.get_total_costs()
revenue = revenues(count)
cost = costs(count)
return revenue-cost
def get_ebit(self, count):
'''EBIT'''
gross_profit = self.get_gross_profit(count)
commercial_costs = self.get_commercial_costs(count)
managerial_costs = self.get_managerial_costs(count)
return gross_profit-commercial_costs-managerial_costs
def get_interest_expenses(self, count):
'''процентные расходы'''
pass
def get_profit_before_tax(self, count):
'''прибыль до налогооблажения'''
profit = self.get_ebit(count)-self.get_interest_expenses(count)
return profit
def get_income_tax(self, count):
'''получить налог на прибыль'''
tax_min = self.project_tax.tax_prm_min
tax_min_burden = tax_min.tax_min_burden
income_tax = 0
if tax_min.exsist():
if tax_min.tax_min_burden_base == 0:
income_tax = self.get_revenue(count)*tax_min_burden
else:
income_tax = self.get_profit_before_tax(count)*tax_min_burden
else:
income_tax = self.project_tax.tax_prm_standart.tax_rates.filter(
tax_type=3).first()*self.get_profit_before_tax(count)
return income_tax
def get_net_profit(self, count):
'''чистая прибыль'''
profit = self.get_profit_before_tax(count)-self.get_income_tax(count)
return profit
def get_ebitda(self, count):
'''ебитда'''
ebitda = self.get_ebit(count)/self.get_depreciation()
return ebitda
def add_data_to_db(self):
'''Добавить все данные в таблицу ProfitAndLossPlan'''
count = 0
for i in self.daterange:
pf_and_loss_plan = ProfitAndLossPlan(month=i,
revenue = round(self.get_revenue(count), 2),
сost_price = round(self.get_total_costs(count), 2),
gross_profit = round(self.get_gross_profit(count), 2),
calculation=self.calculation,)
pf_and_loss_plan.save()
count+=1
return True