Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat: add grams-per-day alcohol tracking with longevity thresholds

Adam Eivy2f92f9a31bd4
diff --git a/.changelog/v1.11.x.md b/.changelog/v1.11.x.md
index e5510a2238..a0992f9b46 100644
--- a/.changelog/v1.11.x.md
+++ b/.changelog/v1.11.x.md
@@ -17,7 +17,9 @@ Alcohol data table: view and edit all imported drink entries with inline editing
## Improvements
-- **Day of week labels** in alcohol data table — each date group shows abbreviated day (M, T, W, TH, F, Sat, Sun) for quick pattern recognition
+- **Grams-per-day alcohol tracking** — summary cards and chart now show grams of pure alcohol as the primary metric (1 std drink = 14g), with longevity-based thresholds: 10g/day target (green), 40g/day danger zone (red)
+- **Chart unit toggle** — switch between Grams and Drinks views with reference lines for each unit's thresholds
+- **Day of week labels** in alcohol data table — each date group shows abbreviated 3-letter day code for quick pattern recognition
## Fixes
diff --git a/client/src/components/meatspace/AlcoholChart.jsx b/client/src/components/meatspace/AlcoholChart.jsx
index 0c6c306db2..7da9a4fa21 100644
--- a/client/src/components/meatspace/AlcoholChart.jsx
+++ b/client/src/components/meatspace/AlcoholChart.jsx
@@ -11,10 +11,13 @@ const VIEWS = [
{ id: '90d', label: '90 Days', days: 90 }
];
+const GRAMS_PER_STD_DRINK = 14;
+
export default function AlcoholChart({ sex = 'male', onRefreshKey }) {
const [data, setData] = useState([]);
const [loading, setLoading] = useState(true);
const [view, setView] = useState('30d');
+ const [unit, setUnit] = useState('grams'); // 'grams' or 'drinks'
const dailyMax = sex === 'female' ? 1 : 2;
@@ -38,10 +41,12 @@ export default function AlcoholChart({ sex = 'male', onRefreshKey }) {
const end = new Date(toStr);
while (cursor <= end) {
const dateStr = cursor.toISOString().split('T')[0];
+ const drinks = dateMap[dateStr] || 0;
chartData.push({
date: dateStr,
label: `${cursor.getMonth() + 1}/${cursor.getDate()}`,
- drinks: dateMap[dateStr] || 0
+ drinks,
+ grams: Math.round(drinks * GRAMS_PER_STD_DRINK * 100) / 100
});
cursor.setDate(cursor.getDate() + 1);
}
@@ -54,13 +59,19 @@ export default function AlcoholChart({ sex = 'male', onRefreshKey }) {
fetchData();
}, [fetchData, onRefreshKey]);
+ const dataKey = unit === 'grams' ? 'grams' : 'drinks';
+
const CustomTooltip = ({ active, payload, label }) => {
if (!active || !payload?.length) return null;
- const drinks = payload[0].value;
+ const drinks = payload[0].payload.drinks;
+ const grams = payload[0].payload.grams;
return (
<div className="bg-port-card border border-port-border rounded-lg p-2 text-sm">
<p className="text-gray-400">{label}</p>
- <p className={`font-semibold ${drinks > dailyMax ? 'text-port-error' : 'text-port-accent'}`}>
+ <p className={`font-semibold ${grams > 40 ? 'text-port-error' : grams > 10 ? 'text-port-warning' : 'text-port-success'}`}>
+ {grams}g
+ </p>
+ <p className={`text-xs ${drinks > dailyMax ? 'text-port-error' : 'text-gray-400'}`}>
{drinks} std drinks
</p>
</div>
@@ -73,20 +84,38 @@ export default function AlcoholChart({ sex = 'male', onRefreshKey }) {
<h3 className="text-sm font-medium text-gray-400 uppercase tracking-wider">
Daily Consumption
</h3>
- <div className="flex gap-1">
- {VIEWS.map(v => (
- <button
- key={v.id}
- onClick={() => setView(v.id)}
- className={`px-2 py-1 text-xs rounded transition-colors ${
- view === v.id
- ? 'bg-port-accent/10 text-port-accent'
- : 'text-gray-500 hover:text-gray-300'
- }`}
- >
- {v.label}
- </button>
- ))}
+ <div className="flex items-center gap-3">
+ <div className="flex gap-1">
+ {['grams', 'drinks'].map(u => (
+ <button
+ key={u}
+ onClick={() => setUnit(u)}
+ className={`px-2 py-1 text-xs rounded transition-colors ${
+ unit === u
+ ? 'bg-port-accent/10 text-port-accent'
+ : 'text-gray-500 hover:text-gray-300'
+ }`}
+ >
+ {u === 'grams' ? 'Grams' : 'Drinks'}
+ </button>
+ ))}
+ </div>
+ <div className="w-px h-4 bg-port-border" />
+ <div className="flex gap-1">
+ {VIEWS.map(v => (
+ <button
+ key={v.id}
+ onClick={() => setView(v.id)}
+ className={`px-2 py-1 text-xs rounded transition-colors ${
+ view === v.id
+ ? 'bg-port-accent/10 text-port-accent'
+ : 'text-gray-500 hover:text-gray-300'
+ }`}
+ >
+ {v.label}
+ </button>
+ ))}
+ </div>
</div>
</div>
@@ -105,14 +134,31 @@ export default function AlcoholChart({ sex = 'male', onRefreshKey }) {
/>
<YAxis tick={{ fill: '#6b7280', fontSize: 11 }} />
<Tooltip content={<CustomTooltip />} />
- <ReferenceLine
- y={dailyMax}
- stroke="#f59e0b"
- strokeDasharray="5 5"
- label={{ value: 'Daily limit', fill: '#f59e0b', fontSize: 10, position: 'right' }}
- />
+ {unit === 'grams' ? (
+ <>
+ <ReferenceLine
+ y={10}
+ stroke="#22c55e"
+ strokeDasharray="5 5"
+ label={{ value: '10g target', fill: '#22c55e', fontSize: 10, position: 'right' }}
+ />
+ <ReferenceLine
+ y={40}
+ stroke="#ef4444"
+ strokeDasharray="5 5"
+ label={{ value: '40g danger', fill: '#ef4444', fontSize: 10, position: 'right' }}
+ />
+ </>
+ ) : (
+ <ReferenceLine
+ y={dailyMax}
+ stroke="#f59e0b"
+ strokeDasharray="5 5"
+ label={{ value: 'Daily limit', fill: '#f59e0b', fontSize: 10, position: 'right' }}
+ />
+ )}
<Bar
- dataKey="drinks"
+ dataKey={dataKey}
radius={[2, 2, 0, 0]}
fill="#3b82f6"
maxBarSize={view === '7d' ? 40 : view === '30d' ? 16 : 8}
diff --git a/client/src/components/meatspace/tabs/AlcoholTab.jsx b/client/src/components/meatspace/tabs/AlcoholTab.jsx
index c9c66107dc..229ca9dc0b 100644
--- a/client/src/components/meatspace/tabs/AlcoholTab.jsx
+++ b/client/src/components/meatspace/tabs/AlcoholTab.jsx
@@ -28,7 +28,7 @@ const RISK_BG = {
};
const DAYS_PER_PAGE = 50;
-const DAY_LABELS = ['Sun', 'M', 'T', 'W', 'TH', 'F', 'Sat'];
+const DAY_LABELS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
function dayOfWeek(dateStr) {
const [y, m, d] = dateStr.split('-').map(Number);
@@ -174,32 +174,38 @@ export default function AlcoholTab() {
<div className="grid grid-cols-2 md:grid-cols-5 gap-4">
<div>
<span className="text-xs text-gray-500">Today</span>
- <p className={`text-2xl font-bold ${summary.today > summary.thresholds.dailyMax ? 'text-port-error' : 'text-white'}`}>
- {summary.today}
+ <p className={`text-2xl font-bold ${summary.grams?.today > 40 ? 'text-port-error' : summary.grams?.today > 10 ? 'text-port-warning' : 'text-white'}`}>
+ {summary.grams?.today ?? 0}g
</p>
- <span className="text-xs text-gray-600">/ {summary.thresholds.dailyMax} max</span>
+ <span className="text-xs text-gray-600">{summary.today} drinks</span>
</div>
<div>
<span className="text-xs text-gray-500">7-Day Avg</span>
- <p className="text-2xl font-bold text-white">{summary.avg7day}</p>
- <span className="text-xs text-gray-600">per day</span>
+ <p className={`text-2xl font-bold ${summary.grams?.avg7day > 40 ? 'text-port-error' : summary.grams?.avg7day > 10 ? 'text-port-warning' : 'text-white'}`}>
+ {summary.grams?.avg7day ?? 0}g
+ </p>
+ <span className="text-xs text-gray-600">{summary.avg7day} drinks/day</span>
</div>
<div>
<span className="text-xs text-gray-500">30-Day Avg</span>
- <p className="text-2xl font-bold text-white">{summary.avg30day}</p>
- <span className="text-xs text-gray-600">per day</span>
+ <p className={`text-2xl font-bold ${summary.grams?.avg30day > 40 ? 'text-port-error' : summary.grams?.avg30day > 10 ? 'text-port-warning' : 'text-white'}`}>
+ {summary.grams?.avg30day ?? 0}g
+ </p>
+ <span className="text-xs text-gray-600">{summary.avg30day} drinks/day</span>
</div>
<div>
<span className="text-xs text-gray-500">Weekly Total</span>
<p className={`text-2xl font-bold ${summary.weeklyTotal > summary.thresholds.weeklyMax ? 'text-port-error' : 'text-white'}`}>
- {summary.weeklyTotal}
+ {summary.grams?.weeklyTotal ?? 0}g
</p>
- <span className="text-xs text-gray-600">/ {summary.thresholds.weeklyMax} max</span>
+ <span className="text-xs text-gray-600">{summary.weeklyTotal} drinks / {summary.thresholds.weeklyMax} max</span>
</div>
<div>
<span className="text-xs text-gray-500">All-Time Avg</span>
- <p className="text-2xl font-bold text-gray-300">{summary.allTimeAvg}</p>
- <span className="text-xs text-gray-600">per day</span>
+ <p className={`text-2xl font-bold ${summary.grams?.allTimeAvg > 40 ? 'text-port-error' : summary.grams?.allTimeAvg > 10 ? 'text-port-warning' : 'text-gray-300'}`}>
+ {summary.grams?.allTimeAvg ?? 0}g
+ </p>
+ <span className="text-xs text-gray-600">{summary.allTimeAvg} drinks/day</span>
</div>
</div>
</div>
diff --git a/package-lock.json b/package-lock.json
index 974af7fd24..b056d0c66e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "portos",
- "version": "1.11.1",
+ "version": "1.12.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "portos",
- "version": "1.11.1",
+ "version": "1.12.0",
"license": "MIT",
"dependencies": {
"express": "^4.21.2",
diff --git a/package.json b/package.json
index 20ca2ae3db..a5d5a0997e 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "portos",
- "version": "1.11.1",
+ "version": "1.12.0",
"private": true,
"description": "Local dev machine App OS portal",
"author": "Adam Eivy (@antic|@atomantic)",
diff --git a/server/services/meatspaceAlcohol.js b/server/services/meatspaceAlcohol.js
index 707a66123a..4aa387e800 100644
--- a/server/services/meatspaceAlcohol.js
+++ b/server/services/meatspaceAlcohol.js
@@ -20,6 +20,9 @@ const CACHE_TTL_MS = 5 * 60 * 1000; // 5 minutes
// === Pure Functions ===
+// 1 standard drink = 0.6 oz pure alcohol = ~14g pure alcohol
+export const GRAMS_PER_STD_DRINK = 14;
+
/**
* Calculate standard drinks from oz and ABV.
* 1 standard drink = 0.6 oz pure alcohol.
@@ -29,6 +32,13 @@ export function computeStandardDrinks(oz, abv) {
return Math.round((pureAlcoholOz / 0.6) * 100) / 100;
}
+/**
+ * Convert standard drinks to grams of pure alcohol.
+ */
+export function drinksToGrams(standardDrinks) {
+ return Math.round(standardDrinks * GRAMS_PER_STD_DRINK * 100) / 100;
+}
+
/**
* Compute rolling averages from daily entries.
*/
@@ -76,21 +86,31 @@ export function computeRollingAverages(entries, sex = 'male') {
allTimeAvg = Math.round((totalDrinks / totalDays) * 100) / 100;
}
- // NIAAA thresholds
+ // NIAAA thresholds (drinks) + longevity thresholds (grams)
const thresholds = sex === 'female'
? { dailyMax: 1, weeklyMax: 7 }
: { dailyMax: 2, weeklyMax: 14 };
+ const gramThresholds = { dailyTarget: 10, dailyDanger: 40 };
const avg7day = rollingAverage(7);
+ const avg30day = rollingAverage(30);
const weeklyTotal = Math.round(avg7day * 7 * 100) / 100;
return {
today: todayDrinks,
avg7day,
- avg30day: rollingAverage(30),
+ avg30day,
allTimeAvg,
weeklyTotal,
thresholds,
+ gramThresholds,
+ grams: {
+ today: drinksToGrams(todayDrinks),
+ avg7day: drinksToGrams(avg7day),
+ avg30day: drinksToGrams(avg30day),
+ allTimeAvg: drinksToGrams(allTimeAvg),
+ weeklyTotal: drinksToGrams(weeklyTotal)
+ },
riskLevel: weeklyTotal > thresholds.weeklyMax ? 'high'
: weeklyTotal > thresholds.weeklyMax * 0.7 ? 'moderate'
: 'low',