Skip to content
Open

Develop #1518

Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[flake8]
inline-quotes = "
ignore = E203, E266, W503, ANN002, ANN003, ANN101, ANN102, ANN401, N807, N818
max-line-length = 79
max-complexity = 18
select = B,C,E,F,W,T4,B9,ANN,Q0,N8,VNE
exclude = venv, tests
[flake8]
inline-quotes = "
ignore = E203, E266, W503, ANN002, ANN003, ANN101, ANN102, ANN401, N807, N818
max-line-length = 79
max-complexity = 18
select = B,C,E,F,W,T4,B9,ANN,Q0,N8,VNE
exclude = venv, tests
74 changes: 37 additions & 37 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
name: Test

on: [push, pull_request_target]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}

- name: Set Up Python 3.14
uses: actions/setup-python@v2
with:
python-version: "3.14"

- name: Install pytest and flake8
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run flake8
run: flake8 app/
- name: Run tests
timeout-minutes: 5
run: pytest tests/
- uses: mate-academy/auto-approve-action@v2
if: ${{ github.event.pull_request && success() }}
with:
github-token: ${{ github.token }}
- uses: mate-academy/auto-reject-action@v2
if: ${{ github.event.pull_request && failure() }}
with:
github-token: ${{ github.token }}
name: Test
on: [push, pull_request_target]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Set Up Python 3.14
uses: actions/setup-python@v2
with:
python-version: "3.14"
- name: Install pytest and flake8
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run flake8
run: flake8 app/
- name: Run tests
timeout-minutes: 5
run: pytest tests/
- uses: mate-academy/auto-approve-action@v2
if: ${{ github.event.pull_request && success() }}
with:
github-token: ${{ github.token }}
- uses: mate-academy/auto-reject-action@v2
if: ${{ github.event.pull_request && failure() }}
with:
github-token: ${{ github.token }}
18 changes: 9 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.idea/
.vscode/
*.iml
.env
.DS_Store
venv/
.pytest_cache/
**__pycache__/
.pickle/
.idea/
.vscode/
*.iml
.env
.DS_Store
venv/
.pytest_cache/
**__pycache__/
.pickle/
178 changes: 89 additions & 89 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,89 @@
# Management System
**Please note:** read [the guideline](https://github.com/mate-academy/py-task-guideline/blob/main/README.md)
before starting.


The Technical Lyceum plans to create a system for managing information about groups and students.
You have to implement the above system using the `dataclasses` module.


You can import the module in such way:

```python
import dataclasses
```

Let`s implement 3 classes:

1. **Specialty**

It has the following attributes:

- `name`;
- `number`.

2. **Student**

It has the following attributes:

- `first_name`;
- `last_name`;
- `birth_date` ;
- `average_mark` — average score of the previous year (or average score of entrance exams for the first-course students), float number;
- `has_scholarship` — information on whether the student receives a scholarship. This is a bool value;
- `phone_number`;
- `address`.

**Please note:** to import datetime, use the following syntax:

```python
from datetime import datetime
```

3. **Group**

It has the following attributes:

- `specialty` - instance of the `Specialty`class;
- `course` - course number/year of study;
- `students` - list of students studying in this group. This should be a list of instances of the `Student` class.


Also implement 4 functions, using module `pickle` in this way:

```python
import pickle
```

1. **write_groups_information**

This function writes all inputted information about the Lyceum groups to the file named `"groups.pickle"`.
The input is a list of the `Group` class instances.
This function returns the maximum number of students from all the groups.


2. **write_students_information**

This function writes information about students to the `"students.pickle"` file.
You should store all the students in one file. The input is a list of the `Student` class instances.
This function returns the number of students.

3. **read_groups_information**

This function reads data from the `"groups.pickle"` file.
It returns all group's specialties' names without repetition.

4. **read_students_information**

This function reads data from the `"students.pickle"` file.
It returns a list of all the `Student` class instances.

<details>
<summary><strong>Hint</strong></summary>

The `pickle` module returns only one recorded object.
It is necessary to implement the reading of each instance from the file for the `read_students_information` and `read_groups_information` functions.

</details>

Implement the described task [here](app/main.py)
# Management System
**Please note:** read [the guideline](https://github.com/mate-academy/py-task-guideline/blob/main/README.md)
before starting.
The Technical Lyceum plans to create a system for managing information about groups and students.
You have to implement the above system using the `dataclasses` module.
You can import the module in such way:
```python
import dataclasses
```
Let`s implement 3 classes:
1. **Specialty**
It has the following attributes:
- `name`;
- `number`.
2. **Student**
It has the following attributes:
- `first_name`;
- `last_name`;
- `birth_date` ;
- `average_mark` — average score of the previous year (or average score of entrance exams for the first-course students), float number;
- `has_scholarship` — information on whether the student receives a scholarship. This is a bool value;
- `phone_number`;
- `address`.
**Please note:** to import datetime, use the following syntax:
```python
from datetime import datetime
```
3. **Group**
It has the following attributes:
- `specialty` - instance of the `Specialty`class;
- `course` - course number/year of study;
- `students` - list of students studying in this group. This should be a list of instances of the `Student` class.
Also implement 4 functions, using module `pickle` in this way:
```python
import pickle
```
1. **write_groups_information**
This function writes all inputted information about the Lyceum groups to the file named `"groups.pickle"`.
The input is a list of the `Group` class instances.
This function returns the maximum number of students from all the groups.
2. **write_students_information**
This function writes information about students to the `"students.pickle"` file.
You should store all the students in one file. The input is a list of the `Student` class instances.
This function returns the number of students.
3. **read_groups_information**
This function reads data from the `"groups.pickle"` file.
It returns all group's specialties' names without repetition.
4. **read_students_information**
This function reads data from the `"students.pickle"` file.
It returns a list of all the `Student` class instances.
<details>
<summary><strong>Hint</strong></summary>
The `pickle` module returns only one recorded object.
It is necessary to implement the reading of each instance from the file for the `read_students_information` and `read_groups_information` functions.
</details>
Implement the described task [here](app/main.py)
61 changes: 60 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -1 +1,60 @@
# write your code here
from dataclasses import dataclass
from datetime import datetime
import pickle


@dataclass
class Specialty:
name: str
number: int


@dataclass
class Student:
first_name: str
last_name: str
birth_date: datetime
average_mark: float
has_scholarship: bool
phone_number: int
address: str


@dataclass
class Group:
specialty: Specialty
students: list[Student]
course: int


def write_groups_information(groups: list[Group]) -> int:
with open("groups.pickle", "wb") as file:
pickle.dump(groups, file)
if not groups:
return 0
return max(len(g.students) for g in groups)


def write_students_information(students: list[Student]) -> int:
with open("students.pickle", "wb") as file:
pickle.dump(students, file)
return len(students)


def read_groups_information() -> list[str]:
with open("groups.pickle", "rb") as file:
groups = pickle.load(file)
groups_specialty = []
for grp in groups:
grp = grp.specialty.name
if not grp:
continue
groups_specialty.append(grp)
groups_specialty = list(set(groups_specialty))
return groups_specialty


def read_students_information() -> list[Student]:
with open("students.pickle", "rb") as file:
students = pickle.load(file)
return students
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
flake8
flake8-annotations
flake8-quotes
flake8-variables-names
pep8-naming
pytest
flake8
flake8-annotations
flake8-quotes
flake8-variables-names
pep8-naming
pytest
Loading
Loading