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

add average frequency tag #1479

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

tadorituki
Copy link

this is a draft.
added a tag that displays the harmonic mean of the frequency ranks
updated a few things from #1303

Copy link

codspeed-hq bot commented Oct 12, 2024

CodSpeed Performance Report

Merging #1479 will not alter performance

Comparing tadorituki:tadoru (37b6431) with master (1bea0f4)

Summary

✅ 3 untouched benchmarks

@tadorituki tadorituki marked this pull request as ready for review October 13, 2024 02:56
@tadorituki tadorituki requested a review from a team as a code owner October 13, 2024 02:56
@tadorituki
Copy link
Author

this is ready for merge, please review

Copy link

github-actions bot commented Oct 14, 2024

⚠️ Visual differences introduced by this PR; please validate if they are desirable.

View Playwright Report (note: open the "playwright-report" artifact)

@tadorituki tadorituki marked this pull request as draft October 14, 2024 18:14
@tadorituki tadorituki marked this pull request as ready for review October 14, 2024 20:13
@tadorituki
Copy link
Author

fixed issues with unit tests, now ready to merge

Copy link
Member

@Kuuuube Kuuuube left a comment

Choose a reason for hiding this comment

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

<div class="settings-item"><div class="settings-item-inner">
<div class="settings-item-left">
<div class="settings-item-label">Average frequencies</div>
<div class="settings-item-description">Compress frequency tags into one "Average" freqeuncy tag.</div>
Copy link
Member

Choose a reason for hiding this comment

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

Clarify that this is the harmonic average not a normal average also typo "freqeuncy".

}
}

const avgFrequencies = Object.keys(averages).flatMap((termName) => Object.keys(averages[termName]).map((readingName) => ({term: termName, reading: readingName, values: [{frequency: Math.round(averages[termName][readingName].currentAvg), displayValue: Math.round(averages[termName][readingName].currentAvg).toString()}]})));
Copy link
Member

Choose a reason for hiding this comment

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

Can this be formatted in a sane way? Maybe splitting out to descriptively named variables or at least adding some newlines in there.

}
results.push({dictionary, frequencies, dictionaryAlias});
}

for (const currentTerm of Object.keys(averages)) {
Copy link
Member

Choose a reason for hiding this comment

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

Should averages really be defined as an object if you need to loop over it here?

for (const currentTerm of Object.keys(averages)) {
const readingArray = Object.keys(averages[currentTerm]);
const nullIndex = readingArray.indexOf('');
if (readingArray.length === 2 && nullIndex >= 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this specifically checking for two readings? What is the point of nullIndex? This feels wrong.

Comment on lines -88 to +91
for (const {term, reading, values} of map2.values()) {
for (let {term, reading, values} of map2.values()) {
Copy link
Member

Choose a reason for hiding this comment

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

It would be better to keep this const and define new variables when you need to modify stuff.

let {currentAvg, count} = averages[term]?.[reading] ?? {currentAvg: 1, count: 0};
if (valuesArray[0].frequency === null) { continue; }

currentAvg = (count / (currentAvg)) + (1 / (valuesArray[0].frequency));
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary parentheses here.

frequencies.push({
term,
reading,
values: [...values.values()],
});
const valuesArray = [...values.values()];
if (reading === null) { reading = ''; }
Copy link
Member

Choose a reason for hiding this comment

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

This feels like the wrong way to handle this.

Comment on lines +1937 to +1945

:root[data-average-frequency=false] .frequency-group-item:last-child {
display: none;
}

:root[data-average-frequency=true] .frequency-group-item:not(:last-child) {
display: none;
}

Copy link
Member

Choose a reason for hiding this comment

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

This seems like a fragile way of setting this up. It would be better to have specific ids or a class.

@Kuuuube
Copy link
Member

Kuuuube commented Oct 15, 2024

It's probably also a good idea to split out the average calculation from the groupTermFrequencies function. Maybe just have a call to a different function inside the groupTermFrequencies that adds on to the data or whatever it needs to do.

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.

2 participants