Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing #51

Merged
merged 6 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
FROM node:14
# Build stage
FROM node:14 as build

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

ARG NODE_ENV
ENV NODE_ENV=$NODE_ENV

RUN if [ "$NODE_ENV" = "production" ]; then npm run build; fi

# Development or Production stage
FROM node:14

WORKDIR /app

COPY --from=build /app .

EXPOSE 3000

CMD ["npm", "start"]
24 changes: 21 additions & 3 deletions client/src/pages/system/Systems.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import InvertColorsSharpIcon from '@mui/icons-material/InvertColorsSharp';
import TungstenSharpIcon from '@mui/icons-material/TungstenSharp';
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
import List from '@mui/material/List';
import ListItem from '@mui/material/ListItem';
import ListItemText from '@mui/material/ListItemText';
import Divider from '@mui/material/Divider';
import { CardActionArea, CardHeader } from '@mui/material';
import Avatar from '@mui/material/Avatar';
import GrassOutlinedIcon from '@mui/icons-material/GrassOutlined';
Expand All @@ -17,14 +21,14 @@ import CardActions from '@mui/material/CardActions';
import PointOfSaleIcon from '@mui/icons-material/PointOfSale';
import SystemPlants from '../../modals/system/SystemPlants';
import SystemAlerts from '../../modals/system/SystemAlerts';
import { useSystems } from '../../hooks/useSystems';
import { useSystems, useLights } from '../../hooks/useSystems';
import { CARD_STYLE, AVATAR_STYLE, CIRCULAR_PROGRESS_STYLE, ICON_STYLE } from '../../constants';
import { EditSharp } from '@mui/icons-material';
import { useNavigate } from 'react-router-dom';
import DeleteOutlineSharpIcon from '@mui/icons-material/DeleteOutlineSharp';
import { NoData, ServerError, Loading } from '../../elements/Page';

