-
Notifications
You must be signed in to change notification settings - Fork 145
Review #8
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
base: master
Are you sure you want to change the base?
Review #8
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,81 +1,98 @@ | ||
| import datetime as dt | ||
| from datetime import datetime as dt | ||
|
Author
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.
|
||
|
|
||
|
|
||
| class Record: | ||
| """- Комментарий""" | ||
| def __init__(self, amount, comment, date=''): | ||
| self.amount = amount | ||
| self.date = ( | ||
| dt.datetime.now().date() if | ||
| not | ||
| date else dt.datetime.strptime(date, '%d.%m.%Y').date()) | ||
| self.date = dt.now().date() if not date else dt.strptime(date, '%d.%m.%Y').date() | ||
|
Author
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.
|
||
| self.comment = comment | ||
|
|
||
|
|
||
| class Calculator: | ||
| """- Комментарий""" | ||
| def __init__(self, limit): | ||
| self.limit = limit | ||
| self.records = [] | ||
|
|
||
| def add_record(self, record): | ||
| """- Комментарий""" | ||
| self.records.append(record) | ||
|
|
||
| def get_today_stats(self): | ||
| """- Комментарий""" | ||
| today_stats = 0 | ||
| for Record in self.records: | ||
|
Author
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.
|
||
| if Record.date == dt.datetime.now().date(): | ||
| today_stats = today_stats + Record.amount | ||
|
|
||
| for record in self.records: | ||
| if record.date == dt.now().date(): | ||
| today_stats += record.amount | ||
|
Author
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. Добавление в счетчик значения можно указывать не явным оператором увеличения (сложения) += |
||
|
|
||
| return today_stats | ||
|
|
||
| def get_week_stats(self): | ||
| """- Комментарий""" | ||
| week_stats = 0 | ||
| today = dt.datetime.now().date() | ||
| today = dt.now().date() | ||
|
|
||
|
Author
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. После изменения импорта, к классу |
||
| for record in self.records: | ||
| if ( | ||
| (today - record.date).days < 7 and | ||
| (today - record.date).days >= 0 | ||
| ): | ||
| if 7 > (today - record.date).days >= 0: | ||
velllum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| week_stats += record.amount | ||
|
|
||
| return week_stats | ||
|
|
||
|
|
||
| class CaloriesCalculator(Calculator): | ||
| def get_calories_remained(self): # Получает остаток калорий на сегодня | ||
| """- Комментарий""" | ||
| def get_calories_remained(self): | ||
| """- Получает остаток калорий на сегодня""" | ||
| x = self.limit - self.get_today_stats() | ||
|
|
||
| if x > 0: | ||
| return f'Сегодня можно съесть что-нибудь' \ | ||
| f' ещё, но с общей калорийностью не более {x} кКал' | ||
| return f''' | ||
| Сегодня можно съесть что-нибудь ещё, | ||
| но с общей калорийностью не более {x} кКал''' | ||
|
Author
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.
|
||
|
|
||
| else: | ||
| return('Хватит есть!') | ||
| return 'Хватит есть!' | ||
|
Author
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. В данном случаи кавычки указывают на, то что метод возвращает кортеж с строкой. |
||
|
|
||
|
|
||
| class CashCalculator(Calculator): | ||
| """- Комментарий""" | ||
| USD_RATE = float(60) # Курс доллар США. | ||
| EURO_RATE = float(70) # Курс Евро. | ||
|
|
||
| def get_today_cash_remained(self, currency, | ||
| USD_RATE=USD_RATE, EURO_RATE=EURO_RATE): | ||
| # def get_today_cash_remained(self, currency): | ||
| def get_today_cash_remained(self, currency, usd_rate=USD_RATE, euro_rate=EURO_RATE): | ||
|
Author
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. По условию технического задания, метод |
||
| """- Комментарий""" | ||
| currency_type = currency | ||
| cash_remained = self.limit - self.get_today_stats() | ||
|
|
||
| if currency == 'usd': | ||
| cash_remained /= USD_RATE | ||
| cash_remained /= usd_rate | ||
|
Author
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. Имена параметров не должны совпадать с именами аргументов класса. |
||
| currency_type = 'USD' | ||
|
|
||
| elif currency_type == 'eur': | ||
| cash_remained /= EURO_RATE | ||
| cash_remained /= euro_rate | ||
|
Author
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. Имена параметров не должны совпадать с именами аргументов класса. |
||
| currency_type = 'Euro' | ||
|
|
||
| elif currency_type == 'rub': | ||
| cash_remained == 1.00 | ||
| currency_type = 'руб' | ||
| cash_remained = 1.00 | ||
|
Author
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. После проверки должно происходить не сравнение, а присвоение через указатель одного равно = |
||
| currency_type = 'Руб' | ||
|
|
||
| if cash_remained > 0: | ||
| return ( | ||
| f'На сегодня осталось {round(cash_remained, 2)} ' | ||
| f'{currency_type}' | ||
| ) | ||
| result = round(cash_remained, 2) | ||
| return f''' | ||
| На сегодня осталось {result} | ||
| {currency_type}''' | ||
|
|
||
|
Author
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.
|
||
| elif cash_remained == 0: | ||
| return 'Денег нет, держись' | ||
| return 'Денег нет, но вы держитесь ;)' | ||
|
|
||
| elif cash_remained < 0: | ||
| return 'Денег нет, держись:' \ | ||
| ' твой долг - {0:.2f} {1}'.format(-cash_remained, | ||
| currency_type) | ||
| return f''' | ||
| Денег нет, но вы держитесь ;) : | ||
| твой долг - {-cash_remained:.2f} {currency_type}''' | ||
|
Author
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. Строку можно прописывать в тройные кавычки. |
||
|
|
||
| def get_week_stats(self): | ||
| """- Комментарий""" | ||
| super().get_week_stats() | ||
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.
Беглый анализ кода.
Классы желательно делить на несколько файлов (но не обязательно), у каждого должен быть свой сценарий работы, дальше с ними можно взаимодействовать при помощи импортов
import.Весь код не комментирован, а если да то, не правильно почитать тут, как привольно надо https://www.python.org/dev/peps/pep-0257/
Отсутствие
typingтайпитингов (указателей типов), для лучшего понимания что возвращается или храниться.Нет реализации клиентской части для проверки работоспособности написанного кода
Отсутствие тестов (пишутся в отдельной папке tests, с обязательным первым словом в имени файла
test). "Должен быть по условию технического задания. "