Article
· Apr 20, 2023 5m read

Using InterSystems IRIS Cloud SQL and IntegratedML to build a sleep analysis application Sheep's Galaxy.

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.

image

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.

image

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.

image

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.

image

Pydantic models automatically validate incoming and outgoing data.

image

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

image

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

image

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:

image

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.

image

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:

image

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:

Discussion (5)1
Log in or sign up to continue

🙌 Thank you so much, Maria Nesterenko, for sharing the valuable testimony and explanation of how you developed the Sheep's Galaxy sleep analysis application using InterSystems IRIS Cloud SQL and IntegratedML technologies.

Your application is truly innovative and provides users with the tools to analyze and improve their sleep quality.

It's impressive how you took into account factors such as noise levels, room lighting, caffeine consumption, and more to help users create optimal conditions for sleep.

The use of Angular framework for frontend, FastApi framework with DB-API package for backend, and IRIS Cloud SQL with IntegratedML to analyze and store data is remarkable. Your team's work is inspiring, and we thank you for contributing to important issues in such a cutting-edge way. 👏

So, to summarize, does the application provide the user with a "sleep score" or does it have additional uses? 🤔

Thank you for your interest in our project and high appreciation of our work! This application demonstrates the use of the technology stack, including Angular, the FastApi framework with DB-API, and IRIS Cloud SQL with IntegratedML, to solve a specific problem. Additionally, the application's functionality can be extended.

I don't see it mentioned in the article, there is also a working demo during the contest: http://sleeptracker.banksiaglobal.com. No need to give it your real personal information or email, it's just a demo to click around.

If you haven't done it yet, go to the contest page and vote for the best projects! https://openexchange.intersystems.com/contest/31

Hi Maria,

Your video is available on InterSystems Developers YouTube:

⏯️ Sleep tracker Sheep's Galaxy

https://www.youtube.com/embed/H3pGSzkOo6c
[This is an embedded link, but you cannot view embedded content directly on the site because you have declined the cookies necessary to access it. To view embedded content, you would need to accept all cookies in your Cookies Settings]

Please enjoy!