Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
d5320c4d
Commit
d5320c4d
authored
3 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
WIP: extend example script
parent
e778c88d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!39
Release 0.4.0
,
!20
created draft for generic analysis method
Pipeline
#16400
failed
3 years ago
Stage: setup
Stage: cert
Stage: style
Stage: unittest
Stage: integrationtest
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosadvancedtools/serverside/example_script.py
+66
-1
66 additions, 1 deletion
src/caosadvancedtools/serverside/example_script.py
with
66 additions
and
1 deletion
src/caosadvancedtools/serverside/example_script.py
+
66
−
1
View file @
d5320c4d
...
...
@@ -29,12 +29,77 @@ with the generic_analysis module.
"""
import
argparse
import
logging
import
sys
from
argparse
import
RawTextHelpFormatter
import
caosdb
as
db
import
matplotlib.pyplot
as
plt
import
numpy
as
np
from
caosadvancedtools.cfood
import
assure_property_is
logger
=
logging
.
getLogger
(
__name__
)
def
main
(
args
):
print
(
args
.
entityid
)
# TODO can these checks be replaced by a more declaritive appoach?
try
:
dataAnalysisRecord
=
db
.
Record
(
id
=
args
.
entityid
).
retrieve
()
except
db
.
TransactionError
:
logger
.
error
(
"
Cannot retrieve dataAnalysisRecord with id ={}
"
.
format
(
args
.
entityid
))
# The script may require certain information to exist. Here, we expect that
# a InputDataSet Property exists that references a numpy file.
if
(
dataAnalysisRecord
.
get_property
(
"
InputDataSet
"
)
is
None
or
db
.
apiutils
.
is_reference
(
dataAnalysisRecord
.
get_property
(
"
InputDataSet
"
))):
raise
RuntimeError
(
"
InputDataSet Refenrence must exist.
"
)
# ####### this core might be replaced by a call to another script ####### #
# Download the data
npobj
=
db
.
File
(
id
=
dataAnalysisRecord
.
get_property
(
"
InputDataSet
"
)).
retrieve
()
npfile
=
npobj
.
download
()
data
=
np
.
load
(
npfile
)
# Plot data
filename
=
"
hist.png
"
plt
.
hist
(
data
)
plt
.
savefig
()
mean
=
data
.
mean
()
# ####################################################################### #
# Insert the result plot
# TODO: how do we find a good file path??
fig
=
db
.
File
(
file
=
filename
,
path
=
"
/uploaded/something/
"
+
filename
)
fig
.
insert
()
# Add the result to the analysis Record
# An update should only be done if necessary: assure_property_is should be
# used instead of direct calls to 'update'.
assure_property_is
(
dataAnalysisRecord
,
"
mean_value
"
,
mean
,
)
# TODO this is not really meaningful since an uploaded file will always
# be different.... Compare checksums of files?
assure_property_is
(
dataAnalysisRecord
,
"
result
"
,
fig
.
id
,
)
# TODO what should be done with the old file? Removed if not referenced?
# TODO inform about updates (reuse stuff from crawler.py?)
# TODO sketch meaningful logging
# TODO how to send an email?
def
parse_args
():
...
...
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