Skip to content

Commit

Permalink
Create games with positionComments map
Browse files Browse the repository at this point in the history
  • Loading branch information
jackstenglein committed Apr 4, 2024
1 parent 30b187c commit cccb18e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend/pgnService/game/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export function getGame(
pgn: chess.renderPgn(),
orientation,
comments: [],
positionComments: {},
unlisted: Boolean(unlisted),
timelineId,
},
Expand Down
3 changes: 3 additions & 0 deletions backend/pgnService/game/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export interface Game {
/** The comments left on the game. */
comments: any[];

/** A map from the normalized FEN of a position to the comments on that position. */
positionComments: Record<string, any>;

/** Whether the game is unlisted. */
unlisted: boolean;

Expand Down
11 changes: 7 additions & 4 deletions scripts/convert_game_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def process_game(batch, game):
comments = game.get('comments', [])
if comments is None:
comments = []

existing_position_comments = game.get('positionComments', None)
if existing_position_comments is not None:
return 0

for c in comments:
new_comment = {
Expand All @@ -33,6 +37,7 @@ def process_game(batch, game):

game['positionComments'] = position_comments
batch.put_item(Item=game)
return 1


def main():
Expand All @@ -46,8 +51,7 @@ def main():

with table.batch_writer() as batch:
for item in items:
process_game(batch, item)
updated += 1
updated += process_game(batch, item)

while lastKey != None:
print(lastKey)
Expand All @@ -56,8 +60,7 @@ def main():
lastKey = res.get('LastEvaluatedKey', None)
items = res.get('Items', [])
for item in items:
process_game(batch, item)
updated += 1
updated += process_game(batch, item)

except Exception as e:
print(e)
Expand Down

0 comments on commit cccb18e

Please sign in to comment.