Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
elanaku committed Oct 11, 2024
1 parent 36bcefd commit e5a192f
Showing 1 changed file with 66 additions and 31 deletions.
97 changes: 66 additions & 31 deletions python/lsst/summit/utils/kafka_attempt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,72 @@


def create_kafka_postISRmedian_topics():
'''This function creates the kafka topics for postISR pixel counts.
Note: I do not understand if you're supposed to only do this once
"""This function creates the kafka topics for postISR pixel counts.
Note: I do not understand if you're supposed to only do this once
or do it every time a new cluster is made, or something else.
Thus I don't really know how this function should be written or if it
should be a function at all.'''

### Note: I'm not sure if you want this on usdf or the summit or the option of doing both
sasquatch_rest_proxy_urls = ["https://summit-lsp.lsst.codes/sasquatch-rest-proxy", "https://usdf-rsp-dev.slac.stanford.edu/sasquatch-rest-proxy"]
Thus I don't really know how this function should be written or if it
should be a function at all."""

# Note: I'm not sure if you want this on usdf or the summit
# or the option of doing both
sasquatch_rest_proxy_urls = [
"https://summit-lsp.lsst.codes/sasquatch-rest-proxy",
"https://usdf-rsp-dev.slac.stanford.edu/sasquatch-rest-proxy",
]

headers = {"content-type": "application/json"}

# make a list of the topics you want to create
### I have no idea what reasonable partition counts or replication factors are, so I just copied from the tutorial
### Not sure of the correct topic name eiter
all_topic_configs = [{
# I have no idea what reasonable partition counts or replication
# factors are, so I just copied from the tutorial
# Not sure of the correct topic name either
all_topic_configs = [
{
"topic_name": "lsst.dm.latiss.postIsrPixelMedian",
"partitions_count": 1,
"replication_factor": 3
"replication_factor": 3,
},
{
{
"topic_name": "lsst.dm.comcam.postIsrPixelMedian",
"partitions_count": 1,
"replication_factor": 3
"replication_factor": 3,
},
]

for sasquatch_url in sasquatch_rest_proxy_urls:

# get cluster id
# get cluster id
r = requests.get(f"{sasquatch_url}/v3/clusters", headers=headers)

cluster_id = r.json()['data'][0]['cluster_id']
cluster_id = r.json()["data"][0]["cluster_id"]

headers = {"content-type": "application/json"}

# create your kafka topics
for topic_config in all_topic_configs:
response = requests.post(f"{sasquatch_url}/v3/clusters/{cluster_id}/topics", json=topic_config, headers=headers)
response = requests.post(
f"{sasquatch_url}/v3/clusters/{cluster_id}/topics",
json=topic_config,
headers=headers,
)

print(response.text) # yes I know this is terrible and I should use a logger

print(response.text) # yes I know this is terrible and I should use a logger


def post_to_sasquatch_latiss_isr(timestamp, obsid, postIsrPixelMedian):
"""I think this function posts to sasquatch"""

def post_to_sasquatch_latiss_isr(timestamp, obsid, postIsrPixelMedian):
'''I think this function posts to sasquatch'''

# not sure again if this will be summit or usdf
url = "https://usdf-rsp-dev.slac.stanford.edu/sasquatch-rest-proxy/topics/lsst.dm.latiss.postIsrPixelMedian"
url = (
"https://usdf-rsp-dev.slac.stanford.edu/sasquatch-rest-proxy/topics/lsst.dm.latiss.postIsrPixelMedian"
)

payload = {
"value_schema": '{"namespace": "lsst.dm.latiss", "type": "record", "name": "postIsrPixelMedian", "fields": [{"name": "timestamp", "type": "long"}, {"name": "obsid", "type": "integer"}, {"name": "instrument", "type": "string", "default": "LATISS"}, {"name": "postIsrPixelMedian","type": "float"}]}',
"value_schema": '{"namespace": "lsst.dm.latiss", "type": "record", \
"name": "postIsrPixelMedian", "fields": \
[{"name": "timestamp", "type": "long"}, \
{"name": "obsid", "type": "integer"}, \
{"name": "instrument", "type": "string", "default": "LATISS"}, \
{"name": "postIsrPixelMedian","type": "float"}]}',
"records": [
{
"value": {
Expand All @@ -69,15 +85,33 @@ def post_to_sasquatch_latiss_isr(timestamp, obsid, postIsrPixelMedian):
}

response = requests.request("POST", url, json=payload, headers=headers)
print(response.text)


def post_to_sasquatch_comcam_isr(
timestamp,
obsid,
postIsrPixelMedian,
postIsrPixelMedianMedian,
postIsrPixelMedianMean,
postIsrPixelMedianMax,
):
"""I think this function posts to sasquatch"""

def post_to_sasquatch_comcam_isr(timestamp, obsid, postIsrPixelMedian, postIsrPixelMedianMedian, postIsrPixelMedianMean, postIsrPixelMedianMax):
'''I think this function posts to sasquatch'''

# not sure again if this will be summit or usdf
url = "https://usdf-rsp-dev.slac.stanford.edu/sasquatch-rest-proxy/topics/lsst.dm.latiss.postIsrPixelMedian"
url = (
"https://usdf-rsp-dev.slac.stanford.edu/sasquatch-rest-proxy/topics/lsst.dm.latiss.postIsrPixelMedian"
)

payload = {
"value_schema": '{"namespace": "lsst.dm.comcam", "type": "record", "name": "postIsrPixelMedian", "fields": [{"name": "timestamp", "type": "long"}, {"name": "obsid", "type": "integer"}, {"name": "instrument", "type": "string", "default": "ComCam"}, {"name": "postIsrPixelMedian","type": "float"}, {"name": "postIsrPixelMedianMedian","type": "float"}, {"name": "postIsrPixelMedianMean","type": "float"}, {"name": "postIsrPixelMedianMax","type": "float"}]}',
"value_schema": '{"namespace": "lsst.dm.comcam", "type": "record", \
"name": "postIsrPixelMedian", "fields": [{"name": "timestamp", \
"type": "long"}, {"name": "obsid", "type": "integer"}, \
{"name": "instrument", "type": "string", "default": "ComCam"}, \
{"name": "postIsrPixelMedian","type": "float"},\
{"name": "postIsrPixelMedianMedian","type": "float"}, \
{"name": "postIsrPixelMedianMean","type": "float"}, \
{"name": "postIsrPixelMedianMax","type": "float"}]}',
"records": [
{
"value": {
Expand All @@ -98,3 +132,4 @@ def post_to_sasquatch_comcam_isr(timestamp, obsid, postIsrPixelMedian, postIsrPi
}

response = requests.request("POST", url, json=payload, headers=headers)
print(response.text)

0 comments on commit e5a192f

Please sign in to comment.