const SystemCard = ({ system, deprecateSystem }) => {
const SystemCard = ({ system, lights, deprecateSystem }) => {
const navigate = useNavigate();
const [isSystemsPlanetsOpen, setIsSystemsPlanetsOpen] = useState(false);
const [isSystemAlertsOpen, setIsSystemsAlertsOpen] = useState(false);
Expand Down Expand Up @@ -71,6 +75,19 @@ const SystemCard = ({ system, deprecateSystem }) => {
/>
<TungstenSharpIcon sx={ICON_STYLE} />
</Box>
<List sx={{ width: '100%', maxWidth: 360, bgcolor: 'background.paper' }}>
<Divider sx={{width: '100%' }} component="li" />
{lights && lights.map((light) => (
<div key={light.id}>
<ListItem
disableGutters
>
<ListItemText primary={light.name} style={{ color: "black" }}/>
</ListItem>
<Divider sx={{width: '100%' }} component="li" />
</div>
))}
</List>
</Box>
</CardContent>
<CardActions disableSpacing>
Expand Down Expand Up @@ -109,6 +126,7 @@ const SystemCard = ({ system, deprecateSystem }) => {

const Systems = () => {
const { systems, isLoading, error, deprecateSystem } = useSystems();
const {lights } = useLights();

if (isLoading) return <Loading/>;
if (error) return <ServerError/>;
Expand All @@ -118,7 +136,7 @@ const Systems = () => {
<Grid container justifyContent="center" spacing={4}>
{systems.map((system) => (
<Grid key={system.id} item>
<SystemCard system={system} deprecateSystem={deprecateSystem}/>
<SystemCard system={system} lights = {lights.filter(light => light.system_id === system.id)} deprecateSystem={deprecateSystem}/>
</Grid>
))}
</Grid>
Expand Down
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
- "8002:5000"
environment:
- MONGODB_URL=mongodb://mongo1:27017
- MONGODB_URL_HIST=mongodb://mongo1:27018
- MONGODB_URL_HIST=mongodb://mongo2:27018
- USE_LOCAL_HARDWARE=true
- ENVIRONMENT=docker
volumes:
Expand All @@ -27,10 +27,10 @@ services:
context: ./server
dockerfile: adaptor/Dockerfile
ports:
- "8003:5000"
- "8003:5001"
environment:
- ENVIRONMENT=docker
- MONGODB_URL=mongodb://mongo2:27017/plnts
- MONGODB_URL=mongodb://mongo1:27017/plnts
volumes:
- ./server/shared:/app/shared
- ./server/adaptor:/app/adaptor
Expand All @@ -56,7 +56,7 @@ services:
volumes:
- mongo_data_2:/data/db
ports:
- "27018:27017"
- "27018:27018"
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 5s
Expand All @@ -69,8 +69,8 @@ services:
build:
context: ./client
dockerfile: Dockerfile
args:
- NODE_ENV=${NODE_ENV:-development}
args:
NODE_ENV: ${NODE_ENV:-development}
ports:
- "3000:3000"
environment:
Expand Down
4 changes: 2 additions & 2 deletions model/identify_plants_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tflite_model_maker.image_classifier import DataLoader

# Load input data specific to an on-device ML app.
data = DataLoader.from_folder('data/test')
data = DataLoader.from_folder("data/test")
train_data, test_data = data.split(0.9)

# Customize the TensorFlow model.
Expand All @@ -13,4 +13,4 @@
loss, accuracy = model.evaluate(test_data)

# Export to Tensorflow Lite model and label file in `export_dir`.
model.export(export_dir='/tmp/')
model.export(export_dir="/tmp/")
2 changes: 1 addition & 1 deletion server/adaptor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ COPY adaptor ./adaptor

ENV PYTHONPATH="/app:${PYTHONPATH}"

CMD ["gunicorn", "--bind", "0.0.0.0:5000", "adaptor.adaptor:app"]
CMD ["gunicorn", "--bind", "0.0.0.0:5001", "adaptor.adaptor:app"]
23 changes: 10 additions & 13 deletions server/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
FROM python:3.9
WORKDIR /app

# Install MongoDB client tools
RUN apt-get update && apt-get install -y gnupg curl
RUN curl -fsSL https://pgp.mongodb.com/server-6.0.asc | \
gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg \
--dearmor
RUN echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg] http://repo.mongodb.org/apt/debian bullseye/mongodb-org/6.0 main" | \
tee /etc/apt/sources.list.d/mongodb-org-6.0.list
RUN apt-get update && apt-get install -y mongodb-mongosh

WORKDIR /app
COPY ../requirements.txt .
RUN pip install -r requirements.txt

# Remove PostgreSQL client and install MongoDB tools instead
RUN apt-get update && apt-get install -y \
wget gnupg \
&& wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | apt-key add - \
&& echo "deb http://repo.mongodb.org/apt/debian bullseye/mongodb-org/7.0 main" | tee /etc/apt/sources.list.d/mongodb-org-7.0.list \
&& apt-get update \
&& apt-get install -y mongodb-mongosh mongodb-database-tools \
&& rm -rf /var/lib/apt/lists/*

COPY . .
COPY ../shared .
RUN chmod -R 755 /app

COPY app/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

EXPOSE 5000
ENTRYPOINT ["/entrypoint.sh"]
36 changes: 28 additions & 8 deletions server/app/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,42 @@ echo "Debugging information:"
cd ../
cd app/

# Wait for the database to be ready
until PGPASSWORD=$POSTGRES_PASSWORD psql -h "db" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c '\q'; do
>&2 echo "Postgres is unavailable - sleeping"
# Print working directory and structure
echo "==== CURRENT DIRECTORY ===="
pwd
# echo "\n==== DIRECTORY STRUCTURE FROM ROOT ===="
# ls -R /
echo "\n==== DIRECTORY STRUCTURE FROM /server ===="
ls -R /server
echo "\n==== DIRECTORY STRUCTURE FROM /app ===="
ls -R /app
echo "\n==== PYTHON PATH ===="
echo $PYTHONPATH
echo "\n==== ENVIRONMENT VARIABLES ===="
env

# Wait for MongoDB connections
echo "\n==== CHECKING MONGODB CONNECTIONS ===="
until mongosh --host mongo1 --port 27017 --eval "db.adminCommand('ping')" > /dev/null 2>&1; do
>&2 echo "Main MongoDB (mongo1:27017) is unavailable - sleeping"
sleep 1
done

until mongosh --host mongo2 --port 27017 --eval "db.adminCommand('ping')" > /dev/null 2>&1; do
>&2 echo "Historical MongoDB (mongo2:27017) is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - executing command"

# Check if the install flag exists
if [ ! -f ".installed" ]; then
echo "Running install script..."
echo "\n==== RUNNING INSTALL SCRIPT ===="
python install.py
touch .installed
else
echo "Install script already run, skipping..."
echo "\n==== INSTALL SCRIPT ALREADY RUN ===="
fi

echo "\n==== STARTING FLASK APP ===="
# Start the Flask application
echo "Starting Flask app..."
exec gunicorn -b 0.0.0.0:5000 app.app:app
cd app/ # This is here because I had a hilariously bad time starting app
exec gunicorn -b 0.0.0.0:5000 app:app
27 changes: 27 additions & 0 deletions server/app/routes/system_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,33 @@ def get_systems_alerts(id):
return jsonify([Schema.ALERT.read(alert) for alert in alerts])


@APIBuilder.register_custom_route(
system_bp, "/systems/<string:id>/lights/", methods=["GET"]
)
def get_systems_lights(id):
"""
Get system's lights.
"""
logger.info("Received request to get a system's alerts")

lights = Table.LIGHT.get_many({"system_id": ObjectId(id)})

return jsonify([Schema.LIGHT.read(light) for light in lights])


# @APIBuilder.register_custom_route(
# system_bp, "/systems/<string:id>/lights/<string:light_id>/", methods=["POST"]
# )
# def resync_light(id, light_id):
# """
# Get system's lights.
# """
# logger.info("Received request to get a system's alerts")

# light = Table.LIGHT.get_one(light_id)

# return jsonify([Schema.LIGHT.read(light) for light in lights])

# @APIBuilder.register_custom_route(system_bp, "/systems/<int:system_id>/video_feed/", ["GET"])
# def get_video_feed(system_id):
# session = Session()
Expand Down
2 changes: 1 addition & 1 deletion server/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self, **kwargs):
self.banished_on = kwargs.get("banished_on")
self.banished_cause = kwargs.get("banished_cause")

def banish(self, cause: Optional[str]=None):
def banish(self, cause: Optional[str] = None):
self.banished = True
self.banished_on = datetime.now()
self.banished_cause = cause
Loading