mirror of
https://github.com/iluvcapra/ptulsconv.git
synced 2025-12-31 08:50:48 +00:00
Some functional util code
This commit is contained in:
1
.idea/dictionaries/jamie.xml
generated
1
.idea/dictionaries/jamie.xml
generated
@@ -1,6 +1,7 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="jamie">
|
||||
<words>
|
||||
<w>adlib</w>
|
||||
<w>fmpxml</w>
|
||||
<w>futura</w>
|
||||
<w>ptulsconv</w>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
from typing import Generator, Callable, Iterator
|
||||
|
||||
|
||||
def apply_appends(source: Iterator,
|
||||
should_append: Callable,
|
||||
do_append: Callable) -> Generator:
|
||||
this_element = next(source)
|
||||
for element in source:
|
||||
if should_append(this_element, element):
|
||||
this_element = do_append(this_element, element)
|
||||
else:
|
||||
yield this_element
|
||||
this_element = element
|
||||
|
||||
yield this_element
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
from .doc_entity import SessionDescriptor
|
||||
from .tagged_string_parser_visitor import parse_tags
|
||||
from .doc_entity import SessionDescriptor, TrackDescriptor, TrackClipDescriptor
|
||||
from typing import Optional, Generator, List, Callable
|
||||
from tagged_string_parser_visitor import parse_tags
|
||||
from itertools import chain
|
||||
from functools import reduce
|
||||
|
||||
from fractions import Fraction
|
||||
# field_map maps tags in the text export to fields in FMPXMLRESULT
|
||||
@@ -69,14 +72,18 @@ class ADRLine:
|
||||
optional: bool
|
||||
done: bool
|
||||
|
||||
@staticmethod
|
||||
def from_clip(clip: TrackClipDescriptor,
|
||||
track: TrackDescriptor,
|
||||
session: SessionDescriptor) -> Optional['ADRLine']:
|
||||
pass
|
||||
|
||||
class ADRDocument:
|
||||
document: SessionDescriptor
|
||||
@staticmethod
|
||||
def generate_lines(session: SessionDescriptor) -> Generator['ADRLine']:
|
||||
for track in session.tracks:
|
||||
for track_clip in track.clips:
|
||||
line = ADRLine.from_clip(track_clip, track, session)
|
||||
if line is not None:
|
||||
yield line
|
||||
|
||||
def __init__(self, session: SessionDescriptor):
|
||||
self.document = session
|
||||
|
||||
def lines(self):
|
||||
header_metadata = parse_tags(self.document.header.session_name)
|
||||
#TODO continue
|
||||
|
||||
|
||||
20
tests/test_utils.py
Normal file
20
tests/test_utils.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import unittest
|
||||
|
||||
from ptulsconv.docparser import apply_appends
|
||||
|
||||
|
||||
class MyTestCase(unittest.TestCase):
|
||||
def test_something(self):
|
||||
v = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
expected = [1, 2, 7, 5, 6, 15, 9, 10]
|
||||
|
||||
should = (lambda x, y: y % 4 == 0)
|
||||
do_combine = (lambda x, y: x + y)
|
||||
|
||||
r = apply_appends(iter(v), should, do_combine)
|
||||
r1 = list(r)
|
||||
self.assertEqual(r1, expected)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user