Ejemplo n.º 1
0
 def getMappingAsString(old_intervals, new_intervals):
     mapping = {}
     for iv_old in old_intervals:
         mapping[I.to_string(iv_old, conv=int)] = []
         for iv_new in new_intervals:
             if iv_new in iv_old:
                 mapping[I.to_string(iv_old, conv=int)]\
                     .append(I.to_string(iv_new, conv=int))
     return mapping
def test_to_string_customized():
    i1, i2, i3, i4 = I.closed(0, 1), I.openclosed(0, 1), I.closedopen(0, 1), I.open(0, 1)
    params = {
        'disj': ' or ',
        'sep': '-',
        'left_open': '<!',
        'left_closed': '<',
        'right_open': '!>',
        'right_closed': '>',
        'conv': lambda s: '"{}"'.format(s),
        'pinf': '+oo',
        'ninf': '-oo',
    }

    assert I.to_string(i1, **params) == '<"0"-"1">'
    assert I.to_string(i2, **params) == '<!"0"-"1">'
    assert I.to_string(i3, **params) == '<"0"-"1"!>'
    assert I.to_string(i4, **params) == '<!"0"-"1"!>'

    assert I.to_string(I.empty(), **params) == '<!!>'
    assert I.to_string(I.singleton(1), **params) == '<"1">'

    assert I.to_string(I.openclosed(-I.inf, 1), **params) == '<!-oo-"1">'
    assert I.to_string(I.closedopen(1, I.inf), **params) == '<"1"-+oo!>'

    assert I.to_string(I.closed(0, 1) | I.closed(2, 3), **params) == '<"0"-"1"> or <"2"-"3">'
Ejemplo n.º 3
0
async def on_disconnect():
    store_dict = {}

    for name, interval in time_intervals.items():
        store_dict[name] = I.to_string(interval, conv = lambda v: v.strftime('%H:%M'))

    with open('TimeFinder.data', 'w+') as file:
        file.write(str(store_dict))
def test_to_string():
    i1, i2, i3, i4 = I.closed(0, 1), I.openclosed(0, 1), I.closedopen(0, 1), I.open(0, 1)

    assert I.to_string(i1) == '[0,1]'
    assert I.to_string(i2) == '(0,1]'
    assert I.to_string(i3) == '[0,1)'
    assert I.to_string(i4) == '(0,1)'

    assert I.to_string(I.empty()) == '()'
    assert I.to_string(I.singleton(1)) == '[1]'

    assert I.to_string(I.openclosed(-I.inf, 1)) == '(-inf,1]'
    assert I.to_string(I.closedopen(1, I.inf)) == '[1,+inf)'

    assert I.to_string(I.closed(0, 1) | I.closed(2, 3)) == '[0,1] | [2,3]'
Ejemplo n.º 5
0
def time_interval_to_str(interval):
    params = {
        'disj': ', ',
        'sep': ' - ',
        'left_closed': '',
        'right_closed': '',
        'left_open': '',
        'right_open': '',
        'conv': lambda s: s.strftime('%H:%M')
    }

    return I.to_string(interval, **params)
Ejemplo n.º 6
0
    args = parser.parse_args()

    #

    d = defaultdict(list)

    for f in args.jsonfiles:
        with open(f, "rb") as infile:
            j = json.load(infile)
            loc = j['location']

            if args.split or args.intervals:
                filename, lines = loc.split(':')
                ls, le = lines.split('-')

                if args.intervals:
                    d[filename].append(intervals.closed(int(ls), int(le)))
                else:
                    print('{} {} {}'.format(filename, ls, le))
            else:
                print(loc)

    if args.intervals:
        for f, ivs in d.items():
            uiv = intervals.empty()
            for iv in ivs:
                uiv = uiv | iv
            print('{} {}'.format(f, intervals.to_string(uiv, disj=',')))

    sys.exit(0)
Ejemplo n.º 7
0
 def convertIntervalsToString(intervals):
     string_intervals = []
     for iv in intervals:
         string_intervals.append(I.to_string(iv, conv=int))
     return string_intervals