The Open Event Server enables organizers to manage events from concerts to conferences and meet-ups. It offers features for events with several tracks and venues. In this blog, we will talk about how to add statistics of event-type on Open Event Server. The focus is on to get number of events of a specific event type.
Number of events of a specific event type
Now, let’s try to understand this API. Here, we are using flask Blueprints to add this API to the API index.
- First of all, we are using the decorator of event_statistics which will append this API route with that of mentioned in the Blueprint event_statistics.
- We will just allow logged in user to access this API using JWT (JSON Web Token)
- To return the response having all the event types alongwith number of events of it, requires a lot of queries if tried to fulfilled by SQLALchemy ORM. So instead of using ORM we will query using SQL command so that we query the number of all the events of different event types in just one query, which will eventually reduces the time of server to return the response.
- In function event_types_count we are using db.engine.execute to run the SQL command of getting the statistics of events respective to event types.
- The response will include id of event_type, name of event_type and count of events of corresponding event_type.
- Finally, we jsonify the list having objects of statistics of events respective to event types.
Similarly, event topics statistics can be implemented to return the number of events of all the event topics.