Spaces:
Sleeping
Sleeping
Update signal_encoder.py
Browse files- signal_encoder.py +6 -14
signal_encoder.py
CHANGED
|
@@ -1,17 +1,9 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
import hashlib
|
| 4 |
-
import json
|
| 5 |
-
|
| 6 |
-
def encode_signal(raw_signal: dict) -> dict:
|
| 7 |
-
"""
|
| 8 |
-
Convert arbitrary web data into a normalized digital signal.
|
| 9 |
-
"""
|
| 10 |
-
canonical = json.dumps(raw_signal, sort_keys=True, separators=(",", ":"))
|
| 11 |
-
bit_hash = hashlib.sha256(canonical.encode()).hexdigest()
|
| 12 |
|
|
|
|
|
|
|
| 13 |
return {
|
| 14 |
-
"
|
| 15 |
-
"
|
| 16 |
-
"entropy_proxy": len(set(canonical))
|
| 17 |
}
|
|
|
|
| 1 |
+
import json, hashlib
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
def encode(obj):
|
| 4 |
+
canonical = json.dumps(obj, sort_keys=True, separators=(",", ":"))
|
| 5 |
return {
|
| 6 |
+
"bits": len(canonical.encode()) * 8,
|
| 7 |
+
"hash": hashlib.sha256(canonical.encode()).hexdigest(),
|
| 8 |
+
"entropy_proxy": len(set(canonical))
|
| 9 |
}
|