Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F2674076
units.py
ArthurPSmith (Arthur Smith)
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
ArthurPSmith
Oct 9 2015, 5:08 PM
2015-10-09 17:08:22 (UTC+0)
Size
938 B
Referenced Files
None
Subscribers
None
units.py
View Options
# time units and their values in multiples of seconds
time_units
=
{
11574
:
1.0
,
# second
7727
:
60.0
,
# minute
25235
:
3600.0
,
# hour
573
:
86400.0
,
# day
23387
:
604800.0
,
# week
5151
:
2.630e6
,
# month (average)
1092296
:
3.156e7
,
# year (annum)
577
:
3.156e7
,
# year (calendar)
723733
:
1.0e-3
,
# millisecond
842015
:
1.0e-6
,
# microsecond
838801
:
1.0e-9
,
# nanosecond
3902709
:
1.0e-12
,
# picosecond
1777507
:
1.0e-15
,
# femtosecond
2483628
:
1.0e-18
# attosecond
}
def
time_quantity_in_seconds
(
claim
):
amount
=
None
if
'mainsnak'
in
claim
:
if
'datavalue'
in
claim
[
'mainsnak'
]:
quantity
=
claim
[
'mainsnak'
][
'datavalue'
][
'value'
]
amount
=
float
(
quantity
[
'amount'
])
unit_uri
=
quantity
[
'unit'
]
# Has form http://www.wikidata.org/entity/Q577
unit_id
=
int
(
unit_uri
.
split
(
'/'
)[
-
1
]
.
replace
(
'Q'
,
''
))
amount
*=
time_units
[
unit_id
]
return
amount
File Metadata
Details
Attached
Mime Type
text/x-python
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2686728
Default Alt Text
units.py (938 B)
Attached To
Mode
T114547: Table of nuclides based on Wikidata
Attached
Detach File
Event Timeline
Log In to Comment