Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hivemind
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
hivemind
Commits
0393c975
Commit
0393c975
authored
6 years ago
by
roadscape
Browse files
Options
Downloads
Patches
Plain Diff
define block_date and block_num
parent
5a8a7600
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hive/utils/normalize.py
+8
-0
8 additions, 0 deletions
hive/utils/normalize.py
tests/test_utils_normalize.py
+10
-0
10 additions, 0 deletions
tests/test_utils_normalize.py
with
18 additions
and
0 deletions
hive/utils/normalize.py
+
8
−
0
View file @
0393c975
...
@@ -61,6 +61,14 @@ def legacy_amount(value):
...
@@ -61,6 +61,14 @@ def legacy_amount(value):
tmpl
=
(
"
%%.%df %%s
"
%
prec
)
tmpl
=
(
"
%%.%df %%s
"
%
prec
)
return
tmpl
%
(
amt
,
asset
)
return
tmpl
%
(
amt
,
asset
)
def
block_num
(
block
):
"""
Given a block object, returns the block number.
"""
return
int
(
block
[
'
block_id
'
][:
8
],
base
=
16
)
def
block_date
(
block
):
"""
Parse block timestamp into datetime object.
"""
return
parse_time
(
block
[
'
timestamp
'
])
def
parse_time
(
block_time
):
def
parse_time
(
block_time
):
"""
Convert chain date into datetime object.
"""
"""
Convert chain date into datetime object.
"""
return
datetime
.
strptime
(
block_time
,
'
%Y-%m-%dT%H:%M:%S
'
)
return
datetime
.
strptime
(
block_time
,
'
%Y-%m-%dT%H:%M:%S
'
)
...
...
This diff is collapsed.
Click to expand it.
tests/test_utils_normalize.py
+
10
−
0
View file @
0393c975
...
@@ -2,6 +2,8 @@ from datetime import datetime
...
@@ -2,6 +2,8 @@ from datetime import datetime
from
decimal
import
Decimal
from
decimal
import
Decimal
from
hive.utils.normalize
import
(
from
hive.utils.normalize
import
(
block_num
,
block_date
,
vests_amount
,
vests_amount
,
steem_amount
,
steem_amount
,
sbd_amount
,
sbd_amount
,
...
@@ -15,6 +17,14 @@ from hive.utils.normalize import (
...
@@ -15,6 +17,14 @@ from hive.utils.normalize import (
safe_img_url
,
safe_img_url
,
)
)
def
test_block_num
():
block
=
dict
(
block_id
=
'
013c33f88c643c92a7352b52efde7237f4d4ee0b
'
)
assert
block_num
(
block
)
==
20722680
def
test_block_date
():
block
=
dict
(
timestamp
=
'
2018-03-16T10:08:42
'
)
assert
block_date
(
block
)
==
datetime
(
2018
,
3
,
16
,
10
,
8
,
42
)
def
test_vests_amount
():
def
test_vests_amount
():
assert
vests_amount
(
'
4.549292 VESTS
'
)
==
Decimal
(
'
4.549292
'
)
assert
vests_amount
(
'
4.549292 VESTS
'
)
==
Decimal
(
'
4.549292
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment