Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Calorimetry_Laboratory
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
Ramirez Saldana, Santiago
Calorimetry_Laboratory
Commits
59601665
Commit
59601665
authored
1 year ago
by
Xia, Ning
Browse files
Options
Downloads
Patches
Plain Diff
added m_labor
parent
98b282b6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
functions/m_labor.py
+95
-0
95 additions, 0 deletions
functions/m_labor.py
main.py
+1
-0
1 addition, 0 deletions
main.py
with
96 additions
and
0 deletions
functions/m_labor.py
0 → 100644
+
95
−
0
View file @
59601665
import
h5py
as
h5
def
logging_heater
(
path
:
str
,
uuid
:
str
)
->
dict
[
str
,
dict
[
str
,
float
]]:
"""
Prompt the user to enter heating data and log it to an HDF5 file.
This function creates a new group in the HDF5 file for a specified UUID (heater
'
s UUID)
and prompts the user to enter current, voltage, and heating time. It validates the
user
'
s input and writes the data to the file under the created group. Each piece
of data is stored in a separate dataset with a corresponding unit attribute.
Args:
path (str): The file path to the HDF5 file where data should be logged.
uuid (str): The UUID to create a group for.
Returns:
dict[str, dict[str, float]]: A dictionary containing the entered data,
organized by UUID and measurement type.
"""
# Define the HDF5 internal path for the heater data.
h5_path
=
"
RawData/{}
"
.
format
(
uuid
)
# Open the HDF5 file and create a new group for the heater using the UUID.
with
h5
.
File
(
path
,
"
a
"
)
as
f
:
# TODO: Create Group
# This line of code throws an exception. This is just to make sure you can see
# all the code you need to refine. If you already know how to implement the program
# or have done so, then you can safely delete the three lines of code below, as well
# as this comment.
raise
NotImplementedError
(
"
Delete these 3 lines if you have finished the code or want to test it.
"
.
upper
()
)
## DONE ##
# Initialize a dictionary to store heater data.
data_dict
=
{
uuid
:
{
"
Current in Ampere
"
:
None
,
"
Voltage in Volt
"
:
None
,
"
Heat time in Seconds
"
:
None
,
}
}
# A flag to indicate if the loop for correct data entry is active.
is_wrong
=
True
# A flag to indicate if the user is entering the data or correcting it.
enter_data
=
True
# Loop until correct data is entered.
while
is_wrong
:
# If entering data, prompt the user for each value.
if
enter_data
:
for
i
in
data_dict
[
uuid
]:
try
:
# Attempt to convert the input to float and store it.
data_dict
[
uuid
][
i
]
=
float
(
input
(
"
{} =
"
.
format
(
i
)))
except
ValueError
:
# If conversion fails, print an error message and set the value to None.
print
(
"
Invalid input, try again after entering the remaining data.
"
)
data_dict
[
uuid
][
i
]
=
None
# Print the current state of data_dict for review.
print
(
data_dict
)
# Prompt the user to confirm if the entered data is correct.
user_input
=
input
(
"
Are the input data correct? [y] to store, [n] to re-enter:
"
)
# Check the user's decision and set flags accordingly.
if
user_input
==
"
y
"
or
user_input
==
"
Y
"
:
# If data is correct, exit the loop.
is_wrong
=
False
elif
user_input
==
"
n
"
or
user_input
==
"
N
"
:
# If data is incorrect, prompt for re-entry.
enter_data
=
True
else
:
# If input is invalid, inform the user and do not re-enter data.
print
(
"
Invalid input
"
)
enter_data
=
False
# Open the HDF5 file to write the data into the corresponding group.
with
h5
.
File
(
path
,
"
r+
"
)
as
f
:
# TODO: Write the data into HDF5
# This line of code throws an exception. This is just to make sure you can see
# all the code you need to refine. If you already know how to implement the program
# or have done so, then you can safely delete the three lines of code below, as well
# as this comment.
raise
NotImplementedError
(
"
Delete these 3 lines if you have finished the code or want to test it.
"
.
upper
()
)
## DONE ##
# Return the dictionary containing the logged data.
return
data_dict
This diff is collapsed.
Click to expand it.
main.py
+
1
−
0
View file @
59601665
...
...
@@ -13,6 +13,7 @@ Author: Benjamin Hermann, M.Sc.
https://git.rwth-aachen.de/ning.xia
Created: 24.04.2023
Last Changes: 03.11.2023
"""
from
functions
import
m_json
from
functions
import
m_pck
...
...
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