Skip to content

Commit

Permalink
Merge pull request #296 from fiit-tp-tim20/main
Browse files Browse the repository at this point in the history
finished_vylepsenia_firiem
  • Loading branch information
lubomirsilny authored May 18, 2024
2 parents 4eaf957 + bd2c85d commit 9f4d122
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions apps/saip-fe/src/api/GetIndustryReport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type IndustryReport = {
finished_upgrades: string;
market_share: number;
net_profit: number | null;
sell_price: number;
Expand Down
6 changes: 6 additions & 0 deletions apps/saip-fe/src/components/reports/IndustryReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ function IndustryReport() {
</th>
<th className="px-4 py-2 text-left table-header text-white">Predajná cena</th>
<th className="px-4 py-2 text-left table-header text-white">Podiel na trhu</th>
<th className="px-4 py-2 text-left table-header text-white">Dokončené vylepšenia</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -178,6 +179,11 @@ function IndustryReport() {
numberWithSpaces(industry[1]?.market_share)}{" "}
%
</td>
<td className="px-4 py-2">
{industry[1]?.finished_upgrades &&
numberWithSpaces(industry[1]?.finished_upgrades)}{" "}

</td>
</tr>
))}
{/* Add row for average stock price */}
Expand Down
24 changes: 17 additions & 7 deletions apps/saip_be/saip_api/views/CompanyManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,30 @@ def get(self, request) -> Response:

company_states = CompaniesState.objects.filter(turn=Turn.objects.get(game=company.game, number=turn.number))
market_state = MarketState.objects.get(turn=Turn.objects.get(game=company.game, number=turn.number))
companies = Company.objects.filter(game=company.game)
upgrades = []
for i in companies:
upgrade_names = ["Brakes", "Frame", "Battery", "Display"]
upgrade = 0
for j in upgrade_names:

upgrade_turn = CompaniesUpgrades.objects.get(company=i, upgrade=Upgrade.objects.get(name=j))
if upgrade_turn.status == 'f':
upgrade += 1
upgrades.append(upgrade)

industry = dict()
for state in company_states:
for state, finished_upgrade in zip(company_states, upgrades):
company_info = dict()
company_info['stock_price'] = round(state.stock_price, 2) if state.stock_price is not None else "N/A"
company_info[
'sell_price'] = state.production.sell_price if state.production.sell_price is not None else "N/A"
company_info['net_profit'] = round(state.net_profit, 2) if state.stock_price is not None else "N/A"
company_info['net_profit'] = round(state.net_profit, 2) if state.net_profit is not None else "N/A"
try:
company_info['market_share'] = round((state.orders_fulfilled / market_state.sold) * 100, 2)
except (ZeroDivisionError, TypeError):
company_info['market_share'] = 0

company_info['finished_upgrades'] = finished_upgrade
industry[state.company.name] = company_info

market_state_previous = MarketState.objects.get(
Expand Down Expand Up @@ -324,8 +335,7 @@ def get(self, request) -> Response:
upgrade_turn = CompaniesUpgrades.objects.get(company=company, upgrade=Upgrade.objects.get(name=i))
if upgrade_turn.status == 'f':
turn_u = upgrade_turn.turn.number
factory_dict['upgrade_turn'].pop(0)
factory_dict['upgrade_turn'].insert(turn_u-1, i)
factory_dict['upgrade_turn'][turn_u - 1] = i
for i in range(1, turn.number + 1):
company_state_new = CompaniesState.objects.get(
turn=Turn.objects.get(game=company.game, number=i), company=company)
Expand Down Expand Up @@ -453,8 +463,8 @@ def get(self, request) -> Response:
balance['capital_investments'] = round(company_state_previous.factory.capital_investments,
2) if company_state_previous.factory.capital_investments is not None else "N/A" # "Kapitálové investície"
balance['assets_summary'] = round((
company_state_previous.cash + company_state_previous.inventory_money + company_state_previous.factory.capital_investments),
2) if (
company_state_previous.cash + company_state_previous.inventory_money + company_state_previous.factory.capital_investments),
2) if (
company_state_previous.cash is not None and company_state_previous.inventory is not None and company_state_previous.production.man_cost is not None and company_state_previous.factory.capital_investments is not None) else "N/A" # "Súčet aktív"

# pasiva
Expand Down

0 comments on commit 9f4d122

Please sign in to comment.