-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #502 from alercebroker/fix/wl_filter_parsing
Fix parsing problems in watchlists
- Loading branch information
Showing
15 changed files
with
163 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,4 +137,6 @@ dmypy.json | |
# Cython debug symbols | ||
cython_debug/ | ||
|
||
.ruff_cache | ||
.ruff_cache | ||
|
||
sample.csv |
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 @@ | ||
import os | ||
from typing import Any | ||
|
||
from psycopg2.sql import SQL | ||
|
||
from watchlist_step.db.connection import DatabaseConfig, PsqlDatabase | ||
|
||
config: DatabaseConfig = { | ||
"HOST": os.environ["ALERTS_DB_HOST"], | ||
"USER": os.environ["ALERTS_DB_USER"], | ||
"PASSWORD": os.environ["ALERTS_DB_PASSWORD"], | ||
"PORT": os.getenv("ALERTS_DB_PORT", "5432"), | ||
"DB_NAME": os.environ["ALERTS_DB_NAME"], | ||
} | ||
|
||
|
||
def run(p: float = 0.0025, seed: int = 42, radius: float = 1): | ||
alerts_db = PsqlDatabase(config) | ||
rows: list[tuple[Any, ...]] | ||
with alerts_db.conn() as conn: | ||
with conn.cursor() as cursor: | ||
query = SQL(""" | ||
SELECT | ||
p.oid, | ||
meanra, | ||
meandec | ||
FROM | ||
probability p | ||
TABLESAMPLE SYSTEM (%s) REPEATABLE (%s) | ||
JOIN | ||
object o | ||
ON | ||
o.oid = p.oid | ||
WHERE | ||
classifier_name = 'lc_classifier' | ||
AND class_name = 'AGN' | ||
AND ranking = 1 | ||
""") | ||
cursor.execute(query, (p * 100.0, seed)) | ||
rows = cursor.fetchall() | ||
with open("./sample.csv", "w+") as file: | ||
file.write("name,ra,dec,radius\n") | ||
file.writelines( | ||
map( | ||
lambda row: f"{row[0]},{row[1]:.5f},{row[2]:.4f},{radius}\n", | ||
rows, | ||
) | ||
) |
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
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
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
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
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
Oops, something went wrong.