-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1001b7
commit 49cdd67
Showing
3 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python | ||
|
||
import logging | ||
import time | ||
from argparse import ArgumentParser | ||
import sqlalchemy as sa | ||
import fastavro | ||
|
||
import boto3 | ||
|
||
from ampel.ztf.t0.ArchiveUpdater import ArchiveUpdater | ||
from ampel.ztf.archive.server.s3 import get_object, get_key_for_url | ||
|
||
|
||
logging.basicConfig(level="INFO", format="[%(asctime)s] %(message)s") | ||
log = logging.getLogger() | ||
|
||
parser = ArgumentParser() | ||
parser.add_argument("uri") | ||
parser.add_argument("--s3-bucket") | ||
parser.add_argument("--s3-endpoint") | ||
|
||
|
||
args = parser.parse_args() | ||
|
||
engine = sa.engine.create_engine(args.uri) | ||
|
||
bucket = boto3.resource("s3", endpoint_url=args.s3_endpoint).Bucket(args.s3_bucket) | ||
|
||
with engine.connect() as connection: | ||
meta = sa.MetaData(connection) | ||
meta.reflect() | ||
|
||
Alert = meta.tables["alert"] | ||
Archive = meta.tables["avro_archive"] | ||
|
||
query = Archive.select(Archive.c.alerts is None) | ||
|
||
for row in connection.execute(query).fetchone(): | ||
key = get_key_for_url(row["uri"]) | ||
reader = fastavro.reader(get_object(bucket, key)) | ||
alerts = len(list(reader)) | ||
|
||
print(row, alerts) | ||
|
||
assert False | ||
|
||
# TODO: update alerts field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
BEGIN; | ||
|
||
ALTER TABLE avro_archive ADD count INTEGER; | ||
|
||
COMMIT; |