Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
ptbcli
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
Daniele Nicolodi
ptbcli
Commits
c428b910
Commit
c428b910
authored
3 years ago
by
Daniele Nicolodi
Browse files
Options
Downloads
Patches
Plain Diff
salaries: Move processing outside the SAP connection context and extend
parent
b23f998d
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
salaries.py
+37
-24
37 additions, 24 deletions
salaries.py
with
37 additions
and
24 deletions
salaries.py
+
37
−
24
View file @
c428b910
...
...
@@ -51,7 +51,8 @@ def sum_amounts(values):
@click.command
()
def
main
():
@click.option
(
'
--save
'
,
metavar
=
'
FILENAME
'
,
help
=
'
Save data into CSV file.
'
)
def
main
(
save
):
psp
=
'
1K-43045
'
fromdate
=
datetime
.
date
(
2020
,
1
,
1
)
todate
=
datetime
.
date
.
today
()
+
datetime
.
timedelta
(
days
=
1
)
...
...
@@ -85,29 +86,41 @@ def main():
# This could be probably be done in the SAP query.
rows
=
list
(
filter
(
sieve
,
get_table_rows
(
table
,
fields
)))
table
=
petl
.
fromdicts
(
rows
)
\
.
convert
(
'
cost-element
'
,
int
)
\
.
selecteq
(
'
cost-element
'
,
5100900
)
# There is no easy way to check whom salary each entry
# corresponds to. The only way is to extract the name from the
# narration string which fortunately most of the times conform
# to a fixed structure. However, there may be typos in the
# names as entered there. To get around this, we extract all
# the possible names from the narration fields and run a
# clustering algorithm to match the mispelled names to the
# correct ones.
names
=
[
m
.
group
(
1
)
for
m
in
[
re
.
match
(
r
'
.*/([A-Z][a-z]+$)
'
,
v
)
for
v
in
table
.
values
(
'
narration
'
)]
if
m
]
clusters
=
cluster
(
names
,
2.0
)
table
=
table
.
addfield
(
'
name
'
,
lambda
x
:
categorize
(
x
.
narration
,
clusters
))
data
=
[]
for
name
in
sorted
(
clusters
.
keys
()):
total
=
sum_amounts
(
table
.
selecteq
(
'
name
'
,
name
).
values
(
'
amount
'
))
data
.
append
({
'
account
'
:
psp
,
'
name
'
:
name
,
'
total
'
:
total
})
res
=
petl
.
fromdicts
(
data
)
print
(
res
)
table
=
petl
.
fromdicts
(
rows
)
\
.
convert
(
'
cost-element
'
,
int
)
\
.
selectne
(
'
cost-element
'
,
5100900
)
\
.
addfield
(
'
account
'
,
psp
,
index
=
0
)
print
(
table
)
if
save
:
table
.
tocsv
(
save
)
print
(
table
.
aggregate
((
'
account
'
,
'
year
'
),
sum_amounts
,
'
amount
'
).
rename
(
'
value
'
,
'
amount
'
))
table
=
petl
.
fromdicts
(
rows
)
\
.
convert
(
'
cost-element
'
,
int
)
\
.
selecteq
(
'
cost-element
'
,
5100900
)
\
.
addfield
(
'
account
'
,
psp
,
index
=
0
)
# To associate a employee name to a table entry it is ncessary to
# extract the employee name from the narration. In most cases, the
# narration text is in the form "Something/ $name" where $name is
# the employee name. However, employee names often contain typos.
# To handle these typos, we extract the names from the narration
# fields and run a clustering algorithm to match the mispelled
# names to the correct ones.
names
=
[
m
.
group
(
1
)
for
m
in
[
re
.
match
(
r
'
.*/([A-Z][a-z]+$)
'
,
v
)
for
v
in
table
.
values
(
'
narration
'
)]
if
m
]
clusters
=
cluster
(
names
,
2.0
)
table
=
table
.
addfield
(
'
name
'
,
lambda
x
:
categorize
(
x
.
narration
,
clusters
))
\
.
cut
(
'
account
'
,
'
year
'
,
'
period
'
,
'
name
'
,
'
amount
'
)
print
(
table
)
print
()
print
(
table
.
aggregate
((
'
account
'
,
'
year
'
,
'
name
'
),
sum_amounts
,
'
amount
'
).
rename
(
'
value
'
,
'
amount
'
))
print
()
print
(
table
.
aggregate
((
'
account
'
,
'
name
'
),
sum_amounts
,
'
amount
'
).
rename
(
'
value
'
,
'
amount
'
))
print
()
print
(
table
.
aggregate
((
'
account
'
,
'
year
'
),
sum_amounts
,
'
amount
'
).
rename
(
'
value
'
,
'
amount
'
))
if
__name__
==
'
__main__
'
:
...
...
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