Skip to content
Snippets Groups Projects
Commit 31bfceae authored by Antoine Gaudron-Desjardins's avatar Antoine Gaudron-Desjardins
Browse files

fix css and other problems

parent e1e37a26
Branches
No related tags found
1 merge request!32fix css and other problems
Pipeline #43993 passed with warnings
......@@ -15,9 +15,11 @@ def get_waiting_time(place: str, db: Session):
""" Get the last estimated waiting time for the given place """
current_date = datetime.now(tz=pytz.timezone("Europe/Paris"))
weekday, current_time = current_date.weekday(), current_date.time()
data = {"status": False, "waiting_time": None, "next_timetable": None }
first_timeslot = get_timeslot(place, weekday, True, db)
if first_timeslot and current_time < first_timeslot[0]:
return first_timeslot[0].hour, first_timeslot[0].minute
data["next_timetable"] = f"{first_timeslot[0].hour}h{first_timeslot[0].minute}"
return data
elif first_timeslot and current_time <= first_timeslot[1]:
waiting_time = db.query(
models.Records.waiting_time
......@@ -26,11 +28,15 @@ def get_waiting_time(place: str, db: Session):
).order_by(
models.Records.date.desc()
).first()
waiting_time_minutes = round(waiting_time[0].total_seconds() / 60)
return waiting_time_minutes, None
if waiting_time:
waiting_time = round(waiting_time.total_seconds() / 60)
data["status"] = True
data["waiting_time"] = waiting_time
return data
second_timeslot = get_timeslot(place, weekday, False, db)
if second_timeslot and current_time < second_timeslot[0]:
return second_timeslot[0].hour, second_timeslot[0].minute
data["next_timetable"] = f"{second_timeslot[0].hour}h{second_timeslot[0].minute}"
return data
elif second_timeslot and current_time <= second_timeslot[1]:
waiting_time = db.query(
models.Records.waiting_time
......@@ -39,9 +45,12 @@ def get_waiting_time(place: str, db: Session):
).order_by(
models.Records.date.desc()
).first()
waiting_time_minutes = round(waiting_time[0].total_seconds() / 60)
return waiting_time_minutes, None
return None, None
if waiting_time:
waiting_time = round(waiting_time.total_seconds() / 60)
data["status"] = True
data["waiting_time"] = waiting_time
return data
return data
def get_avg_graph_points(place: str, weekday: int, min_time: time, max_time: time, interval: timedelta, db: Session):
......@@ -152,15 +161,15 @@ def get_current_graph(place: str, db: Session):
weekday, day, current_time = current_date.weekday(), current_date.date(), current_date.time()
first_timeslot = get_timeslot(place, weekday, True, db)
if first_timeslot and current_time <= first_timeslot[0]:
return None
return []
elif first_timeslot and current_time <= first_timeslot[1]:
return get_current_graph_points(place, day, first_timeslot[0], current_time, timedelta(minutes=5), db)
second_timeslot = get_timeslot(place, weekday, False, db)
if second_timeslot and current_time <= second_timeslot[0]:
return None
return []
elif second_timeslot and current_time <= second_timeslot[1]:
return get_current_graph_points(place, day, second_timeslot[0], current_time, timedelta(minutes=5), db)
return None
return []
# Define CRUD operation for the comments
......@@ -234,10 +243,7 @@ def delete_news(id: int, db: Session):
def get_opening_hours(place: str, db: Session):
""" Get the opening hours for the given place """
opening_hours = db.query(
models.OpeningHours.day,
models.OpeningHours.timeslot,
models.OpeningHours.open_time,
models.OpeningHours.close_time,
models.OpeningHours
).filter(
models.OpeningHours.place == place
).order_by(
......@@ -318,8 +324,10 @@ def get_restaurants(db: Session):
).order_by(
models.Records.date.desc()
).first()
waiting_time_minutes = round(waiting_time[0].total_seconds() / 60)
restaurant["waiting_time"] = waiting_time_minutes
if waiting_time:
restaurant["waiting_time"] = round(waiting_time.total_seconds() / 60)
else:
restaurant["waiting_time"] = None
else:
restaurant["waiting_time"] = None
......
......@@ -9,7 +9,7 @@ from db.database import get_db
router = APIRouter(prefix="/api", tags=["stats"])
@router.get('/{place}/waiting_time', response_model=tuple)
@router.get('/{place}/waiting_time', response_model=dict)
async def waiting_time(place: str, db: Session = Depends(get_db)):
return crud.get_waiting_time(place, db)
......
......@@ -11,8 +11,21 @@ import {
} from "recharts";
import "../styles/Graph.css";
const CustomTooltip = ({ active, payload }) => {
return (
<>
{active && payload && payload.length && (
<div className="custom-tooltip">
<p className="label">{`Temps d'attente : ${payload[0].value} minutes`}</p>
</div>
)}
</>
);
};
export default function Graph({ place, type }) {
const [data, setData] = React.useState(null);
const [data, setData] = React.useState([]);
React.useEffect(() => {
axios
.get(
......@@ -24,20 +37,10 @@ export default function Graph({ place, type }) {
setData(response.data);
});
}, []);
if (!data) return null;
const CustomTooltip = ({ active, payload }) => {
if (active && payload && payload.length) {
return (
<div className="custom-tooltip">
<p className="label">{`Temps d'attente : ${payload[0].value} minutes`}</p>
</div>
);
}
return null;
};
return (
<>
{!!data.length && (
<div style={{ height: "60%", padding: "3rem" }}>
<div className="graph">
<ResponsiveContainer width="100%" height="100%">
......@@ -90,5 +93,7 @@ export default function Graph({ place, type }) {
</div>
<div className="graph-title">Temps d&apos;attente estimé depuis l&apos;ouverture</div>
</div>
)}
</>
);
}
......@@ -17,7 +17,9 @@ export default function Header({ selection, setSelection }) {
<Link id="header-home-link" to="/" onClick={() => setSelection(null)}>
<h2>{width || !selection ? "Eatfast" : selection.name}</h2>
</Link>
<div id="header-timetable">{selection && `horaires : ${selection.timetable}`}</div>
<div id="header-timetable">
{selection && (width ? `Horaires : ${selection.timetable}` : selection.timetable)}
</div>
</div>
);
}
......@@ -4,33 +4,35 @@ import axios from "axios";
import "../styles/WaitingTime.css";
export default function WaitingTime({ place }) {
const [post, setPost] = useState([null, null]);
const [data, setData] = useState({ status: true, waiting_time: null, next_timetable: null });
React.useEffect(() => {
axios
.get(`${process.env.REACT_APP_BASE_URL_BACK}/${encodeURIComponent(place)}/waiting_time`)
.then((res) => {
setPost(res.data);
setData(res.data);
});
}, []);
return (
<div id="waiting-time-parent">
{post[1] ? (
{data.status ? (
data.waiting_time ? (
<div id="waiting-time-display">
Le RU ouvre aujourd&apos;hui à :
Le temps d&apos;attente est estimé à
<div className="waiting-time-minutes">
<b id="waiting-time-number">
{String(post[0]).padStart(2, "0")}h{String(post[1]).padStart(2, "0")}
</b>
<b id="waiting-time-number">{data.waiting_time}</b> minutes
</div>
</div>
) : post[0] ? (
) : (
<div className="waiting-time-minutes">Pas de données</div>
)
) : data.next_timetable ? (
<div id="waiting-time-display">
Le temps d&apos;attente est estimé à :
<div className="waiting-time-minutes">
<b id="waiting-time-number">{post[0]}</b> minutes
</div>
Le RU ouvre aujourd&apos;hui à
<span className="waiting-time-minutes">
<b id="waiting-time-number">{data.next_timetable}</b>
</span>
</div>
) : (
<div className="waiting-time-minutes">Le RU est fermé pour aujourd&apos;hui.</div>
......
......@@ -10,6 +10,8 @@
#home-selection-title {
margin-bottom: 0;
padding-bottom: 2%;
padding-left: 5%;
padding-right: 5%;
}
#home-table {
......
......@@ -8,14 +8,15 @@
#waiting-time-display {
font-size: 1.4rem;
padding-left: 3rem;
padding-right: 3rem;
}
.waiting-time-minutes {
font-size: 1.8rem;
display: inline;
vertical-align: baseline;
padding-left: 3rem;
padding-right: 3rem;
margin-left: 0.5rem;
}
#waiting-time-number {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment