Skip to content
Open
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
Binary file added elevator_system.db
Binary file not shown.
25 changes: 25 additions & 0 deletions init_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
import sqlite3

if os.path.exists("elevator_system.db"):
os.remove("elevator_system.db")
print("Previous database deleted.")

conn = sqlite3.connect("elevator_system.db")
cursor = conn.cursor()

with open("src/schema.sql", "r") as f:
schema = f.read()

cursor.executescript(schema)
conn.commit()

cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cursor.fetchall()
print("Created tables:")
for table in tables:
print(f"- {table[0]}")

conn.close()

print("Database initialized successfully.")
58 changes: 58 additions & 0 deletions readme copy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Dev Test

## Elevators
When an elevator is empty and not moving this is known as it's resting floor.
The ideal resting floor to be positioned on depends on the likely next floor that the elevator will be called from.

We can build a prediction engine to predict the likely next floor based on historical demand, if we have the data.

The goal of this project is to model an elevator and save the data that could later be used to build a prediction engine for which floor is the best resting floor at any time
- When people call an elevator this is considered a demand
- When the elevator is vacant and not moving between floors, the current floor is considered its resting floor
- When the elevator is vacant, it can stay at the current position or move to a different floor
- The prediction model will determine what is the best floor to rest on


_The requirement isn't to complete this system but to start building a system that would feed into the training and prediction
of an ML system_

You will need to talk through your approach, how you modelled the data and why you thought that data was important, provide endpoints to collect the data and
a means to store the data. Testing is important and will be used verify your system

## A note on AI generated code
This project isn't about writing code, AI can and will do that for you.
The next step in this process is to talk through your solution and the decisions you made to come to them. It makes for an awkward and rather boring interview reviewing chatgpt's solution.

If you use a tool to help you write code, that's fine, but we want to see _your_ thought process.

Provided under the chatgpt folder is the response you get back from chat4o.
If your intention isn't to complete the project but to get an AI to spec it for you please, feel free to submit this instead of wasting OpenAI's server resources.


## Problem statement recap
This is a domain modeling problem to build a fit for purpose data storage with a focus on ai data ingestion
- Model the problem into a storage schema (SQL DB schema or whatever you prefer)
- CRUD some data
- Add some flair with a business rule or two
- Have the data in a suitable format to feed to a prediction training algorithm

---

#### To start
- Fork this repo and begin from there
- For your submission, PR into the main repo. We will review it, a offer any feedback and give you a pass / fail if it passes PR
- Don't spend more than 4 hours on this. Projects that pass PR are paid at the standard hourly rate

#### Marking
- You will be marked on how well your tests cover the code and how useful they would be in a prod system
- You will need to provide storage of some sort. This could be as simple as a sqlite or as complicated as a docker container with a migrations file
- Solutions will be marked against the position you are applying for, a Snr Dev will be expected to have a nearly complete solution and to have thought out the domain and built a schema to fit any issues that could arise
A Jr. dev will be expected to provide a basic design and understand how ML systems like to ingest data


#### Trip-ups from the past
Below is a list of some things from previous submissions that haven't worked out
- Built a prediction engine
- Built a full website with bells and whistles
- Spent more than the time allowed (you won't get bonus points for creating an intricate solution, we want a fit for purpose solution)
- Overcomplicated the system mentally and failed to start
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Flask==2.0.1
Werkzeug==2.0.1
Flask-SQLAlchemy==2.5.1
SQLAlchemy==1.4.23
pytest==7.3.1
pytest-flask==1.2.0
python-dotenv==1.0.0
42 changes: 42 additions & 0 deletions src/db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
from contextlib import contextmanager
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.ext.declarative import declarative_base

# DB setup - using SQLite by default, but can override with env var
db_url = os.environ.get('DATABASE_URL', 'sqlite:///elevator_system.db')

# Set up SQLAlchemy stuff
engine = create_engine(db_url, echo=False) # Set echo=True for debugging SQL
factory = sessionmaker(bind=engine)
Session = scoped_session(factory)

# This is used as the base class for all our models
Base = declarative_base()

# Create all the tables
def init_db():
# Import models here to avoid circular imports
from src.models import Building, Elevator, ElevatorCall, ElevatorTrip, ElevatorState, TimeStatistic, FloorStatistic
Base.metadata.create_all(engine)
print("DB initialized!")

# Helper for managing DB sessions
@contextmanager
def get_db_session():
# Get a session, use it, then clean up properly
s = Session()
try:
# Let the caller use the session
yield s
# Auto-commit if no exceptions
s.commit()
except Exception as e:
# Something went wrong, rollback
print(f"DB Error: {e}")
s.rollback()
raise
finally:
# Always close the session
s.close()
Loading
Loading