-
Notifications
You must be signed in to change notification settings - Fork 0
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 more metrics and clean up old code #40
Conversation
src/index.ts
Outdated
// console.log(`lichess link to game played: ${siteLink}`); | ||
for (const metric of metrics) { | ||
const historyGenerator = cjsmin.historyGenerator(game.moves); | ||
metric.processGame(Array.from(historyGenerator), siteLink); |
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.
if i understand this correctly, we are processing siteLink for every game, not just the ones that "win" the metric? that seems inefficient
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 is. I think below you mention passing the metadata. We can do that instead and it's probably a better pattern
if (singleGameMap[uas].total > this.pieceMaxes.distance) { | ||
this.pieceMaxes.uasArray = [uas as UASymbol]; | ||
this.pieceMaxes.distance = singleGameMap[uas].total; | ||
// this.singleGameMaxPiece.link = undefined; // TODO: add game link support |
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.
how can we pull out metadata data from the game being processed? shouldn't it be similar given this is under a for loop with games passed to it? is the issue that the move and board don't contain the metadata?
if yes, we just need to add the metadata as a third array as part of game no?
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.
now passing md
}; | ||
} | ||
logResults(): void { | ||
console.timeEnd('Task 2: getMoveDistanceSetOfGames'); |
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.
this needs to be changed as this function name is obsolete?
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.
deleted
maxAvgDistance: number; | ||
minAvgDistance: number; | ||
totalDistance: number; | ||
maxSingleGameTotal: number; |
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.
should be maxSingleGameDistance no?
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.
using this in all spots now
for (const uas of Object.keys(singleGameMap)) { | ||
this.distanceMap[uas].total += singleGameMap[uas].total; | ||
if ( | ||
singleGameMap[uas].total > this.distanceMap[uas].maxSingleGameDistance |
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.
where does maxSingleGameDistance come from? you have defined maxSingleGame, and maxSingleGameTotal, but not maxSingleGameDistance. i think you might be using both maxSingleGameTotal and maxSingleGameDistance for the same purpose, need to pick one
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.
there are some typing issues with indexed based on the object mapper keys that I didn't want to deal with, one of these should be throwing a compiler error but it's masked by the object indexing. I've switched to just one
|
||
export interface FileReaderGame { | ||
moves: string; | ||
metadata: string[]; | ||
} | ||
|
||
export type UAPMap<T> = { | ||
[key in UASymbol]: T; |
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.
T as the key? to set it to something that wouldn't be used as starting value?
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.
look up generic types
} | ||
|
||
/** | ||
* A utitily function to create an object with unambiguous piece symbols as keys |
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.
utility spelled wrong ;)
return map as { [key in UASymbol]: T }; | ||
} | ||
|
||
export function createBoardMap<T extends Object>(object: T): BoardMap<T> { |
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.
in what contexts do you imagine these being used?
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'm using it rn
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.
when we need a map of squares --> UAS --> some tracking counts
@@ -3,7 +3,7 @@ import { Chess } from '../cjsmin/src/chess'; | |||
|
|||
const pgnEP = `1. d2d4 f7f5 2. b2b3 e7e6 3. c1b2 d7d5 4. g1f3 f8d6 5. e2e3 g8f6 6. b1d2 e8g8 7. c2c4 c7c6 8. f1d3 b8d7 9. e1g1 f6e4 10. a1c1 g7g5 11. h2h3 d8e8 12. d3e4 d5e4 13. f3g5 e8g6 14. h3h4 h7h6 15. g5h3 d7f6 16. f2f4 e4f3 17. d2f3 f6g4 18. d1e2 d6g3 19. h3f4 g6g7 20. d4d5 g7f7 21. d5e6 c8e6 22. f3e5 g4e5 23. b2e5 g8h7 24. h4h5 f8g8 25. e2f3 g3f4 26. e5f4 g8g4 27. g2g3 a8g8 28. c1c2 b7b5 29. c4b5 e6d5 30. f3d1 f7h5 31. c2h2 g4g3+ 32. f4g3 g8g3+ 33. g1f2 h5h2+ 34. f2e1 g3g2 35. d1d3 d5e4 36. d3d7+ h7g6 37. b5c6 g2e2+ 38. e1d1 e2a2 0-1`; | |||
|
|||
xdescribe('Game history for en passant move should show valid captured piece', () => { | |||
describe('Game history for en passant move should show valid captured piece', () => { |
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.
test looks good to me. can you add expects for unambiguous pieces
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.
all of your comments are above the code that actually matters. PR comments show the lines you select, or the 4 above your comment
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 don't understand what you wan the test here to do
@@ -1,6 +1,6 @@ | |||
import { Chess } from '../cjsmin/src/chess'; | |||
|
|||
xdescribe('Queenside castling is detected', () => { | |||
describe('Queenside castling is detected', () => { |
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.
where does the .filter function come from? chess.js?
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.
this is old test. Filter is a method applicable to arrays
No description provided.