Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/util/licenses/purchase/consts.ts
Views: 687
/*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";67import costVersions from "./cost-versions";89// version for licenses before we were using versioning; this is what10// is used when the version is not defined.11const FALLBACK_VERSION = "1";1213export const CURRENT_VERSION = "1";1415// Another gamble implicit in this is that pre's are available. When they16// aren't, cocalc.com switches to uses MUCH more expensive non-preemptibles.1718export interface CostMap {19ram: number;20dedicated_ram: number;21cpu: number;22dedicated_cpu: number;23disk: number;24always_running: number;25member: number;26}2728// BASIC, STANDARD and MAX have nothing to do with defining pricing. They29// are just some presets that might have been used at some point (?).3031export const BASIC: CostMap = {32ram: 1,33cpu: 1,34disk: 3,35dedicated_ram: 0,36dedicated_cpu: 0,37always_running: 0,38member: 1,39} as const;4041export const STANDARD: CostMap = {42ram: 2,43cpu: 2,44dedicated_ram: 0,45dedicated_cpu: 0,46disk: 3,47always_running: 0,48member: 1,49} as const;5051export const MAX: CostMap = {52ram: 16,53cpu: 3,54dedicated_ram: 8,55dedicated_cpu: 2,56disk: 20,57always_running: 1,58member: 1,59} as const;6061export const MIN_QUOTE = 100;6263interface GoogleComputeEngine {64ram: number;65cpu: number;66disk: number;67non_pre_factor: number;68}6970interface CostsStructure {71version: string;7273// these are critical to defining and computing the cost of a license74user_discount: { [user in User]: number };75sub_discount: { [sub in Subscription]: number };76custom_cost: { [key in CustomUpgrades]: number };77custom_max: { [key in CustomUpgrades]: number };78gce: GoogleComputeEngine;7980// not even sure if any of this is ever used anymore -- it's generic.81min_quote: number;82basic: { [key in CustomUpgrades]: number };83standard: { [key in CustomUpgrades]: number };84max: { [key in CustomUpgrades]: number };85}8687export function getCosts(version = FALLBACK_VERSION): CostsStructure {88const {89SUB_DISCOUNT,90GCE_COSTS,91COST_MULTIPLIER,92NONMEMBER_DENSITY,93ACADEMIC_DISCOUNT,94DISK_FACTOR,95RAM_OVERCOMMIT,96CPU_OVERCOMMIT,97ALWAYS_RUNNING_FACTOR,98} = costVersions[version];99100const CUSTOM_COST: CostMap = {101ram:102(COST_MULTIPLIER * GCE_COSTS.ram) / ACADEMIC_DISCOUNT / NONMEMBER_DENSITY,103dedicated_ram:104(RAM_OVERCOMMIT * (COST_MULTIPLIER * GCE_COSTS.ram)) /105ACADEMIC_DISCOUNT /106NONMEMBER_DENSITY,107cpu:108(COST_MULTIPLIER * GCE_COSTS.cpu) / ACADEMIC_DISCOUNT / NONMEMBER_DENSITY,109dedicated_cpu:110(CPU_OVERCOMMIT * (COST_MULTIPLIER * GCE_COSTS.cpu)) /111ACADEMIC_DISCOUNT /112NONMEMBER_DENSITY,113disk: (DISK_FACTOR * COST_MULTIPLIER * GCE_COSTS.disk) / ACADEMIC_DISCOUNT,114always_running: ALWAYS_RUNNING_FACTOR,115member: NONMEMBER_DENSITY,116} as const;117118return {119version,120121user_discount: { academic: ACADEMIC_DISCOUNT, business: 1 },122sub_discount: SUB_DISCOUNT,123custom_cost: CUSTOM_COST,124custom_max: MAX,125gce: GCE_COSTS,126127min_quote: MIN_QUOTE,128basic: BASIC,129standard: STANDARD,130max: MAX,131} as const;132}133134const COSTS = getCosts(CURRENT_VERSION);135export { COSTS };136137export const discount_pct = Math.round(138(1 - COSTS.user_discount["academic"]) * 100,139);140141export const discount_monthly_pct = Math.round(142(1 - COSTS.sub_discount["monthly"]) * 100,143);144145export const discount_yearly_pct = Math.round(146(1 - COSTS.sub_discount["yearly"]) * 100,147);148149150