generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 42
London | 25-SDC-Nov | Aida Eslamimoghadam | Sprint 5 | Implement laptop allocation #300
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
aydaeslami
wants to merge
6
commits into
CodeYourFuture:main
Choose a base branch
from
aydaeslami:laptop
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5efefcd
Implement laptop allocation
aydaeslami fbcbc5c
Fixed return type
aydaeslami cc0cd9c
Fixed return type
aydaeslami 74631bf
Merge branch 'CodeYourFuture:main' into laptop
aydaeslami a2210c0
Resolve merge conflict in myLaptop.py
aydaeslami 1d170b9
change Var names
aydaeslami 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| from dataclasses import dataclass | ||
| from enum import Enum | ||
| from typing import List | ||
|
|
||
| class OperatingSystem(Enum): | ||
| MACOS = "macOS" | ||
| ARCH = "Arch Linux" | ||
| UBUNTU = "Ubuntu" | ||
| WINDOWS = "Windows" | ||
|
|
||
| @dataclass(frozen=True) | ||
| class Person: | ||
| name: str | ||
| age: int | ||
| preferred_operating_system: List[OperatingSystem] | ||
|
|
||
| @dataclass(frozen=True) | ||
| class Laptop: | ||
| id: int | ||
| manufacturer: str | ||
| model: str | ||
| screen_size_in_inches: float | ||
| operating_system: OperatingSystem | ||
|
|
||
|
|
||
| def allocate_laptops( | ||
| people: List[Person], | ||
| laptops: List[Laptop] | ||
| ) -> dict[str, tuple[str, int]]: | ||
|
|
||
| allocation_map = {} | ||
| available_laptops = laptops.copy() | ||
|
|
||
| if len(laptops) < len(people): | ||
| print("Not enough laptops for all people") | ||
|
|
||
| for person in people: | ||
| sadnessNumber = 100 | ||
|
|
||
| for laptop in available_laptops: | ||
| if laptop.operating_system in person.preferred_operating_system: | ||
| sadnessNumber = person.preferred_operating_system.index(laptop.operating_system) | ||
| allocation_map[person.name] = (laptop.operating_system.value, sadnessNumber) | ||
| available_laptops.remove(laptop) | ||
| break | ||
| if sadnessNumber == 100: | ||
| allocation_map[person.name] = ("No Laptop Assigned", sadnessNumber) | ||
|
|
||
| return allocation_map | ||
|
|
||
|
|
||
| personList = [ | ||
| Person(name="Aida", age=30, preferred_operating_system=[OperatingSystem.UBUNTU]), | ||
| Person(name="Elizaveta", age=28, preferred_operating_system=[OperatingSystem.UBUNTU, OperatingSystem.WINDOWS, OperatingSystem.ARCH]), | ||
| Person(name="Zahra", age=35, preferred_operating_system=[OperatingSystem.UBUNTU]), | ||
| Person(name="Tobi", age=35, preferred_operating_system=[OperatingSystem.WINDOWS, OperatingSystem.MACOS, OperatingSystem.ARCH]), | ||
| ] | ||
|
|
||
| laptopList = [ | ||
| Laptop(id=1, manufacturer="Dell", model="XPS", screen_size_in_inches=13, operating_system=OperatingSystem.ARCH), | ||
| Laptop(id=4, manufacturer="EDell", model="XPS", screen_size_in_inches=13, operating_system=OperatingSystem.ARCH), | ||
| Laptop(id=2, manufacturer="Dell", model="XPS", screen_size_in_inches=15, operating_system=OperatingSystem.UBUNTU), | ||
| Laptop(id=3, manufacturer="Apple", model="macBook", screen_size_in_inches=13, operating_system=OperatingSystem.MACOS), | ||
| ] | ||
|
|
||
| result = allocate_laptops(personList, laptopList) | ||
| lenResult = len(result) | ||
| for key, value in result.items(): | ||
| print (f" {key } has ** {value[0]} ** and Sadness is: {value[1]}" ) | ||
|
|
||
|
|
||
|
|
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.
Uh oh!
There was an error while loading. Please reload this page.