Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
quality-kpi
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stumpe, Marius
quality-kpi
Commits
a13db573
Commit
a13db573
authored
2 years ago
by
Hock, Martin
Browse files
Options
Downloads
Patches
Plain Diff
Renaming of file and classes to fit exercise description
parent
04b9c92a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
datasheets/create_json_from_excel.py
+2
-2
2 additions, 2 deletions
datasheets/create_json_from_excel.py
functions/classes.py
+0
-1
0 additions, 1 deletion
functions/classes.py
test-classes.ipynb
+2
-2
2 additions, 2 deletions
test-classes.ipynb
test-classes.py
+12
-3
12 additions, 3 deletions
test-classes.py
with
16 additions
and
8 deletions
datasheets/create_json_from_excel.py
+
2
−
2
View file @
a13db573
...
...
@@ -14,8 +14,8 @@ HELP_TXT = """
1. The source excel file. (e.g. test.xlsx)
2. The destination folder for the json file. (e.g. test_folder)
3. Override the folder if existing. (OPTIONAL, False)
Providing only
'
-- help
'
will show this text and exit.
Providing only
'
-- help
'
will show this text and exit.
"""
...
...
This diff is collapsed.
Click to expand it.
functions/
lego_
classes.py
→
functions/classes.py
+
0
−
1
View file @
a13db573
...
...
@@ -2,7 +2,6 @@
File consists of several classes for the different elements of a device.
'''
from
__future__
import
annotations
from
enum
import
Enum
,
auto
import
uuid
from
typing
import
Any
,
Union
,
Literal
,
TypedDict
,
TypeVar
,
Type
,
List
,
Optional
,
Dict
...
...
This diff is collapsed.
Click to expand it.
test-
lego
classes.ipynb
→
test-classes.ipynb
+
2
−
2
View file @
a13db573
...
...
@@ -7,8 +7,8 @@
"outputs": [],
"source": [
"# import functions.lego_classes as lego_classes\n",
"from functions.
lego_
classes import LegoItem\n",
"from functions.
lego_
classes import LegoComponent"
"from functions.classes import LegoItem\n",
"from functions.classes import LegoComponent"
]
},
{
...
...
%% Cell type:code id: tags:
```
python
# import functions.lego_classes as lego_classes
from
functions.
lego_
classes
import
LegoItem
from
functions.
lego_
classes
import
LegoComponent
from
functions.classes
import
LegoItem
from
functions.classes
import
LegoComponent
```
%% Cell type:code id: tags:
```
python
# Test manually creating some item and components
item1
=
LegoItem
(
1
,
0.10
,
10
)
item2
=
LegoItem
(
3
,
0.30
,
30
)
item3
=
LegoItem
(
2
,
0.2
,
20
)
component1
=
LegoComponent
()
# component1.add_item(item1)
component2
=
LegoComponent
(
item2
)
componentall
=
LegoComponent
([
component1
,
component2
])
# This will be saved as items for some reasaon
# component3 = LegoComponent(item3,component1)
# component3.add(item2) # Can't really use an item twice
# component3.add(component2)
print
(
componentall
.
items
)
```
%% Output
[<functions.lego_classes.LegoComponent object at 0x000002720F4BF7F0>, <functions.lego_classes.LegoComponent object at 0x000002720F4BF790>]
%% Cell type:code id: tags:
```
python
``
`
%%
Cell
type
:
code
id
:
tags
:
```
python
## Let's test the json stuff
import json
# import tkinter as tk
```
%% Cell type:code id: tags:
```
python
# First level list handling
def read_json(file_path):
with open(file_path, 'r') as f:
data = json.load(f)
return data
json_list_data = read_json('example_item_data_list.json')
# that produces a list, we'd prefer a dict
# Clever way to just create an item for each listed element
def create_all_items(data):
items = []
for item_data in data:
item_number = item_data.get('item_number')
mass = item_data.get('mass')
delivery_time = item_data.get('delivery_time')
# specific_data = item_data.get('specific_data', {})
item = LegoItem(item_number, mass, delivery_time)
items.append(item)
return items
all_items = create_all_items(json_list_data)
# How to get entries for a specific item
def get_item_by_number(data, item_number):
datasheet = [item for item in data if item['item_number' ] == item_number]
return datasheet
sheet1 = get_item_by_number(json_list_data, 2) # this is a list? meh
```
%% Cell type:code id: tags:
```
python
# vs first level dict handling
with open('example_item_data_dict.json') as json_file:
json_dict = json.load(json_file)
print(type(json_dict))
print(json_dict["1"])
sheet2_from_dict = json_dict["2"]
# Create an item for this:
def create_item_from_sheet(dict):
item_number = dict["item_number"]
mass = dict["mass"]
delivery_time =["delivery_time"]
item = LegoItem(item_number, mass, delivery_time)
return item
itemfromdict = create_item_from_sheet(sheet2_from_dict)
```
%% Output
<class 'dict'>
{'item_number': 1, 'mass': 10, 'delivery_time': 1}
...
...
This diff is collapsed.
Click to expand it.
test-
lego
classes.py
→
test-classes.py
+
12
−
3
View file @
a13db573
# import functions.lego_classes as lego_classes
from
functions.lego_classes
import
*
# import standard libraries
import
json
import
pprint
# import classes from the classes module in functions package
from
functions.classes
import
LegoComponent
from
functions.classes
import
LegoAssembly
from
functions.classes
import
ComponentCategory
from
functions.classes
import
AggregationLayer
from
functions.classes
import
KPIEncoder
from
functions.classes
import
print_assembly_tree
# Test manually creating some item and components
battery
=
LegoComponent
(
"
nice battery
"
,
ComponentCategory
.
BATTERY
,
"
bat42
"
,
1
,
2
,
3
)
...
...
@@ -20,9 +27,11 @@ chassis.add_assembly(door2)
engine
=
LegoAssembly
(
"
Engine
"
,
AggregationLayer
.
ASSEMBLY
)
engine
.
add_component
(
motor
.
clone
())
fuel_tank
=
LegoAssembly
(
"
Fuel Tank
"
,
AggregationLayer
.
ASSEMBLY
)
fuel_tank
.
add_component
(
battery
.
clone
())
wheels
=
LegoAssembly
(
"
Wheels
"
,
AggregationLayer
.
ASSEMBLY
)
for
_
in
range
(
4
):
wheels
.
add_component
(
wheel
.
clone
())
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment