Skip to content

Instantly share code, notes, and snippets.

@miriamhochwaldartist
Forked from pedronauck/README.md
Last active December 2, 2021 02:19
Show Gist options
  • Save miriamhochwaldartist/b784caee26440703083d2d70e0addc62 to your computer and use it in GitHub Desktop.
Save miriamhochwaldartist/b784caee26440703083d2d70e0addc62 to your computer and use it in GitHub Desktop.
Sample file for README.md

Deputy Software Engineering Challenge

The problem is to find the subordinate user files based on the role level input.

"Come up with a function, for an arbitrary collection of roles and users, given a user Id returns a list of ALL their subordinates (i.e: including their subordinate's subordinates)."

Sample roles and user input are input as two different list dictionaries. Role levels are not unique to one user.

The problem can be approached from either comparing the role level input with the list dictionary entries. The test set returns the subordinates list of a particular role level.

Alternately it can be looked at from creating object oriented classes for role and user. Making lists of the entries by inputing the data into classes (role or user) and then appending for a list. The list of users can be inspected to find subordinates to a particular role. Alternately a tree could be created, then parsed to find and return particular associations between roles and subordination.

Detailed Description

In our system each user belongs to a user-group with a defined set of permissions. We name such a group "Role". A certain role (unless it is the root) must have a parent role to whom it reports to. For example a customer may have these 4 roles in their account.

Notice how the System Administrator has no parent role and how Employee has as parent role the Supervisor. Naturally this cascading parent-child relationship means that Location Manager, Supervisor, Employee, Trainer are all children roles to System Administrator.

Parent: user-group – “Role(n)”

Child: user – “Role”(n+1)

Role must have a parent to whom it reports (a supervisor)

objectRole_n = {
   “Id” : n,
   “Name” : “Noun N”
   “Parent” : n – 1,
};

objectRole_n.n = {1,2,3,4,5} # Note: could be more

objectRole.name = {System Administrator, Location Manager, Supervisor, Employee, Trainer}

objectUser_m = {
   “Id” : m,
   “Name” : “Noun M”
   “Role” :  objectRole_n.n  
}

Ground rules

  1. Package your solution in any way you would like (e.g: zip file, github repo, etc)
  2. Include a README.md with your solution
  3. Tell us how to get it running in some unix environment
  4. Produce a test suite that we can run with everything passing
  5. Make sure you write readable code.
  6. Feel free to write comments explaining your solution so we understand your thinking behind it
  7. Email the solution to your recruiter. They will forward it to the engineers involved in your role
  8. Have fun!

Installation

Run in UNIX

1. Make active working directory where the file is located

  • Keep changing folders until you find the right one

  • Change directory to the folder name within the existing folder % cd folderName

  • Go back a folder % cd ..

  • List the files in current folder % ls

  • Obtain the path of the current folder % pwd

  • Go directly to the folder using the entire path % cd pathName

2. Run the python file (use current version of Python)

% python3 role_user_initialise_test_a.py

Usage

The user can obtain a non-ordered list of user information (Id, Name, Role) which are subordinate to the role level input.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Sample Input

roles = [ 
   { 
   "Id": 1,
   "Name": "System Administrator",
   "Parent": 0
   }, 
   { 
   "Id": 2,
   "Name": "Location Manager",
   "Parent": 1,
   }, 
   { 
   "Id": 3,
   "Name": "Supervisor",
   "Parent": 2,
   }, 
   { 
   "Id": 4,
   "Name": "Employee",
   "Parent": 3,
   }, 
   { 
   "Id": 5,
   "Name": "Trainer",
   "Parent": 3,
   } 
] 
users = [ 
   { 
   "Id": 1,
   "Name": "Adam Admin",
   "Role": 1
   }, 
   { 
   "Id": 2,
   "Name": "Emily Employee",
   "Role": 4
         }, 
   { 
   "Id": 3,
   "Name": "Sam Supervisor",
   "Role": 3
   }, 
   { 
   "Id": 4,
   "Name": "Mary Manager",
   "Role": 2
   }, 
   { 
   "Id": 5,
   "Name": "Trainer",
   "Role": 3,
   } 
]

Testing

User set: objUser1:{'userId': 1, 'userName': 'Adam Admin', 'roleId': 1} objUser2:{'userId': 2, 'userName': 'Emily Employee', 'roleId': 4} objUser3:{'userId': 3, 'userName': 'Sam Supervisor', 'roleId': 3} objUser4:{'userId': 4, 'userName': 'Mary Manager', 'roleId': 2} objUser5:{'userId': 5, 'userName': 'Trainer', 'roleId': 5}

If you were give user #1 (Adam Admin), you should output a list containing [objUser2, objUser3, objUser4, objUser5] in no particular order.

getSubOrdinates(1); 

// should return 
[
{"Id": 2, "Name": "Emily Employee", "Role": 4}, 
{"Id": 3, "Name": "Sam Supervisor", "Role": 3},
{"Id": 4, "Name": "Mary Manager", "Role": 2}, 
{"Id": 5, "Name": "Steve Trainer", "Role": 5}
]

For example if you were given user #3 (Sam Supervisor), you should output objUser2 (Emily Employee) and objUser5 (Steve Trainer)

getSubOrdinates(3); 

// should return 
[
{"Id": 2, "Name": "Emily Employee", "Role": 4}, 
{"Id": 5, "Name": "Steve Trainer", "Role": 5}
]

