Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Oceano2python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
US191
Oceano2python
Commits
f14579bf
Commit
f14579bf
authored
5 years ago
by
jacques.grelet_ird.fr
Browse files
Options
Downloads
Patches
Plain Diff
give the float type to numeric value
parent
bcbe6fe6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
physicalParameter.py
+16
-8
16 additions, 8 deletions
physicalParameter.py
with
16 additions
and
8 deletions
physicalParameter.py
+
16
−
8
View file @
f14579bf
...
@@ -27,11 +27,11 @@ class Roscop:
...
@@ -27,11 +27,11 @@ class Roscop:
return
'
Class Roscop, file: %s, size = %d
'
%
(
self
.
file
,
len
(
self
))
return
'
Class Roscop, file: %s, size = %d
'
%
(
self
.
file
,
len
(
self
))
def
__getitem__
(
self
,
key
):
def
__getitem__
(
self
,
key
):
'''
overload r[key]
'''
overload r[key]
for a given key return the values as a dictionary
'''
for a given key return the values as a dictionary
'''
if
key
not
in
self
.
__hash
:
if
key
not
in
self
.
__hash
:
logging
.
error
(
logging
.
error
(
"
I
nvalid key:
\"
{}
\"
"
.
format
(
key
))
"
physicalParametr.py: i
nvalid key:
\"
{}
\"
"
.
format
(
key
))
else
:
else
:
return
self
.
__hash
[
key
]
return
self
.
__hash
[
key
]
...
@@ -39,14 +39,14 @@ class Roscop:
...
@@ -39,14 +39,14 @@ class Roscop:
'''
overload r[key] = value
'''
'''
overload r[key] = value
'''
if
type
(
value
)
is
not
dict
:
if
type
(
value
)
is
not
dict
:
logging
.
error
(
logging
.
error
(
"
T
he value:
\"
{}
\"
must be a dictionary
"
.
format
(
value
))
"
physicalParametr.py: t
he value:
\"
{}
\"
must be a dictionary
"
.
format
(
value
))
return
return
if
key
not
in
self
.
__hash
:
if
key
not
in
self
.
__hash
:
self
.
__hash
[
key
]
=
value
self
.
__hash
[
key
]
=
value
else
:
else
:
logging
.
error
(
logging
.
error
(
"
M
odify the existing key:
\"
{}
\"
is not allowed
"
.
format
(
key
))
"
physicalParametr.py: m
odify the existing key:
\"
{}
\"
is not allowed
"
.
format
(
key
))
def
__repr__
(
self
):
def
__repr__
(
self
):
'''
overload print()
'''
'''
overload print()
'''
...
@@ -65,18 +65,26 @@ class Roscop:
...
@@ -65,18 +65,26 @@ class Roscop:
# read code roscop file
# read code roscop file
def
read
(
self
):
def
read
(
self
):
with
open
(
self
.
file
,
'
rt
'
)
as
f
:
with
open
(
self
.
file
,
'
rt
'
)
as
f
:
# Create an object that maps the information in each row to an OrderedDict
# the values in the first row of file f will be used as the fieldnames.
reader
=
csv
.
DictReader
(
f
,
delimiter
=
'
;
'
)
reader
=
csv
.
DictReader
(
f
,
delimiter
=
'
;
'
)
for
row
in
reader
:
for
row
in
reader
:
theKey
=
row
[
reader
.
fieldnames
[
0
]]
theKey
=
row
[
reader
.
fieldnames
[
0
]]
for
k
in
reader
.
fieldnames
:
for
k
in
reader
.
fieldnames
:
# if the value of key is empty
# if the value of key is empty
if
row
[
k
]
==
''
or
k
==
'
key
'
:
if
row
[
k
]
==
''
or
k
==
'
key
'
:
# remove the key
# remove the key
row
.
pop
(
k
)
row
.
pop
(
k
)
else
:
else
:
# use the second line with key string to convert each numeric type into float
if
theKey
!=
'
string
'
:
if
self
[
'
string
'
][
k
]
==
'
numeric
'
:
row
[
k
]
=
float
(
row
[
k
])
logging
.
debug
(
logging
.
debug
(
"
{} -> {}
:
{}
"
.
format
(
theKey
,
k
,
row
[
k
]))
"
{} -> {}
, {} =
{}
"
.
format
(
theKey
,
k
,
type
(
row
[
k
]),
row
[
k
]))
self
.
__hash
[
theKey
]
=
row
self
.
__hash
[
theKey
]
=
row
return
return
...
@@ -87,7 +95,7 @@ class Roscop:
...
@@ -87,7 +95,7 @@ class Roscop:
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
# usage:
# usage:
# > python physicalParameter.py code_roscop.csv -k TEMP
# > python physicalParameter.py code_roscop.csv -k TEMP
-d
parser
=
argparse
.
ArgumentParser
(
parser
=
argparse
.
ArgumentParser
(
description
=
'
This class Roscop parse a csv file describing physical parameter codification
'
)
description
=
'
This class Roscop parse a csv file describing physical parameter codification
'
)
parser
.
add_argument
(
"
-d
"
,
"
--debug
"
,
help
=
"
display debug informations
"
,
parser
.
add_argument
(
"
-d
"
,
"
--debug
"
,
help
=
"
display debug informations
"
,
...
@@ -116,9 +124,9 @@ if __name__ == "__main__":
...
@@ -116,9 +124,9 @@ if __name__ == "__main__":
# if args list is empty, key contain NoneType
# if args list is empty, key contain NoneType
if
key
is
not
None
:
if
key
is
not
None
:
for
k
in
key
:
for
k
in
key
:
r
.
displayCode
(
k
)
r
[
k
]
print
(
"
{}: {}
"
.
format
(
key
[
0
],
r
.
returnCode
(
key
[
0
]
)
[
'
long_name
'
]))
print
(
"
{}: {}
"
.
format
(
key
[
0
],
r
[
key
[
0
]
]
[
'
long_name
'
]))
r
[
'
TOTO
'
]
=
{
'
uncle
'
:
'
tata
'
}
r
[
'
TOTO
'
]
=
{
'
uncle
'
:
'
tata
'
}
print
(
r
[
'
TOTO
'
])
print
(
r
[
'
TOTO
'
])
r
[
'
TEMP
'
]
=
'
tata
'
r
[
'
TEMP
'
]
=
'
tata
'
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