Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions codes/ecg-image-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ The process of scanning and digitizing ECG images is governed by some fundamenta
## Installation
- Setup with Conda env:
```
conda env create -f environment_droplet.yml
conda activate myenv
conda env create -f environment.yml
conda activate ecg-image-generator
```

- Set up with pip:
Expand Down
29 changes: 24 additions & 5 deletions codes/ecg-image-generator/TemplateFiles/generate_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,47 @@

test_date1 = date(1940, 1, 1)

import random
from datetime import datetime, timedelta

def random_datetime(start_date, end_date):
"""Generate random datetime between two dates"""
time_between = end_date - start_date
total_seconds = time_between.total_seconds()
random_seconds = random.uniform(0, total_seconds)
return start_date + timedelta(seconds=random_seconds)

def generate_template(header_file):
filename, extn = os.path.splitext(header_file)
fields = wfdb.rdheader(filename)

start = datetime(1960, 1, 1)
end = datetime(2022, 1, 1)
random_dt = random_datetime(start, end)

if fields.comments == []:
attributes = {}

if fields.base_date is not None:
attributes['Date'] = fields.base_date
else:
attributes['Date'] = ""
attributes['Date'] = random_dt.strftime(random.choice(["%d/%m/%Y", "%d-%m-%Y"]))
if fields.base_time is not None:
attributes['Time'] = str(fields.base_time)
else:
attributes['Time'] = ""
attributes['Time'] = random_dt.strftime("%H:%M:%S")
attributes['ID'] = 'ID: ' + filename.split('/')[-1]
attributes['Name'] = 'Name: '
if attributes['Date'] != "":
attributes['Date'] = 'Date:' + str(attributes['Date'])
if attributes['Time'] != "":
attributes['Date'] += ', ' + attributes['Time']
attributes['Sex'] = f"Sex: {random.choice(['Male', 'Female'])}"
attributes['Age'] = f"Age: {random.choice(range(12, 75))} yrs"
printedText = {}
printedText[0] = ['ID', 'Name', 'Date']
printedText[1] = ["Age"]
printedText[2] = ["Sex"]

return printedText, attributes, 1

Expand All @@ -39,21 +57,22 @@ def generate_template(header_file):

attributes = {}


if fields.base_date is not None:
attributes['Date'] = fields.base_date
else:
attributes['Date'] = ""
attributes['Date'] = random_dt.strftime(random.choice(["%d/%m/%Y", "%d-%m-%Y"]))
if fields.base_time is not None:
attributes['Time'] = str(fields.base_time)
else:
attributes['Time'] = ""
attributes['Time'] = random_dt.strftime("%H:%M:%S")

attributes['ID'] = 'ID: ' + filename.split('/')[-1]
attributes['Name'] = 'Name: ' #+ str(str(random.randint(10**(8-1), (10**8)-1)))

attributes['Height'] = ''
attributes['Weight'] = ''
attributes['Sex'] = ''
attributes['Sex'] = random.choice(["Male", "Female"])

for c in comments:
col = c.split(':')[0]
Expand Down
Loading