Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/util/licenses/purchase/consts.ts
6022 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { CustomUpgrades, Subscription, User } from "./types";
7
import costVersions from "./cost-versions";
8
9
export const CURRENT_VERSION = "3";
10
11
// Another gamble implicit in this is that pre's are available. When they
12
// aren't, cocalc.com switches to uses MUCH more expensive non-preemptibles.
13
14
export interface CostMap {
15
ram: number;
16
dedicated_ram: number;
17
cpu: number;
18
dedicated_cpu: number;
19
disk: number;
20
always_running: number;
21
member: number;
22
}
23
24
// BASIC, STANDARD and MAX have nothing to do with defining pricing. They
25
// are just some presets that might have been used at some point (?).
26
27
export const BASIC: CostMap = {
28
ram: 1,
29
cpu: 1,
30
disk: 3,
31
dedicated_ram: 0,
32
dedicated_cpu: 0,
33
always_running: 0,
34
member: 1,
35
} as const;
36
37
export const STANDARD: CostMap = {
38
ram: 2,
39
cpu: 2,
40
dedicated_ram: 0,
41
dedicated_cpu: 0,
42
disk: 3,
43
always_running: 0,
44
member: 1,
45
} as const;
46
47
export const MAX: CostMap = {
48
ram: 16,
49
cpu: 3,
50
dedicated_ram: 8,
51
dedicated_cpu: 2,
52
disk: 20,
53
always_running: 1,
54
member: 1,
55
} as const;
56
57
export const MIN_QUOTE = 100;
58
59
interface GoogleComputeEngine {
60
ram: number;
61
cpu: number;
62
disk: number;
63
non_pre_factor: number;
64
}
65
66
interface CostsStructure {
67
version: string;
68
69
// these are critical to defining and computing the cost of a license
70
user_discount: { [user in User]: number };
71
sub_discount: { [sub in Subscription]: number };
72
custom_cost: { [key in CustomUpgrades]: number };
73
custom_max: { [key in CustomUpgrades]: number };
74
gce: GoogleComputeEngine;
75
76
// not even sure if any of this is ever used anymore -- it's generic.
77
min_quote: number;
78
basic: { [key in CustomUpgrades]: number };
79
standard: { [key in CustomUpgrades]: number };
80
max: { [key in CustomUpgrades]: number };
81
}
82
83
export function getCosts(version: string): CostsStructure {
84
const {
85
SUB_DISCOUNT,
86
GCE_COSTS,
87
COST_MULTIPLIER,
88
NONMEMBER_DENSITY,
89
ACADEMIC_DISCOUNT,
90
DISK_FACTOR,
91
RAM_OVERCOMMIT,
92
CPU_OVERCOMMIT,
93
ALWAYS_RUNNING_FACTOR,
94
} = costVersions[version] ?? costVersions[CURRENT_VERSION];
95
96
const CUSTOM_COST: CostMap = {
97
ram:
98
(COST_MULTIPLIER * GCE_COSTS.ram) / ACADEMIC_DISCOUNT / NONMEMBER_DENSITY,
99
dedicated_ram:
100
(RAM_OVERCOMMIT * (COST_MULTIPLIER * GCE_COSTS.ram)) /
101
ACADEMIC_DISCOUNT /
102
NONMEMBER_DENSITY,
103
cpu:
104
(COST_MULTIPLIER * GCE_COSTS.cpu) / ACADEMIC_DISCOUNT / NONMEMBER_DENSITY,
105
dedicated_cpu:
106
(CPU_OVERCOMMIT * (COST_MULTIPLIER * GCE_COSTS.cpu)) /
107
ACADEMIC_DISCOUNT /
108
NONMEMBER_DENSITY,
109
disk: (DISK_FACTOR * COST_MULTIPLIER * GCE_COSTS.disk) / ACADEMIC_DISCOUNT,
110
always_running: ALWAYS_RUNNING_FACTOR,
111
member: NONMEMBER_DENSITY,
112
} as const;
113
114
return {
115
version,
116
117
user_discount: { academic: ACADEMIC_DISCOUNT, business: 1 },
118
sub_discount: SUB_DISCOUNT,
119
custom_cost: CUSTOM_COST,
120
custom_max: MAX,
121
gce: GCE_COSTS,
122
123
min_quote: MIN_QUOTE,
124
basic: BASIC,
125
standard: STANDARD,
126
max: MAX,
127
} as const;
128
}
129
130
const COSTS = getCosts(CURRENT_VERSION);
131
export { COSTS };
132
133
export const discount_pct = Math.round(
134
(1 - COSTS.user_discount["academic"]) * 100,
135
);
136
137
export const discount_monthly_pct = Math.round(
138
(1 - COSTS.sub_discount["monthly"]) * 100,
139
);
140
141
export const discount_yearly_pct = Math.round(
142
(1 - COSTS.sub_discount["yearly"]) * 100,
143
);
144
145