Credits

Challenge set by Deputy (company) and enacted by Miriam Hochwald (individual)

License

Use under "Attribution (BY)" creative commons liscence Creative Commons

<snippet>
<content><![CDATA[
# ${1:Deputy Software Engineering Challenge}
The problem is to find the subordinate user files based on the role level input.
"Come up with a function, for an arbitrary collection of roles and users, given a user Id returns a list of ALL their subordinates (i.e: including their subordinate's subordinates)."
Sample roles and user input are input as two different list dictionaries. Role levels are not unique to one user.
The problem can be approached from either comparing the role level input with the list dictionary entries. The test set returns the subordinates list of a particular role level.
Alternately it can be looked at from creating object oriented classes for role and user. Making lists of the entries by inputing the data into classes (role or user) and then appending for a list. The list of users can be inspected to find subordinates to a particular role. Alternately a tree could be created, then parsed to find and return particular associations between roles and subordination.
## Detailed Description
In our system each user belongs to a user-group with a defined set of permissions.
We name such a group "Role". A certain role (unless it is the root) must have a parent role to whom it reports to. For example a customer may have these 4 roles in their account.
Notice how the System Administrator has no parent role and how Employee has as parent role the Supervisor.
Naturally this cascading parent-child relationship means that Location Manager, Supervisor, Employee, Trainer are all children roles to System Administrator.
Parent: user-group – “Role(n)”
Child: user – “Role”(n+1)
Role must have a parent to whom it reports (a supervisor)
```
objectRole_n = {
“Id” : n,
“Name” : “Noun N”
“Parent” : n – 1,
};
```
objectRole_n.n = {1,2,3,4,5} # Note: could be more
objectRole.name = {System Administrator, Location Manager, Supervisor, Employee, Trainer}
```
objectUser_m = {
“Id” : m,
“Name” : “Noun M”
“Role” : objectRole_n.n
}
```
## Ground rules
1. Package your solution in any way you would like (e.g: zip file, github repo, etc)
2. Include a README.md with your solution
3. Tell us how to get it running in some unix environment
4. Produce a test suite that we can run with everything passing
5. Make sure you write readable code.
6. Feel free to write comments explaining your solution so we understand your thinking behind it
7. Email the solution to your recruiter. They will forward it to the engineers involved in your role
8. Have fun!
## Installation
### Run in UNIX
#### 1. Make active working directory where the file is located
* Keep changing folders until you find the right one
* Change directory to the folder name within the existing folder `% cd folderName`
* Go back a folder `% cd ..`
* List the files in current folder `% ls`
* Obtain the path of the current folder `% pwd`
* Go directly to the folder using the entire path `% cd pathName`
#### 2. Run the python file (use current version of Python)
`% python3 role_user_initialise_test_a.py`
## Usage
The user can obtain a non-ordered list of user information (Id, Name, Role) which are subordinate to the role level input.
## Contributing
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D
## Sample Input
```
roles = [
{
"Id": 1,
"Name": "System Administrator",
"Parent": 0
},
{
"Id": 2,
"Name": "Location Manager",
"Parent": 1,
},
{
"Id": 3,
"Name": "Supervisor",
"Parent": 2,
},
{
"Id": 4,
"Name": "Employee",
"Parent": 3,
},
{
"Id": 5,
"Name": "Trainer",
"Parent": 3,
}
]
```
```
users = [
{
"Id": 1,
"Name": "Adam Admin",
"Role": 1
},
{
"Id": 2,
"Name": "Emily Employee",
"Role": 4
},
{
"Id": 3,
"Name": "Sam Supervisor",
"Role": 3
},
{
"Id": 4,
"Name": "Mary Manager",
"Role": 2
},
{
"Id": 5,
"Name": "Trainer",
"Role": 3,
}
]
```
## Testing
User set:
objUser1:{'userId': 1, 'userName': 'Adam Admin', 'roleId': 1}
objUser2:{'userId': 2, 'userName': 'Emily Employee', 'roleId': 4}
objUser3:{'userId': 3, 'userName': 'Sam Supervisor', 'roleId': 3}
objUser4:{'userId': 4, 'userName': 'Mary Manager', 'roleId': 2}
objUser5:{'userId': 5, 'userName': 'Trainer', 'roleId': 5}
If you were give user #1 (Adam Admin), you should output a list containing [objUser2, objUser3, objUser4, objUser5] in no particular order.
```
getSubOrdinates(1);
// should return
[
{"Id": 2, "Name": "Emily Employee", "Role": 4},
{"Id": 3, "Name": "Sam Supervisor", "Role": 3},
{"Id": 4, "Name": "Mary Manager", "Role": 2},
{"Id": 5, "Name": "Steve Trainer", "Role": 5}
]
```
For example if you were given user #3 (Sam Supervisor), you should output objUser2 (Emily Employee) and objUser5 (Steve Trainer)
```
getSubOrdinates(3);
// should return
[
{"Id": 2, "Name": "Emily Employee", "Role": 4},
{"Id": 5, "Name": "Steve Trainer", "Role": 5}
]
```
## Credits
Challenge set by Deputy (company) and enacted by Miriam Hochwald (individual)
## License
Use under "Attribution (BY)" creative commons liscence
[Creative Commons](https://creativecommons.org.au/learn/licences/ "Creative Commons")
]]></content>
<tabTrigger>readme</tabTrigger>
</snippet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment