Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Binary paint shop problem
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jiří Kalvoda
Binary paint shop problem
Commits
37ea0d4e
Commit
37ea0d4e
authored
1 year ago
by
Jiří Kalvoda
Browse files
Options
Downloads
Patches
Plain Diff
Lepší knihovna na parsování dat
parent
6a159c17
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
data_lib.py
+88
-0
88 additions, 0 deletions
data_lib.py
stats.py
+9
-10
9 additions, 10 deletions
stats.py
with
97 additions
and
10 deletions
data.py
→
data
_lib
.py
+
88
−
0
View file @
37ea0d4e
...
...
@@ -3,10 +3,12 @@ import os
import
subprocess
class
Algorithm
():
def
__init__
(
self
,
name
):
def
__init__
(
self
,
data_cls
,
name
):
self
.
data_cls
=
data_cls
self
.
name
=
name
if
data_cls
.
validate_versions
:
try
:
with
subprocess
.
Popen
([
"
build/
"
+
self
.
name
,
"
-v
"
],
stdout
=
subprocess
.
PIPE
)
as
proc
:
with
subprocess
.
Popen
([
"
../
build/
"
+
self
.
name
,
"
-v
"
],
stdout
=
subprocess
.
PIPE
)
as
proc
:
self
.
current_version
=
int
(
proc
.
stdout
.
read
())
except
FileNotFoundError
:
self
.
current_version
=
None
...
...
@@ -14,11 +16,12 @@ class Algorithm():
class
Run
:
def
__init__
(
self
,
json
):
def
__init__
(
self
,
data_cls
,
json
):
self
.
data_cls
=
data_cls
algo
=
json
[
"
algo
"
].
split
(
"
/
"
)[
-
1
]
if
algo
not
in
algorithms
:
algorithms
[
algo
]
=
Algorithm
(
algo
)
self
.
algo
=
algorithms
[
algo
]
if
algo
not
in
data_cls
.
algorithms
:
data_cls
.
algorithms
[
algo
]
=
Algorithm
(
data_cls
,
algo
)
self
.
algo
=
data_cls
.
algorithms
[
algo
]
self
.
algo_version
=
json
[
"
version
"
]
self
.
args
=
json
[
"
args
"
]
if
"
args
"
in
json
else
[]
...
...
@@ -34,7 +37,7 @@ class Run:
self
.
mistakes
=
json
[
"
mistakes
"
]
if
"
mistakes
"
in
json
else
None
if
"
from
"
in
json
:
self
.
_from
=
Run
(
json
[
"
from
"
])
self
.
_from
=
Run
(
data_cls
,
json
[
"
from
"
])
self
.
seed
=
self
.
_from
.
seed
else
:
self
.
_from
=
None
...
...
@@ -59,17 +62,27 @@ class Run:
return
False
return
self
.
algo_version
==
self
.
algo
.
current_version
logfile
=
os
.
environ
.
get
(
'
LOGFILE
'
,
'
log
'
)
class
Data
:
def
__init__
(
self
,
logfile
=
None
,
validate_versions
=
True
):
self
.
validate_versions
=
validate_versions
logfile
=
logfile
or
os
.
environ
.
get
(
'
LOGFILE
'
,
'
log
'
)
raw_json
=
"
[
"
+
open
(
logfile
,
mode
=
'
r
'
).
read
()[
0
:
-
2
]
+
"
]
"
data
=
json
.
loads
(
raw_json
)
raw_
data
=
json
.
loads
(
raw_json
)
algorithms
=
{}
pipelines
=
{}
runs
=
[]
self
.
algorithms
=
{}
self
.
pipelines
=
{}
self
.
runs
=
[]
for
it
in
data
:
run
=
Run
(
it
)
runs
.
append
(
run
)
if
run
.
is_up_to_date
():
pipelines
.
setdefault
(
run
.
print_pipeline
(),
[])
pipelines
[
run
.
print_pipeline
()].
append
(
run
)
for
it
in
raw_data
:
run
=
Run
(
self
,
it
)
self
.
runs
.
append
(
run
)
if
not
validate_versions
or
self
.
run
.
is_up_to_date
():
self
.
pipelines
.
setdefault
(
run
.
print_pipeline
(),
[])
self
.
pipelines
[
run
.
print_pipeline
()].
append
(
run
)
def
group_by_n
(
arr
):
by_n
=
{}
for
i
in
arr
:
by_n
.
setdefault
(
i
.
n
,
[])
by_n
[
i
.
n
].
append
(
i
)
return
by_n
This diff is collapsed.
Click to expand it.
stats.py
+
9
−
10
View file @
37ea0d4e
#!/usr/bin/env python3
import
data
import
data
_lib
import
sys
data
=
data_lib
.
Data
()
def
f
(
val
):
return
(
str
(
val
)
+
"
"
)[
0
:
8
]
...
...
@@ -9,25 +11,22 @@ def f(val):
for
pipeline_name
,
pipeline
in
data
.
pipelines
.
items
():
print
(
pipeline_name
)
print
(
""
.
join
(
"
=
"
for
_
in
pipeline_name
))
by_n
=
{}
for
i
in
pipeline
:
by_n
.
setdefault
(
i
.
n
,
[])
by_n
[
i
.
n
].
append
(
i
)
by_n
=
data_lib
.
group_by_n
(
pipeline
)
for
n
in
sorted
(
by_n
.
keys
()):
d
ata
=
by_n
[
n
]
scores
=
[
i
.
score
/
n
for
i
in
d
ata
]
d
=
by_n
[
n
]
scores
=
[
i
.
score
/
n
for
i
in
d
]
scores
.
sort
()
l
=
len
(
scores
)
avg
=
sum
(
scores
)
/
l
print
(
f
"
{
n
:
8
}
:
{
len
(
scores
)
:
4
}
x
{
f
(
avg
)
}
10%:
{
f
(
scores
[
l
//
10
])
}
90%:
{
f
(
scores
[
l
-
1
-
l
//
10
])
}
"
)
if
any
(
i
.
mistakes
is
not
None
for
i
in
d
ata
):
scores
=
[
i
.
mistakes
/
n
for
i
in
d
ata
]
if
any
(
i
.
mistakes
is
not
None
for
i
in
d
):
scores
=
[
i
.
mistakes
/
n
for
i
in
d
]
scores
.
sort
()
l
=
len
(
scores
)
avg
=
sum
(
scores
)
/
l
print
(
f
"
mistakes:
{
f
(
avg
)
}
10%:
{
f
(
scores
[
l
//
10
])
}
90%:
{
f
(
scores
[
l
-
1
-
l
//
10
])
}
"
)
for
arg
in
sys
.
argv
[
1
:]:
scores
=
[
eval
(
arg
)
for
i
in
d
ata
]
scores
=
[
eval
(
arg
)
for
i
in
d
]
scores
.
sort
()
l
=
len
(
scores
)
avg
=
sum
(
scores
)
/
l
...
...
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