Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tvbd_diff: Add write_log option #40

Closed
wants to merge 3 commits into from
Closed

tvbd_diff: Add write_log option #40

wants to merge 3 commits into from

Conversation

DeadNews
Copy link
Contributor

For example:

frames = [
    3093, 3094, 3095, 3096, 3097, 3098, 3099, 3100, 3101, 3102, 3103, 3104, 3105, 3106, 3107, 3108, 3109, 3110, 3111,
    3112, 3113, 3114, 3115, 3116, 3117, 3118, 3119, 3120, 3121, 3122, 3123, 3124, 3125, 3126, 3127, 3128, 3129, 3130,
    3131, 3132, 3133, 3134, 3135, 3136, 3137, 3138, 3139, 3140, 3141, 3142, 3143, 3144, 3145, 3146, 3147, 3148, 3149,
    3150, 3151, 3152, 3153, 3154, 3155, 3156, 3157, 3158, 3159, 3160, 3161, 3162, 3163, 3164, 3165, 3166, 3167, 3168,
    3169, 3170, 3171, 3172, 3173, 3174, 3175, 34645, 34646, 34647, 34648, 34649, 34650, 34651, 34652, 34653, 34654,
    34655, 34656, 34657, 34658, 34659, 34660, 34661, 34662, 34663, 34664, 34665, 34666, 34667, 34668, 34669, 34670,
    34671, 34672, 34673, 34674, 34675, 34676, 34677, 34678, 34679, 34680, 34681, 34682, 34683, 34684, 34685, 34686,
    34687, 34688, 34689, 34690, 34691, 34692
]

write_log = True
#ep_name = 'e1'
ep_name = 'e2'

if write_log:
    from itertools import groupby, count

    def intervals(frames: list) -> list:
        out = []
        counter = count()

        for key, group in groupby(frames, key=lambda x: x - next(counter)):
            block = tuple(group)
            out.append((block[0], block[-1]))
        return out

    with open('./diff.log', 'a') as log:
        if ep_name:
            log.write(f"{ep_name}: ")
        log.write(f"{str(intervals(frames))} \n\n")

will create ./diff.log that contains:

e1: [(3093, 3175), (34645, 34692)] 

e2: [(3093, 3175), (34645, 34692)] 

@@ -483,7 +483,9 @@ def stack_planes(clip: vs.VideoNode, /, stack_vertical: bool = False) -> vs.Vide
def tvbd_diff(tv: vs.VideoNode, bd: vs.VideoNode,
thr: float = 72,
height: int = 288,
return_array: bool = False) -> vs.VideoNode:
return_array: bool = False,
write_log: bool = False,
Copy link
Collaborator

@tomato39 tomato39 Dec 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel like we should just pass a file handle (maybe typing.Optional[typing.TextIO]?), then the caller can prepend/append any extra data they want (like episode name) as well as use a specific path

another option is just returning the list and letting the caller deal with it/letting them just process the data however they want

@@ -536,6 +541,23 @@ def tvbd_diff(tv: vs.VideoNode, bd: vs.VideoNode,
if not frames:
raise ValueError("tvbd_diff: no differences found")

if write_log:
from itertools import groupby, count
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

itertools is pretty standard so there's not really a reason to defer this import rather than putting it at the top of the py file

if write_log:
from itertools import groupby, count

def intervals(frames: list) -> list:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no real reason to nest this this deeply, can just make it a top-level function like _get_diff_intervals
also the correct typehint for frames should be typing.List[int] and it returns typing.List[typing.Tuple[int, int]]

return out

with open('./diff.log', 'a') as log:
if ep_name:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per above, this can be handled by the caller

from itertools import groupby, count

def intervals(frames: list) -> list:
out = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably needs typehinted

out = []
counter = count()

for key, group in groupby(frames, key=lambda x: x - next(counter)):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use _ for key as a placeholder to make linters happier since it's unused

@DeadNews
Copy link
Contributor Author

DeadNews commented Dec 27, 2020

On second thought, maybe just add the ability to return frames too?

return frames, Stack((tvbd_stack, diff), direction=Direction.VERTICAL).clip

That would be enough for me.

@tomato39
Copy link
Collaborator

i think returning the frame list would be a good option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants