Path: blob/master/src/packages/util/licenses/purchase/consts.ts
6022 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { CustomUpgrades, Subscription, User } from "./types";6import costVersions from "./cost-versions";78export const CURRENT_VERSION = "3";910// Another gamble implicit in this is that pre's are available. When they11// aren't, cocalc.com switches to uses MUCH more expensive non-preemptibles.1213export interface CostMap {14ram: number;15dedicated_ram: number;16cpu: number;17dedicated_cpu: number;18disk: number;19always_running: number;20member: number;21}2223// BASIC, STANDARD and MAX have nothing to do with defining pricing. They24// are just some presets that might have been used at some point (?).2526export const BASIC: CostMap = {27ram: 1,28cpu: 1,29disk: 3,30dedicated_ram: 0,31dedicated_cpu: 0,32always_running: 0,33member: 1,34} as const;3536export const STANDARD: CostMap = {37ram: 2,38cpu: 2,39dedicated_ram: 0,40dedicated_cpu: 0,41disk: 3,42always_running: 0,43member: 1,44} as const;4546export const MAX: CostMap = {47ram: 16,48cpu: 3,49dedicated_ram: 8,50dedicated_cpu: 2,51disk: 20,52always_running: 1,53member: 1,54} as const;5556export const MIN_QUOTE = 100;5758interface GoogleComputeEngine {59ram: number;60cpu: number;61disk: number;62non_pre_factor: number;63}6465interface CostsStructure {66version: string;6768// these are critical to defining and computing the cost of a license69user_discount: { [user in User]: number };70sub_discount: { [sub in Subscription]: number };71custom_cost: { [key in CustomUpgrades]: number };72custom_max: { [key in CustomUpgrades]: number };73gce: GoogleComputeEngine;7475// not even sure if any of this is ever used anymore -- it's generic.76min_quote: number;77basic: { [key in CustomUpgrades]: number };78standard: { [key in CustomUpgrades]: number };79max: { [key in CustomUpgrades]: number };80}8182export function getCosts(version: string): CostsStructure {83const {84SUB_DISCOUNT,85GCE_COSTS,86COST_MULTIPLIER,87NONMEMBER_DENSITY,88ACADEMIC_DISCOUNT,89DISK_FACTOR,90RAM_OVERCOMMIT,91CPU_OVERCOMMIT,92ALWAYS_RUNNING_FACTOR,93} = costVersions[version] ?? costVersions[CURRENT_VERSION];9495const CUSTOM_COST: CostMap = {96ram:97(COST_MULTIPLIER * GCE_COSTS.ram) / ACADEMIC_DISCOUNT / NONMEMBER_DENSITY,98dedicated_ram:99(RAM_OVERCOMMIT * (COST_MULTIPLIER * GCE_COSTS.ram)) /100ACADEMIC_DISCOUNT /101NONMEMBER_DENSITY,102cpu:103(COST_MULTIPLIER * GCE_COSTS.cpu) / ACADEMIC_DISCOUNT / NONMEMBER_DENSITY,104dedicated_cpu:105(CPU_OVERCOMMIT * (COST_MULTIPLIER * GCE_COSTS.cpu)) /106ACADEMIC_DISCOUNT /107NONMEMBER_DENSITY,108disk: (DISK_FACTOR * COST_MULTIPLIER * GCE_COSTS.disk) / ACADEMIC_DISCOUNT,109always_running: ALWAYS_RUNNING_FACTOR,110member: NONMEMBER_DENSITY,111} as const;112113return {114version,115116user_discount: { academic: ACADEMIC_DISCOUNT, business: 1 },117sub_discount: SUB_DISCOUNT,118custom_cost: CUSTOM_COST,119custom_max: MAX,120gce: GCE_COSTS,121122min_quote: MIN_QUOTE,123basic: BASIC,124standard: STANDARD,125max: MAX,126} as const;127}128129const COSTS = getCosts(CURRENT_VERSION);130export { COSTS };131132export const discount_pct = Math.round(133(1 - COSTS.user_discount["academic"]) * 100,134);135136export const discount_monthly_pct = Math.round(137(1 - COSTS.sub_discount["monthly"]) * 100,138);139140export const discount_yearly_pct = Math.round(141(1 - COSTS.sub_discount["yearly"]) * 100,142);143144145