-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Added categorization for data_selector.Selection #1324
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3b5caeb
Added categorization for data_selector.Selection
stephanwlee f0c3c3a
Pipe the tags information to selection
stephanwlee 780be5d
Promise to write test
stephanwlee 2082ad9
Bug fix: accessed map with get
stephanwlee 9c40b4c
Sort the tag name when search returns
stephanwlee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,10 +28,10 @@ export enum CategoryType { | |
| PREFIX_GROUP, | ||
| } | ||
| export interface PrefixGroupMetadata { | ||
| type: CategoryType.PREFIX_GROUP; | ||
| type: CategoryType; | ||
| } | ||
| export interface SearchResultsMetadata { | ||
| type: CategoryType.SEARCH_RESULTS; | ||
| type: CategoryType; | ||
| validRegex: boolean; | ||
| universalRegex: boolean; // is the search query ".*"? ("(?:)" doesn't count) | ||
| } | ||
|
|
@@ -45,6 +45,18 @@ export interface Category<T> { | |
| export type TagCategory = Category<{tag: string, runs: string[]}>; | ||
| export type RunTagCategory = Category<{tag: string, run: string}>; | ||
|
|
||
| /** | ||
| * Organize data by tagPrefix, tag, then list of series which is comprised of | ||
| * an experiment and a run. | ||
| */ | ||
| export type SeriesCategory = Category<{ | ||
| tag: string, | ||
| series: Array<{ | ||
| experiment: string, | ||
| run: string, | ||
| }>, | ||
| }>; | ||
|
|
||
| export type RawCategory = Category<string>; // Intermediate structure. | ||
|
|
||
| /** | ||
|
|
@@ -110,25 +122,103 @@ export function categorizeTags( | |
| query?: string): TagCategory[] { | ||
| const tags = tf_backend.getTags(runToTag); | ||
| const categories = categorize(tags, query); | ||
| const tagToRuns: {[tag: string]: string[]} = {}; | ||
| tags.forEach(tag => { | ||
| tagToRuns[tag] = []; | ||
| }); | ||
| selectedRuns.forEach(run => { | ||
| (runToTag[run] || []).forEach(tag => { | ||
| tagToRuns[tag].push(run); | ||
| }); | ||
| }); | ||
| const tagToRuns = createTagToRuns(_.pick(runToTag, selectedRuns)); | ||
|
|
||
| return categories.map(({name, metadata, items}) => ({ | ||
| name, | ||
| metadata, | ||
| items: items.map(tag => ({ | ||
| tag, | ||
| runs: tagToRuns[tag].slice(), | ||
| runs: tagToRuns.get(tag).slice(), | ||
| })), | ||
| })); | ||
| } | ||
|
|
||
| /** | ||
| * Creates grouping of the data based on selection from tf-data-selector. It | ||
| * groups data by prefixes of tag names and by tag names. Each group contains | ||
| * series, a tuple of experiment name and run name. | ||
| */ | ||
| export function categorizeSelection( | ||
| selection: tf_data_selector.Selection[], pluginName: string): | ||
| SeriesCategory[] { | ||
| const tagToSeries = new Map(); | ||
| const searchTags = new Set(); | ||
|
|
||
| selection.forEach(({experiment, runs, tagRegex}) => { | ||
| const runNames = runs.map(({name}) => name); | ||
| const selectedRunToTag = createRunToTagForPlugin(runs, pluginName); | ||
| const tagToSelectedRuns = createTagToRuns(selectedRunToTag); | ||
| const tags = tf_backend.getTags(selectedRunToTag); | ||
|
|
||
| const searchCategory = categorizeBySearchQuery(tags, tagRegex); | ||
| // list of matching tags. | ||
| searchCategory.items.forEach(tag => searchTags.add(tag)); | ||
|
|
||
| // list of all tags that has selected runs. | ||
| tags.forEach(tag => { | ||
| const series = tagToSeries.get(tag) || []; | ||
| series.push(...tagToSelectedRuns.get(tag) | ||
| .map(run => ({experiment: experiment.name, run}))); | ||
| tagToSeries.set(tag, series); | ||
| }); | ||
| }); | ||
|
|
||
| const searchCategory = { | ||
| name: selection.length == 1 ? selection[0].tagRegex : 'multi', | ||
| metadata: { | ||
| type: CategoryType.SEARCH_RESULTS, | ||
| validRegex: false, | ||
| universalRegex: false, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do the false values for these properties (validRegex, universalRegex) actually matter here? Or will they get overridden and/or ignored later on somehow? |
||
| }, | ||
| items: Array.from(searchTags) | ||
| .sort(vz_sorting.compareTagNames) | ||
| .map(tag => ({ | ||
| tag, | ||
| series: tagToSeries.get(tag), | ||
| })), | ||
| }; | ||
|
|
||
| // Organize the tag to items by prefix. | ||
| const prefixCategories = categorizeByPrefix(Array.from(tagToSeries.keys())) | ||
| .map(({name, metadata, items}) => ({ | ||
| name, | ||
| metadata, | ||
| items: items.map(tag => ({ | ||
| tag, | ||
| series: tagToSeries.get(tag), | ||
| })), | ||
| })); | ||
|
|
||
| return [ | ||
| searchCategory, | ||
| ...prefixCategories, | ||
| ]; | ||
| } | ||
|
|
||
| function createTagToRuns(runToTag: RunToTag): Map<string, string[]> { | ||
| const tagToRun = new Map(); | ||
| Object.keys(runToTag).forEach(run => { | ||
| runToTag[run].forEach(tag => { | ||
| const runs = tagToRun.get(tag) || []; | ||
| runs.push(run); | ||
| tagToRun.set(tag, runs); | ||
| }); | ||
| }); | ||
| return tagToRun; | ||
| } | ||
|
|
||
| function createRunToTagForPlugin(runs: tf_backend.Run[], pluginName: string): | ||
| RunToTag { | ||
| const runToTag = {}; | ||
| runs.forEach((run) => { | ||
| runToTag[run.name] = run.tags | ||
| .filter(tag => tag.pluginName == pluginName) | ||
| .map(({name}) => name); | ||
| }) | ||
| return runToTag; | ||
| } | ||
|
|
||
| function compareTagRun(a, b: {tag: string, run: string}): number { | ||
| const c = vz_sorting.compareTagNames(a.tag, b.tag); | ||
| if (c != 0) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we probably want to resort searchTags at some point so that the result is still in "tag-comparison order" (same as now) within the "search" category pane. Right now if I'm not mistaken, each individual batch of tags is sorted but they aren't sorted overall, and Set just preserves insertion order, so you might get a result like "aa, zz, ab, ac" if "aa, zz" are in the first experiment and "aa, ab, ac" are in the second one, which seems undesirable.
Maybe good to have a test for this case too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Thanks for the insight