Yearly forecast: solar return, transits, progressions, profection, eclipses
- astro-engine: forecast module (solar return moment, slow-planet transits
with exact dates and periods, natal house ingresses, secondary
progressions, annual profection, eclipses via Swiss Ephemeris)
- horoscope-api: POST /v1/forecast, solar return chart cast for the place
of the birthday
- backend: forecasts table, /v1/charts/{id}/forecasts, /v1/forecasts/{id}
and its analyses using a new 'forecast' unit; current year of life open,
the next one 30 days before the birthday
- packages: Páros and Család include forecasts (6 000 / 11 000 Ft),
+1 éves előrejelzés add-on 2 500 Ft; Egy elemzés unchanged
- worker and prompt: forecast kind with five sections and forecast rules
(trends, no event predictions); no birth data, place or exact age sent
- frontend: /kepletek/{id}/elorejelzes with the solar return wheel, the
keys of the year, a monthly timeline, transit list and detailed forecast
- data export: forecasts added, model name removed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -280,6 +280,218 @@ pub fn synastry(chart1: &Value, chart2: &Value, result: &Value) -> String {
|
||||
out
|
||||
}
|
||||
|
||||
/// "2026-08-03, 2027-01-15 (retrograde)" from a list of exact hits.
|
||||
fn exact_dates(list: &Value) -> String {
|
||||
list.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(|e| {
|
||||
let date = e["date"].as_str().unwrap_or("?");
|
||||
if e["retrograde"].as_bool() == Some(true) { format!("{date} (retrograde)") } else { date.to_string() }
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
}
|
||||
|
||||
/// One contact of a transiting or progressed planet with a natal point.
|
||||
fn contact_line(out: &mut String, c: &Value, moving: &str) {
|
||||
let planet = c["planet"].as_str().unwrap_or("?");
|
||||
let natal = c["natal_point"].as_str().unwrap_or("?");
|
||||
let mut line = format!(
|
||||
"- {moving}{} {} natal {} ({})",
|
||||
point_name(planet),
|
||||
words(c["aspect"].as_str().unwrap_or("?")),
|
||||
point_name(natal),
|
||||
c["nature"].as_str().unwrap_or("neutral")
|
||||
);
|
||||
// A planet back at its own natal place (or in aspect to it, for transits): a life cycle.
|
||||
if planet == natal && (moving.is_empty() || c["aspect"] == "conjunction") {
|
||||
line.push_str(", cycle");
|
||||
}
|
||||
let exact = exact_dates(&c["exact"]);
|
||||
if exact.is_empty() {
|
||||
let _ = write!(
|
||||
line,
|
||||
": not exact this year, closest {:.1}° around {}",
|
||||
c["min_orb"].as_f64().unwrap_or(0.0),
|
||||
c["peak"].as_str().unwrap_or("?")
|
||||
);
|
||||
} else {
|
||||
let _ = write!(line, ": exact {exact}");
|
||||
}
|
||||
let periods: Vec<String> = c["periods"]
|
||||
.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(|p| format!("{} to {}", p["start"].as_str().unwrap_or("?"), p["end"].as_str().unwrap_or("?")))
|
||||
.collect();
|
||||
if !periods.is_empty() {
|
||||
let _ = write!(line, "; within orb {}", periods.join(", "));
|
||||
}
|
||||
if let Some(h) = c["house"].as_i64() {
|
||||
let _ = write!(line, "; {moving}{} in natal house {h}", point_name(planet));
|
||||
}
|
||||
let _ = writeln!(out, "{line}");
|
||||
}
|
||||
|
||||
/// One year of a chart: the natal chart, then the stored horoscope-api
|
||||
/// `/v1/forecast` result (solar return chart, profection, transits,
|
||||
/// progressions, eclipses). The place of the birthday and the exact age are
|
||||
/// left out; the age goes in by decade.
|
||||
pub fn forecast(chart: &Value, result: &Value) -> String {
|
||||
let f = &result["forecast"];
|
||||
let known = time_known(chart);
|
||||
let mut out = format!(
|
||||
"YEARLY FORECAST: one year of life, from the solar return on {} to the next one on {}.\n",
|
||||
f["start"].as_str().unwrap_or("?"),
|
||||
f["end"].as_str().unwrap_or("?")
|
||||
);
|
||||
if let Some(age) = f["age"].as_i64() {
|
||||
let _ = writeln!(out, "Age group: {}s.", age / 10 * 10);
|
||||
}
|
||||
out.push('\n');
|
||||
out.push_str(&natal(chart));
|
||||
|
||||
let sr = &result["solar_return"];
|
||||
if sr.is_object() {
|
||||
out.push_str("\nSOLAR RETURN CHART (cast for the moment of the solar return at the place of the birthday):\n");
|
||||
angle_lines(&mut out, sr, "");
|
||||
if let Some(h) = sr["natal_house_of_ascendant"].as_i64() {
|
||||
let _ = writeln!(out, "- The solar return Ascendant falls in natal house {h}.");
|
||||
}
|
||||
point_lines(&mut out, sr, "", true);
|
||||
aspect_lines(&mut out, &sr["aspects"], "Solar return aspects (tightest first):", 15);
|
||||
} else {
|
||||
out.push_str("\nSOLAR RETURN CHART: none, because the birth time is unknown.\n");
|
||||
}
|
||||
|
||||
let p = &f["profection"];
|
||||
if p.is_object() {
|
||||
let planets = names(&p["planets_in_sign"]);
|
||||
let _ = writeln!(
|
||||
out,
|
||||
"\nANNUAL PROFECTION: the year activates natal house {} ({}); lord of the year: {} (natal {} in {}, house {}).{}",
|
||||
p["house"],
|
||||
capitalize(p["sign"].as_str().unwrap_or("?")),
|
||||
point_name(p["lord"].as_str().unwrap_or("?")),
|
||||
point_name(p["lord"].as_str().unwrap_or("?")),
|
||||
capitalize(p["lord_sign"].as_str().unwrap_or("?")),
|
||||
p["lord_house"],
|
||||
if planets.is_empty() { String::new() } else { format!(" Natal planets in that sign: {planets}.") }
|
||||
);
|
||||
}
|
||||
|
||||
out.push_str("\nSLOW-PLANET TRANSITS to the natal chart (orb 1°; in order of their peak; dates are local days):\n");
|
||||
let transits = f["transits"].as_array().map(Vec::as_slice).unwrap_or_default();
|
||||
if transits.is_empty() {
|
||||
out.push_str("- none\n");
|
||||
}
|
||||
for c in transits {
|
||||
contact_line(&mut out, c, "");
|
||||
}
|
||||
|
||||
let houses = f["transit_houses"].as_array().map(Vec::as_slice).unwrap_or_default();
|
||||
if known && !houses.is_empty() {
|
||||
out.push_str("\nSlow planets in the natal houses:\n");
|
||||
for h in houses {
|
||||
let mut line = format!(
|
||||
"- {}: house {} at the start",
|
||||
point_name(h["planet"].as_str().unwrap_or("?")),
|
||||
h["house_at_start"]
|
||||
);
|
||||
for i in h["ingresses"].as_array().into_iter().flatten() {
|
||||
let retro = if i["retrograde"].as_bool() == Some(true) { " (retrograde)" } else { "" };
|
||||
let _ = write!(line, "; enters house {} on {}{retro}", i["house"], i["date"].as_str().unwrap_or("?"));
|
||||
}
|
||||
let _ = writeln!(out, "{line}");
|
||||
}
|
||||
}
|
||||
|
||||
let prog = &f["progressions"];
|
||||
out.push_str("\nSECONDARY PROGRESSIONS (a day for a year), at the start of the year:\n");
|
||||
for b in prog["bodies"].as_array().into_iter().flatten() {
|
||||
let mut line = format!("- Progressed {}: {}", point_name(b["planet"].as_str().unwrap_or("?")), position(b));
|
||||
if let Some(h) = b["house"].as_i64() {
|
||||
let _ = write!(line, ", natal house {h}");
|
||||
}
|
||||
if b["retrograde"].as_bool() == Some(true) {
|
||||
line.push_str(", retrograde");
|
||||
}
|
||||
if b["approximate"].as_bool() == Some(true) {
|
||||
line.push_str(" (uncertain: the birth time is unknown)");
|
||||
}
|
||||
for i in b["sign_changes"].as_array().into_iter().flatten() {
|
||||
let _ = write!(
|
||||
line,
|
||||
"; enters {} on {}",
|
||||
capitalize(i["sign"].as_str().unwrap_or("?")),
|
||||
i["date"].as_str().unwrap_or("?")
|
||||
);
|
||||
}
|
||||
for i in b["house_changes"].as_array().into_iter().flatten() {
|
||||
let _ = write!(line, "; enters natal house {} on {}", i["house"], i["date"].as_str().unwrap_or("?"));
|
||||
}
|
||||
let _ = writeln!(out, "{line}");
|
||||
}
|
||||
if let Some(phase) = prog["lunar_phase"].as_str() {
|
||||
let change = &prog["lunar_phase_change"];
|
||||
let change = if change.is_object() {
|
||||
format!(
|
||||
", turns {} on {}",
|
||||
words(change["phase"].as_str().unwrap_or("?")),
|
||||
change["date"].as_str().unwrap_or("?")
|
||||
)
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
let _ = writeln!(out, "- Progressed lunation phase: {}{change}", words(phase));
|
||||
}
|
||||
let contacts = prog["contacts"].as_array().map(Vec::as_slice).unwrap_or_default();
|
||||
if !contacts.is_empty() {
|
||||
out.push_str("Progressed planets in aspect to natal points (orb 1°):\n");
|
||||
for c in contacts {
|
||||
contact_line(&mut out, c, "progressed ");
|
||||
}
|
||||
}
|
||||
|
||||
let eclipses = f["eclipses"].as_array().map(Vec::as_slice).unwrap_or_default();
|
||||
if !eclipses.is_empty() {
|
||||
out.push_str("\nECLIPSES during the year:\n");
|
||||
for e in eclipses {
|
||||
let mut line = format!(
|
||||
"- {}: {} {} eclipse at {}",
|
||||
e["date"].as_str().unwrap_or("?"),
|
||||
e["eclipse_type"].as_str().unwrap_or("?"),
|
||||
e["kind"].as_str().unwrap_or("?"),
|
||||
position(e)
|
||||
);
|
||||
if let Some(h) = e["house"].as_i64() {
|
||||
let _ = write!(line, ", natal house {h}");
|
||||
}
|
||||
let hits: Vec<String> = e["contacts"]
|
||||
.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(|c| {
|
||||
format!(
|
||||
"{} natal {} (orb {:.1}°)",
|
||||
words(c["aspect"].as_str().unwrap_or("?")),
|
||||
point_name(c["point"].as_str().unwrap_or("?")),
|
||||
c["orb"].as_f64().unwrap_or(0.0)
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
if hits.is_empty() {
|
||||
line.push_str("; no close contact with the natal chart");
|
||||
} else {
|
||||
let _ = write!(line, "; {}", hits.join(", "));
|
||||
}
|
||||
let _ = writeln!(out, "{line}");
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Aspects between main points and angles, tightest first.
|
||||
fn aspect_lines(out: &mut String, aspects: &Value, heading: &str, limit: usize) {
|
||||
let mut list: Vec<&Value> = aspects
|
||||
@@ -362,6 +574,32 @@ mod tests {
|
||||
assert!(text.contains("- Venus: Libra 4°12', domicile"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forecast_view() {
|
||||
// The stored horoscope-api /v1/forecast result of the chart below (year 2026).
|
||||
let text = forecast(&fixture("natal-1990-03-15.json"), &fixture("forecast-1990-03-15.json"));
|
||||
assert_private(&text);
|
||||
for expected in [
|
||||
"YEARLY FORECAST: one year of life, from the solar return on 2026-03-15 to the next one on 2027-03-15.",
|
||||
"Age group: 30s.",
|
||||
"NATAL CHART",
|
||||
"SOLAR RETURN CHART (cast for",
|
||||
"- The solar return Ascendant falls in natal house 10.",
|
||||
"ANNUAL PROFECTION: the year activates natal house 1 (Leo); lord of the year: Sun",
|
||||
"- progressed Moon trine natal Moon (harmonious): exact 2027-02-24",
|
||||
"- Neptune sextile natal Mars (harmonious): exact 2026-04-19, 2026-09-30 (retrograde), 2027-02-20",
|
||||
"Slow planets in the natal houses:",
|
||||
"SECONDARY PROGRESSIONS",
|
||||
"- Progressed lunation phase:",
|
||||
"ECLIPSES during the year:",
|
||||
] {
|
||||
assert!(text.contains(expected), "missing '{expected}' in:\n{text}");
|
||||
}
|
||||
for absent in ["Europe/Budapest", "08:02", "Age group: 36", "36s"] {
|
||||
assert!(!text.contains(absent), "'{absent}' in:\n{text}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn synastry_view() {
|
||||
// The full horoscope-api response, with both persons' birth data in it.
|
||||
|
||||
Reference in New Issue
Block a user