Daily Control Quality Score — Design Specification

Purpose

Converts a day’s logged control data (sleep, stress, exercise, medication flags, menstrual phase) into a reliability weight between 0.0 and 1.0 for that day’s symptom data. The weight is used by the symptom correlator to determine how much statistical influence each observation has on the correlation.

The critical design decision: this score is per-category, not global. The same day can have quality 0.0 for histamine analysis and quality 0.8 for FODMAP analysis, depending on which flags are active.

Inputs

  • A DailyControl record (sleep_quality, stress_level, sleep_hours, exercise_intensity)
  • That record’s associated DailyControlFlags
  • An optional FoodSensitivityCategory (when nil, returns the global baseline without category-specific adjustments)

Output

A float between 0.0 and 1.0. Higher = more reliable signal for that category on that day.


Spec 1: Baseline Score from Sleep and Stress

What

The baseline score before any flag adjustments is computed from sleep quality and stress level.

Why

Sleep deprivation increases mast cell reactivity and lowers pain thresholds (see Sleep and Histamine). Stress triggers mast cell degranulation directly via CRH (see The HPA Axis and Mast Cells). Both inflate symptom scores independent of food. Days with poor sleep or high stress produce noisier food-symptom data.

Behavior

sleep_score = sleep_quality / 5.0          (nil → 0.5)
stress_score = 1.0 - (stress_level - 1) / 4.0   (nil → 0.5)
baseline = sleep_score × stress_score

A small bonus (0.1) is applied when sleep_hours falls in the 7-9 hour range. The result is clamped to [0.0, 1.0].

Key Properties

  • Perfect conditions (sleep_quality=5, stress_level=1, sleep_hours=8) → ~1.0
  • Worst conditions (sleep_quality=1, stress_level=5) → near 0.0
  • Missing data defaults to 0.5 per missing field — conservative, not optimistic

Spec 2: Per-Category Flag Modifiers

What

Flags are applied as multiplicative discounts to the baseline, and which flags apply depends on the category being evaluated.

Why

Each confounder flag has a specific biochemical mechanism that affects specific mediator pathways. Antihistamines block histamine receptors but have no effect on FODMAP fermentation. NSAIDs inhibit COX enzymes (confounding salicylate analysis) and inhibit DAO (confounding histamine analysis) but don’t affect lectin binding. Applying all flags to all categories throws away valid data.


Spec 3: Antihistamine Flag

Affects: Histamine category only

Biochemical Basis

H1 and H2 antihistamines compete with histamine at receptor sites, blocking vasodilation, gastric acid secretion, itch, and bronchoconstriction. This masks the symptom signal from histamine-mediated food reactions. They have zero effect on FODMAP osmotic/fermentation mechanisms, oxalate crystal deposition, lectin binding, glutamate receptor activation, or capsaicin TRPV1 signaling.

Behavior

  • Histamine category: quality → 0.0 (complete exclusion — the signal is fully masked)
  • All other categories: no modifier applied

Spec 4: NSAID Flag

Affects: Salicylate category (heavily), Histamine category (moderately)

Biochemical Basis

NSAIDs inhibit COX enzymes — the same mechanism as dietary salicylates. Taking ibuprofen and then testing for salicylate sensitivity is testing against a background of pharmaceutical COX inhibition. The signal is contaminated.

NSAIDs also inhibit DAO, reducing histamine clearance capacity. This adds exogenous histamine-pathway noise independent of dietary histamine.

NSAIDs do not affect FODMAP fermentation, lectin binding, or capsaicin signaling.

Behavior

  • Salicylate category: quality × 0.2 (heavy discount — NSAIDs are literally salicylates)
  • Histamine category: quality × 0.5 (moderate discount — DAO inhibition adds noise)
  • All other categories: no modifier

Spec 5: Mast Cell Stabilizer Flag

Affects: Histamine category, Salicylate category

Biochemical Basis

Mast cell stabilizers (cromolyn, ketotifen) prevent degranulation, suppressing release of all mast cell mediators — histamine, prostaglandins, leukotrienes, tryptase. This masks both histamine-mediated symptoms and leukotriene-mediated symptoms (the downstream pathway that salicylate sensitivity works through).

Stabilizers don’t affect FODMAP fermentation or oxalate crystal deposition.

Behavior

  • Histamine category: quality × 0.4
  • Salicylate category: quality × 0.5
  • All other categories: no modifier

Spec 6: Menstrual Phase Flags

Affects: Histamine category only

Biochemical Basis

Estrogen primes mast cells and lowers the degranulation threshold. Progesterone has a partial stabilizing effect. The menstrual cycle creates rhythmic variation in mast cell reactivity:

  • Follicular: Estrogen rising, no progesterone counterbalance. Moderate mast cell priming.
  • Ovulatory: Estrogen peaks. Can be a symptom spike point.
  • Luteal: Progesterone rises significantly and stabilizes mast cells. Despite moderate estrogen, the progesterone counterbalance makes this potentially the best testing window for histamine sensitivity.
  • Perimenstrual: Both hormones drop. Loss of progesterone stabilization. Worst symptom days for many.
  • Menstrual: Low estrogen and progesterone. Prostaglandin release during menstruation adds to mediator load.

The luteal phase is NOT a discount period

A previous version of the science docs incorrectly described the luteal phase as having “low progesterone, relatively higher estrogen.” The luteal phase has the HIGHEST progesterone levels in the cycle. It should not be discounted — it may actually be the cleanest testing window for histamine foods because progesterone is providing mast cell stabilization.

