-
Notifications
You must be signed in to change notification settings - Fork 307
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
Feature: adds display of tag descriptions and regexp searching for tags #528
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f54e6b4
add descriptions for tags if they are present
fcollman 50c2557
add tag description and searching
fcollman 4cd8ebe
fix formatting
fcollman e77bd2c
fix const array
fcollman ab8a98a
fix formatting again
fcollman 2e4dd73
allow tag searching with no labels
fcollman 748a1d3
formatting fix
fcollman a4ba48d
removing console.log messages
fcollman 601df64
format fix
fcollman 3d478af
change to for loop implementation
fcollman fa07cf7
format fix
fcollman 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 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 |
---|---|---|
|
@@ -677,7 +677,7 @@ export function parseSegmentQuery( | |
}); | ||
continue; | ||
} | ||
if (labels === undefined) { | ||
if (labels === undefined && tagNames.length == 0) { | ||
errors.push({ | ||
begin: startIndex, | ||
end: endIndex, | ||
|
@@ -778,7 +778,7 @@ export function parseSegmentQuery( | |
}); | ||
continue; | ||
} | ||
if (labels === undefined) { | ||
if (labels === undefined && tagNames.length == 0) { | ||
errors.push({ | ||
begin: startIndex, | ||
end: endIndex, | ||
|
@@ -806,6 +806,7 @@ export interface TagCount { | |
tag: string; | ||
tagIndex: number; | ||
count: number; | ||
desc: string; | ||
} | ||
|
||
export interface PropertyHistogram { | ||
|
@@ -860,7 +861,10 @@ export function executeSegmentQuery( | |
} | ||
const properties = inlineProperties?.properties; | ||
const totalIds = inlineProperties.ids.length / 2; | ||
const totalTags = db?.tags?.tags?.length || 0; | ||
let indices = makeIndicesArray(totalIds, totalIds); | ||
const showTags = makeIndicesArray(totalTags, totalTags); | ||
showTags.fill(1); | ||
for (let i = 0; i < totalIds; ++i) { | ||
indices[i] = i; | ||
} | ||
|
@@ -877,16 +881,54 @@ export function executeSegmentQuery( | |
} | ||
indices = indices.subarray(0, outIndex); | ||
}; | ||
const filterByTagDescriptions = (regexp: RegExp) => { | ||
const tagDescriptions = db!.tags!.tagDescriptions!; | ||
const tags = db!.tags!.tags!; | ||
const matchingTagDescriptions = tagDescriptions | ||
.map((desc, index) => ({ desc, index })) | ||
.filter(({ desc }) => desc.match(regexp) !== null) | ||
.map(({ index }) => index); | ||
const matchingTags = tags | ||
.map((tag, index) => ({ tag, index })) | ||
.filter(({ tag }) => tag.match(regexp) !== null) | ||
.map(({ index }) => index); | ||
|
||
// set showTags based on matchingTags | ||
showTags.fill(0); | ||
matchingTagDescriptions.forEach((index) => (showTags[index] = 1)); | ||
matchingTags.forEach((index) => (showTags[index] = 1)); | ||
}; | ||
|
||
// Filter by label | ||
if (query.regexp !== undefined || query.prefix !== undefined) { | ||
const values = db!.labels!.values; | ||
const { regexp, prefix } = query; | ||
if (regexp !== undefined) { | ||
filterIndices((index) => values[index].match(regexp) !== null); | ||
if (db!.labels !== undefined) { | ||
console.log("test"); | ||
const values = db!.labels!.values; | ||
if (regexp !== undefined) { | ||
filterIndices((index) => values[index].match(regexp) !== null); | ||
} | ||
if (prefix !== undefined) { | ||
console.log("prefix", prefix); | ||
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. remove console.log 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. fixed! |
||
filterIndices((index) => values[index].startsWith(prefix)); | ||
} | ||
} | ||
if (prefix !== undefined) { | ||
filterIndices((index) => values[index].startsWith(prefix)); | ||
console.log(indices.length); | ||
// if the regular expression returns nothing | ||
// then assudme the user wants to search through the tags | ||
// and/or tag descriptions | ||
if ( | ||
(indices.length == 0 && regexp !== undefined) || | ||
(db!.labels == undefined && regexp != undefined) | ||
) { | ||
console.log("test3"); | ||
indices = makeIndicesArray(totalIds, totalIds); | ||
for (let i = 0; i < totalIds; ++i) { | ||
indices[i] = i; | ||
} | ||
filterByTagDescriptions(regexp); | ||
// reset regexp to none so that it doesn't get applied again | ||
query.regexp = undefined; | ||
} | ||
} | ||
|
||
|
@@ -924,7 +966,6 @@ export function executeSegmentQuery( | |
const regexp = new RegExp(pattern); | ||
filterIndices((index) => values[index].match(regexp) !== null); | ||
} | ||
|
||
let intermediateIndicesMask: IndicesArray | undefined; | ||
let intermediateIndices: IndicesArray | undefined; | ||
|
||
|
@@ -970,7 +1011,7 @@ export function executeSegmentQuery( | |
let tagStatistics: TagCount[] = []; | ||
if (tagsProperty !== undefined) { | ||
const tagStatisticsInQuery: TagCount[] = []; | ||
const { tags, values } = tagsProperty; | ||
const { tags, values, tagDescriptions } = tagsProperty; | ||
const tagCounts = new Uint32Array(tags.length); | ||
for (let i = 0, n = indices.length; i < n; ++i) { | ||
const value = values[indices[i]]; | ||
|
@@ -983,9 +1024,16 @@ export function executeSegmentQuery( | |
tagIndex < numTags; | ||
++tagIndex | ||
) { | ||
if (showTags[tagIndex] === 0) continue; | ||
const count = tagCounts[tagIndex]; | ||
const tag = tags[tagIndex]; | ||
const tagCount = { tag, tagIndex, count: tagCounts[tagIndex] }; | ||
const tagDesc = tagDescriptions[tagIndex]; | ||
const tagCount = { | ||
tag, | ||
tagIndex, | ||
count: tagCounts[tagIndex], | ||
desc: tagDesc, | ||
}; | ||
if (query.includeTags.includes(tag) || query.excludeTags.includes(tag)) { | ||
tagStatisticsInQuery.push(tagCount); | ||
} else if (count > 0) { | ||
|
This file contains 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.
It would probably be more efficient to just iterate over the tags with a for loop --- then we wouldn't need to create all of these temporary arrays.
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 i've addressed this.. it's failing tests for unrelated reasons.
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.
see #544 for python linting error fix