Skip to content

Conversation

@HutchyBen
Copy link
Contributor

No description provided.

@beer-psi
Copy link
Contributor

beer-psi commented Sep 15, 2025

Fetching all scores and processing them in-memory is obscenely expensive. Other live-service games on Tachi with partitioned rating systems (e.g. old/new on GekiChuMai) have dropped in-game rating and only use NaiveRating. I think DDR should also drop in-game flare skill for a simple sum of best 90 play flare skills.

You can probably run the entire profile FlareSkill calculation as a MongoDB aggregation, though I'm not sure if that's better or worse
db.scores.aggregate([
    {
        $match: {
            game,
            playtype,
            userID,
            isPrimary: true,
            "calculatedData.flareSkill": {
                $type: "number"
            }
        }
    },
    {
        $group: {
            _id: "$chartID",
            songID: { $first: "$songID" }, // shouldn't be a problem since each chartID has only one songID
            flareSkill: { $max: "$calculatedData.flareSkill" }
        }
    },
    {
        $lookup: {
            from: "songs-ddr",
            localField: "songID",
            foreignField: "id",
            as: "song",
        }
    },
    {
        $set: {
            song: {
                $first: "$song"
            }
        }
    },
    {
        $sort: {
            "flareSkill": -1
        }
    },
    {
        $group: {
            _id: "$song.data.flareCategory",
            flareSkills: {
                $push: "$flareSkill"
            }
        }
    },
    {
        $set: {
            flareSkills: {
                $slice: ["$flareSkills", 30]
            }
        }
    },
    {
        $match: { _id: { $ne: "NONE" } }
    },
    {
        $group: {
            _id: null,
            flareSkill: {
                $sum: {
                    $sum: "$flareSkills"
                }
            }
        }
    }
])

This aggregation returns { flareSkill?: number; }. If we were on MongoDB 5.2+ we can replace the $sort, $group, $slice dance with a $topN accumulator, but I think we're on 5.0, since that's what the devcontainer is on.

{
  $group: {
    _id: "$song.data.flareCategory",
    flareSkills: {
      $topN: {
        n: 30,
        sortBy: {
          flareSkill: -1
        },
        output: "$flareSkill"
      }
    }
  }
}

@HutchyBen
Copy link
Contributor Author

I initially thought there could be some sort of PB merge for best flare but I wasn't too sure how to go about that, I'll have another look now and if I cant figure it out i'll just close this PR and leave it as an issue for another time.

@beer-psi
Copy link
Contributor

beer-psi commented Sep 16, 2025

@HutchyBen
Copy link
Contributor Author

Yeah, I think when I was initailly looking at doing a PB merge I was trying to merge flareSkill and not the actual flare which is a bit silly thinking back now. I'll test it out merging the flare in a little bit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants