-
Notifications
You must be signed in to change notification settings - Fork 0
HW_2 #2
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
Open
veronica-kirenkina
wants to merge
8
commits into
main
Choose a base branch
from
veronica-kirenkina-patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
HW_2 #2
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d7331f0
report.py
veronica-kirenkina 7114773
Delete CountVectorizer.py
veronica-kirenkina e7c6131
Create CountVectorizer
veronica-kirenkina 6334671
Rename CountVectorizer to CountVectorizer.py
veronica-kirenkina 508f1f9
Delete CountVectorizer.py
veronica-kirenkina 96a7db1
Create CountVectorizer.py
veronica-kirenkina f7a6267
Create CountVectorizer_hw.py
veronica-kirenkina 442242c
Delete CountVectorizer.py
veronica-kirenkina 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,145 +1 @@ | ||
| import csv | ||
| from collections import defaultdict | ||
|
|
||
|
|
||
| def open_csv_file(input_path: str) -> list: | ||
| """ | ||
| The function reads a csv file and saves it in the form of a list consisting of lists | ||
| :param input_path: The path to csv file we are getting information from | ||
| :type: str | ||
| :return: list | ||
| """ | ||
| try: | ||
| with open(input_path, encoding='utf-8', newline='') as csvfile: | ||
| reader = csv.reader(csvfile, delimiter=';') | ||
| data = list(reader) | ||
| return data[1::] | ||
| except FileNotFoundError: | ||
| return 'Ссылка на файл не корректна. Попробуйте еще раз!' | ||
|
|
||
|
|
||
| def command_hierarchy(data: list) -> None: | ||
| """ | ||
| The function gets a list with the profiles of each employee in the company | ||
| and displays the department and the branches that they include | ||
| :param data: The list of the profiles of each employee | ||
| :type: list | ||
| :return: None | ||
| """ | ||
| departments_branches = defaultdict(set) | ||
| for lst in data: | ||
| departments_branches[lst[1]].add(lst[2]) | ||
| print("Иерархия команд:") | ||
| print() | ||
| for department, branches in departments_branches.items(): | ||
| print(f"Название департамента:\n{department}") | ||
| print("Отделы, входящие в этот департамент: ", *branches, sep='\n') | ||
| print() | ||
|
|
||
|
|
||
| def total_report(data: list) -> list: | ||
| """ | ||
| The function gets a list with the profiles of each employee in the company | ||
| and displays the report on each department | ||
| :param data: The list of the profiles of each employee | ||
| :type: list | ||
| :return: list | ||
| """ | ||
| salary = defaultdict(list) | ||
| for lst in data: | ||
| salary[lst[1]].append(int(lst[-1])) | ||
| report = [] | ||
| for key, value in salary.items(): | ||
| line = [] | ||
| line.append(key) | ||
| line.append(len(value)) | ||
| line.append(min(value)) | ||
| line.append(max(value)) | ||
| line.append(sum(value) // len(value)) | ||
| report.append(line) | ||
| return report | ||
|
|
||
|
|
||
| def summary_report(report: list) -> None: | ||
| """ | ||
| The function gets a list with the report on each department and displays it | ||
| :param report: The list the report on each department | ||
| :type: list | ||
| :return: None | ||
| """ | ||
| print('Сводный отчёт по департаментам:') | ||
| for lst in report: | ||
| print(f'Департамент: {lst[0]}') | ||
| print(f'Численность: {lst[1]}') | ||
| print('"Вилка" зарплат:') | ||
| print(f'Минимальная зарплата: {lst[2]}') | ||
| print(f'Максимальная зарплата: {lst[3]}') | ||
| print(f'Средняя зарплата: {lst[4]}') | ||
| print('-' * 30) | ||
|
|
||
|
|
||
| def close_csv_file(report: list, output_path: str) -> None: | ||
| """ | ||
| The function gets the list with the summary report on each department | ||
| and writes it to a csv file | ||
| :param report: The list the report on each department | ||
| :type: list | ||
| :param output_path: The path to csv file we are writing information in | ||
| :type: str | ||
| :return: None | ||
| """ | ||
| columns = ['Департамент', 'Численность', 'Минимальная зарплата', | ||
| 'Максимальная зарплата', 'Средняя зарплата'] | ||
| with open(output_path, 'w', encoding='utf-8', newline='') as csvfile: | ||
| writer = csv.writer(csvfile, delimiter=';') | ||
| writer.writerow(columns) | ||
| writer.writerows(report) | ||
| print('Ваш отчет сохранен.') | ||
|
|
||
|
|
||
| def main() -> None: | ||
| """ | ||
| The function gives several options to choose from and performs the specified actions set in them | ||
| :return: None | ||
| """ | ||
| options = {0: '0. Выход', | ||
| 1: '1. Вывести иерархию команд', | ||
| 2: '2. Вывести сводный отчёт по департаментам', | ||
| 3: '3. Сохранить сводный отчёт в виде csv-файла'} | ||
| print('Добрый день!', *options.values(), sep='\n') | ||
| var = '' | ||
| if var == 0: | ||
| return None | ||
| while var != 0: | ||
| var = int(input('Выберете опцию(0/1/2/3): ')) | ||
| while var not in options: | ||
| try: | ||
| var = int(input('Выберете опцию(0/1/2/3): ')) | ||
| except ValueError: | ||
| print('Введите цифру из предложенных.') | ||
| if var == 1: | ||
| data = input('Введите название csv файла, с которым будем работать: ') | ||
| while not data[-4:] == '.csv': | ||
| print('Название файла введено неверно.') | ||
| data = input('Введите название csv файла, с которым будем работать: ') | ||
| command_hierarchy(open_csv_file(data)) | ||
| elif var == 2: | ||
| data = input('Введите название csv файла, с которым будем работать: ') | ||
| while not data[-4:] == '.csv': | ||
| print('Название файла введено неверно.') | ||
| data = input('Введите название csv файла, с которым будем работать: ') | ||
| summary_report(total_report(open_csv_file(data))) | ||
| elif var == 3: | ||
| data = input('Введите название csv файла, с которым будем работать: ') | ||
| while not data[-4:] == '.csv': | ||
| print('Название файла введено неверно.') | ||
| data = input('Введите название csv файла, с которым будем работать: ') | ||
| output_path = input('Введите название csv файла в который вы хотите сохранить сводный отчет: ') | ||
| while not output_path[-4:] == '.csv': | ||
| print('Название файла введено неверно.') | ||
| output_path = input('Введите название csv файла в который вы хотите сохранить сводный отчет: ') | ||
| close_csv_file(total_report(open_csv_file(data)), output_path) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
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.
Тут нужно заменить на float судя по всему. Иначе падает на некоторых строках