Behavior

  • Perimenstrual phase: histamine quality × 0.5
  • Menstrual phase: histamine quality × 0.5
  • Ovulatory phase: histamine quality × 0.7 (acute estrogen peak)
  • Luteal phase: no modifier (progesterone is stabilizing)
  • Follicular phase: no modifier
  • All other categories: no modifier for any phase

Spec 7: Illness Flag

Affects: All categories

Biochemical Basis

Active illness (cold, flu, infection, autoimmune flare) elevates baseline inflammation across all immune pathways. Cytokines from the illness response interact with mast cell activation, gut permeability increases, and the entire immune system is in an elevated state. Food-symptom data from sick days is contaminated by illness-driven inflammation regardless of category.

Behavior

  • All categories: quality × 0.3

Spec 8: Alcohol Flag

Affects: Histamine category (heavily), All categories (moderately for heavy use)

Biochemical Basis

Alcohol has a triple mechanism for histamine: it contains dietary histamine (in wine/beer), acts as a histamine liberator, AND inhibits DAO. It’s the single strongest histamine confounder.

Heavy alcohol use also increases intestinal permeability acutely, which can affect all categories by allowing more trigger molecules across the gut barrier.

Behavior

  • Histamine category: quality × 0.2 (triple mechanism — nearly as contaminated as antihistamine days)
  • All other categories when heavy alcohol flagged: quality × 0.6
  • All other categories when moderate alcohol flagged: no modifier

Spec 9: Intense Exercise Flag

Affects: All categories, Histamine category more

Biochemical Basis

Intense exercise triggers mast cell activation (exercise-induced histamine release), increases gut permeability temporarily, and raises core temperature (another mast cell trigger). These effects add mediator load independent of food.

Behavior

  • Histamine category: quality × 0.5
  • All other categories: quality × 0.7

Spec 10: Temperature Extreme Flag

Affects: All categories (mildly)

Biochemical Basis

Heat and cold are both direct mast cell triggers — heat through membrane fluidity changes, cold through ion channel activation. Extreme temperature days add non-food mediator load.

Behavior

  • All categories: quality × 0.8

Spec 11: Flag Stacking

What

Multiple flags on the same day compound multiplicatively.

Why

A day with alcohol + poor sleep + perimenstrual phase is worse for histamine-category analysis than any single factor alone. Each mechanism adds independent noise.

Behavior

Start with the baseline score. Apply each applicable flag modifier in sequence by multiplication. Clamp the final result to [0.0, 1.0].

Example for histamine category: baseline 0.64 × alcohol 0.2 × perimenstrual 0.5 = 0.064. This day contributes almost nothing to histamine-category correlations.


Spec 12: Fasting State and Osmotic Context

Affects: All categories (as an attribution confounder, not a quality discount)

What

The system should capture whether a meal was eaten on an empty or near-empty stomach, and whether concentrated beverages (electrolyte solutions, supplements) were consumed on minimal food. This is not a quality score modifier — it’s a confounding context flag that the correlator uses to identify potential osmotic/mechanical symptom drivers.

Why

A concentrated electrolyte solution on an empty stomach produces osmotic distension and gastrocolic reflex activation that mimics food sensitivity reactions. Without this context, the correlator attributes the resulting symptoms to whatever food was eaten closest to the symptom onset. This produces false positives for food ingredients and false negatives for the actual driver (meal timing and osmotic load).

See Gastrocolic Reflex and Osmotic Dumping for the full mechanism. In brief: hyperosmolar solutions on an empty stomach pass rapidly through the pylorus, draw water into the small bowel, distend the gut wall, mechanically activate mast cells, and trigger the gastrocolic reflex — all within 15-30 minutes. The symptoms (bloating, cramping, nausea) are identical to food sensitivity reactions but are driven by the conditions of eating, not the food itself.

Behavior

This is captured as a meal-level flag (on the Meal record or as a DailyControlFlag), not a day-level quality modifier:

  • fasting_state: fed / light / fasted — how much the user had eaten before this meal. fasted = nothing or trivial food in the preceding 4+ hours.
  • concentrated_beverage: boolean — whether a concentrated electrolyte, supplement, or hyperosmolar drink was consumed within 1 hour before the meal on limited food.

How the Correlator Uses It

The correlator does NOT discount these days across the board — the food data may still be valid. Instead, when a symptom is attributed to a meal that has a fasted + concentrated_beverage context, the correlator flags this observation as potentially confounded by osmotic load. If the same food produces symptoms both with and without fasting context, the food signal is real. If the food only produces symptoms when eaten on an empty stomach after electrolytes, the osmotic context is the driver.

Over multiple observations, this pattern separates out naturally: the fasting flag becomes an explanatory variable that either correlates with symptoms (osmotic driver) or doesn’t (food driver). The v0.2 mixed effects model can include fasting state as a covariate directly.

User-Facing Communication

“You logged symptoms after garlic chicken today. We noticed you’d also had electrolytes on an empty stomach. Some of today’s symptoms may be related to meal timing rather than the food itself. We’ll track this pattern over time.”

This is not a dismissal of the symptom. It’s context that helps the user (and the model) distinguish food chemistry from meal mechanics.


Dependencies

  • DailyControl and DailyControlFlag models
  • FoodSensitivityCategory for per-category dispatch

Consumers

  • Symptom Correlator — uses quality scores as observation weights, uses fasting context for attribution
  • User-facing daily log display — “This day is marked as lower confidence due to [flag]”