Compare commits
2 Commits
f7ce1c3fd6
...
25d1774e53
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
25d1774e53 | ||
|
|
25aa7de043 |
@@ -7,6 +7,7 @@ WORKDIR /app
|
|||||||
# Copy only the necessary files for TailwindCSS build
|
# Copy only the necessary files for TailwindCSS build
|
||||||
COPY package.json package-lock.json ./
|
COPY package.json package-lock.json ./
|
||||||
COPY ./app/templates ./app/templates
|
COPY ./app/templates ./app/templates
|
||||||
|
COPY ./app/static/js ./app/static/js
|
||||||
COPY tailwind.config.js ./
|
COPY tailwind.config.js ./
|
||||||
|
|
||||||
# Install Node.js dependencies
|
# Install Node.js dependencies
|
||||||
@@ -39,6 +40,7 @@ COPY . .
|
|||||||
|
|
||||||
# Copy the built TailwindCSS assets from the first stage
|
# Copy the built TailwindCSS assets from the first stage
|
||||||
COPY --from=tailwind-builder /app/app/static/css/tailwind.css ./app/static/css/tailwind.css
|
COPY --from=tailwind-builder /app/app/static/css/tailwind.css ./app/static/css/tailwind.css
|
||||||
|
COPY --from=tailwind-builder /app/app/static/js/diy-turbo.min.js ./app/static/js/diy-turbo.min.js
|
||||||
|
|
||||||
# Run tests during the build process
|
# Run tests during the build process
|
||||||
RUN pytest --maxfail=5 --disable-warnings -v || (echo "Tests failed. Exiting." && exit 1)
|
RUN pytest --maxfail=5 --disable-warnings -v || (echo "Tests failed. Exiting." && exit 1)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from flask_migrate import Migrate
|
|||||||
from flask_bcrypt import Bcrypt
|
from flask_bcrypt import Bcrypt
|
||||||
from flask_login import LoginManager
|
from flask_login import LoginManager
|
||||||
from flask_compress import Compress
|
from flask_compress import Compress
|
||||||
|
from flask_minify import Minify
|
||||||
|
|
||||||
# Initialize Flask extensions
|
# Initialize Flask extensions
|
||||||
db = SQLAlchemy()
|
db = SQLAlchemy()
|
||||||
@@ -12,6 +13,7 @@ migrate = Migrate()
|
|||||||
bcrypt = Bcrypt()
|
bcrypt = Bcrypt()
|
||||||
login_manager = LoginManager()
|
login_manager = LoginManager()
|
||||||
compress = Compress()
|
compress = Compress()
|
||||||
|
minify = Minify(html=True, js=True, cssless=True, fail_safe=True)
|
||||||
|
|
||||||
login_manager.login_view = 'auth.login'
|
login_manager.login_view = 'auth.login'
|
||||||
login_manager.login_message_category = 'info'
|
login_manager.login_message_category = 'info'
|
||||||
@@ -29,6 +31,8 @@ def create_app():
|
|||||||
bcrypt.init_app(app)
|
bcrypt.init_app(app)
|
||||||
login_manager.init_app(app)
|
login_manager.init_app(app)
|
||||||
compress.init_app(app)
|
compress.init_app(app)
|
||||||
|
minify.init_app(app)
|
||||||
|
|
||||||
|
|
||||||
# Import models here to avoid circular imports
|
# Import models here to avoid circular imports
|
||||||
from app.models import User # Import the User model
|
from app.models import User # Import the User model
|
||||||
|
|||||||
@@ -17,16 +17,17 @@ def manage_data():
|
|||||||
try:
|
try:
|
||||||
csv_data = csv.reader(StringIO(file.read().decode('utf-8')))
|
csv_data = csv.reader(StringIO(file.read().decode('utf-8')))
|
||||||
next(csv_data) # Skip the header row
|
next(csv_data) # Skip the header row
|
||||||
|
readings_to_add = []
|
||||||
for row in csv_data:
|
for row in csv_data:
|
||||||
timestamp, systolic, diastolic, heart_rate = row
|
timestamp, systolic, diastolic, heart_rate = row
|
||||||
reading = Reading(
|
readings_to_add.append(Reading(
|
||||||
user_id=current_user.id,
|
user_id=current_user.id,
|
||||||
timestamp=datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S'),
|
timestamp=datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S'),
|
||||||
systolic=int(systolic),
|
systolic=int(systolic),
|
||||||
diastolic=int(diastolic),
|
diastolic=int(diastolic),
|
||||||
heart_rate=int(heart_rate),
|
heart_rate=int(heart_rate),
|
||||||
)
|
))
|
||||||
db.session.add(reading)
|
db.session.bulk_save_objects(readings_to_add)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash('Data imported successfully!', 'success')
|
flash('Data imported successfully!', 'success')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -288,12 +288,9 @@ def prepare_graph_data(readings):
|
|||||||
|
|
||||||
def calculate_progress_badges(user_id, user_tz):
|
def calculate_progress_badges(user_id, user_tz):
|
||||||
"""Generate badges based on user activity and milestones using optimized queries."""
|
"""Generate badges based on user activity and milestones using optimized queries."""
|
||||||
total_readings = Reading.query.filter_by(user_id=user_id).count()
|
# Fetch only timestamps (index-only scan on the composite index)
|
||||||
if total_readings == 0:
|
|
||||||
return []
|
|
||||||
|
|
||||||
# Fetch only timestamps (highly optimized compared to fetching full objects)
|
|
||||||
timestamps = db.session.query(Reading.timestamp).filter(Reading.user_id == user_id).order_by(Reading.timestamp.desc()).all()
|
timestamps = db.session.query(Reading.timestamp).filter(Reading.user_id == user_id).order_by(Reading.timestamp.desc()).all()
|
||||||
|
total_readings = len(timestamps)
|
||||||
return _compute_badges(total_readings, timestamps, user_tz)
|
return _compute_badges(total_readings, timestamps, user_tz)
|
||||||
|
|
||||||
def _compute_badges(total_readings, timestamps, user_tz, now_local=None):
|
def _compute_badges(total_readings, timestamps, user_tz, now_local=None):
|
||||||
|
|||||||
1
app/static/js/diy-turbo.min.js
vendored
Normal file
1
app/static/js/diy-turbo.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
document.addEventListener("click",async t=>{const e=t.target.closest("a");if(!e)return;const o=e.getAttribute("href");if(o&&!o.startsWith("#")&&!o.startsWith("javascript:")&&e.origin===window.location.origin&&!("_blank"===e.target||e.hasAttribute("download")||t.ctrlKey||t.shiftKey||t.metaKey||t.altKey||"false"===e.getAttribute("data-turbo"))){t.preventDefault(),document.body.style.cursor="wait";try{const t=await fetch(o);if(!t.ok)throw new Error("Fetch failed");const e=await t.text(),r=(new DOMParser).parseFromString(e,"text/html");document.title=r.title,document.body.innerHTML=r.body.innerHTML,document.body.className=r.body.className,document.body.style.cursor="default",window.history.pushState({},"",o),window.scrollTo(0,0),document.dispatchEvent(new Event("diy-turbo:load"))}catch(t){console.error("DIY Turbo navigation error:",t),window.location.href=o}}}),window.addEventListener("popstate",async()=>{document.body.style.cursor="wait";try{const t=await fetch(window.location.href);if(!t.ok)throw new Error("Fetch failed");const e=await t.text(),o=(new DOMParser).parseFromString(e,"text/html");document.title=o.title,document.body.innerHTML=o.body.innerHTML,document.body.className=o.body.className,document.body.style.cursor="default",document.dispatchEvent(new Event("diy-turbo:load"))}catch(t){console.error("DIY Turbo popstate error:",t),window.location.reload()}});
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
<title>{% block title %}BP Tracker{% endblock %}</title>
|
<title>{% block title %}BP Tracker{% endblock %}</title>
|
||||||
<link rel="icon" type="image/svg+xml" sizes="any" href="{{ url_for('static', filename='images/favicon.svg') }}">
|
<link rel="icon" type="image/svg+xml" sizes="any" href="{{ url_for('static', filename='images/favicon.svg') }}">
|
||||||
<link href="/static/css/tailwind.css" rel="stylesheet">
|
<link href="/static/css/tailwind.css" rel="stylesheet">
|
||||||
<script src="{{ url_for('static', filename='js/diy-turbo.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/diy-turbo.min.js') }}"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="bg-gray-50 text-gray-800 font-sans antialiased">
|
<body class="bg-gray-50 text-gray-800 font-sans antialiased">
|
||||||
|
|||||||
77
package-lock.json
generated
77
package-lock.json
generated
@@ -8,10 +8,14 @@
|
|||||||
"name": "bloodpressure",
|
"name": "bloodpressure",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"tailwindcss": "^3.0.0"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "^10.4.20",
|
"autoprefixer": "^10.4.20",
|
||||||
"postcss": "^8.4.49",
|
"postcss": "^8.4.49",
|
||||||
"tailwindcss": "^3.4.17"
|
"tailwindcss": "^3.4.17",
|
||||||
|
"terser": "^5.46.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@alloc/quick-lru": {
|
"node_modules/@alloc/quick-lru": {
|
||||||
@@ -75,6 +79,16 @@
|
|||||||
"node": ">=6.0.0"
|
"node": ">=6.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@jridgewell/source-map": {
|
||||||
|
"version": "0.3.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.11.tgz",
|
||||||
|
"integrity": "sha512-ZMp1V8ZFcPG5dIWnQLr3NSI1MiCU7UETdS/A0G8V/XWHvJv3ZsFqutJn1Y5RPmAPX6F3BiE397OqveU/9NCuIA==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@jridgewell/gen-mapping": "^0.3.5",
|
||||||
|
"@jridgewell/trace-mapping": "^0.3.25"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@jridgewell/sourcemap-codec": {
|
"node_modules/@jridgewell/sourcemap-codec": {
|
||||||
"version": "1.5.0",
|
"version": "1.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz",
|
||||||
@@ -136,6 +150,18 @@
|
|||||||
"node": ">=14"
|
"node": ">=14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/acorn": {
|
||||||
|
"version": "8.16.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz",
|
||||||
|
"integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==",
|
||||||
|
"dev": true,
|
||||||
|
"bin": {
|
||||||
|
"acorn": "bin/acorn"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/ansi-regex": {
|
"node_modules/ansi-regex": {
|
||||||
"version": "6.1.0",
|
"version": "6.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz",
|
||||||
@@ -293,6 +319,12 @@
|
|||||||
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
|
"node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/buffer-from": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"node_modules/camelcase-css": {
|
"node_modules/camelcase-css": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/camelcase-css/-/camelcase-css-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/camelcase-css/-/camelcase-css-2.0.1.tgz",
|
||||||
@@ -1175,6 +1207,15 @@
|
|||||||
"url": "https://github.com/sponsors/isaacs"
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/source-map": {
|
||||||
|
"version": "0.6.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||||
|
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
|
||||||
|
"dev": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/source-map-js": {
|
"node_modules/source-map-js": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
|
||||||
@@ -1184,6 +1225,16 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/source-map-support": {
|
||||||
|
"version": "0.5.21",
|
||||||
|
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz",
|
||||||
|
"integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"buffer-from": "^1.0.0",
|
||||||
|
"source-map": "^0.6.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/string-width": {
|
"node_modules/string-width": {
|
||||||
"version": "5.1.2",
|
"version": "5.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz",
|
||||||
@@ -1351,6 +1402,30 @@
|
|||||||
"node": ">=14.0.0"
|
"node": ">=14.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/terser": {
|
||||||
|
"version": "5.46.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/terser/-/terser-5.46.0.tgz",
|
||||||
|
"integrity": "sha512-jTwoImyr/QbOWFFso3YoU3ik0jBBDJ6JTOQiy/J2YxVJdZCc+5u7skhNwiOR3FQIygFqVUPHl7qbbxtjW2K3Qg==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@jridgewell/source-map": "^0.3.3",
|
||||||
|
"acorn": "^8.15.0",
|
||||||
|
"commander": "^2.20.0",
|
||||||
|
"source-map-support": "~0.5.20"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"terser": "bin/terser"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/terser/node_modules/commander": {
|
||||||
|
"version": "2.20.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
|
||||||
|
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"node_modules/thenify": {
|
"node_modules/thenify": {
|
||||||
"version": "3.3.1",
|
"version": "3.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npx tailwindcss -o ./app/static/css/tailwind.css --minify",
|
"build": "npx tailwindcss -o ./app/static/css/tailwind.css --minify && npx terser ./app/static/js/diy-turbo.js -o ./app/static/js/diy-turbo.min.js -c -m",
|
||||||
"serve": "npx tailwindcss -o ./app/static/css/tailwind.css --minify --watch"
|
"serve": "npx tailwindcss -o ./app/static/css/tailwind.css --minify --watch"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "^10.4.20",
|
"autoprefixer": "^10.4.20",
|
||||||
"postcss": "^8.4.49",
|
"postcss": "^8.4.49",
|
||||||
"tailwindcss": "^3.4.17"
|
"tailwindcss": "^3.4.17",
|
||||||
|
"terser": "^5.46.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,3 +37,5 @@ typing-extensions==4.12.2
|
|||||||
werkzeug==3.1.3
|
werkzeug==3.1.3
|
||||||
wtforms==3.2.1
|
wtforms==3.2.1
|
||||||
zipp==3.21.0
|
zipp==3.21.0
|
||||||
|
Flask-Minify==0.43
|
||||||
|
Brotli==1.2.0
|
||||||
|
|||||||
Reference in New Issue
Block a user