Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
buba-fetcher
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dbnomics-fetchers
buba-fetcher
Commits
1e54094d
Commit
1e54094d
authored
6 years ago
by
Pierre Dittgen
Browse files
Options
Downloads
Patches
Plain Diff
Normalize time series names
parent
0347af2a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
convert.py
+13
-1
13 additions, 1 deletion
convert.py
with
13 additions
and
1 deletion
convert.py
+
13
−
1
View file @
1e54094d
...
...
@@ -46,6 +46,9 @@ YEAR_RE = re.compile(r'^([12]\d{3})$')
MONTH_RE
=
re
.
compile
(
r
'
^([12]\d{3})-([01]\d)$
'
)
DAY_RE
=
re
.
compile
(
r
'
^([12]\d{3})-([01]\d)-([0-3]\d)$
'
)
# Helps normalize space
NORM_SPACES_RE
=
re
.
compile
(
r
'
\s+
'
)
def
write_series_file
(
file_path
:
Path
,
periods
,
observations
,
obs_status
=
None
):
"""
write series tsv file from period and value list
"""
...
...
@@ -62,6 +65,15 @@ def write_series_file(file_path: Path, periods, observations, obs_status=None):
fd
.
write
(
'
{}
\n
'
.
format
(
'
\t
'
.
join
(
tup
)))
def
norm_space
(
str_value
):
"""
Converts
'
abc de f
'
into
'
abc de f
'
>>>
norm_space
(
"
ab
\t
c de f
"
)
'
ab c de f
'
"""
return
NORM_SPACES_RE
.
sub
(
'
'
,
str_value
).
strip
()
def
norm_period
(
period_str
,
freq
):
"""
Normalize period respecting frequency value
...
...
@@ -120,7 +132,7 @@ def load_series_xml_file(xml_file: Path):
if
elt
.
tag
==
SERIES_TAG
:
info
[
'
code
'
]
=
elt
.
attrib
[
'
BBK_ID
'
]
name_attr
=
'
BBK_TITLE_ENG
'
if
'
BBK_TITLE_ENG
'
in
elt
.
attrib
else
'
BBK_TITLE
'
info
[
'
name
'
]
=
elt
.
attrib
[
name_attr
]
info
[
'
name
'
]
=
norm_space
(
elt
.
attrib
[
name_attr
]
)
info
[
'
freq
'
]
=
elt
.
attrib
[
'
FREQ
'
]
info
[
'
periods
'
]
=
[]
info
[
'
obs
'
]
=
[]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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