Compare commits
2 Commits
c29f85752b
...
c1013ca691
| Author | SHA1 | Date | |
|---|---|---|---|
| c1013ca691 | |||
|
|
3d07c59287 |
43
app.py
43
app.py
@@ -38,6 +38,7 @@ class Event(db.Model):
|
|||||||
|
|
||||||
class Room(db.Model):
|
class Room(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
type = db.Column(db.String)
|
||||||
room = db.Column(db.String(64), unique=True)
|
room = db.Column(db.String(64), unique=True)
|
||||||
count = db.Column(db.Integer, default=0)
|
count = db.Column(db.Integer, default=0)
|
||||||
max = db.Column(db.Integer, default=2)
|
max = db.Column(db.Integer, default=2)
|
||||||
@@ -142,6 +143,9 @@ def scan():
|
|||||||
student = Student.query.filter_by(uid=data["uid"]).first()
|
student = Student.query.filter_by(uid=data["uid"]).first()
|
||||||
location = data["location_id"]
|
location = data["location_id"]
|
||||||
room = Room.query.filter_by(room=location).first()
|
room = Room.query.filter_by(room=location).first()
|
||||||
|
if not room:
|
||||||
|
room = Room(room=location)
|
||||||
|
db.session.add(room)
|
||||||
student.last_reader = location
|
student.last_reader = location
|
||||||
student.last_scan = now()
|
student.last_scan = now()
|
||||||
if action == "":
|
if action == "":
|
||||||
@@ -176,12 +180,16 @@ def scan():
|
|||||||
def lightsBathroom(id):
|
def lightsBathroom(id):
|
||||||
|
|
||||||
room = Room.query.filter_by(room=id).first()
|
room = Room.query.filter_by(room=id).first()
|
||||||
bathroom = Room.query.filter_by(room=room.bathroom_id).first()
|
|
||||||
if not room:
|
if not room:
|
||||||
room = Room(room=id)
|
room = Room(room=id)
|
||||||
db.session.add(room)
|
db.session.add(room)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
if (room.bathroom and bathroom.count < bathroom.max):
|
bathroom = Room.query.filter_by(room=room.bathroom_id).first()
|
||||||
|
if not bathroom:
|
||||||
|
bathroomCount = True
|
||||||
|
else:
|
||||||
|
bathroomCount = bathroom.count < bathroom.max
|
||||||
|
if (room.bathroom and bathroomCount):
|
||||||
code = 202
|
code = 202
|
||||||
else:
|
else:
|
||||||
code = 200
|
code = 200
|
||||||
@@ -222,11 +230,33 @@ def admin_rooms():
|
|||||||
|
|
||||||
rooms = Room.query.all()
|
rooms = Room.query.all()
|
||||||
|
|
||||||
|
bathrooms = Room.query.filter_by(
|
||||||
|
type="bathroom"
|
||||||
|
).all()
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"admin/rooms.html",
|
"admin/rooms.html",
|
||||||
rooms=rooms
|
rooms=rooms,
|
||||||
|
bathrooms=bathrooms
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@app.route(
|
||||||
|
"/admin/room/create",
|
||||||
|
methods=["POST"]
|
||||||
|
)
|
||||||
|
def create_room():
|
||||||
|
|
||||||
|
room = Room(
|
||||||
|
room=request.form["room"],
|
||||||
|
type=request.form["room_type"],
|
||||||
|
max=int(request.form["max"]),
|
||||||
|
count=0
|
||||||
|
)
|
||||||
|
|
||||||
|
db.session.add(room)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return admin_rooms()
|
||||||
|
|
||||||
@app.route("/admin/anomalies")
|
@app.route("/admin/anomalies")
|
||||||
def admin_anomalies():
|
def admin_anomalies():
|
||||||
@@ -294,7 +324,10 @@ def merge_student():
|
|||||||
)
|
)
|
||||||
def update_room(id):
|
def update_room(id):
|
||||||
|
|
||||||
room = Room.query.get(id)
|
room = Room.query.filter_by(id=id).first()
|
||||||
|
room.type = request.form[
|
||||||
|
"room_type"
|
||||||
|
]
|
||||||
|
|
||||||
room.max = int(
|
room.max = int(
|
||||||
request.form["max"]
|
request.form["max"]
|
||||||
@@ -304,7 +337,7 @@ def update_room(id):
|
|||||||
"bathroom_id"
|
"bathroom_id"
|
||||||
]
|
]
|
||||||
|
|
||||||
room.tracks_bathroom = (
|
room.bathroom = (
|
||||||
"tracks_bathroom"
|
"tracks_bathroom"
|
||||||
in request.form
|
in request.form
|
||||||
)
|
)
|
||||||
|
|||||||
60
simulator.py
Normal file
60
simulator.py
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
# simulator.py
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
SERVER = "https://5000--main--orange-crane-13--harry-esses.coder.harryesses.com/scan"
|
||||||
|
|
||||||
|
print("RFID Scan Simulator")
|
||||||
|
print("Type 'exit' to quit")
|
||||||
|
print()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
uid = input("UID: ").strip()
|
||||||
|
|
||||||
|
if uid.lower() == "exit":
|
||||||
|
break
|
||||||
|
|
||||||
|
location = input(
|
||||||
|
"Location ID: "
|
||||||
|
).strip()
|
||||||
|
|
||||||
|
action = input(
|
||||||
|
"Action (blank/bathroom): "
|
||||||
|
).strip()
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"uid": uid,
|
||||||
|
"location_id": location,
|
||||||
|
"action": action
|
||||||
|
}
|
||||||
|
|
||||||
|
print()
|
||||||
|
print("Sending Scan:")
|
||||||
|
print(payload)
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
response = requests.post(
|
||||||
|
SERVER,
|
||||||
|
json=payload,
|
||||||
|
timeout=5
|
||||||
|
)
|
||||||
|
|
||||||
|
print()
|
||||||
|
print(
|
||||||
|
f"Status: {response.status_code}"
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
print(response.json())
|
||||||
|
except:
|
||||||
|
print(response.text)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print()
|
||||||
|
print(f"Error: {e}")
|
||||||
|
|
||||||
|
print()
|
||||||
|
print("-" * 40)
|
||||||
|
print()
|
||||||
@@ -1,19 +1,101 @@
|
|||||||
<div>
|
<div>
|
||||||
|
|
||||||
<div class="flex justify-between items-center mb-4">
|
<!-- HEADER -->
|
||||||
|
|
||||||
<h2 class="text-2xl font-bold">
|
<div class="flex justify-between items-center mb-6">
|
||||||
|
|
||||||
|
<h2 class="text-3xl font-bold">
|
||||||
Rooms
|
Rooms
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- NEW ROOM -->
|
||||||
|
|
||||||
|
<div class="bg-gray-900 p-6 rounded-xl border border-gray-800 mb-6">
|
||||||
|
|
||||||
|
<h3 class="text-xl font-bold mb-4">
|
||||||
|
Add New Room
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<form
|
||||||
|
hx-post="/admin/room/create"
|
||||||
|
hx-target="#content"
|
||||||
|
class="grid grid-cols-4 gap-4"
|
||||||
|
>
|
||||||
|
|
||||||
|
<!-- ROOM NAME -->
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="room"
|
||||||
|
placeholder="Room Name"
|
||||||
|
required
|
||||||
|
class="bg-gray-800 p-2 rounded"
|
||||||
|
>
|
||||||
|
|
||||||
|
<!-- ROOM TYPE -->
|
||||||
|
|
||||||
|
<select
|
||||||
|
name="room_type"
|
||||||
|
class="bg-gray-800 p-2 rounded"
|
||||||
|
>
|
||||||
|
|
||||||
|
<option value="classroom">
|
||||||
|
Classroom
|
||||||
|
</option>
|
||||||
|
|
||||||
|
<option value="bathroom">
|
||||||
|
Bathroom
|
||||||
|
</option>
|
||||||
|
|
||||||
|
<option value="office">
|
||||||
|
Office
|
||||||
|
</option>
|
||||||
|
|
||||||
|
<option value="hallway">
|
||||||
|
Hallway
|
||||||
|
</option>
|
||||||
|
|
||||||
|
<option value="gym">
|
||||||
|
Gym
|
||||||
|
</option>
|
||||||
|
|
||||||
|
<option value="cafeteria">
|
||||||
|
Cafeteria
|
||||||
|
</option>
|
||||||
|
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- MAX -->
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
name="max"
|
||||||
|
value="30"
|
||||||
|
class="bg-gray-800 p-2 rounded"
|
||||||
|
>
|
||||||
|
|
||||||
|
<button
|
||||||
|
class="bg-green-700 hover:bg-green-600 rounded px-4"
|
||||||
|
>
|
||||||
|
Create Room
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- EXISTING ROOMS -->
|
||||||
|
|
||||||
<div class="grid grid-cols-3 gap-4">
|
<div class="grid grid-cols-3 gap-4">
|
||||||
|
|
||||||
{% for r in rooms %}
|
{% for r in rooms %}
|
||||||
|
|
||||||
<div class="bg-gray-900 p-4 rounded-xl border border-gray-800">
|
<div class="bg-gray-900 p-4 rounded-xl border border-gray-800">
|
||||||
|
|
||||||
|
<!-- TITLE -->
|
||||||
|
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
@@ -22,14 +104,13 @@
|
|||||||
{{ r.room }}
|
{{ r.room }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="text-gray-400 text-sm">
|
<div class="text-sm text-gray-400">
|
||||||
Current Occupancy:
|
{{ r.type }}
|
||||||
{{ r.count }}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if r.bathroom %}
|
{% if r.tracks_bathroom %}
|
||||||
<span class="bg-blue-700 px-2 py-1 rounded text-sm">
|
<span class="bg-blue-700 px-2 py-1 rounded text-sm">
|
||||||
Bathroom Tracking
|
Bathroom Tracking
|
||||||
</span>
|
</span>
|
||||||
@@ -37,13 +118,84 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- OCCUPANCY -->
|
||||||
|
|
||||||
|
<div class="mt-4 text-sm space-y-1">
|
||||||
|
|
||||||
|
<div>
|
||||||
|
Occupancy:
|
||||||
|
<b>{{ r.count }}</b>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
Max:
|
||||||
|
<b>{{ r.max }}</b>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- UPDATE FORM -->
|
||||||
|
|
||||||
<form
|
<form
|
||||||
hx-post="/admin/room/update/{{ r.id }}"
|
hx-post="/admin/room/update/{{ r.id }}"
|
||||||
hx-target="#content"
|
hx-target="#content"
|
||||||
class="mt-4 space-y-3"
|
class="mt-4 space-y-3"
|
||||||
>
|
>
|
||||||
|
|
||||||
<!-- MAX OCCUPANCY -->
|
<!-- ROOM TYPE -->
|
||||||
|
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<label class="block text-sm mb-1">
|
||||||
|
Room Type
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<select
|
||||||
|
name="room_type"
|
||||||
|
class="bg-gray-800 p-2 rounded w-full"
|
||||||
|
>
|
||||||
|
|
||||||
|
<option
|
||||||
|
value="classroom"
|
||||||
|
{% if r.type == "classroom" %}
|
||||||
|
selected
|
||||||
|
{% endif %}
|
||||||
|
>
|
||||||
|
Classroom
|
||||||
|
</option>
|
||||||
|
|
||||||
|
<option
|
||||||
|
value="bathroom"
|
||||||
|
{% if r.type == "bathroom" %}
|
||||||
|
selected
|
||||||
|
{% endif %}
|
||||||
|
>
|
||||||
|
Bathroom
|
||||||
|
</option>
|
||||||
|
|
||||||
|
<option
|
||||||
|
value="office"
|
||||||
|
{% if r.type == "office" %}
|
||||||
|
selected
|
||||||
|
{% endif %}
|
||||||
|
>
|
||||||
|
Office
|
||||||
|
</option>
|
||||||
|
|
||||||
|
<option
|
||||||
|
value="hallway"
|
||||||
|
{% if r.type == "hallway" %}
|
||||||
|
selected
|
||||||
|
{% endif %}
|
||||||
|
>
|
||||||
|
Hallway
|
||||||
|
</option>
|
||||||
|
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- MAX -->
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
||||||
@@ -60,31 +212,47 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- BATHROOM GROUP -->
|
<!-- BATHROOM DROPDOWN -->
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
||||||
<label class="block text-sm mb-1">
|
<label class="block text-sm mb-1">
|
||||||
Bathroom Group ID
|
Bathroom Room
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<input
|
<select
|
||||||
type="text"
|
|
||||||
name="bathroom_id"
|
name="bathroom_id"
|
||||||
value="{{ r.bathroom_id }}"
|
|
||||||
placeholder="example: floor2_west"
|
|
||||||
class="bg-gray-800 p-2 rounded w-full"
|
class="bg-gray-800 p-2 rounded w-full"
|
||||||
>
|
>
|
||||||
|
|
||||||
|
<option value="">
|
||||||
|
None
|
||||||
|
</option>
|
||||||
|
|
||||||
|
{% for b in bathrooms %}
|
||||||
|
|
||||||
|
<option
|
||||||
|
value="{{ b.room }}"
|
||||||
|
{% if r.bathroom_id == b.room %}
|
||||||
|
selected
|
||||||
|
{% endif %}
|
||||||
|
>
|
||||||
|
{{ b.room }}
|
||||||
|
</option>
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</select>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- TRACK BATHROOM -->
|
<!-- TRACK -->
|
||||||
|
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
name="bathroom"
|
name="tracks_bathroom"
|
||||||
{% if r.bathroom %}
|
{% if r.bathroom %}
|
||||||
checked
|
checked
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -97,6 +265,8 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- SAVE -->
|
||||||
|
|
||||||
<button
|
<button
|
||||||
class="bg-blue-700 hover:bg-blue-600 px-4 py-2 rounded w-full"
|
class="bg-blue-700 hover:bg-blue-600 px-4 py-2 rounded w-full"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
<div class="mt-4 text-sm space-y-1">
|
<div class="mt-4 text-sm space-y-1">
|
||||||
|
|
||||||
<div>
|
<!-- <div>
|
||||||
Current Room:
|
Current Room:
|
||||||
<b>{{ s.current_room }}</b>
|
<b>{{ s.current_room }}</b>
|
||||||
</div>
|
</div>
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
<div>
|
<div>
|
||||||
Previous Room:
|
Previous Room:
|
||||||
<b>{{ s.previous_room }}</b>
|
<b>{{ s.previous_room }}</b>
|
||||||
</div>
|
</div> -->
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
Expected Return:
|
Expected Return:
|
||||||
|
|||||||
Reference in New Issue
Block a user