Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions dashboard_pianoroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,16 @@ def main():


def prepare_fragments(df: pd.DataFrame, piece: MidiPiece, n: int) -> list[dict]:
# Unpack
# Filter fragments with most variants (top 5)
df = df.nlargest(5, "n_variants")

fragments = []
max_fragments = 5
max_variants = 5
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to separate this logic from the prepare_fragments function. If we want the dashboard to be helpful in reviewing different fragmentation methods, a structure like this would be better:

fragments = prepare_fragments(df, piece, n)

filtering_method = st.select_box(
  label="Filtering method",
  options=["Top 5", "Fastes", "Longest"],
)

if filtering_method == "Top 5":
  filtered_fragments = top_five_filtering(fragments)
elif filtering_method == "Fastes":
  filtered_fragments = get_fastests_filtering(fragments)
...

for fragment in filtered_fragments:
  # Dsiplay
  ...

That way, you'll also be forced to come up with names for different filtering strategies, which will be useful in reviewing :)


for it, row in df.iterrows():
variants = []

for idx in row.idxs:
start_idx = idx - row.left_shift
start_idx = max(start_idx, 0)
Expand All @@ -94,8 +100,19 @@ def prepare_fragments(df: pd.DataFrame, piece: MidiPiece, n: int) -> list[dict]:
finish_note_index=int(finish_idx),
)
variants.append(variant)
fragment = dict(variants=variants)
fragments.append(fragment)

# Filter out fragments with long pauses
max_pause_duration = 2.0
if finish_time - start_time > max_pause_duration:
Copy link
Member

Choose a reason for hiding this comment

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

I'm not convinced that this filters out fragments with long pauses - this condition seems to be true for every variant that is longer than 2s :)

if len(variants) >= max_variants:
break

if len(variants) > 0:
fragment = dict(variants=variants)
fragments.append(fragment)

if len(fragments) >= max_fragments:
break

return fragments

Expand Down