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/purchases/project-quotas.ts
Views: 687
1
export const DESCRIPTION = {
2
cores: "price per month for 1 vCPU",
3
memory: "price per month for 1GB of RAM",
4
disk_quota: "price per month for 1GB of disk",
5
member_host: "non-disk part of non-member hosting cost is divided by this",
6
};
7
8
export function getPricePerHour(
9
quota: {
10
cores?: number;
11
disk_quota?: number;
12
memory?: number;
13
member_host?: number;
14
},
15
price_per_month: {
16
cores: number; // price per month for 1 vCPU
17
disk_quota: number; // price per month for 1GB of disk
18
memory: number; // price per month for 1GB RAM
19
member_host: number; // cost multiple for non pre-emptible/less loaded (i.e., member hosting)
20
}
21
): number {
22
// start with the core and memory pricing, which are separate.
23
let price =
24
(quota.cores ?? 1) * price_per_month.cores +
25
((quota.memory ?? 1000) * price_per_month.memory) / 1000;
26
27
// member hosting
28
if (!quota.member_host) {
29
price /= price_per_month.member_host;
30
}
31
32
// disk price doesn't depend on member or not.
33
// The first 3GB are included for free.
34
if (quota.disk_quota && quota.disk_quota > 3000) {
35
price += ((quota.disk_quota - 3000) * price_per_month.disk_quota) / 1000;
36
}
37
38
// convert from month to hour
39
price /= 24 * 30.5;
40
41
return price;
42
}
43
44