Improving API to collect Elevator Demand and compile it as CSV file#75
Improving API to collect Elevator Demand and compile it as CSV file#75kalmik wants to merge 1 commit intoCitric-Sheep:masterfrom
Conversation
AI Detection Analysis 🔍Confidence Score: 30% Reasoning: The content of this pull request strongly resembles the work of a human developer, particularly one with a solid understanding of database schema design, REST API development with FastAPI, and data engineering for machine learning purposes. Though the structure and organization of code are clean and consistent, several elements, including the informal and sometimes unpolished writing style, contextual understanding of elevator systems, and detailed inline explanations, all suggest a human rather than AI-generated authorship. If this were AI-generated, we would expect better grammar and formatting consistency, fewer colloquialisms, and more rigidly organized code comments and documentation. Key Indicators: Human Indicators:
Potential AI-Indicators (minor):
Overall, the natural imperfections, thoughtful design decisions, and domain-specific phrasing are more consistent with human authorship. ✅ No strong indicators of AI generation detected |
AI Detection Analysis 🔍Confidence Score: 40% Reasoning: Additionally, the testing suite and the edge case handling in the implementation (like DB-level uniqueness constraints for race conditions, timestamp segmentation for ML readiness, inference-focused design decisions, SQLModel transactions, test structure using pytest fixtures, exception handling, and API routing) demonstrate a moderately advanced grasp of backend design that suggests human authorship. Some comments, typos (e.g., "rece condition", "whatevet", "demends", "Testsing"), and informal phrasing also support a human origin. Key Indicators:
Taken together, the programming and planning complexity as well as the human error patterns lower the confidence that this was AI-generated. Thus, while some technical language could be LLM-assisted, the overall structure and quality suggest primarily human authorship. ✅ No strong indicators of AI generation detected |
Implementing the NextLevel-Elevator API with a simple and basic implementation focusing on supplying the necessary to store users' demands.
This API has 4 endpoints.
POST /api/v1/elevatorthat will create a new elevatorPUT /api/v1/elevator/{elevator_id}that initiates a new demandPOST /api/v1/elevator/{elevator_id}/stateTo react to an elevator state when it reaches a new levelGET /api/v1/elevator/dataset.csvTo retrieve the dataset that will be used to train the prediction modelSince the main goal is to provide data to predict the best level for the elevator rest, we basically need to provide data to predict where the next demand will be. Let's work on the demand itself.
I´m considering that the elevator will be controlled by its own control system, and this API is only to react to elevator events, such as a demand or a state update.
And how its going to work.
Whenever a user calls the elevator to a certain level the elevator system will query this api to store the user demand, and it needs to be unique until the elevator attends that demand. for that requiremente lets rely on SQL DB unique contraint and do it atomically waiting and reacting the DB Integrity Error to make sure that will never be a rece condition on that.
So The is the basic model of a Elevator Demand where will store the elevator_id, the timestamp and the leval, and each demand will be unique using the (elevator_id, level) columns
The next important rule is how to reacts the elevator state, Whenever a elevator stop in any level it must call the api to store the new state. At this time the backend will query for any demand opened for that level, if it founds it will create a new entry into a new table called elevator_demand_history with the necessary data to be used in training system and it will DELETE the entry that it founds opening a new slot to a new demand to that level all that in the same transaction to archieve consistency.
Storing the demand that was completelly attended by the Elevator and splitting the timestamp into
week_day,hour,minuteandsecondfor the given demand, so it will be more easy to group demand by any time heuristics with second precision.This model can be enriched with more data it demends considering the seasonal information like if it is a holyday and something like that but I decide to take it more straight foward
The end user can now query the endpoint to retrieve the dataset in a CSV format with the following info
elevator_id,week_day,hour,minute,second,levelit can use the elevator_id, week_day, hour, minute, second, to be the input of the ML model with any precision of time the users want since, grouping by quarter of a minute, half a minute or whatevet it wants. and use the level to be the output of the ML model
once Trained it can be used by the elevator control system any time the elevator is resting it can run the inference system to discover where will be the next demand.