Skip to content

Commit

Permalink
🪭🏋🏽 ↝ [CPW-12 GP-18]: Working on packages & putting stuff into the ap…
Browse files Browse the repository at this point in the history
…i repo
  • Loading branch information
Gizmotronn committed May 8, 2024
1 parent b0d0c79 commit d8bfe1b
Show file tree
Hide file tree
Showing 13 changed files with 424 additions and 2 deletions.
Binary file modified .DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions database/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

# Create Supabase client

SUPABASE_URL = ''
SUPABASE_KEY = ''
SUPABASE_URL = 'https://qwbufbmxkjfaikoloudl.supabase.co'
SUPABASE_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InF3YnVmYm14a2pmYWlrb2xvdWRsIiwicm9sZSI6ImFub24iLCJpYXQiOjE2Njk5NDE3NTksImV4cCI6MTk4NTUxNzc1OX0.RNz5bvsVwLvfYpZtUjy0vBPcho53_VS2AIVzT8Fm-lk'
supabase = create_client(SUPABASE_URL, SUPABASE_KEY)

# class InventoryUsers(db.Model):
Expand Down
34 changes: 34 additions & 0 deletions galaxy/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from flask import Flask, jsonify
from supabase_py import create_client

app = Flask(__name__)

# app.config["SQLALCHEMY_DATABASE_URI"] = ""
# db.init_app(app)

# Create Supabase client
SUPABASE_URL = 'https://qwbufbmxkjfaikoloudl.supabase.co'
SUPABASE_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InF3YnVmYm14a2pmYWlrb2xvdWRsIiwicm9sZSI6ImFub24iLCJpYXQiOjE2Njk5NDE3NTksImV4cCI6MTk4NTUxNzc1OX0.RNz5bvsVwLvfYpZtUjy0vBPcho53_VS2AIVzT8Fm-lk'
supabase = create_client(SUPABASE_URL, SUPABASE_KEY)

@app.route('/test')
def test():
return "Test"

# Route to fetch items from inventoryITEMS table
@app.route('/items')
def get_items():
# Query items from inventoryITEMS table
items = supabase.table('inventoryITEMS').select('*').execute()
return jsonify(items['data'])

# Route to fetch user inventory from inventoryUSERS table
@app.route('/inventory/<user_id>')
def get_user_inventory(user_id):
# Query user inventory from inventoryUSERS table
user_inventory = supabase.table('inventoryUSERS').select('*').eq('owner', user_id).execute()
return jsonify(user_inventory['data'])

# Main function to run the Flask app
if __name__ == '__main__':
app.run(debug=True)
10 changes: 10 additions & 0 deletions galaxy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3.8'

services:
web:
build: .
ports:
- "5001:5000"
environment:
- SUPABASE_URL=https://qwbufbmxkjfaikoloudl.supabase.co
- SUPABASE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InF3YnVmYm14a2pmYWlrb2xvdWRsIiwicm9sZSI6ImFub24iLCJpYXQiOjE2Njk5NDE3NTksImV4cCI6MTk4NTUxNzc1OX0.RNz5bvsVwLvfYpZtUjy0vBPcho53_VS2AIVzT8Fm-lk
21 changes: 21 additions & 0 deletions galaxy/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Use an official Python runtime as a parent image
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR /app

# Add the current directory contents into the container at /app
ADD . /app

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

# Make port 5000 available to the world outside this container
EXPOSE 5000

# Define environment variable
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0

# Run app.py when the container launches
CMD ["flask", "run"]
39 changes: 39 additions & 0 deletions galaxy/lightkurve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from flask import Flask, request, jsonify
import lightkurve as lk
import logging
import numpy as np

app = Flask(__name__)

@app.route('/lightcurve/summary', methods=['POST'])
def get_lightcurve_summary():
try:
request_data = request.get_json()
if not request_data or 'tic_id' not in request_data:
return jsonify({'error': 'Missing required field "tic_id"'}), 400

tic_id = request_data['tic_id']
if not tic_id.startswith("TIC "):
return jsonify({'error': 'Invalid TIC ID format'}), 400

lightcurve_data = lk.search_lightcurve(tic_id).download()
if lightcurve_data is None:
return jsonify({'error': 'No light curve found'}), 404

flux_values = lightcurve_data.flux.value
statistics_summary = {
'mean': float(np.mean(flux_values)),
'median': float(np.median(flux_values)),
'standard_deviation': float(np.std(flux_values)),
'peak_to_peak': float(np.ptp(flux_values)),
'interquartile_range': float(np.percentile(flux_values, 75) - np.percentile(flux_values, 25)),
}

return jsonify(statistics_summary)

except Exception as e:
logging.error(f"Error processing request: {str(e)}")
return jsonify({'error': str(e)}), 500

if __name__ == '__main__':
app.run(debug=True)
5 changes: 5 additions & 0 deletions galaxy/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flask
psycopg2-binary
Flask-SQLAlchemy
Flask-CORS
supabase-py
2 changes: 2 additions & 0 deletions packages/classifydata/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
.git
2 changes: 2 additions & 0 deletions packages/classifydata/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
.git
25 changes: 25 additions & 0 deletions packages/classifydata/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "ssailors-data",
"version": "1.0.0",
"description": "Fetch citizen science data for use in your own tools, formulated & populated the Star Sailors way",
"main": "index.js",
"scripts": {
"build": "next build",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/signal-k/sytizen.git"
},
"author": "Signal Kinetics PTY LTD, Copernic Space Inc, Liam Arbuckle, Rhys Campbell, Manu Olariu",
"license": "MIT",
"bugs": {
"url": "https://github.com/signal-k/sytizen/issues"
},
"homepage": "https://github.com/signal-k/sytizen#readme",
"dependencies": {
"@supabase/auth-helpers-react": "^0.5.0",
"axios": "^1.6.8",
"react": "^18.3.1"
}
}
51 changes: 51 additions & 0 deletions packages/classifydata/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { useState, useEffect } from "react";
import axios from "axios";

export const RoverImage = ({ date, rover, onImageMetadataChange }: { date: string; rover: string; onImageMetadataChange: string; }) => {
const [imageUrl, setImageUrl] = useState('');
const apiKey = 'iT0FQTZKpvadCGPzerqXdO5F4b62arNBOP0dtkXE';

const [imageMetadata, setImageMetadata] = useState('');
const [metadata, setMetadata] = useState('');

useEffect(() => {
const apiUrl = `https://api.nasa.gov/mars-photos/api/v1/rovers/${rover}/photos?sol=${date}&api_key=${apiKey}`;

axios.get(apiUrl)
.then((response) => {
if (response.data.photos && response.data.photos.length > 0) {
const firstImageMetadata = response.data.photos[0];
// setImageUrl(firstImageMetadata.img_src || '');
const firstImage = response.data.photos[0].img_src;
setImageUrl(firstImage);
const metadataText = JSON.stringify(firstImageMetadata, null, 2);
setImageMetadata(metadataText);
setMetadata(metadataText)
// onImageMetadataChange(metadataText);
} else {
setImageUrl('No images found for the given date & rover.');
setImageMetadata('No images found for the given date & rover' + JSON.stringify(response));
}
})
.catch((error) => {
setImageUrl('An error occurred while fetching the image');
setImageMetadata('Error fetching image');
console.error(error);
});
}, [date, rover, onImageMetadataChange]);
};

/*
{/* <h2>Your Rover Photo</h2>
<p>Date: {date}</p>
<p>Rover model: {rover}</p>
{imageUrl ? (
<>
<img src={imageUrl} alt="Rover image" />
{/* <RoverContentPostForm metadata={metadata} imageLink={imageUrl} />
{/* <pre>{imageUrl}</pre>
</>
) : (
<p>Loading...</p>
)}
*/
Binary file added packages/classifydata/ssailors-data-v1.0.0.tgz
Binary file not shown.
Loading

0 comments on commit d8bfe1b

Please sign in to comment.