Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OSUG
RESIF
resif_data_reporter
Commits
dea8f76b
Commit
dea8f76b
authored
Apr 13, 2022
by
Jonathan Schaeffer
Browse files
Récupérer les volumétries depuis la table rall.
À tester
parent
b282111a
Pipeline
#96373
failed with stage
in 48 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
config.yml.example
View file @
dea8f76b
...
...
@@ -17,3 +17,12 @@ postgres:
port: 5432 # Postgres port
database: statistics # Database having the dataholdings table
user: statistics # Password is taken from PGPASSWORD environment variable
inventory:
pghost: resif-pgprod.u-ga.fr
pgport: 5432
pgdatabase: resifInv-Prod
pguser: resifinv_ro # Password is taken from INVENTORY_PGPASSWORD environment variable
repositories:
- name: rall
type: validated
resifdatareporter/resifdatareporter.py
View file @
dea8f76b
...
...
@@ -108,6 +108,47 @@ def scan_ph5_volume(volpath):
)
return
data
def
scan_validated_data
(
cfg
):
# Plutôt que de scanner des fichers dans le volume, on prend la valeur dans la table rall
data
=
[]
logger
.
info
(
"Getting sizes from inventory database."
)
with
psycopg2
.
connect
(
dbname
=
cfg
[
"pgdatabase"
],
user
=
cfg
[
"pguser"
],
host
=
cfg
[
"pghost"
],
port
=
cfg
[
"pgport"
],
password
=
os
.
getenv
(
'INVENTORY_PGPASSWORD'
,
''
)
)
as
conn
:
for
table
in
cfg
[
"repositories"
]:
logger
.
info
(
"Scanning table %s"
,
table
[
"name"
])
with
conn
.
cursor
()
as
cur
:
cur
.
execute
(
f
"""
select n.network, n.start_year, r.year, s.station, c.channel, sum(r.size)
from
{
table
[
"name"
]
}
as r join channel as c on r.channel_id=c.channel_id join station as s on c.station_id = s.station_id join networks as n on n.network_id = s.network_id
group by 1,2,3,4,5
"""
)
for
record
in
cur
:
if
re
.
match
(
'^[A-W]'
,
record
[
0
]):
net
=
record
[
0
]
is_perm
=
True
else
:
net
=
record
[
0
]
+
str
(
record
[
1
])
is_perm
=
False
data
.
append
(
{
"year"
:
record
[
2
],
"network"
:
net
,
"station"
:
record
[
3
],
"channel"
:
record
[
4
],
"size"
:
record
[
5
],
"is_permanent"
:
is_perm
,
"type"
:
"validated"
}
)
logger
.
info
(
"Done"
)
return
data
def
scan_volumes
(
volumes
):
# volumes is a complex data type :
...
...
@@ -204,6 +245,7 @@ def cli(configfile, force_scan, dryrun, verbose, version):
sys
.
exit
(
0
)
statistics
=
scan_volumes
(
cfg
[
"volumes"
])
statistics
.
append
(
scan_validated_data
(
cfg
[
"inventory"
]))
if
dryrun
:
logger
.
info
(
"Dryrun mode, dump stats and exit"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment