Commit dea8f76b authored by Jonathan Schaeffer's avatar 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
......@@ -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
......@@ -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")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment