whatap-python 2.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- whatap/LICENSE +0 -0
- whatap/README.rst +49 -0
- whatap/__init__.py +923 -0
- whatap/__main__.py +4 -0
- whatap/agent/darwin/amd64/whatap_python +0 -0
- whatap/agent/darwin/arm64/whatap_python +0 -0
- whatap/agent/linux/amd64/whatap_python +0 -0
- whatap/agent/linux/arm64/whatap_python +0 -0
- whatap/agent/windows/whatap_python.exe +0 -0
- whatap/bootstrap/__init__.py +0 -0
- whatap/bootstrap/sitecustomize.py +19 -0
- whatap/build.py +4 -0
- whatap/conf/__init__.py +0 -0
- whatap/conf/configuration.py +280 -0
- whatap/conf/configure.py +105 -0
- whatap/conf/license.py +49 -0
- whatap/control/__init__.py +0 -0
- whatap/counter/__init__.py +14 -0
- whatap/counter/counter_manager.py +45 -0
- whatap/counter/tasks/__init__.py +3 -0
- whatap/counter/tasks/base_task.py +26 -0
- whatap/counter/tasks/llm_evaluator_task.py +501 -0
- whatap/counter/tasks/llm_log_sink_task.py +309 -0
- whatap/counter/tasks/llm_stat_task.py +78 -0
- whatap/counter/tasks/openfiledescriptor.py +67 -0
- whatap/io/__init__.py +1 -0
- whatap/io/data_inputx.py +161 -0
- whatap/io/data_outputx.py +262 -0
- whatap/llm/__init__.py +17 -0
- whatap/llm/definitions.py +43 -0
- whatap/llm/evaluators/__init__.py +136 -0
- whatap/llm/evaluators/base.py +114 -0
- whatap/llm/evaluators/builtins/__init__.py +91 -0
- whatap/llm/evaluators/builtins/answer_relevance.py +46 -0
- whatap/llm/evaluators/builtins/combined_judge.py +271 -0
- whatap/llm/evaluators/builtins/factuality.py +71 -0
- whatap/llm/evaluators/builtins/hallucination.py +97 -0
- whatap/llm/evaluators/builtins/llm_judge.py +516 -0
- whatap/llm/evaluators/builtins/pii_leak.py +214 -0
- whatap/llm/evaluators/builtins/prompt_injection.py +71 -0
- whatap/llm/evaluators/builtins/toxicity.py +53 -0
- whatap/llm/evaluators/builtins/url_scan.py +194 -0
- whatap/llm/evaluators/registry.py +192 -0
- whatap/llm/evaluators/sampler.py +83 -0
- whatap/llm/evaluators/scope.py +334 -0
- whatap/llm/features.py +66 -0
- whatap/llm/log_sink_packs/__init__.py +9 -0
- whatap/llm/log_sink_packs/llm_input_message.py +16 -0
- whatap/llm/log_sink_packs/llm_log_sink_pack.py +72 -0
- whatap/llm/log_sink_packs/llm_output_message.py +19 -0
- whatap/llm/log_sink_packs/llm_step_eval_status.py +94 -0
- whatap/llm/log_sink_packs/llm_step_status.py +118 -0
- whatap/llm/log_sink_packs/llm_system_message.py +16 -0
- whatap/llm/log_sink_packs/llm_tool_calls.py +44 -0
- whatap/llm/log_sink_packs/llm_tool_results.py +16 -0
- whatap/llm/log_sink_packs/llm_tx_status.py +108 -0
- whatap/llm/pricing.py +236 -0
- whatap/llm/prompt_meta.py +288 -0
- whatap/llm/providers/__init__.py +0 -0
- whatap/llm/providers/anthropic/__init__.py +37 -0
- whatap/llm/providers/anthropic/messages/__init__.py +0 -0
- whatap/llm/providers/anthropic/messages/messages.py +70 -0
- whatap/llm/providers/anthropic/messages/messages_context.py +76 -0
- whatap/llm/providers/anthropic/messages/messages_extractor.py +126 -0
- whatap/llm/providers/interceptor.py +182 -0
- whatap/llm/providers/openai/__init__.py +133 -0
- whatap/llm/providers/openai/chat/__init__.py +0 -0
- whatap/llm/providers/openai/chat/chat.py +82 -0
- whatap/llm/providers/openai/chat/chat_context.py +78 -0
- whatap/llm/providers/openai/chat/chat_extractor.py +127 -0
- whatap/llm/providers/openai/completions/__init__.py +0 -0
- whatap/llm/providers/openai/completions/completions.py +70 -0
- whatap/llm/providers/openai/completions/completions_context.py +31 -0
- whatap/llm/providers/openai/completions/completions_extractor.py +61 -0
- whatap/llm/providers/openai/content_parser.py +41 -0
- whatap/llm/providers/openai/embeddings/__init__.py +0 -0
- whatap/llm/providers/openai/embeddings/embeddings.py +59 -0
- whatap/llm/providers/openai/embeddings/embeddings_context.py +25 -0
- whatap/llm/providers/openai/embeddings/embeddings_extractor.py +26 -0
- whatap/llm/providers/openai/responses/__init__.py +0 -0
- whatap/llm/providers/openai/responses/responses.py +70 -0
- whatap/llm/providers/openai/responses/responses_context.py +88 -0
- whatap/llm/providers/openai/responses/responses_extractor.py +126 -0
- whatap/llm/providers/stream_accumulator.py +73 -0
- whatap/llm/stats/__init__.py +35 -0
- whatap/llm/stats/active_stat.py +86 -0
- whatap/llm/stats/answer_relevance_eval_stat.py +10 -0
- whatap/llm/stats/api_status_stat.py +35 -0
- whatap/llm/stats/base_stat.py +107 -0
- whatap/llm/stats/combined_judge_eval_stat.py +11 -0
- whatap/llm/stats/error_stat.py +59 -0
- whatap/llm/stats/eval_stat.py +225 -0
- whatap/llm/stats/factuality_eval_stat.py +10 -0
- whatap/llm/stats/feature_stat.py +104 -0
- whatap/llm/stats/finish_stat.py +105 -0
- whatap/llm/stats/hallucination_eval_stat.py +10 -0
- whatap/llm/stats/meter.py +18 -0
- whatap/llm/stats/perf_stat.py +117 -0
- whatap/llm/stats/pii_leak_eval_stat.py +12 -0
- whatap/llm/stats/prompt_injection_eval_stat.py +10 -0
- whatap/llm/stats/token_usage_stat.py +133 -0
- whatap/llm/stats/toxicity_eval_stat.py +10 -0
- whatap/llm/stats/url_scan_eval_stat.py +12 -0
- whatap/net/__init__.py +0 -0
- whatap/net/async_sender.py +107 -0
- whatap/net/packet_enum.py +44 -0
- whatap/net/packet_type_enum.py +31 -0
- whatap/net/param_def.py +69 -0
- whatap/net/stackhelper.py +87 -0
- whatap/net/udp_session.py +394 -0
- whatap/net/udp_thread.py +54 -0
- whatap/pack/__init__.py +0 -0
- whatap/pack/logSinkPack.py +77 -0
- whatap/pack/pack.py +34 -0
- whatap/pack/pack_enum.py +41 -0
- whatap/pack/tagCountPack.py +61 -0
- whatap/scripts/__init__.py +208 -0
- whatap/trace/__init__.py +12 -0
- whatap/trace/mod/__init__.py +0 -0
- whatap/trace/mod/amqp/__init__.py +0 -0
- whatap/trace/mod/amqp/kombu.py +122 -0
- whatap/trace/mod/amqp/pika.py +62 -0
- whatap/trace/mod/application/__init__.py +0 -0
- whatap/trace/mod/application/bottle.py +34 -0
- whatap/trace/mod/application/celery.py +81 -0
- whatap/trace/mod/application/cherrypy.py +30 -0
- whatap/trace/mod/application/django.py +287 -0
- whatap/trace/mod/application/django_asgi.py +266 -0
- whatap/trace/mod/application/django_py3.py +251 -0
- whatap/trace/mod/application/fastapi/__init__.py +31 -0
- whatap/trace/mod/application/fastapi/endpoint.py +73 -0
- whatap/trace/mod/application/fastapi/exception_log.py +63 -0
- whatap/trace/mod/application/fastapi/instrumentation.py +204 -0
- whatap/trace/mod/application/fastapi/scope.py +115 -0
- whatap/trace/mod/application/fastapi/transaction.py +67 -0
- whatap/trace/mod/application/flask.py +52 -0
- whatap/trace/mod/application/frappe.py +224 -0
- whatap/trace/mod/application/graphql.py +170 -0
- whatap/trace/mod/application/nameko.py +39 -0
- whatap/trace/mod/application/odoo.py +63 -0
- whatap/trace/mod/application/starlette.py +126 -0
- whatap/trace/mod/application/tornado.py +163 -0
- whatap/trace/mod/application/wsgi.py +195 -0
- whatap/trace/mod/database/__init__.py +0 -0
- whatap/trace/mod/database/cxoracle.py +49 -0
- whatap/trace/mod/database/mongo.py +169 -0
- whatap/trace/mod/database/mysql.py +80 -0
- whatap/trace/mod/database/neo4j.py +90 -0
- whatap/trace/mod/database/psycopg2.py +45 -0
- whatap/trace/mod/database/psycopg3.py +359 -0
- whatap/trace/mod/database/redis.py +122 -0
- whatap/trace/mod/database/sqlalchemy.py +213 -0
- whatap/trace/mod/database/sqlite3.py +130 -0
- whatap/trace/mod/database/util.py +630 -0
- whatap/trace/mod/email/__init__.py +0 -0
- whatap/trace/mod/email/smtp.py +78 -0
- whatap/trace/mod/httpc/__init__.py +0 -0
- whatap/trace/mod/httpc/django.py +31 -0
- whatap/trace/mod/httpc/httplib.py +70 -0
- whatap/trace/mod/httpc/httpx.py +62 -0
- whatap/trace/mod/httpc/requests.py +20 -0
- whatap/trace/mod/httpc/urllib3.py +27 -0
- whatap/trace/mod/httpc/util.py +388 -0
- whatap/trace/mod/logging.py +161 -0
- whatap/trace/mod/plugin.py +84 -0
- whatap/trace/mod/standalone/__init__.py +0 -0
- whatap/trace/mod/standalone/multiple.py +293 -0
- whatap/trace/mod/standalone/single.py +135 -0
- whatap/trace/simple_trace_context.py +18 -0
- whatap/trace/trace_context.py +212 -0
- whatap/trace/trace_context_manager.py +244 -0
- whatap/trace/trace_error.py +84 -0
- whatap/trace/trace_handler.py +89 -0
- whatap/trace/trace_import.py +91 -0
- whatap/trace/trace_module_definition.py +156 -0
- whatap/util/__init__.py +0 -0
- whatap/util/bit_util.py +49 -0
- whatap/util/cardinality/__init__.py +0 -0
- whatap/util/cardinality/hyperloglog.py +84 -0
- whatap/util/cardinality/murmurhash.py +20 -0
- whatap/util/cardinality/registerset.py +60 -0
- whatap/util/compare_util.py +19 -0
- whatap/util/date_util.py +55 -0
- whatap/util/debug_util.py +73 -0
- whatap/util/escape_literal_sql.py +233 -0
- whatap/util/frame_util.py +20 -0
- whatap/util/hash_util.py +103 -0
- whatap/util/hexa32.py +66 -0
- whatap/util/int_set.py +199 -0
- whatap/util/ip_util.py +63 -0
- whatap/util/keygen.py +11 -0
- whatap/util/linked_list.py +113 -0
- whatap/util/linked_map.py +359 -0
- whatap/util/metering_util.py +103 -0
- whatap/util/request_double_queue.py +68 -0
- whatap/util/request_queue.py +60 -0
- whatap/util/string_util.py +20 -0
- whatap/util/throttle_util.py +99 -0
- whatap/util/userid_util.py +134 -0
- whatap/value/__init__.py +1 -0
- whatap/value/blob_value.py +38 -0
- whatap/value/boolean_value.py +33 -0
- whatap/value/decimal_value.py +36 -0
- whatap/value/double_summary.py +86 -0
- whatap/value/double_value.py +33 -0
- whatap/value/float_array.py +42 -0
- whatap/value/float_value.py +34 -0
- whatap/value/int_array.py +42 -0
- whatap/value/ip4_value.py +50 -0
- whatap/value/list_value.py +105 -0
- whatap/value/long_array.py +44 -0
- whatap/value/long_summary.py +83 -0
- whatap/value/map_value.py +154 -0
- whatap/value/null_value.py +21 -0
- whatap/value/number_value.py +33 -0
- whatap/value/summary_value.py +39 -0
- whatap/value/text_array.py +58 -0
- whatap/value/text_hash_value.py +37 -0
- whatap/value/text_value.py +43 -0
- whatap/value/value.py +26 -0
- whatap/value/value_enum.py +80 -0
- whatap/whatap.conf +14 -0
- whatap_python-2.1.0.dist-info/METADATA +87 -0
- whatap_python-2.1.0.dist-info/RECORD +227 -0
- whatap_python-2.1.0.dist-info/WHEEL +5 -0
- whatap_python-2.1.0.dist-info/entry_points.txt +6 -0
- whatap_python-2.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
from whatap.value.boolean_value import BooleanValue
|
|
2
|
+
from whatap.value.decimal_value import DecimalValue
|
|
3
|
+
from whatap.value.double_value import DoubleValue
|
|
4
|
+
from whatap.value.float_value import FloatValue
|
|
5
|
+
from whatap.value.number_value import NumberValue
|
|
6
|
+
from whatap.value.text_value import TextValue
|
|
7
|
+
|
|
8
|
+
from whatap.value.value import Value
|
|
9
|
+
from whatap.value.value_enum import ValueEnum
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ListValue(Value):
|
|
13
|
+
def __init__(self, valueList=None):
|
|
14
|
+
super(ListValue, self).__init__()
|
|
15
|
+
self.valueList = valueList if isinstance(valueList, list) else []
|
|
16
|
+
|
|
17
|
+
def getBoolean(self, i):
|
|
18
|
+
v = self.valueList[i]
|
|
19
|
+
if isinstance(v, BooleanValue):
|
|
20
|
+
return v.value
|
|
21
|
+
return False
|
|
22
|
+
|
|
23
|
+
def getDouble(self, i):
|
|
24
|
+
v = self.valueList[i]
|
|
25
|
+
if isinstance(v, NumberValue):
|
|
26
|
+
return v.doubleValue()
|
|
27
|
+
return 0.0
|
|
28
|
+
|
|
29
|
+
def getLong(self, i):
|
|
30
|
+
v = self.valueList[i]
|
|
31
|
+
if isinstance(v, NumberValue):
|
|
32
|
+
return v.longValue()
|
|
33
|
+
return 0
|
|
34
|
+
|
|
35
|
+
def getInt(self, i):
|
|
36
|
+
v = self.valueList[i]
|
|
37
|
+
if isinstance(v, NumberValue):
|
|
38
|
+
return v.intValue()
|
|
39
|
+
return 0
|
|
40
|
+
|
|
41
|
+
def getString(self, i):
|
|
42
|
+
v = self.valueList[i]
|
|
43
|
+
if isinstance(v, TextValue):
|
|
44
|
+
return v.value
|
|
45
|
+
if not v:
|
|
46
|
+
return None
|
|
47
|
+
return v
|
|
48
|
+
|
|
49
|
+
def set(self, i, value):
|
|
50
|
+
self.valueList[i] = value
|
|
51
|
+
|
|
52
|
+
def addValue(self, value):
|
|
53
|
+
self.valueList.append(value)
|
|
54
|
+
return self
|
|
55
|
+
|
|
56
|
+
def addBoolean(self, value):
|
|
57
|
+
self.valueList.append(BooleanValue(value))
|
|
58
|
+
return self
|
|
59
|
+
|
|
60
|
+
def addDouble(self, value):
|
|
61
|
+
self.valueList.append(DoubleValue(value))
|
|
62
|
+
return self
|
|
63
|
+
|
|
64
|
+
def addLong(self, value):
|
|
65
|
+
self.valueList.append(DecimalValue(value))
|
|
66
|
+
return self
|
|
67
|
+
|
|
68
|
+
def addFloat(self, value):
|
|
69
|
+
self.valueList.append(FloatValue(value))
|
|
70
|
+
return self
|
|
71
|
+
|
|
72
|
+
def addString(self, value):
|
|
73
|
+
self.valueList.append(TextValue(value))
|
|
74
|
+
return self
|
|
75
|
+
|
|
76
|
+
def addStringArray(self, value):
|
|
77
|
+
if isinstance(value, list):
|
|
78
|
+
for v in value:
|
|
79
|
+
self.addString(v)
|
|
80
|
+
return self
|
|
81
|
+
|
|
82
|
+
def addValueArray(self, value):
|
|
83
|
+
if isinstance(value, list):
|
|
84
|
+
for v in value:
|
|
85
|
+
self.addValue(v)
|
|
86
|
+
return self
|
|
87
|
+
|
|
88
|
+
def size(self):
|
|
89
|
+
return len(self.valueList)
|
|
90
|
+
|
|
91
|
+
def write(self, dout):
|
|
92
|
+
size = self.size()
|
|
93
|
+
dout.writeDecimal(size)
|
|
94
|
+
for i in range(size):
|
|
95
|
+
dout.writeValue(self.valueList[i])
|
|
96
|
+
|
|
97
|
+
def read(self, din):
|
|
98
|
+
for _ in range(din.readDecimal()):
|
|
99
|
+
self.addValue(din.readValue())
|
|
100
|
+
|
|
101
|
+
def getValueType(self):
|
|
102
|
+
return ValueEnum.LIST
|
|
103
|
+
|
|
104
|
+
def toObject(self):
|
|
105
|
+
return self.valueList
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from whatap.value.value import Value
|
|
2
|
+
from whatap.value.value_enum import ValueEnum
|
|
3
|
+
|
|
4
|
+
from whatap.util.compare_util import CompareUtil
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class LongArray(Value):
|
|
8
|
+
def __init__(self, value=None):
|
|
9
|
+
super(LongArray, self).__init__()
|
|
10
|
+
self.value = value if isinstance(value, list) else []
|
|
11
|
+
self._hash = 0
|
|
12
|
+
|
|
13
|
+
def compareTo(self, object):
|
|
14
|
+
if isinstance(object, LongArray):
|
|
15
|
+
return CompareUtil.compareTo(self.value, object.value)
|
|
16
|
+
return 1
|
|
17
|
+
|
|
18
|
+
def equals(self, object):
|
|
19
|
+
if isinstance(object, LongArray):
|
|
20
|
+
return self.value == object.value
|
|
21
|
+
return False
|
|
22
|
+
|
|
23
|
+
def hashCode(self):
|
|
24
|
+
if not self._hash:
|
|
25
|
+
if not self.value:
|
|
26
|
+
return 0
|
|
27
|
+
|
|
28
|
+
result = 1
|
|
29
|
+
for v in self.value:
|
|
30
|
+
element = v ^ (v >> 32)
|
|
31
|
+
result = 31 * result + element
|
|
32
|
+
|
|
33
|
+
self._hash = result
|
|
34
|
+
return self._hash
|
|
35
|
+
|
|
36
|
+
def write(self, dout):
|
|
37
|
+
dout.writLongeArray(self.value)
|
|
38
|
+
|
|
39
|
+
def read(self, din):
|
|
40
|
+
self.value = din.readLongArray()
|
|
41
|
+
return self
|
|
42
|
+
|
|
43
|
+
def getValueType(self):
|
|
44
|
+
return ValueEnum.ARRAY_LONG
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from whatap.value.summary_value import SummaryValue
|
|
2
|
+
from whatap.value.value_enum import ValueEnum
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class LongSummary(SummaryValue):
|
|
6
|
+
def __init__(self):
|
|
7
|
+
super(LongSummary, self).__init__()
|
|
8
|
+
self.sum = 0
|
|
9
|
+
self.count = 0
|
|
10
|
+
self.min = 0
|
|
11
|
+
self.max = 0
|
|
12
|
+
|
|
13
|
+
def getValueType(self):
|
|
14
|
+
return ValueEnum.LONG_SUMMARY
|
|
15
|
+
|
|
16
|
+
def write(self, dout):
|
|
17
|
+
dout.writeLong(self.sum)
|
|
18
|
+
dout.writeInt(self.count)
|
|
19
|
+
dout.writeLong(self.min)
|
|
20
|
+
dout.writeLong(self.max)
|
|
21
|
+
|
|
22
|
+
def read(self, din):
|
|
23
|
+
self.sum = din.readLong()
|
|
24
|
+
self.count = din.readInt()
|
|
25
|
+
self.min = din.readLong()
|
|
26
|
+
self.max = din.readLong()
|
|
27
|
+
return self
|
|
28
|
+
|
|
29
|
+
def addCount(self):
|
|
30
|
+
self.count += 1
|
|
31
|
+
|
|
32
|
+
def add(self, value):
|
|
33
|
+
if not value:
|
|
34
|
+
return self
|
|
35
|
+
|
|
36
|
+
if isinstance(value, int):
|
|
37
|
+
if not self.count:
|
|
38
|
+
self.sum = value
|
|
39
|
+
self.count = 1
|
|
40
|
+
self.max = value
|
|
41
|
+
self.min = value
|
|
42
|
+
else:
|
|
43
|
+
self.sum += value
|
|
44
|
+
self.count += 1
|
|
45
|
+
self.max = max(self.max, value)
|
|
46
|
+
self.min = min(self.min, value)
|
|
47
|
+
|
|
48
|
+
elif isinstance(value, SummaryValue):
|
|
49
|
+
if not value.getCount():
|
|
50
|
+
return self
|
|
51
|
+
|
|
52
|
+
self.count += value.getCount()
|
|
53
|
+
self.sum += value.doubleSum()
|
|
54
|
+
self.min = min(self.min, value.doubleMin())
|
|
55
|
+
self.max = max(self.max, value.doubleMax())
|
|
56
|
+
return self
|
|
57
|
+
|
|
58
|
+
def longSum(self):
|
|
59
|
+
return self.sum
|
|
60
|
+
|
|
61
|
+
def longMin(self):
|
|
62
|
+
return self.min
|
|
63
|
+
|
|
64
|
+
def longMax(self):
|
|
65
|
+
return self.max
|
|
66
|
+
|
|
67
|
+
def longAvg(self):
|
|
68
|
+
return 0 if not self.count else self.sum / self.count
|
|
69
|
+
|
|
70
|
+
def doubleSum(self):
|
|
71
|
+
return self.sum
|
|
72
|
+
|
|
73
|
+
def doubleMin(self):
|
|
74
|
+
return self.min
|
|
75
|
+
|
|
76
|
+
def doubleMax(self):
|
|
77
|
+
return self.max
|
|
78
|
+
|
|
79
|
+
def doubleAvg(self):
|
|
80
|
+
return 0 if not self.count else self.sum / self.count
|
|
81
|
+
|
|
82
|
+
def getCount(self):
|
|
83
|
+
return self.count
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from whatap.value.boolean_value import BooleanValue
|
|
2
|
+
from whatap.value.decimal_value import DecimalValue
|
|
3
|
+
from whatap.value.number_value import NumberValue
|
|
4
|
+
from whatap.value.text_value import TextValue
|
|
5
|
+
from whatap.value.float_value import FloatValue
|
|
6
|
+
from whatap.value.value import Value
|
|
7
|
+
from whatap.value.value_enum import ValueEnum
|
|
8
|
+
|
|
9
|
+
from whatap.value.list_value import ListValue
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class MapValue(Value):
|
|
13
|
+
def __init__(self):
|
|
14
|
+
super(MapValue, self).__init__()
|
|
15
|
+
self.table = {} #OrderedDict()
|
|
16
|
+
|
|
17
|
+
def equals(self, obj):
|
|
18
|
+
if self == obj:
|
|
19
|
+
return True
|
|
20
|
+
elif not obj:
|
|
21
|
+
return False
|
|
22
|
+
|
|
23
|
+
elif not self.table:
|
|
24
|
+
if obj.table:
|
|
25
|
+
return False
|
|
26
|
+
elif self.table != obj.table:
|
|
27
|
+
return False
|
|
28
|
+
return True
|
|
29
|
+
|
|
30
|
+
def size(self):
|
|
31
|
+
return len(self.table)
|
|
32
|
+
|
|
33
|
+
def isEmpty(self):
|
|
34
|
+
return self.size() == 0
|
|
35
|
+
|
|
36
|
+
def containsKey(self, key):
|
|
37
|
+
return self.get(key) is not None
|
|
38
|
+
|
|
39
|
+
def keys(self):
|
|
40
|
+
return self.table.keys()
|
|
41
|
+
|
|
42
|
+
def get(self, key):
|
|
43
|
+
return self.table.get(key)
|
|
44
|
+
|
|
45
|
+
def getBoolean(self, key):
|
|
46
|
+
v = self.get(key)
|
|
47
|
+
if isinstance(v, BooleanValue):
|
|
48
|
+
return v.value
|
|
49
|
+
return False
|
|
50
|
+
|
|
51
|
+
def getInt(self, key):
|
|
52
|
+
v = self.get(key)
|
|
53
|
+
if isinstance(v, NumberValue):
|
|
54
|
+
return v.intValue()
|
|
55
|
+
return 0
|
|
56
|
+
|
|
57
|
+
def getLong(self, key):
|
|
58
|
+
v = self.get(key)
|
|
59
|
+
if isinstance(v, NumberValue):
|
|
60
|
+
return v.longValue()
|
|
61
|
+
return 0
|
|
62
|
+
|
|
63
|
+
def getFloat(self, key):
|
|
64
|
+
v = self.get(key)
|
|
65
|
+
if isinstance(v, NumberValue):
|
|
66
|
+
return v.floatValue()
|
|
67
|
+
return 0
|
|
68
|
+
|
|
69
|
+
def getText(self, key):
|
|
70
|
+
v = self.get(key)
|
|
71
|
+
if isinstance(v, TextValue):
|
|
72
|
+
return v.value
|
|
73
|
+
return None
|
|
74
|
+
|
|
75
|
+
def put(self, key, value):
|
|
76
|
+
self.table[key] = value
|
|
77
|
+
return self
|
|
78
|
+
|
|
79
|
+
def putAuto(self, key, value):
|
|
80
|
+
# key가 string이 아닐 경우, 경고 메시지를 출력하고 아무 것도 하지 않음
|
|
81
|
+
if not isinstance(key, str):
|
|
82
|
+
#print("키는 문자열이어야 합니다.")
|
|
83
|
+
return self
|
|
84
|
+
|
|
85
|
+
# value의 타입에 따라 적절하게 감싸기
|
|
86
|
+
if isinstance(value, int):
|
|
87
|
+
wrapped_value = DecimalValue(value)
|
|
88
|
+
elif isinstance(value, float):
|
|
89
|
+
wrapped_value = FloatValue(value)
|
|
90
|
+
elif isinstance(value, (str)):
|
|
91
|
+
wrapped_value = TextValue(value)
|
|
92
|
+
else:
|
|
93
|
+
#print("지원하지 않는 값 타입입니다.")
|
|
94
|
+
return self
|
|
95
|
+
|
|
96
|
+
# key-value 쌍을 저장
|
|
97
|
+
self.table[key] = wrapped_value
|
|
98
|
+
return self
|
|
99
|
+
|
|
100
|
+
def putValue(self, key, value):
|
|
101
|
+
self.table[key] = value
|
|
102
|
+
return self
|
|
103
|
+
|
|
104
|
+
def putString(self, key, value):
|
|
105
|
+
self.table[key] = TextValue(value)
|
|
106
|
+
return self
|
|
107
|
+
|
|
108
|
+
def putLong(self, key, value):
|
|
109
|
+
self.table[key] = DecimalValue(value)
|
|
110
|
+
|
|
111
|
+
def remove(self, key):
|
|
112
|
+
val = self.table[key]
|
|
113
|
+
del self.table[key]
|
|
114
|
+
return val
|
|
115
|
+
|
|
116
|
+
def clear(self):
|
|
117
|
+
self.table = {}
|
|
118
|
+
|
|
119
|
+
def getValueType(self):
|
|
120
|
+
return ValueEnum.MAP
|
|
121
|
+
|
|
122
|
+
def write(self, dout):
|
|
123
|
+
dout.writeDecimal(self.size())
|
|
124
|
+
for key in self.table.keys():
|
|
125
|
+
dout.writeText(key)
|
|
126
|
+
dout.writeValue(self.get(key))
|
|
127
|
+
|
|
128
|
+
def read(self, din):
|
|
129
|
+
count = din.readDecimal()
|
|
130
|
+
for _ in range(count):
|
|
131
|
+
key = din.readText()
|
|
132
|
+
value = din.readValue()
|
|
133
|
+
self.putValue(key, value)
|
|
134
|
+
return self
|
|
135
|
+
|
|
136
|
+
def newList(self, name):
|
|
137
|
+
list = ListValue()
|
|
138
|
+
self.putValue(name, list)
|
|
139
|
+
return list
|
|
140
|
+
|
|
141
|
+
def getList(self, key):
|
|
142
|
+
return self.get(key)
|
|
143
|
+
|
|
144
|
+
def toObject(self):
|
|
145
|
+
return self.table
|
|
146
|
+
|
|
147
|
+
def putAllMap(self, m):
|
|
148
|
+
for key in self.table.keys():
|
|
149
|
+
value = m.get(key)
|
|
150
|
+
if isinstance(value, Value):
|
|
151
|
+
self.table[key] = value
|
|
152
|
+
|
|
153
|
+
def putAllMapValue(self, m):
|
|
154
|
+
self.putAllMap(m.table)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from whatap.value.value import Value
|
|
2
|
+
from whatap.value.value_enum import ValueEnum
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class NullValue(Value):
|
|
6
|
+
def __init__(self):
|
|
7
|
+
super(NullValue, self).__init__()
|
|
8
|
+
|
|
9
|
+
def compareTo(self, object):
|
|
10
|
+
if isinstance(object, NullValue):
|
|
11
|
+
return 0
|
|
12
|
+
return 1
|
|
13
|
+
|
|
14
|
+
def equals(self, object):
|
|
15
|
+
return isinstance(object, NullValue)
|
|
16
|
+
|
|
17
|
+
def hashCode(self):
|
|
18
|
+
return 0
|
|
19
|
+
|
|
20
|
+
def getValueType(self):
|
|
21
|
+
return ValueEnum.NULL
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from whatap.value.value import Value
|
|
2
|
+
from whatap.value.value_enum import ValueEnum
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class NumberValue(Value):
|
|
6
|
+
def __init__(self):
|
|
7
|
+
super(NumberValue, self).__init__()
|
|
8
|
+
|
|
9
|
+
def doubleValue(self):
|
|
10
|
+
return self.value
|
|
11
|
+
|
|
12
|
+
def floatValue(self):
|
|
13
|
+
return self.value
|
|
14
|
+
|
|
15
|
+
def intValue(self):
|
|
16
|
+
return self.value
|
|
17
|
+
|
|
18
|
+
def longValue(self):
|
|
19
|
+
return self.value
|
|
20
|
+
|
|
21
|
+
def add(self, num):
|
|
22
|
+
if not num or not isinstance(num, NumberValue):
|
|
23
|
+
return self
|
|
24
|
+
|
|
25
|
+
if isinstance(num, ValueEnum.DECIMAL):
|
|
26
|
+
self.value += num.longValue()
|
|
27
|
+
elif isinstance(num, ValueEnum.FLOAT):
|
|
28
|
+
self.value += num.floatValue()
|
|
29
|
+
elif isinstance(num, ValueEnum.DOUBLE):
|
|
30
|
+
self.value += num.doubleValue()
|
|
31
|
+
else:
|
|
32
|
+
from whatap.value.double_value import DoubleValue
|
|
33
|
+
return DoubleValue(self.doubleValue() + num.doubleValue())
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from whatap.value.value import Value
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SummaryValue(Value):
|
|
5
|
+
def __init__(self):
|
|
6
|
+
super(SummaryValue, self).__init__()
|
|
7
|
+
|
|
8
|
+
def add(self, value):
|
|
9
|
+
return self
|
|
10
|
+
|
|
11
|
+
def addCount(self):
|
|
12
|
+
return
|
|
13
|
+
|
|
14
|
+
def longSum(self):
|
|
15
|
+
return
|
|
16
|
+
|
|
17
|
+
def longMin(self):
|
|
18
|
+
return
|
|
19
|
+
|
|
20
|
+
def longMax(self):
|
|
21
|
+
return
|
|
22
|
+
|
|
23
|
+
def longAvg(self):
|
|
24
|
+
return
|
|
25
|
+
|
|
26
|
+
def doubleSum(self):
|
|
27
|
+
return
|
|
28
|
+
|
|
29
|
+
def doubleMin(self):
|
|
30
|
+
return
|
|
31
|
+
|
|
32
|
+
def doubleMax(self):
|
|
33
|
+
return
|
|
34
|
+
|
|
35
|
+
def doubleAvg(self):
|
|
36
|
+
return
|
|
37
|
+
|
|
38
|
+
def getCount(self):
|
|
39
|
+
return
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from whatap.value.value import Value
|
|
2
|
+
from whatap.value.value_enum import ValueEnum
|
|
3
|
+
|
|
4
|
+
from whatap.util.compare_util import CompareUtil
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TextArray(Value):
|
|
8
|
+
def __init__(self, value=None):
|
|
9
|
+
super(TextArray, self).__init__()
|
|
10
|
+
self.value = value if isinstance(value, list) else []
|
|
11
|
+
self._hash = 0
|
|
12
|
+
|
|
13
|
+
def compareTo(self, object):
|
|
14
|
+
if isinstance(object, TextArray):
|
|
15
|
+
return CompareUtil.compareTo(self.value, object.value)
|
|
16
|
+
return 1
|
|
17
|
+
|
|
18
|
+
def equals(self, object):
|
|
19
|
+
if isinstance(object, TextArray):
|
|
20
|
+
return self.value == object.value
|
|
21
|
+
return False
|
|
22
|
+
|
|
23
|
+
def hashCode(self):
|
|
24
|
+
if not self._hash:
|
|
25
|
+
if not self.value:
|
|
26
|
+
return 0
|
|
27
|
+
|
|
28
|
+
result = 1
|
|
29
|
+
for v in self.value:
|
|
30
|
+
element = v
|
|
31
|
+
hashtmp = 0
|
|
32
|
+
if len(element):
|
|
33
|
+
for e in element:
|
|
34
|
+
hashtmp = ((hashtmp << 5) - hashtmp) + str(e)
|
|
35
|
+
hashtmp |= 0
|
|
36
|
+
|
|
37
|
+
result = 31 * result + element
|
|
38
|
+
|
|
39
|
+
self._hash = result
|
|
40
|
+
return self._hash
|
|
41
|
+
|
|
42
|
+
def write(self, dout):
|
|
43
|
+
if not self.value:
|
|
44
|
+
dout.writeShort(0)
|
|
45
|
+
else:
|
|
46
|
+
dout.writeShort(self.value)
|
|
47
|
+
for v in self.value:
|
|
48
|
+
dout.writeText(v)
|
|
49
|
+
|
|
50
|
+
def read(self, din):
|
|
51
|
+
ln = din.readShort()
|
|
52
|
+
self.value = [None for _ in range(ln)]
|
|
53
|
+
for i in range(ln):
|
|
54
|
+
self.value[i] = din.readText()
|
|
55
|
+
return self
|
|
56
|
+
|
|
57
|
+
def getValueType(self):
|
|
58
|
+
return ValueEnum.ARRAY_TEXT
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
from whatap.value.value import Value
|
|
2
|
+
from whatap.value.value_enum import ValueEnum
|
|
3
|
+
|
|
4
|
+
from whatap.util.hash_util import HashUtil
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TextHashValue(Value):
|
|
8
|
+
def __init__(self, value=None):
|
|
9
|
+
super(TextHashValue, self).__init__()
|
|
10
|
+
self.value = HashUtil.crc32(value)
|
|
11
|
+
|
|
12
|
+
def compareTo(self, object):
|
|
13
|
+
if isinstance(object, TextHashValue):
|
|
14
|
+
if self.value < object.value:
|
|
15
|
+
return -1
|
|
16
|
+
elif self.value == object.value:
|
|
17
|
+
return 0
|
|
18
|
+
return 1
|
|
19
|
+
return 1
|
|
20
|
+
|
|
21
|
+
def equals(self, object):
|
|
22
|
+
if isinstance(object, TextHashValue):
|
|
23
|
+
return self.value == object.value
|
|
24
|
+
return False
|
|
25
|
+
|
|
26
|
+
def hashCode(self):
|
|
27
|
+
return self.value
|
|
28
|
+
|
|
29
|
+
def write(self, dout):
|
|
30
|
+
dout.writeInt(self.value)
|
|
31
|
+
|
|
32
|
+
def read(self, din):
|
|
33
|
+
self.value = din.readInt()
|
|
34
|
+
return self
|
|
35
|
+
|
|
36
|
+
def getValueType(self):
|
|
37
|
+
return ValueEnum.TEXT_HASH
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from whatap.value.value import Value
|
|
2
|
+
from whatap.value.value_enum import ValueEnum
|
|
3
|
+
|
|
4
|
+
from whatap.util.compare_util import CompareUtil
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TextValue(Value):
|
|
8
|
+
def __init__(self, value=None):
|
|
9
|
+
super(TextValue, self).__init__()
|
|
10
|
+
self.value = str('' if not value else value)
|
|
11
|
+
|
|
12
|
+
def compareTo(self, object):
|
|
13
|
+
if isinstance(object, TextValue):
|
|
14
|
+
return CompareUtil.compareTo(self.value, object.value)
|
|
15
|
+
return 1
|
|
16
|
+
|
|
17
|
+
def equals(self, object):
|
|
18
|
+
if isinstance(object, TextValue):
|
|
19
|
+
if self.value is None:
|
|
20
|
+
return object.value is None
|
|
21
|
+
return self.value == object.value
|
|
22
|
+
return False
|
|
23
|
+
|
|
24
|
+
def hashCode(self):
|
|
25
|
+
if not self.value:
|
|
26
|
+
return 0
|
|
27
|
+
return 0
|
|
28
|
+
|
|
29
|
+
hash = 0
|
|
30
|
+
if not hash and len(self.value):
|
|
31
|
+
for v in self.value:
|
|
32
|
+
hash = 31 * hash + v
|
|
33
|
+
return hash
|
|
34
|
+
|
|
35
|
+
def write(self, dout):
|
|
36
|
+
dout.writeText(self.value)
|
|
37
|
+
|
|
38
|
+
def read(self, din):
|
|
39
|
+
self.value = din.readText()
|
|
40
|
+
return self
|
|
41
|
+
|
|
42
|
+
def getValueType(self):
|
|
43
|
+
return ValueEnum.TEXT
|
whatap/value/value.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class Value(object):
|
|
2
|
+
def __init__(self):
|
|
3
|
+
return
|
|
4
|
+
|
|
5
|
+
def __repr__(self):
|
|
6
|
+
to_str = '{0}: '.format(type(self).__name__)
|
|
7
|
+
for key, value in self.__dict__.items():
|
|
8
|
+
to_str += '{0}={1}, '.format(key, value)
|
|
9
|
+
return to_str
|
|
10
|
+
|
|
11
|
+
def equals(self, object):
|
|
12
|
+
if isinstance(object, Value):
|
|
13
|
+
return self.value == object.value
|
|
14
|
+
return False
|
|
15
|
+
|
|
16
|
+
def getValueType(self):
|
|
17
|
+
return 0
|
|
18
|
+
|
|
19
|
+
def toObject(self):
|
|
20
|
+
return self
|
|
21
|
+
|
|
22
|
+
def write(self, dout):
|
|
23
|
+
return
|
|
24
|
+
|
|
25
|
+
def read(self, din):
|
|
26
|
+
return self
|