Git Product home page Git Product logo

ecg_to_sql's Introduction

ECG to SQL

ecg_to_sql.png

ECG to SQL is a collection of python scripts to store electrocardiography (ECG) data into an SQLite database. The data used to develop this repo are provided by the PhysioNet/CinC challenge 2021 on the detection of atrial fibrillation.

The database structure is mainly based on the online analytical processing (OLAP) approach with the following entity relationship diagram. eer_diagram

To ensure data integrity during entries insertion and minimize data redundancy, the design of this dataset satisfies the first three normal form rules. The ecg time series were stored into a single table per patient.

Usage

Aggregate all the metadata in csv files, one for each dataset

from data_access.prepare import prepare_summary_csv

prepare_summary_csv()

Create and populate the dataset

from create_db import CreateDb
from pathlib import Path
from parameters import DefaultArguments

data_dir = Path('./path')
builder = CreateDb(data_dir, db_file_name='af_detection.db')

builder.populate_schema(dataset_name=DefaultArguments.ChapmanShaoxing)
builder.populate_data_tables(dataset_name=DefaultArguments.ChapmanShaoxing)
builder.db.close()

Load the dataset and retrieve one patient data

from load_db import LoadDb
from pathlib import Path
import matplotlib.pyplot as plt
import numpy as np

data_dir = Path('./path')
loader = LoadDb(data_dir=data_dir, 
                db_file_name='af.db')

original_id, diagnosis = loader.get_single_patient_data(patient_id=42)
ecg = loader.get_ecg(patient_id=42, leads=[1])

time = np.array(list(range(len(ecg)))) / loader.SAMPLING_FREQUENCY
plt.title(f'Patient id: {original_id} | diagnosis: {diagnosis}')
plt.xlabel('Time (s)')
plt.ylabel('mV')
plt.plot(time, ecg)

test_JS05301.png

License

Distributed under the MIT License. See LICENSE.txt for more information.

Contact

Gaetano Scebba - @GScebba

Acknowledgments

ecg_to_sql's People

Stargazers

 avatar

Watchers

 avatar

Forkers

9hoton

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.