Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
firanka
Manage
Activity
Members
Labels
Plan
Issues
0
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
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
firanka
Commits
4ee5a588
Commit
4ee5a588
authored
7 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
what timeproviders?
parent
d1d6e4e4
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+0
-6
0 additions, 6 deletions
README.md
firanka/builders.py
+4
-4
4 additions, 4 deletions
firanka/builders.py
firanka/timeproviders.py
+0
-59
0 additions, 59 deletions
firanka/timeproviders.py
tests/test_timeproviders.py
+0
-20
0 additions, 20 deletions
tests/test_timeproviders.py
with
4 additions
and
89 deletions
README.md
+
0
−
6
View file @
4ee5a588
...
@@ -149,9 +149,3 @@ Or you can check for strict inclusion
...
@@ -149,9 +149,3 @@ Or you can check for strict inclusion
```
python
```
python
Range
(
'
<-1;1>
'
)
in
Range
(
'
<-2;2>
'
)
Range
(
'
<-1;1>
'
)
in
Range
(
'
<-2;2>
'
)
```
```
## TimeProviders
**EXPERIMENTAL**
Can be imported from _sai.timeproviders_.
This diff is collapsed.
Click to expand it.
firanka/builders.py
+
4
−
4
View file @
4ee5a588
...
@@ -5,6 +5,7 @@ import logging
...
@@ -5,6 +5,7 @@ import logging
import
copy
import
copy
from
.series
import
Series
,
DiscreteSeries
from
.series
import
Series
,
DiscreteSeries
from
.ranges
import
Range
from
.ranges
import
Range
from
sortedcontainers
import
SortedList
"""
"""
Update knowledge of current discrete series
Update knowledge of current discrete series
...
@@ -43,11 +44,10 @@ class DiscreteSeriesBuilder(object):
...
@@ -43,11 +44,10 @@ class DiscreteSeriesBuilder(object):
:return: a new DiscreteSeries instance
:return: a new DiscreteSeries instance
"""
"""
new_data
=
[]
new_data
=
SortedList
()
cp_new_data
=
copy
.
copy
(
self
.
new_data
)
cp_new_data
=
copy
.
copy
(
self
.
new_data
)
# Update
# Update
- series.data is sorted, so no worries :)
for
k
,
v
in
self
.
series
.
data
:
for
k
,
v
in
self
.
series
.
data
:
if
k
in
cp_new_data
:
if
k
in
cp_new_data
:
v
=
cp_new_data
.
pop
(
k
)
v
=
cp_new_data
.
pop
(
k
)
...
@@ -55,6 +55,6 @@ class DiscreteSeriesBuilder(object):
...
@@ -55,6 +55,6 @@ class DiscreteSeriesBuilder(object):
# Add those that remained
# Add those that remained
for
k
,
v
in
cp_new_data
.
items
():
for
k
,
v
in
cp_new_data
.
items
():
new_data
.
a
ppen
d
((
k
,
v
))
new_data
.
a
d
d
((
k
,
v
))
return
DiscreteSeries
(
new_data
,
self
.
domain
)
return
DiscreteSeries
(
new_data
,
self
.
domain
)
This diff is collapsed.
Click to expand it.
firanka/timeproviders.py
deleted
100644 → 0
+
0
−
59
View file @
d1d6e4e4
# coding=UTF-8
from
__future__
import
print_function
,
absolute_import
,
division
from
.ranges
import
Range
from
.series
import
Series
class
BijectionMapping
(
object
):
def
__init__
(
self
,
user2float
,
float2user
):
"""
:param user2float: callable/1 => float, mapping from your time system to floats
:param float2user: callable/float => 1, mapping from float to your time systen
"""
self
.
user2float
=
user2float
self
.
float2user
=
float2user
def
to_float
(
self
,
user
):
return
self
.
user2float
(
user
)
def
to_user
(
self
,
flt
):
return
self
.
float2user
(
flt
)
class
TimeProvidedSeries
(
Series
):
"""
If your time is something else than simple floats, this will help you out
"""
def
__init__
(
self
,
series
,
mapping
,
*
args
,
**
kwargs
):
"""
:param series: series to overlay
"""
super
(
TimeProvidedSeries
,
self
).
__init__
(
series
.
domain
,
*
args
,
**
kwargs
)
self
.
mapping
=
mapping
self
.
series
=
series
def
_withmap
(
self
,
series
):
return
TimeProvidedSeries
(
series
,
self
.
mapping
)
def
__getitem__
(
self
,
item
):
if
isinstance
(
item
,
slice
):
item
=
slice
(
float
(
'
-inf
'
)
if
slice
.
start
is
None
else
self
.
to_float
(
slice
.
start
),
float
(
'
+inf
'
)
if
slice
.
stop
is
None
else
self
.
to_float
(
slice
.
stop
),
)
return
self
.
_withmap
(
self
.
series
[
item
])
elif
isinstance
(
item
,
Range
):
return
self
.
_withmap
(
self
.
series
[
item
])
else
:
return
self
.
series
[
self
.
mapping
.
to_float
(
item
)]
def
_get_for
(
self
,
item
):
return
self
.
series
[
self
.
l2f
(
item
)]
def
join
(
self
,
series
,
fun
):
return
TimeProvidedSeries
(
self
.
series
.
join
(
series
,
fun
),
self
.
mapping
)
This diff is collapsed.
Click to expand it.
tests/test_timeproviders.py
deleted
100644 → 0
+
0
−
20
View file @
d1d6e4e4
# coding=UTF-8
from
__future__
import
print_function
,
absolute_import
,
division
import
unittest
from
firanka.series
import
DiscreteSeries
from
firanka.timeproviders
import
TimeProvidedSeries
,
BijectionMapping
class
TestTimeproviders
(
unittest
.
TestCase
):
def
test_base
(
self
):
map
=
BijectionMapping
(
lambda
hhmm
:
hhmm
[
0
]
*
60
+
hhmm
[
1
],
lambda
t
:
(
t
//
60
,
t
%
60
)
)
ser
=
DiscreteSeries
([(
0
,
17
),
(
60
,
20
),
(
120
,
18
)])
ts
=
TimeProvidedSeries
(
ser
,
map
)
self
.
assertEqual
(
ts
[(
2
,
0
)],
18
)
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