惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
小众软件
小众软件
爱范儿
爱范儿
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
量子位
博客园_首页
T
Tailwind CSS Blog
The Cloudflare Blog
J
Java Code Geeks
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
U
Unit 42
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
N
Netflix TechBlog - Medium
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
腾讯CDC
P
Proofpoint News Feed
aimingoo的专栏
aimingoo的专栏
Recent Announcements
Recent Announcements
T
The Blog of Author Tim Ferriss
D
Docker
Microsoft Azure Blog
Microsoft Azure Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Computing a real, point-inclusive price
Aulvem · 2026-06-20 · via DEV Community

Aulvem

"Option A has the lower sticker price, but option B gives more points back — so which is actually cheaper?" You want to answer that in code. The naive version is one line:

const effectivePrice = displayPrice - totalPoints; // this inflates the number

But subtract every point and you're in trouble. Entry-required campaigns and your own loyalty multiplier get folded in, so the "cheapest" becomes a price you only reach if every condition is met — not a floor anyone can count on. The cause is mixing points you'll definitely get with points you might get.

I hit this while computing points for Japanese marketplaces (Rakuten, Yahoo!), and settled on splitting points by certainty into three layers. The code is short; the idea is the point.

Split points by certainty into three layers

Layer Contents Used for ranking
① Confirmed Actual points the API returns Yes
② Conditional Known campaigns ("5 and 0 days", etc.) No
③ Assumed Your own loyalty multiplier / shop-hopping No

Rank on the confirmed layer only, and show ② and ③ as "the most it could drop." The order comes out the same for everyone, and the upside flexes per person. It also avoids the behavior where whoever inflates their loyalty settings most reshuffles the top.

Minimal implementation

Floor each layer before summing. Sum first and floor once, and you land a few yen off the real grant.

type Tier = "confirmed" | "conditional" | "assumed";

function computeEffectivePrice(
  base: number,
  layers: { rate: number; cap?: number; tier: Tier }[],
) {
  let confirmed = 0,
    conditional = 0,
    assumed = 0;
  for (const l of layers) {
    let pts = Math.floor(base * l.rate); // floor per layer
    if (l.cap != null) pts = Math.min(pts, l.cap); // cap applies after floor
    if (l.tier === "confirmed") confirmed += pts;
    else if (l.tier === "conditional") conditional += pts;
    else assumed += pts;
  }
  const rankKey = base - confirmed; // ranking subtracts the confirmed layer only
  const total = confirmed + conditional + assumed;
  const effectivePrice = Math.max(0, base - total); // display subtracts all, guarded
  return { rankKey, effectivePrice };
}

The ranking key (rankKey) subtracts only the confirmed layer; the displayed effectivePrice subtracts every layer. Same price, different layers for ranking versus display — that's the crux. High-reward items can push total points past the price, so Math.max(0, …) guards against a negative.

Gotchas

  • Floor order: the cap takes Math.min against the floored point-yen. Cap first, floor second, and you're off by one. Real grants are usually floored per campaign too, so per-layer flooring lands closer to the actual amount.
  • Store rates as the increment: a campaign's "+4×" is the added grant on top of the tax-inclusive price. Multiply by the raw multiplier and you double-count the standard points everyone already gets. The base 1× is increment zero.

Wrapping up

A real price reads as "sticker minus points" in one line, but a trustworthy one needs the certainty split: rank on the confirmed layer, show conditional and assumed as a range, floor per layer before summing. That alone prevents "the cheapest one was actually conditional."

Leaving shipping out (no marketplace API returns it, so I don't guess), disclosing entry/cap requirements, and wiring this into price history and notifications are on the Aulvem site → Computing the real, point-inclusive price across marketplaces