Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lichenggang
/
bom_identify
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b94926d2
authored
Jan 21, 2021
by
陈森彬
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
添加新的标准单位
parent
0b784f1b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
6 deletions
config.py
utils/functions.py
config.py
View file @
b94926d2
...
...
@@ -35,6 +35,7 @@ unit_map = {
'Nf'
:
1000
,
'nf'
:
1000
,
'µF'
:
1000000
,
'μF'
:
1000000
,
'uF'
:
1000000
,
'UF'
:
1000000
,
'Uf'
:
1000000
,
...
...
@@ -55,6 +56,7 @@ unit_map = {
'μh'
:
1000000
,
'uh'
:
1000000
,
'Uh'
:
1000000
,
'uH'
:
1000000
,
'mH'
:
1000000000
,
'Mh'
:
1000000000
,
'MH'
:
1000000000
,
...
...
@@ -98,4 +100,6 @@ cast_map = {
'瓦'
:
'W'
,
}
unit_regex
=
"μΩ|uΩ|mΩ|Ω|kΩ|KΩ|MΩ|GΩ|TΩ|pF|PF|Pf|pf|nF|NF|Nf|nf|µF|uF|UF|Uf|uf|mF|MF|Mf|mf|F|pH|Ph|PH|ph|nH|µH|UH|μh|uh|Uh|mH|Mh|MH|mh|H|mA|A|a|V|v|kV|Kv|kv|KV|W|w|kW|kw|KW|Kw|
%
|毫欧|欧姆|欧|千欧|兆欧|伏特|伏|千伏|瓦特|瓦"
unit_regex
=
"μΩ|uΩ|mΩ|Ω|kΩ|KΩ|MΩ|GΩ|TΩ|pF|PF|Pf|pf|nF|NF|Nf|nf|µF|μF|uF|UF|Uf|uf|mF|MF|Mf|mf|F|pH|Ph|PH|ph|nH|µH|UH|μh|uh|Uh|uH|mH|Mh|MH|mh|H|mA|A|a|V|v|kV|Kv|kv|KV|W|w|kW|kw|KW|Kw|
%
|毫欧|欧姆|欧|千欧|兆欧|伏特|伏|千伏|瓦特|瓦"
special_tuple
=
(
"-"
,)
utils/functions.py
View file @
b94926d2
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import
re
from
config
import
unit_map
,
cast_map
,
unit_regex
from
config
import
unit_map
,
cast_map
,
unit_regex
,
special_tuple
unit_pattern
=
re
.
compile
(
'(
\
d+|
\
d+[
\\
\
./
]
\
d+)('
+
unit_regex
+
')([.*a-zA-Z
]?)'
)
unit_pattern
=
re
.
compile
(
'(
\
d+|
\
d+[
\\
\
./
?]
\
d+)('
+
unit_regex
+
')([.a-zA-Z
\\
-
]?)'
)
def
is_float
(
s
):
...
...
@@ -30,6 +30,11 @@ def pre_judge(kw):
def
cut_params
(
kw
):
"""
根据符号,强制切割
:param kw:
:return:
"""
res
=
kw
.
split
(
" "
)
if
len
(
res
)
>
1
:
return
res
...
...
@@ -55,12 +60,13 @@ def check_param(kw):
:return:
"""
check_res
=
unit_pattern
.
findall
(
kw
)
print
(
check_res
)
if
len
(
check_res
)
<
2
:
check_res
=
[
kw
]
else
:
new_list
=
[]
for
param
in
check_res
:
if
not
param
[
2
]
.
isalpha
():
if
not
param
[
2
]
.
isalpha
()
and
param
[
2
]
not
in
special_tuple
:
new_list
.
append
(
param
[
0
]
+
param
[
1
])
check_res
=
new_list
return
check_res
...
...
@@ -115,7 +121,7 @@ def unit_conversion(unit_res, kw):
if
"
%
"
in
kw
:
# 百分号的单独处理
unit_num
=
int
(
kw
.
replace
(
unit_str
,
""
))
true_unit
=
str
(
delete_extra_zero
(
unit_num
*
unit_data
[
unit_str
]))
elif
"."
in
kw
:
elif
"."
in
kw
:
# 处理小数点
unit_num
=
float
(
kw
.
replace
(
unit_str
,
""
))
true_unit
=
str
(
delete_extra_zero
(
unit_num
*
unit_data
[
unit_str
]))
+
unit_key
else
:
...
...
@@ -131,7 +137,11 @@ def unit_conversion(unit_res, kw):
def
delete_extra_zero
(
n
):
'''删除小数点后多余的0'''
"""
删除小数点后多余的0
:param n:
:return:
"""
if
isinstance
(
n
,
int
):
return
n
if
isinstance
(
n
,
float
):
...
...
@@ -141,10 +151,21 @@ def delete_extra_zero(n):
def
round_up
(
value
):
"""
保留三位小数
:param value:
:return:
"""
return
round
(
value
*
1000
)
/
1000.0
def
get_not_exist_list
(
attrs_list
,
cut_list
):
"""
筛选还未确定的字符串
:param attrs_list:
:param cut_list:
:return:
"""
exist_list
=
[]
for
attr
in
attrs_list
:
for
cut_word
in
cut_list
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment