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

simplify replace system #16721

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions modules/relay/src/main/RelayPlayerEnrich.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,18 @@ private case class RelayPlayersTextarea(text: String):
lines.nonEmpty.so:
text.linesIterator.take(1000).toList.flatMap(parse).toMap

// Original name / Optional rating / Optional title / Optional replacement name
// Original name / Optional FideID / Optional title / Optional rating / Optional replacement name
private def parse(line: String): Option[(PlayerName, RelayPlayerLine)] =
Comment on lines +53 to 54
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this change break all previous broadcasts replace?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it will break the previous Broadcasts a little...

but it also doesn't make sense to have 2 different systems (if 1 is used, it will alert broadcasters)

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we could do what happened with the change of the old system: leave "a month" with the system running 2 systems and then delete the old one

line.split('=').map(_.trim) match
case Array(nameStr, fideId) =>
val name = PlayerName(nameStr)
val parts = fideId.split('/').map(_.trim)
parts
.lift(0)
.flatMap(_.toIntOption)
.map: id =>
name -> RelayPlayerLine(name.some, none, parts.lift(1).flatMap(PlayerTitle.get), FideId(id).some)
case _ =>
val arr = line.split('/').map(_.trim)
arr
.lift(0)
.map: fromName =>
PlayerName(fromName) -> RelayPlayerLine(
name = PlayerName.from(arr.lift(3).filter(_.nonEmpty)),
rating = IntRating.from(arr.lift(1).flatMap(_.toIntOption)),
title = arr.lift(2).flatMap(PlayerTitle.get)
)
val arr = line.split('/').map(_.trim)
arr
.lift(0)
.map: fromName =>
PlayerName(fromName) -> RelayPlayerLine(
name = PlayerName.from(arr.lift(4).filter(_.nonEmpty)),
rating = IntRating.from(arr.lift(3).flatMap(_.toIntOption)),
title = arr.lift(2).flatMap(PlayerTitle.get),
fideId = arr.lift(1).flatMap(_.toIntOption).map(FideId(_))
)

private case class RelayPlayerLines(players: Map[PlayerName, RelayPlayerLine]):

Expand Down
12 changes: 6 additions & 6 deletions modules/relay/src/main/ui/RelayFormUi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -547,20 +547,20 @@ final class RelayFormUi(helpers: Helpers, ui: RelayUi, tourUi: RelayTourUi):
trb.replacePlayerTags(),
help = frag( // do not translate
"One line per player, formatted as such:",
pre("player name = FIDE ID"),
pre("player name / FIDE ID"),
"Example:",
pre("""Magnus Carlsen = 1503014"""),
pre("""Magnus Carlsen / 1503014"""),
"Player names ignore case and punctuation, and match all possible combinations of 2 words:",
br,
""""Jorge Rick Vito" will match "Jorge Rick", "jorge vito", "Rick, Vito", etc.""",
br,
"If the player is NM or WNM, you can:",
pre("""Player Name = FIDE ID / Title"""),
pre("""Player Name / FIDE ID / title"""),
"Alternatively, you may set tags manually, like so:",
pre("player name / rating / title / new name"),
pre("player name / FIDE ID / title / rating / new name"),
"All values are optional. Example:",
pre("""Magnus Carlsen / 2863 / GM
YouGotLittUp / 1890 / / Louis Litt""")
pre("""Magnus Carlsen / / GM / 2863
YouGotLittUp / / / 1890 / Louis Litt""")
).some,
half = true
)(form3.textarea(_)(rows := 3, spellcheck := "false", cls := "monospace")),
Expand Down
Loading