Weekly horoscope: its own page, a Monday e-mail, and one page for every e-mail setting
- The week's sky on the member's own chart (horoscope-api POST /v1/week, astro_engine::week): the planets' aspects to the natal points with the day each is exact, positions, the Moon's signs, lunar phases, stations and sign changes; stored once per chart and week (weekly_skies, migration 0047). - Its text is a 'weekly' analysis written by the summary's (cheap) model when the member opens /heti-horoszkop: one month per page, the newest week first, the waiting animation while it is written. In the menu, and linked from the chart page. - Monday 7:00 e-mail (worker task 'weekly'): only that it is there; on by default for everyone with a chart, members of today too. Its footer opens /ertesitesek?token=…, where the weekly e-mail and every forum e-mail can be set without logging in; the mail client's one-click unsubscribe turns off the weekly one. Also a switch on the page and on the Profile page. - Privacy notice (HU/EN) describes it; ratings, admin labels and the model page know the new kind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -7,7 +7,8 @@
|
||||
//! instead, free of charge, so the same chart is never paid for twice.
|
||||
//!
|
||||
//! Every saved chart also gets a free short summary (`summary` kind, written
|
||||
//! by `SUMMARY_MODEL`); the detailed analyses are paid.
|
||||
//! by `SUMMARY_MODEL`); the detailed analyses are paid. The own chart's free
|
||||
//! weekly horoscope (`weekly` kind, see [`super::weekly`]) uses the summary's model.
|
||||
|
||||
use analysis_prompt::Kind;
|
||||
use axum::Json;
|
||||
@@ -18,7 +19,7 @@ use axum_extra::extract::WithRejection;
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Value, json};
|
||||
use sqlx::PgPool;
|
||||
use time::OffsetDateTime;
|
||||
use time::{Date, OffsetDateTime};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::auth::validate_locale;
|
||||
@@ -53,11 +54,14 @@ pub struct AnalysisRow {
|
||||
pub next_attempt_at: OffsetDateTime,
|
||||
/// When the current text was asked for (set again by a regeneration).
|
||||
pub requested_at: OffsetDateTime,
|
||||
/// The Monday of a weekly horoscope.
|
||||
pub week_start: Option<Date>,
|
||||
}
|
||||
|
||||
pub(super) const ANALYSIS_COLUMNS: &str = "id, kind, chart_id, synastry_id, forecast_id, language, prompt_version, status, \
|
||||
content, error, \
|
||||
credits_charged, created_at, completed_at, attempts, next_attempt_at, requested_at";
|
||||
credits_charged, created_at, completed_at, attempts, next_attempt_at, requested_at, \
|
||||
week_start";
|
||||
|
||||
impl AnalysisRow {
|
||||
pub fn view(&self) -> Value {
|
||||
@@ -78,6 +82,7 @@ impl AnalysisRow {
|
||||
"attempts": self.attempts,
|
||||
"next_attempt_at": rfc3339(self.next_attempt_at),
|
||||
"requested_at": rfc3339(self.requested_at),
|
||||
"week_start": self.week_start.map(|d| d.to_string()),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -143,6 +148,12 @@ pub(super) enum Target {
|
||||
chart_id: Uuid,
|
||||
hash: String,
|
||||
},
|
||||
/// The own chart's weekly horoscope (free); `hash` covers the chart and the week.
|
||||
Weekly {
|
||||
chart_id: Uuid,
|
||||
hash: String,
|
||||
week_start: Date,
|
||||
},
|
||||
}
|
||||
|
||||
async fn request(
|
||||
@@ -197,6 +208,11 @@ pub(super) async fn queue(
|
||||
Target::Synastry { synastry_id, hash } => ("synastry", hash, None, Some(*synastry_id), None),
|
||||
Target::Forecast { forecast_id, hash } => ("forecast", hash, None, None, Some(*forecast_id)),
|
||||
Target::Celebrity { chart_id, hash } => ("celebrity", hash, Some(*chart_id), None, None),
|
||||
Target::Weekly { chart_id, hash, .. } => ("weekly", hash, Some(*chart_id), None, None),
|
||||
};
|
||||
let week_start = match target {
|
||||
Target::Weekly { week_start, .. } => Some(*week_start),
|
||||
_ => None,
|
||||
};
|
||||
let (model, fallback) = &crate::models::models_for(state, Kind::parse(kind).expect("known kind")).await?;
|
||||
let (cache_key, prompt_version) = &versions(state, kind, hash, model, language).await?;
|
||||
@@ -225,8 +241,9 @@ pub(super) async fn queue(
|
||||
let insert = format!(
|
||||
"INSERT INTO analyses (id, kind, chart_id, synastry_id, requested_by, language, model, prompt_version, \
|
||||
cache_key, status, content, input_tokens, output_tokens, credits_charged, completed_at, \
|
||||
forecast_id, fallback_model) \
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) RETURNING {ANALYSIS_COLUMNS}"
|
||||
forecast_id, fallback_model, week_start) \
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18) \
|
||||
RETURNING {ANALYSIS_COLUMNS}"
|
||||
);
|
||||
let id = Uuid::now_v7();
|
||||
|
||||
@@ -263,6 +280,7 @@ pub(super) async fn queue(
|
||||
.bind(OffsetDateTime::now_utc())
|
||||
.bind(forecast_id)
|
||||
.bind(fallback)
|
||||
.bind(week_start)
|
||||
.fetch_one(&mut *tx)
|
||||
.await?;
|
||||
tx.commit().await?;
|
||||
@@ -288,6 +306,7 @@ pub(super) async fn queue(
|
||||
.bind(None::<OffsetDateTime>)
|
||||
.bind(forecast_id)
|
||||
.bind(fallback)
|
||||
.bind(week_start)
|
||||
.fetch_one(&mut *tx)
|
||||
.await?;
|
||||
if let Some(unit) = unit {
|
||||
@@ -395,6 +414,14 @@ pub async fn request_for_forecast(
|
||||
/// The hash of what the analysis is about (chart, comparison or forecast),
|
||||
/// part of its cache key; `None` when that was deleted.
|
||||
pub(super) async fn target_hash(db: &PgPool, row: &AnalysisRow) -> Result<Option<String>, sqlx::Error> {
|
||||
if row.kind == "weekly" {
|
||||
let hash: Option<String> = sqlx::query_scalar("SELECT chart_hash FROM charts WHERE id = $1")
|
||||
.bind(row.chart_id)
|
||||
.fetch_optional(db)
|
||||
.await?;
|
||||
let week = row.week_start.map(|d| d.to_string()).unwrap_or_default();
|
||||
return Ok(hash.map(|h| super::weekly::target_hash(&h, &week)));
|
||||
}
|
||||
let (query, id) = match row.kind.as_str() {
|
||||
"synastry" => ("SELECT synastry_hash FROM synastries WHERE id = $1", row.synastry_id),
|
||||
"forecast" => ("SELECT forecast_hash FROM forecasts WHERE id = $1", row.forecast_id),
|
||||
|
||||
Reference in New Issue
Block a user