This repository has been archived by the owner on Mar 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
knowledge.py
193 lines (159 loc) · 5.3 KB
/
knowledge.py
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
from experta import *
import schema
class ProjectType(Fact):
type = Field(schema.Or("mobile app", "website", "design", "ai system"))
class TimeScope(Fact):
time = Field(int, mandatory=True)
class Tools(Fact):
tools = Field(schema.Or(
"C++",
"golang",
"Javascript",
"Java",
"C#",
"Rust",
"React Native",
"Swift",
"Flutter",
"Kotlin"
))
class Prototype(Fact):
pr = Field(schema.Or(
'yes', 'no'
))
class Requirements(Fact):
n_req = Field(int, mandatory=True)
# tipe=mobile add cost_type=20000 and est_time=4
# tipe=web add cost_type=30000 and est_time=5
# tipe=ai add cost_type=40000 and est_time=8
# tipe=design add cost_type=50000 and est_time=2
# tech=flutter add raise=10% and exp=10
# tech=javascript add raise=10% and exp=10
# tech=python add raise=20% and exp=20
# tech=rust add raise=40% and exp=40
# tech=golang add raise=10% and exp=10
# tech=kotlin add raise=15% and exp=15
# time - est_time == 0 add raise_time=10%
# time - est_time > 0 add raise_time=0%
# time - est_time < 0 add raise_time=20%
# prototipe=ya add reduce_cost=5%
# prototipe=tidak add reduce_cost=0%
# n_req=val add extra_cost=val*100000
class ProjectCost(KnowledgeEngine):
def __init__(self):
super().__init__()
self.EXP = 0
self.MIN_LEVEL = 0
self.PAYMENT = 0
@DefFacts()
def _declare_initial_fact(self, tipe, tech, time, prototipe, n_req):
yield Fact(tipe=tipe, time=time, tech=tech, prototipe=prototipe, n_req=n_req)
@Rule(Fact(tipe='mobile'))
def mobile_type(self):
self.declare(Fact(est_time=4))
self.declare(Fact(q1=True))
self.declare(Fact(cost=2000000))
@Rule(Fact(tipe='web'))
def web_type(self):
self.declare(Fact(est_time=5))
self.declare(Fact(q1=True))
self.declare(Fact(cost=4000000))
@Rule(Fact(tipe='ai'))
def ai_type(self):
self.declare(Fact(est_time=8))
self.declare(Fact(q1=True))
self.declare(Fact(cost=3000000))
@Rule(Fact(tipe='design'))
def design_type(self):
self.declare(Fact(est_time=2))
self.declare(Fact(q1=True))
self.declare(Fact(cost=200000))
@Rule(Fact(tech='flutter'), Fact(q1=True))
def flutter_tech(self):
self.declare(Fact(raise_tech=10))
self.declare(Fact(exp=10))
self.declare(Fact(q2=True))
@Rule(Fact(tech='javascript'), Fact(q1=True))
def javascript_tech(self):
self.declare(Fact(raise_tech=10))
self.declare(Fact(exp=10))
self.declare(Fact(q2=True))
@Rule(Fact(tech='python'), Fact(q1=True))
def python_tech(self):
self.declare(Fact(raise_tech=20))
self.declare(Fact(exp=10))
self.declare(Fact(q2=True))
@Rule(Fact(tech='rust'), Fact(q1=True))
def rust_tech(self):
self.declare(Fact(raise_tech=40))
self.declare(Fact(exp=10))
self.declare(Fact(q2=True))
@Rule(Fact(tech='golang'), Fact(q1=True))
def golang_tech(self):
self.declare(Fact(raise_tech=10))
self.declare(Fact(exp=10))
self.declare(Fact(q2=True))
@Rule(Fact(tech='kotlin'), Fact(q1=True))
def kotlin_tech(self):
self.declare(Fact(raise_tech=15))
self.declare(Fact(exp=10))
self.declare(Fact(q2=True))
@Rule(
Fact(time=MATCH.time),
Fact(est_time=MATCH.est_time),
TEST(lambda time, est_time: time > est_time),
Fact(q2=True)
)
def time_gt(self, time, est_time):
self.declare(Fact(raise_time=0))
self.declare(Fact(q3=True))
@Rule(
Fact(time=MATCH.time),
Fact(est_time=MATCH.est_time),
TEST(lambda time, est_time: time < est_time),
Fact(q2=True)
)
def time_lt(self, time, est_time):
self.declare(Fact(raise_time=20))
self.declare(Fact(q3=True))
@Rule(
Fact(time=MATCH.time),
Fact(est_time=MATCH.est_time),
TEST(lambda time, est_time: time == est_time),
Fact(q2=True)
)
def time_eq(self, time, est_time, raise_tech):
self.declare(Fact(raise_time=10))
self.declare(Fact(q3=True))
@Rule(Fact(prototipe='ada'), Fact(q3=True))
def prototipe_ada(self):
self.declare(Fact(reduce_cost=5))
self.declare(Fact(q4=True))
# print('q3')
@Rule(Fact(prototipe='tidak'), Fact(q3=True))
def prototipe_tidak(self):
self.declare(Fact(reduce_cost=0))
self.declare(Fact(q4=True))
@Rule(
Fact(n_req=MATCH.n_req),
TEST(lambda n_req: n_req > 0),
Fact(q4=True),
Fact(raise_time=MATCH.raise_time),
Fact(raise_tech=MATCH.raise_tech),
Fact(exp=MATCH.exp),
Fact(reduce_cost=MATCH.reduce_cost),
Fact(cost=MATCH.cost)
# Fact(reduce_cost=MATCH.reduce_cost)
)
def n_requirement(self, n_req, raise_time, raise_tech, exp, reduce_cost, cost):
total_raise = raise_tech + raise_time - reduce_cost
level = exp*10 + n_req
final_cost = cost*(1+total_raise/100) + n_req*(0.1)
# print(f'{total_raise} {exp} {final_cost}')
# return {level, exp, final_cost}
# global EXP
# global MIN_LEVEL
# global PAYMENT
self.EXP = exp
self.MIN_LEVEL = level
self.PAYMENT = final_cost