Many factors affect a person's quality of life, and one of the most important is sleep. The quality of our sleep determines our ability to function during the day and affects our mental and physical health. Good quality sleep is critical to our overall health and well-being. Therefore, by analyzing indicators preceding sleep, we can determine the quality of our sleep. This is precisely the functionality of the Sheep's Galaxy application.
Sheep's Galaxy is a sample application that works with InterSystems' IntegratedML and IRIS Cloud SQL technologies and provides the user with a tool to analyze and improve sleep quality. The analysis of sleep takes into account factors such as noise levels, room lighting, sleep duration, caffeine consumption, and more, allowing the user to reconsider their sleep-related habits and create optimal conditions for sleep in the future.
Presentation video:
https://www.youtube.com/watch?v=eZ9Wak831x4&ab_channel=MariaGladkova
The app is based on the following technologies:
Frontend part:
To build this app we used Angular framework. It helped us to create a simple single page application. We used Angular v15, and all Angular components were implemented as standalones to streamline the authoring experience. We didn’t use Angular modules and it's a good practice to scale an app in the future if it need.
We also used Smart Component Architecture – all components in our frontend application are divided into "smart" and "dumb" components. This concepts helps us to separate the business logic code and presentation code between these components.
All business logic and requests to server are kept in the isolated services. To process our backend data we use RxJS - a library for composing asynchronous and event-based programs by using observable sequences.
To style our app we used Angular Material - it is a User Interface component library which developers can use in their Angular projects to speed up development of elegant and consistent user interfaces. This library offers a lot of reusable and beautiful UI components - we added some of them like Cards, Inputs, Data Tables, Datepickers, and much more.
Below we present an overview of typical user workflow. First, user goes through either the registration process, if using it for the first time, or through authorization screen.

Using the app, the user enters information about sleep, such as activity level during the day, number of cups of coffee, sleeping comfort, stress level and amount of positive emotions, as well as room light and bedtime.

After each data entry, the user will receive a notification of sleep quality. This data is then analyzed using machine learning algorithms to provide users with insights into their sleep patterns.

Backend part:
Fastapi is a python framework based on two technologies: Pydantic and Starlette.
It has the following features:
- Is based on open standards: OpenAPI, JSON schema, OAuth2;
- Automatic API documentation in swagger;
- Dependencies implementation;
- Uses features of modern python: type annotation, asyncio;
- Supports synchronous and asynchronous code;
The project structure consists of routers with endpoints, models for each entity and processing services.
Each endpoint appears in the atomic documentation at /docs and endpoint fields have a relationship to the data models in the database.

Pydantic models automatically validate incoming and outgoing data.

The process of working with user data is built on the protocol, which allows you to work with data in a secure way.

The process of interaction with the database is implemented through IRIS SQL connection using the DB API.

IRIS Cloud SQL with IntegratedML:
First, you need to login to InterSystems Cloud Services Portal. Here you need to create a new IRIS Cloud SQL deployment. Be sure to include IntegratedML when you create a new deployment. When it's ready, you can obtain connection parameters to use in docker-compose.yml:

By opening 'IntegratedML Tools' menu you have access to create, train, validate your model, and have the ability to generate predictions on a selected field in your model table.

In our app, we predict sleep quality based on user data. To do this, we fill in the fields in the Prediction section as follows:

In the generated query, the prediction field contains a prediction of the quality of sleep, the probability_quality field contains the probability that the dream will be "qualitative".
Links:
To learn more about our project or use it as a template for your future work:
https://openexchange.intersystems.com/package/Sheep%E2%80%99s-Galaxy
Thanks:
Our team would like to thank InterSystems and Banksia Global for an opportunity to work with cutting-edge technology on important issues.
Developers of project: