-
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.
🧪🤼♂️ ↝ Adding post method to get TIC data, sending it to Deepnote/ju…
…pyter for matplotlib manipulations https://www.notion.so/skinetics/January-Week-3-8dcc344a601842959a025940a90c1cc4#6b761b8a793041e1972ad2ecba5b93f0 NFT integration: #18 #6 #1 Signal-K/Silfur#28 -> contract calls Frontend API interaction: #16 Signal-K/Silfur#29 -> handled with Supabase in Gizmotronn/comments@9e70ab0 Signal-K/Silfur#26 Signal-K/Silfur#25 -> starting to implement proposals board in Next with Supabase, then will build in contract calls for web3/eth interaction Signal-K/Silfur#24 Signal-K/Silfur#22 -> minting will now be handled by a minimal UI & the API wrapper in Server/thirdweb_handler & moralis_handler Signal-K/Silfur#21 -> custom post types and fields are in Signal-K/client@4cff28c & Signal-K/client@5ce80a5 & Signal-K/client@c950d66, so we're starting off with building it on postgres before adding Lens interactions Signal-K/Silfur#3
- Loading branch information
1 parent
230fce4
commit 2039fd2
Showing
10 changed files
with
1,103 additions
and
12 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
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
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,79 @@ | ||
from flask import Blueprint, request | ||
from thirdweb import ThirdwebSDK | ||
import matplotlib.pyplot as plt | ||
import lightkurve as lk | ||
from io import BytesIO | ||
import base64 | ||
import os | ||
from dotenv import load_dotenv | ||
import psycopg2 | ||
from storage3 import create_client | ||
|
||
tic_classify = Blueprint('tic_classify', __name__) | ||
|
||
# Global variables (anomaly base stats) | ||
tic = '' | ||
|
||
# Database setup | ||
load_dotenv() | ||
url = os.getenv("DATABASE_URL") | ||
storage_url = os.getenv("STORAGE_URL") | ||
key = os.getenv("ANON_KEY") | ||
headers = {"apiKey": key, 'Authorization': f"Bearer {key}"} | ||
storage_client = create_client(storage_url, headers, is_async=False) | ||
connection = psycopg2.connect(url) | ||
# PostgreSQL queries -> see more at database/connection.py | ||
CREATE_PLANETS_TABLE = ( | ||
"""CREATE TABLE IF NOT EXISTS planets (id SERIAL PRIMARY KEY, user_id INTEGER, temperature REAL, date TIMESTAMP, FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE);""" | ||
) | ||
INSERT_PLANET = ( | ||
'INSERT INTO planets (user_id, temperature, date) VALUES (%s, %s, %s);' | ||
) | ||
"""CREATE_TIC_TABLE = ( # Link this with the main planets table -> create a new table with a foreign key ref | ||
#CREATE TABLE IF NOT EXISTS tic (tic_id SERIAL PRIMARY KEY, tic TEXT, planet_id INTEGER, FOREIGN KEY(planet_id) REFERENCES planets(id) ON DELETE CASCADE); | ||
#)""" | ||
CREATE_TIC_TABLE = ( | ||
'CREATE TABLE IF NOT EXISTS tic (id SERIAL PRIMARY KEY, tic_id TEXT);' | ||
) | ||
INSERT_TIC = ( | ||
'INSERT INTO tic (tic_id) VALUES (%s);' | ||
) | ||
|
||
@tic_classify.route('/ticId', methods=['GET', "POST"]) | ||
def ticId(): | ||
TIC = 'TIC 284475976' | ||
sector_data = lk.search_lightcurve(TIC, author = 'SPOC', sector = 23) | ||
|
||
buf = BytesIO() | ||
sector_data.savefig(buf, format='png') | ||
data = base64.b64encode(buf.getbuffer()).decode("ascii") # embed result in html output | ||
return f"<img src='data:image/png;base64,{data}'/>" | ||
|
||
@tic_classify.route('/search', methods=['GET', 'POST']) | ||
def search(): | ||
data = request.get_json() | ||
tic = data['ticid'] | ||
|
||
sector_data = lk.search_lightcurve(tic, author = 'SPOC', sector = 18) | ||
# post tic & other request data to https://deepnote.com/workspace/star-sailors-49d2efda-376f-4329-9618-7f871ba16007/project/lightkurvehandler-dca7e16c-429d-42f1-904d-43898efb2321/ | ||
|
||
# Connect to the database | ||
with connection: | ||
with connection.cursor() as cursor: | ||
cursor.execute(CREATE_PLANETS_TABLE) | ||
cursor.execute(CREATE_TIC_TABLE) | ||
cursor.execute(INSERT_TIC, (tic,)) | ||
#tic_id = cursor.fetchone()[0] | ||
# Get the id of inserted row returned, send to Supabase | ||
|
||
|
||
sector_data = lk.search_lightcurve(tic, author = 'SPOC', sector = 18) | ||
#available_data_all = lk.search_lightcurve(tic, author = 'SPOC') | ||
#select_sectors = available_data_all[0:4] | ||
#lc_collection = select_sectors.download_all() | ||
|
||
lc = lk.search_lightcurve(tic, author='SPOC', sector=18).download() | ||
#lc = lc.remove_nans().remove_outliers() | ||
#lc.to_fits(path='lightcurve.fits') | ||
|
||
return(storage_client.list_buckets()) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
Make sure to initialise the Flask app with `pipenv` and run the command `export FLASK_APP=app.py` | ||
|
||
We'll have a simple wrapper on Deepnote that will communicate with the multi-layered (aka file) Flask app here, until Deepnote supports multiple files in a Flask container | ||
We'll have a simple wrapper on Deepnote that will communicate with the multi-layered (aka file) Flask app here, until Deepnote supports multiple files in a Flask container | ||
|
||
[Public Deepnote collection](https://deepnote.com/workspace/star-sailors-49d2efda-376f-4329-9618-7f871ba16007/projects/Star-Sailors-Interactions-58526396-6398-4022-8c99-f2bc8aa41e97) |