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
f0e7434e
Commit
f0e7434e
authored
3 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
FIX: example script
parent
9c1411d5
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!39
Release 0.4.0
,
!20
created draft for generic analysis method
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosadvancedtools/serverside/examples/example_script.py
+28
-11
28 additions, 11 deletions
src/caosadvancedtools/serverside/examples/example_script.py
with
28 additions
and
11 deletions
src/caosadvancedtools/serverside/examples/example_script.py
+
28
−
11
View file @
f0e7434e
...
...
@@ -26,6 +26,17 @@
"""
An exemplary script that illustrates how scripts can be used in conjunction
with the generic_analysis module.
Data model:
Analysis:
sources: REFEERENCE
scripts: FILE
results: REFEERENCE
mean_value: DOUBLE
Person:
Email: TEXT
"""
import
argparse
...
...
@@ -37,7 +48,7 @@ from datetime import datetime
import
caosdb
as
db
import
matplotlib.pyplot
as
plt
import
numpy
as
np
from
caosadvancedtools.cfood
import
assure_property_is
from
caosadvancedtools.cfood
import
assure_property_is
,
get_property
from
caosadvancedtools.guard
import
INSERT
,
UPDATE
from
caosadvancedtools.guard
import
global_guard
as
guard
from
caosadvancedtools.serverside.helper
import
send_mail
as
main_send_mail
...
...
@@ -47,7 +58,7 @@ logger = logging.getLogger(__name__)
guard
.
set_level
(
level
=
UPDATE
)
def
send_mail
(
self
,
changes
,
receipient
):
def
send_mail
(
changes
,
receipient
):
"""
calls sendmail in order to send a mail to the curator about pending
changes
...
...
@@ -78,11 +89,15 @@ The following changes where done automatically.
def
main
(
args
):
if
hasattr
(
args
,
"
auth_token
"
)
and
args
.
auth_token
:
db
.
configure_connection
(
auth_token
=
args
.
auth_token
)
# TODO (maybe) 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
dataAnalysis
Record with id ={}
"
.
format
(
logger
.
error
(
"
Cannot retrieve Record with id ={}
"
.
format
(
args
.
entityid
))
...
...
@@ -123,40 +138,42 @@ def main(args):
# An update should only be done if necessary: assure_property_is should be
# used instead of direct calls to 'update'.
to_be_updated
=
[]
to_be_updated
=
db
.
Container
()
assure_property_is
(
dataAnalysisRecord
,
"
mean_value
"
,
mean
,
to_be_updated
=
to_be_updated
)
# TODO (maybe) this is not really meaningful since an uploaded file will
always
# be different.... Compare checksums of files?
# TODO (maybe) this is not really meaningful since an uploaded file will
#
always
be different.... Compare checksums of files?
assure_property_is
(
dataAnalysisRecord
,
"
results
"
,
fig
.
id
,
[
fig
.
id
]
,
to_be_updated
=
to_be_updated
)
if
len
(
to_be_updated
)
>
0
:
people
=
db
.
execute_query
(
"
FIND RECORD Person WHICH IS REFERENCEED BY
"
print
(
to_be_updated
)
to_be_updated
.
update
()
people
=
db
.
execute_query
(
"
FIND RECORD Person WHICH IS REFERENCED BY
"
"
{}
"
.
format
(
dataAnalysisRecord
.
id
))
for
person
in
people
:
if
person
.
get_property
(
"
Email
"
)
is
not
None
:
send_mail
(
to_be_updated
,
receipient
=
person
.
get_property
(
"
Email
"
))
send_mail
(
[
str
(
el
)
for
el
in
to_be_updated
],
receipient
=
person
.
get_property
(
"
Email
"
)
.
value
)
# TODO (must) what should be done with the old file? Removed if not referenced?
# TODO (maybe) inform about updates (reuse stuff from crawler.py?)
# TODO (must) sketch meaningful logging
# TODO (must) how to send an email?
def
parse_args
():
parser
=
argparse
.
ArgumentParser
(
description
=
__doc__
,
formatter_class
=
RawTextHelpFormatter
)
parser
.
add_argument
(
"
--auth-token
"
)
parser
.
add_argument
(
"
entityid
"
,
help
=
"
The ID of the DataAnalysis Record.
"
,
type
=
int
)
...
...
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