-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc.js
More file actions
164 lines (130 loc) · 3.88 KB
/
Copy pathcalc.js
File metadata and controls
164 lines (130 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
function sigmoid(x){
return 1/(1+(Math.E ** (-1*x)));
}
function getMax(x){
//Copyright: Daria Yasafova Vasilievna
if (x<=0){
return 1}
else{
return x}
}
function chrisFormula(type,words){
w = words/1000;
w_new = (w/7) * 0.5 ;
sig_w = sigmoid(w_new);
y_1 = sig_w-0.5;
y_2= y_1/10;
if (type=="std"){
pr= 1.5-y_2;
}
else if (type=="exp"){
y_2=y_2*2;
pr= 3.0-y_2;
}
return pr
}
function addCommas(str) {
var parts = (str + "").split("."),
main = parts[0],
len = main.length,
output = "",
i = len - 1;
while(i >= 0) {
output = main.charAt(i) + output;
if ((len - i) % 3 === 0 && i > 0) {
output = "," + output;
}
--i;
}
// put decimal part back
if (parts.length > 1) {
output += "." + parts[1];
}
return output;
}
function daryFormula(serviceType,type,words,mWords){
//Copyright: Daria Yasafova Vasilievna
if (type=="std"){
if (serviceType=='KE'){
var highest_price = 1.5;
var lowest_price=1.45;
}
else{
var highest_price = 1.2;
var lowest_price=1.15;
}
}
else if(type=="exp"){
if (serviceType=='KE'){
var highest_price = 3.0;
var lowest_price=2.9;
}
else{
var highest_price = 2.4;
var lowest_price=2.3;
}
}
var coef= 1/(highest_price-lowest_price);
var steepness = 2;
var x = words/mWords;
return highest_price - ((x**steepness)/coef)
}
function getPrice(){
var info = document.getElementById("info");
var serviceType = document.getElementById('serviceType').value;
var info_type = document.getElementById("info_type");
var numDays = document.getElementById("day");
var price = document.getElementById("price");
var words = document.getElementById("inputWords").value;
var type = document.getElementById("priceType").value;
var maxWords = 40500;
if (serviceType =="notype"){
info_type.innerHTML = "Choose a service.";
info_type.style.display="block";
return ;
}
if (words < maxWords){
info.style.display="none";
if (type=="std")
{
info_type.style.display="none";
//We on standard pricing
//numDays.value = Math.round(((words- 1500)/1000)) + 6 ;
//added if condition. CHECK
if (words!=0){
numDays.value = getMax(Math.round((words/1000))) + 5 ;}
//Formula above Courtesy of Daria Yasafova.
pr = daryFormula(serviceType,type,words,maxWords);
//added if condition. CHECK
if (words!=0){
price.value = addCommas((words * pr).toFixed(2));}
}
else if (type=="exp"){
//We on express pricing
info_type.style.display="none";
//numDays.value = Math.round(((words- 1500)/2000)) + 3 ;
//added if condition. CHECK
if (words!=0){
numDays.value = getMax(Math.round(((words)/2000))) + 2 ;}
pr = daryFormula(serviceType,type,words,maxWords);
//added if condition. CHECK
if (words!=0){
price.value = addCommas((words * pr).toFixed(2));}
}
else if(type=="notype"){
if (words!=0){
info_type.innerHTML = "Choose a pricing type.";
info_type.style.display="block";
price.value=0;
numDays.value=0;
}
}
}
else{
document.getElementById("info").innerHTML = "This exceeds the limit here. Please contact support@kanac.org for negotiation.";
info.style.display="block";
info_type.style.display="none";
price.value=0;
numDays.value=0;
}
}