CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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