Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MetObsCommon
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository 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
MetObs
MetObsCommon
Commits
74cab76d
Commit
74cab76d
authored
7 years ago
by
Alex Diebold
Browse files
Options
Downloads
Patches
Plain Diff
Updating _query()
parent
318dbcc9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
metobscommon/archive/db.py
+52
-22
52 additions, 22 deletions
metobscommon/archive/db.py
with
52 additions
and
22 deletions
metobscommon/archive/db.py
+
52
−
22
View file @
74cab76d
...
...
@@ -27,8 +27,10 @@ class C(Enum):
SITE
=
'
site
'
END
=
'
end
'
START
=
'
start
'
PATTERN
=
'
pattern
'
PATH
=
'
path
'
GLOB
=
'
glob_pattern
'
FORMAT
=
'
format_pattern
'
LEVEL
=
'
level
'
PERIOD
=
'
period
'
INTERVAL
=
'
interval
'
DESC
=
'
description
'
...
...
@@ -39,10 +41,10 @@ class C(Enum):
TEST
=
'
test
'
class
OUTPUT
(
Enum
):
INST
=
'
num - name - site - description
'
INST
=
'
num - name - site -
filetype -
description
'
SITE
=
'
num - name - experiment - description
'
EXP
=
'
num - name - start_time - end_time - site - description
'
FILETYPE
=
'
num -
pattern - interval
- description
'
FILETYPE
=
'
num -
level - glob_pattern - format_pattern - interval - period - instrument
- description
'
FILE
=
'
num - instrument - experiment - filetype - relative_path - start_time - end_time
'
# association_table = Table('association', Base.metdadata,
...
...
@@ -80,7 +82,7 @@ class Instrument(Base):
class
Instrument_FileType
(
Base
):
_tablename__
=
'
Instrument_FileTypes
'
_
_tablename__
=
'
Instrument_FileTypes
'
instrument_filetype_id
=
Column
(
Integer
,
primary_key
=
True
,
unique
=
True
)
instrument_id
=
Column
(
Integer
,
ForeignKey
(
'
Instruments.instrument_id
'
),
primary_key
=
True
)
...
...
@@ -433,18 +435,14 @@ def _create(args):
level
=
d
[
'
level
'
]
else
:
level
=
None
if
'
version
'
in
d
.
keys
():
version
=
d
[
'
version
'
]
else
:
version
=
None
curr_file
=
File
(
name
=
f
,
glob_pattern
=
d
[
'
glob_pattern
'
],
format_pattern
=
d
[
'
format_pattern
'
],
level
=
level
,
version
=
version
,
period
=
d
[
'
period
'
])
curr_file
.
add_instrument
(
curr_inst
)
curr_filetype
=
FileType
(
name
=
f
,
glob_pattern
=
d
[
'
glob_pattern
'
],
format_pattern
=
d
[
'
format_pattern
'
],
level
=
level
,
period
=
d
[
'
period
'
])
curr_filetype
.
add_instrument
(
curr_inst
)
#remove database if process failed
except
:
os
.
remove
(
args
.
filename
)
print
(
traceback
.
format_exc
())
print
(
'
Error in creating database -- process aborted.
'
)
print
(
'
Error in creating database -- process aborted.
\n
'
)
else
:
raise
FileExistsError
(
'
database
\'
{}
\'
already exists
'
.
format
(
args
.
filename
))
...
...
@@ -526,12 +524,14 @@ def _query(args):
C
.
SITE
:
'
Site (empty if want all, separate multiple by commas):
'
,
C
.
START
:
'
Start Time (YYMMDD -- empty for today):
'
,
C
.
END
:
'
End Time (YYMMDD -- empty for Start Time):
'
,
C
.
PATTERN
:
'
Filename Pattern (empty for all, separate multiple by commas):
'
,
C
.
GLOB
:
'
Glob Pattern (empty if want all, separate multiple by commas)
'
,
C
.
FORMAT
:
'
Format Pattern (empty if want all, separate multiple by commas)
'
,
C
.
LEVEL
:
'
Level (empty if want all, separate multiple by commas)
'
,
C
.
PERIOD
:
'
Period (empty if want all, separate multiple by commas)
'
,
C
.
INTERVAL
:
'
FileType Interval (empty for all, separate multiple by commas):
'
,
C
.
INST
:
'
Instrument Name (empty for all, separate multiple by commas):
'
,
C
.
EXP
:
'
Experiment Name (empty for all, separate multiple by commas):
'
,
C
.
FILETYPE
:
'
FileType (empty for all, separate multiple by commas):
'
,
C
.
PATH
:
'
Relative path (path/to/file/):
'
}
#holds query input -- allows for querying of multiple things
...
...
@@ -540,28 +540,28 @@ def _query(args):
if
args
.
instrument
:
inst_in
=
{}
print
(
'
\n
INSTRUMENT query:
'
)
for
in_option
in
(
C
.
NAME
,
C
.
SITE
):
for
in_option
in
(
C
.
NAME
,
C
.
SITE
,
C
.
FILETYPE
):
inst_in
[
in_option
]
=
input
(
query_input_options
[
in_option
])
query_in
[
C
.
INST
]
=
inst_in
#get SITE query input and put into input dict
if
args
.
site
:
site_in
=
{}
print
(
'
\n
SITE query:
'
)
for
in_option
in
(
C
.
NAME
,):
for
in_option
in
(
C
.
NAME
,
C
.
EXP
):
site_in
[
in_option
]
=
input
(
query_input_options
[
in_option
])
query_in
[
C
.
SITE
]
=
site_in
#get EXPERIMENT query input
if
args
.
experiment
:
exp_in
=
{}
print
(
'
\n
EXPERIMENT query:
'
)
for
in_option
in
(
C
.
NAME
,
C
.
START
,
C
.
END
):
for
in_option
in
(
C
.
NAME
,
C
.
START
,
C
.
END
,
C
.
SITE
):
exp_in
[
in_option
]
=
input
(
query_input_options
[
in_option
])
query_in
[
C
.
EXP
]
=
exp_in
#get FILETYPE query input
if
args
.
filetype
:
filetype_in
=
{}
print
(
'
\n
FILETYPE query:
'
)
for
in_option
in
(
C
.
PATTERN
,
C
.
INTERVAL
):
for
in_option
in
(
C
.
NAME
,
C
.
LEVEL
,
C
.
GLOB
,
C
.
FORMAT
,
C
.
INTERVAL
,
C
.
PERIOD
):
filetype_in
[
in_option
]
=
input
(
query_input_options
[
in_option
])
query_in
[
C
.
FILETYPE
]
=
filetype_in
#get FILE query input
...
...
@@ -575,7 +575,7 @@ def _query(args):
#separates multiple query specifiers into a list
for
key
in
query_in
.
keys
():
for
second_key
in
query_in
[
key
]:
if
second_key
in
(
C
.
NAME
,
C
.
SITE
,
C
.
PATTERN
,
C
.
INTERVAL
,
C
.
INST
,
C
.
EXP
,
C
.
FILETYPE
):
if
second_key
in
(
C
.
NAME
,
C
.
SITE
,
C
.
GLOB
,
C
.
FORMAT
,
C
.
LEVEL
,
C
.
PERIOD
,
C
.
INTERVAL
,
C
.
INST
,
C
.
EXP
,
C
.
FILETYPE
):
query_in
[
key
][
second_key
]
=
query_in
[
key
][
second_key
].
replace
(
'
'
,
''
).
split
(
'
,
'
)
#holds the actual queries
...
...
@@ -603,6 +603,16 @@ def _query(args):
for
qry
in
temp
:
for
i_site
in
query_in
[
C
.
INST
][
C
.
SITE
]:
queries
[
C
.
INST
].
append
(
qry
.
filter
(
Instrument
.
site
.
has
(
name
=
i_site
)))
# check if specific filetype(s) was/were specified
if
query_in
[
C
.
INST
][
C
.
FILETYPE
][
0
]:
#make copy of current queries
temp
=
queries
[
C
.
INST
].
copy
()
#clear out current queries
queries
[
C
.
INST
].
clear
()
#loop through each query and filter by filetype name
for
qry
in
temp
:
for
i_ft
in
query_in
[
C
.
INST
][
C
.
FILETYPE
]:
queries
[
C
.
INST
].
append
(
qry
.
filter
(
Instrument
.
filetype
.
any
(
name
=
i_ft
)))
#print out query results
print
(
'
\n
INSTRUMENT query output
'
)
print
(
OUTPUT
.
INST
.
value
)
...
...
@@ -624,6 +634,16 @@ def _query(args):
queries
[
C
.
SITE
].
append
(
init_site_query
.
filter
(
Site
.
name
==
s_name
))
else
:
queries
[
C
.
SITE
].
append
(
init_site_query
)
#check if there are any experiments to use to filter
if
query_in
[
C
.
SITE
][
C
.
EXP
][
0
]:
#make copy of current queries
temp
=
queries
[
C
.
SITE
].
copy
()
#clear out current queries
queries
[
C
.
SITE
].
clear
()
#loop through each query and filter by experiment name
for
qry
in
temp
:
for
s_exp
in
query_in
[
C
.
SITE
][
C
.
EXP
]:
queries
[
C
.
SITE
].
append
(
qry
.
filter
(
Site
.
experiment
.
any
(
name
=
s_exp
)))
#print out query results
print
(
'
\n
SITE query output
'
)
print
(
OUTPUT
.
SITE
.
value
)
...
...
@@ -645,6 +665,16 @@ def _query(args):
queries
[
C
.
EXP
].
append
(
init_exp_query
.
filter
(
Experiment
.
name
==
e_name
))
else
:
queries
[
C
.
EXP
].
append
(
init_exp_query
)
#check if there are any sites to use to filter
if
query_in
[
C
.
EXP
][
C
.
SITE
][
0
]:
#make copy of current queries
temp
=
queries
[
C
.
EXP
].
copy
()
#clear out current queries
queries
[
C
.
EXP
].
clear
()
#loop through each query and filter by experiment name
for
qry
in
temp
:
for
e_site
in
query_in
[
C
.
EXP
][
C
.
SITE
]:
queries
[
C
.
EXP
].
append
(
qry
.
filter
(
Experiment
.
site
.
any
(
name
=
e_site
)))
#print out query results
print
(
'
\n
EXPERIMENT query output
'
)
print
(
OUTPUT
.
EXP
.
value
)
...
...
@@ -660,10 +690,10 @@ def _query(args):
#initial FileType query
init_ft_query
=
session
.
query
(
FileType
)
#check if there are any filename pattern to use to filter
if
query_in
[
C
.
FILETYPE
][
C
.
PATTERN
][
0
]:
if
query_in
[
C
.
FILETYPE
][
C
.
NAME
][
0
]:
#filter using pattern(s)
for
ft_
pattern
in
query_in
[
C
.
FILETYPE
][
C
.
PATTERN
]:
queries
[
C
.
FILETYPE
].
append
(
init_ft_query
.
filter
(
FileType
.
pattern
==
ft_pattern
))
for
ft_
name
in
query_in
[
C
.
FILETYPE
][
C
.
NAME
]:
queries
[
C
.
FILETYPE
].
append
(
init_ft_query
.
filter
(
FileType
.
name
==
ft_name
))
else
:
queries
[
C
.
FILETYPE
].
append
(
init_ft_query
)
#check if there are any interavl amounts to use to filter
...
...
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