Comparisons (synastry) of the own chart and persons
CI / test (push) Successful in 45s
CI / build (push) Successful in 4m19s
CI / deploy (push) Skipped

/osszevetesek compares any two of the user's charts (own and persons); the
person card and the person's chart page have "Összevetés velem". The
comparison page shows a double wheel (first person inside with houses, second
outside, aspects between them), the aspects by character, and tabs: paid
relationship analysis (synastry unit), the cross aspect grid, house overlays,
composite and the full aspect list.

Correcting a person within the hour now deletes the user's own comparisons
with them instead of being refused; still refused after a paid analysis or
when someone else's comparison uses the chart.

The relationship analysis prompt is editable on /admin/promptok too, and can be
tried on one of the admin's comparisons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-17 16:04:44 +00:00
co-authored by Claude Opus 5.5
parent b77dafdb26
commit 0bd5c39080
27 changed files with 1541 additions and 146 deletions
+66 -56
View File
@@ -27,7 +27,7 @@ use crate::error::{ApiError, ApiResult};
use crate::views::{rfc3339, rfc3339_opt};
/// The kinds whose prompt the admin page edits.
const EDITABLE: [Kind; 2] = [Kind::Summary, Kind::Natal];
const EDITABLE: [Kind; 3] = [Kind::Summary, Kind::Natal, Kind::Synastry];
const MAX_CHARS: usize = 50_000;
const HISTORY: i64 = 20;
/// Test runs of one admin waiting or being written at the same time.
@@ -158,55 +158,46 @@ pub async fn save(
pub struct StartPreview {
/// The draft to try (it need not be saved).
system: String,
/// One of the admin's own charts (own or a person).
chart_id: Uuid,
/// One of the admin's own charts (own or a person), for a summary or natal analysis.
chart_id: Option<Uuid>,
/// One of the admin's own comparisons, for a synastry analysis.
synastry_id: Option<Uuid>,
}
type PreviewRow = (
Uuid,
String,
Uuid,
String,
String,
String,
Option<Value>,
Option<String>,
Option<String>,
Option<i32>,
Option<i32>,
Option<f64>,
OffsetDateTime,
Option<OffsetDateTime>,
Option<OffsetDateTime>,
);
#[derive(sqlx::FromRow)]
struct PreviewRow {
id: Uuid,
kind: String,
chart_id: Option<Uuid>,
synastry_id: Option<Uuid>,
language: String,
model: String,
status: String,
content: Option<Value>,
error: Option<String>,
model_used: Option<String>,
input_tokens: Option<i32>,
output_tokens: Option<i32>,
cost_usd: Option<f64>,
created_at: OffsetDateTime,
started_at: Option<OffsetDateTime>,
completed_at: Option<OffsetDateTime>,
}
const PREVIEW_COLUMNS: &str = "id, kind, chart_id, language, model, status, content, error, model_used, \
const PREVIEW_COLUMNS: &str = "id, kind, chart_id, synastry_id, language, model, status, content, error, model_used, \
input_tokens, output_tokens, cost_usd, created_at, started_at, completed_at";
fn preview_view(row: PreviewRow) -> Value {
let (
id,
kind,
chart_id,
language,
model,
status,
content,
error,
model_used,
input,
output,
cost,
created,
started,
completed,
) = row;
let seconds = started.zip(completed).map(|(s, c)| (c - s).whole_seconds());
json!({
"id": id, "kind": kind, "chart_id": chart_id, "language": language, "model": model, "status": status,
"content": content, "error": error, "model_used": model_used, "input_tokens": input, "output_tokens": output,
"cost_usd": cost, "created_at": rfc3339(created), "completed_at": rfc3339_opt(completed), "seconds": seconds,
})
impl PreviewRow {
fn view(self) -> Value {
let seconds = self.started_at.zip(self.completed_at).map(|(s, c)| (c - s).whole_seconds());
json!({
"id": self.id, "kind": self.kind, "chart_id": self.chart_id, "synastry_id": self.synastry_id,
"language": self.language, "model": self.model, "status": self.status, "content": self.content,
"error": self.error, "model_used": self.model_used, "input_tokens": self.input_tokens,
"output_tokens": self.output_tokens, "cost_usd": self.cost_usd, "created_at": rfc3339(self.created_at),
"completed_at": rfc3339_opt(self.completed_at), "seconds": seconds,
})
}
}
pub async fn start_preview(
@@ -217,12 +208,30 @@ pub async fn start_preview(
) -> ApiResult<(StatusCode, Json<Value>)> {
let kind = parse_target(&state, &kind, &language)?;
let system = clean_system(&req.system)?;
let own: Option<(Uuid,)> = sqlx::query_as("SELECT id FROM charts WHERE id = $1 AND owner_id = $2")
.bind(req.chart_id)
.bind(admin.id())
.fetch_optional(&state.db)
.await?;
own.ok_or(ApiError::NotFound("chart"))?;
// The target must be the admin's own: a chart, or for a synastry analysis a comparison.
let (chart_id, synastry_id, found) = match (kind, req.chart_id, req.synastry_id) {
(Kind::Synastry, None, Some(id)) => {
let row: Option<(Uuid,)> = sqlx::query_as("SELECT id FROM synastries WHERE id = $1 AND owner_id = $2")
.bind(id)
.bind(admin.id())
.fetch_optional(&state.db)
.await?;
(None, Some(id), row.map(|_| "synastry"))
}
(Kind::Summary | Kind::Natal, Some(id), None) => {
let row: Option<(Uuid,)> = sqlx::query_as("SELECT id FROM charts WHERE id = $1 AND owner_id = $2")
.bind(id)
.bind(admin.id())
.fetch_optional(&state.db)
.await?;
(Some(id), None, row.map(|_| "chart"))
}
(Kind::Synastry, ..) => return Err(ApiError::BadRequest("a synastry analysis needs synastry_id".into())),
_ => return Err(ApiError::BadRequest("this analysis needs chart_id".into())),
};
if found.is_none() {
return Err(ApiError::NotFound(if synastry_id.is_some() { "synastry" } else { "chart" }));
}
let (open,): (i64,) = sqlx::query_as(
"SELECT count(*) FROM prompt_previews WHERE created_by = $1 AND status IN ('pending', 'running')",
)
@@ -240,19 +249,20 @@ pub async fn start_preview(
_ => &state.config.analysis_model,
};
let row: PreviewRow = sqlx::query_as(&format!(
"INSERT INTO prompt_previews (id, kind, chart_id, language, model, system, created_by) \
VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING {PREVIEW_COLUMNS}"
"INSERT INTO prompt_previews (id, kind, chart_id, synastry_id, language, model, system, created_by) \
VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING {PREVIEW_COLUMNS}"
))
.bind(Uuid::now_v7())
.bind(kind.as_str())
.bind(req.chart_id)
.bind(chart_id)
.bind(synastry_id)
.bind(&language)
.bind(model)
.bind(&system)
.bind(admin.id())
.fetch_one(&state.db)
.await?;
Ok((StatusCode::ACCEPTED, Json(preview_view(row))))
Ok((StatusCode::ACCEPTED, Json(row.view())))
}
pub async fn get_preview(
@@ -266,5 +276,5 @@ pub async fn get_preview(
.bind(admin.id())
.fetch_optional(&state.db)
.await?;
Ok(Json(preview_view(row.ok_or(ApiError::NotFound("preview"))?)))
Ok(Json(row.ok_or(ApiError::NotFound("preview"))?.view()))
}