Analytics review fixes: - Store Twitter analytics coverage as discrete intervals instead of a single contiguous window so disjoint fetch ranges no longer mask inner gaps as covered (fetch per uncovered range, add gap regression tests) - Compute real AvgEngagement/Correlation in getEngagementDrivers instead of all-zero placeholders - Make parseAnalyticsTimeRange surface invalid timestamps, cap merged analytics posts at limit, and normalize sentiment by timestamped posts only - gofmt: fix misalignment in config.go and types.go - Include Twitter in the default aggregate analytics scope; its API costs are passed to the caller through paid tool pricing x402 cost passing: - computeTwitterStyleProfileCost now charges base cost ($0.10) + user lookup ($0.01) + $0.005 per Twitter post, guaranteeing the charge always clears the underlying API cost (never break-even or loss) - Return a $-prefixed dollar string for the settlement override, fixing the previously off-by-factor-100 raw-atomic-unit amount - Raise getStyleProfile base registration to $0.36 to authorize the max Twitter charge - Add tests for the cost formula, profitable floor, and dollar formatting
113 lines
2.6 KiB
Go
113 lines
2.6 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: AnalyticsPosts.sql
|
|
|
|
package store
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
const getAnalyticsPostsInRange = `-- name: GetAnalyticsPostsInRange :many
|
|
SELECT post_id, post_text, post_timestamp, likes, reposts, replies, quotes
|
|
FROM analytics_posts
|
|
WHERE user_id = $1 AND platform = $2 AND post_timestamp >= $3 AND post_timestamp <= $4
|
|
ORDER BY post_timestamp DESC
|
|
LIMIT $5
|
|
`
|
|
|
|
type GetAnalyticsPostsInRangeParams struct {
|
|
UserID string
|
|
Platform string
|
|
PostTimestamp time.Time
|
|
PostTimestamp_2 time.Time
|
|
Limit int32
|
|
}
|
|
|
|
type GetAnalyticsPostsInRangeRow struct {
|
|
PostID string
|
|
PostText string
|
|
PostTimestamp time.Time
|
|
Likes int64
|
|
Reposts int64
|
|
Replies int64
|
|
Quotes int64
|
|
}
|
|
|
|
func (q *Queries) GetAnalyticsPostsInRange(ctx context.Context, arg GetAnalyticsPostsInRangeParams) ([]GetAnalyticsPostsInRangeRow, error) {
|
|
rows, err := q.db.QueryContext(ctx, getAnalyticsPostsInRange,
|
|
arg.UserID,
|
|
arg.Platform,
|
|
arg.PostTimestamp,
|
|
arg.PostTimestamp_2,
|
|
arg.Limit,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetAnalyticsPostsInRangeRow
|
|
for rows.Next() {
|
|
var i GetAnalyticsPostsInRangeRow
|
|
if err := rows.Scan(
|
|
&i.PostID,
|
|
&i.PostText,
|
|
&i.PostTimestamp,
|
|
&i.Likes,
|
|
&i.Reposts,
|
|
&i.Replies,
|
|
&i.Quotes,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const upsertAnalyticsPosts = `-- name: UpsertAnalyticsPosts :exec
|
|
INSERT INTO analytics_posts (user_id, platform, post_id, post_text, post_timestamp, likes, reposts, replies, quotes)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
ON CONFLICT (user_id, platform, post_id)
|
|
DO UPDATE SET post_text = EXCLUDED.post_text,
|
|
post_timestamp = EXCLUDED.post_timestamp,
|
|
likes = EXCLUDED.likes,
|
|
reposts = EXCLUDED.reposts,
|
|
replies = EXCLUDED.replies,
|
|
quotes = EXCLUDED.quotes
|
|
`
|
|
|
|
type UpsertAnalyticsPostsParams struct {
|
|
UserID string
|
|
Platform string
|
|
PostID string
|
|
PostText string
|
|
PostTimestamp time.Time
|
|
Likes int64
|
|
Reposts int64
|
|
Replies int64
|
|
Quotes int64
|
|
}
|
|
|
|
func (q *Queries) UpsertAnalyticsPosts(ctx context.Context, arg UpsertAnalyticsPostsParams) error {
|
|
_, err := q.db.ExecContext(ctx, upsertAnalyticsPosts,
|
|
arg.UserID,
|
|
arg.Platform,
|
|
arg.PostID,
|
|
arg.PostText,
|
|
arg.PostTimestamp,
|
|
arg.Likes,
|
|
arg.Reposts,
|
|
arg.Replies,
|
|
arg.Quotes,
|
|
)
|
|
return err
|
|
}
|