-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fix bib and card_numbers indexes #440
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b585787
fix: fix bib and card_numbers indexes
alex-karpov ff6ce95
fix: index sportorg files with several days
alex-karpov df46930
feat: rebuild indexes on Rechecking (Ctrl+R) action.
alex-karpov c62302c
fix: use set_bib() and set_card_number() instead of property setters
alex-karpov a1c10c7
fix: fix typo
alex-karpov 73a5afc
fix: change string formatting in logger
alex-karpov 8590f15
Merge branch 'bibs-and-cards-index' of https://github.com/alex-karpov…
alex-karpov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
get_current_race_index, | ||
move_down_race, | ||
move_up_race, | ||
race, | ||
races, | ||
set_current_race_index, | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1282,8 +1282,8 @@ def __init__(self): | |
self.name = '' | ||
self.surname = '' | ||
|
||
self.card_number = 0 | ||
self.bib = 0 | ||
self._card_number = 0 | ||
self._bib = 0 | ||
|
||
self.birth_date: Optional[date] = None | ||
self.organization: Optional[Organization] = None | ||
|
@@ -1372,8 +1372,8 @@ def to_dict(self): | |
def update_data(self, data): | ||
self.name = str(data['name']) | ||
self.surname = str(data['surname']) | ||
self.change_card(data['card_number']) | ||
self.change_bib(int(data['bib'])) | ||
self.set_card_number(int(data['card_number'])) | ||
self.set_bib(int(data['bib'])) | ||
self.contact = [] | ||
if data['world_code']: | ||
self.world_code = str(data['world_code']) | ||
|
@@ -1393,25 +1393,64 @@ def update_data(self, data): | |
elif 'year' in data and data['year']: # back compatibility with v 1.0.0 | ||
self.set_year(int(data['year'])) | ||
|
||
def change_bib(self, new_bib: int): | ||
if self.bib == new_bib: | ||
@property | ||
def bib(self): | ||
return self._bib | ||
|
||
@bib.setter | ||
def bib(self, new_bib: int): | ||
raise NotImplementedError('Please, use set_bib()') | ||
|
||
def set_bib(self, new_bib: int) -> None: | ||
if self._bib == new_bib: | ||
return | ||
self._index_bib(new_bib) | ||
self._bib = new_bib | ||
|
||
def _index_bib(self, new_bib: int) -> None: | ||
r = race() | ||
if self.bib in r.person_index_bib: | ||
if self._bib != new_bib and self._bib in r.person_index_bib: | ||
r.person_index_bib.pop(self.bib) | ||
self.bib = new_bib | ||
r.index_person(self) | ||
if new_bib > 0 and new_bib in r.person_index_bib: | ||
other_person = r.person_index_bib[new_bib] | ||
if not other_person is self: | ||
logging.info( | ||
f'Duplicate bib {new_bib} (do nothing): {self} | {other_person}' | ||
) | ||
r.person_index_bib[new_bib] = self | ||
|
||
def index_bib(self) -> None: | ||
self._index_bib(self.bib) | ||
|
||
@property | ||
def card_number(self): | ||
return self._card_number | ||
|
||
@card_number.setter | ||
def card_number(self, new_card: int): | ||
raise NotImplementedError('Please, use set_card_number()') | ||
|
||
def change_card(self, new_card: int): | ||
if self.card_number == new_card: | ||
def set_card_number(self, new_card: int): | ||
if self._card_number == new_card: | ||
return | ||
|
||
self._index_card(new_card) | ||
self._card_number = new_card | ||
|
||
def _index_card(self, new_card): | ||
r = race() | ||
if self.card_number in r.person_index_card: | ||
r.person_index_card.pop(self.card_number) | ||
self.card_number = new_card | ||
r.index_person(self) | ||
if self._card_number != new_card and self._card_number in r.person_index_card: | ||
r.person_index_card.pop(self._card_number) | ||
if new_card > 0 and new_card in r.person_index_card: | ||
other_person = r.person_index_card[new_card] | ||
if not other_person is self: | ||
logging.info( | ||
f'Duplicate card {new_card} (do nothing): {self} | {other_person}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same ⬆️ |
||
) | ||
r.person_index_card[new_card] = self | ||
|
||
def index_card(self): | ||
self._index_card(self._card_number) | ||
|
||
|
||
class RaceData(Model): | ||
|
@@ -1714,27 +1753,49 @@ def get_setting(self, setting, nvl_value=None): | |
def get_days(self, date_=None): | ||
return self.data.get_days(date_) | ||
|
||
def person_card_number(self, person, number=0): | ||
person.change_card(number) | ||
def person_card_number(self, person: Person, number=0): | ||
person.set_card_number(number) | ||
for p in self.persons: | ||
if p.card_number == number and p != person: | ||
p.card_number = 0 | ||
p.set_card_number(0) | ||
p.is_rented_card = False | ||
return p | ||
|
||
def rebuild_indexes(self): | ||
self.person_index_bib = {} | ||
self.person_index_card = {} | ||
for person in self.persons: | ||
person.index_bib() | ||
person.index_card() | ||
|
||
def delete_persons(self, indexes): | ||
indexes = sorted(indexes, reverse=True) | ||
persons = [] | ||
for i in indexes: | ||
person = self.persons[i] | ||
persons.append(person) | ||
for result in self.results: | ||
if result.person is person: | ||
result.person = None | ||
result.bib = person.bib | ||
self.remove_person_from_indexes(person) | ||
del self.persons[i] | ||
return persons | ||
|
||
def remove_person_from_indexes(self, person: Person): | ||
for result in self.results: | ||
if result.person is person: | ||
result.person = None | ||
result.bib = person.bib | ||
if ( | ||
person.bib | ||
and person.bib in self.person_index_bib | ||
and self.person_index_bib[person.bib] is person | ||
): | ||
del self.person_index_bib[person.bib] | ||
if ( | ||
person.card_number | ||
and person.card_number in self.person_index_card | ||
and self.person_index_card[person.card_number] is person | ||
): | ||
del self.person_index_card[person.card_number] | ||
|
||
def delete_results(self, indexes): | ||
indexes = sorted(indexes, reverse=True) | ||
results = [] | ||
|
@@ -1789,12 +1850,12 @@ def find_person_result(self, person: Person) -> Optional[Result]: | |
return i | ||
return None | ||
|
||
def find_person_by_bib(self, bib: int): | ||
def find_person_by_bib(self, bib: int) -> Person: | ||
if bib in self.person_index_bib: | ||
return self.person_index_bib[bib] | ||
return None | ||
|
||
def find_person_by_card(self, card: int): | ||
def find_person_by_card(self, card: int) -> Person: | ||
if card in self.person_index_card: | ||
return self.person_index_card[card] | ||
return None | ||
|
@@ -2295,7 +2356,7 @@ def is_out_of_competition(self): | |
|
||
def set_bib(self): | ||
if self.person: | ||
self.person.change_bib(self.get_bib()) | ||
self.person.set_bib(self.get_bib()) | ||
|
||
def set_person(self, person): | ||
self.person = person | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.