Skip to content

Commit

Permalink
Merge branch 'minmatarfleet:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
beautifulmim authored Sep 24, 2024
2 parents 9f6d1c5 + 4bc463c commit b96cce1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
32 changes: 27 additions & 5 deletions backend/moons/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ class ParsedEveMoonQuantity(BaseModel):
moon_id: int


class MoonParsingResult(BaseModel):
systems_added: int = 0
systems_ignored: int = 0
moons_added: int = 0
moons_ignored: int = 0
ids_added: List[int] = []


def _parse_eve_moon_format(moon_paste: str) -> List[ParsedEveMoonQuantity]:
"""
Example moon format
Expand Down Expand Up @@ -65,9 +73,15 @@ def _parse_eve_moon_format(moon_paste: str) -> List[ParsedEveMoonQuantity]:
return moons


def process_moon_paste(moon_paste: str, user_id: int = None) -> List[int]:
def process_moon_paste(
moon_paste: str, user_id: int = None
) -> MoonParsingResult:
parsed_moons = _parse_eve_moon_format(moon_paste)
ids = []

result = MoonParsingResult()

ignored_moons = {}

for parsed_moon in parsed_moons:
system, _ = EsiSolarSystem.objects.get_or_create_esi(
id=parsed_moon.system_id
Expand All @@ -80,13 +94,18 @@ def process_moon_paste(moon_paste: str, user_id: int = None) -> List[int]:
# Name comes back as Rahadalon VI - Moon 1
moon, _ = EsiMoon.objects.get_or_create_esi(id=parsed_moon.moon_id)
moon_number = int(moon.name.split(" ")[-1])
eve_moon, _ = EveMoon.objects.get_or_create(
eve_moon, created = EveMoon.objects.get_or_create(
system=system.name,
planet=planet_number,
moon=moon_number,
defaults={"reported_by_id": user_id},
)

if created:
result.moons_added += 1
else:
ignored_moons[moon.name] = True

if not EveMoonDistribution.objects.filter(
moon=eve_moon, ore=parsed_moon.ore
).exists():
Expand All @@ -96,5 +115,8 @@ def process_moon_paste(moon_paste: str, user_id: int = None) -> List[int]:
yield_percent=parsed_moon.quantity,
)

ids.append(eve_moon.id)
return ids
result.ids_added.append(eve_moon.id)

result.moons_ignored = len(ignored_moons)

return result
12 changes: 7 additions & 5 deletions backend/moons/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from authentication import AuthBearer
from moons.models import EveMoon, EveMoonDistribution

from .parser import process_moon_paste
from .parser import process_moon_paste, MoonParsingResult

moons_router = Router(tags=["Moons"])
moons_paste_router = Router(tags=["Moons"])
Expand Down Expand Up @@ -58,21 +58,23 @@ class MoonSummaryResponse(BaseModel):
@moons_paste_router.post(
"",
response={
200: List[int],
200: MoonParsingResult,
403: ErrorResponse,
},
auth=AuthBearer(),
)
def create_moon_from_paste(
request, moon_paste_request: CreateMoonFromPasteRequest
):
) -> MoonParsingResult:
if not request.user.has_perm("moons.add_evemoon"):
return 403, ErrorResponse(
detail="You do not have permission to add moons"
)

ids = process_moon_paste(moon_paste_request.paste, user_id=request.user.id)
return ids
results = process_moon_paste(
moon_paste_request.paste, user_id=request.user.id
)
return results


def count_scanned_moons(eve_moons) -> List[MoonSummaryResponse]:
Expand Down
1 change: 0 additions & 1 deletion frontend/app/src/components/blocks/AddMoonButton.astro
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const ADD_MOON_RESULT_PARTIAL_URL = translatePath('/partials/add_moon_result_com
import Button from '@components/blocks/Button.astro';
import AddIcon from '@components/icons/buttons/AddIcon.astro';
---

<Button
Expand Down
1 change: 1 addition & 0 deletions frontend/app/src/components/blocks/IntelReel.astro
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import PlanetEVEIcon from '@components/icons/PlanetEVEIcon.astro';
{can_add_moons &&
<AddMoonButton
size='sm'
color='fleet-red'
iconed={false}
/>
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/i18n/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const ui = {
'page_finder.fleets.history.description': 'History of fleets',

'intel.page_title': 'Intel',
'intel.leading_text': 'Structures are the largest conflict driver in EVE Online. They are the primary target during all wars, and lead to all of those large fleet battles that you see in the news. There are three important elements that a fleet commander must know for every structure.',
'intel.leading_text': 'Structures are the largest conflict driver in EVE Online. They are the primary target during all wars, and lead to all of those large fleet battles that you see in the news.',
'intel.meta_description': 'Learn more about intel at Minmatar Fleet Alliance, and report various timers.',
'intel.cover_alt': 'A Probe spacecraft scanning an Athanor station, set against the backdrop of a moon mining site.',
'intel.description': 'Inspect active structure timers and submit new ones and moon scans',
Expand Down

0 comments on commit b96cce1

Please sign in to comment.