Skip to content

Conversation

@warriorstar-orion
Copy link
Contributor

@warriorstar-orion warriorstar-orion commented May 26, 2025

This PR creates a v2 API namespace for Parastats, and adds its first method.

Besides any new API endpoints not present on v1, the v2 namespace is differentiated because it returns JSON-formatted results of feedback data, rather than a stringified JSON value.

/v2/stats/feedback:

  • accepts a feedback key key_name, and two dates, start_date and end_date, which must consist of a span of two months max.
  • returns a list of objects which provide a round ID and the data of the feedback for that round's key_name.

This makes it painless to quickly perform queries on individual feedback keys and helps to lessen the need for mirroring feedback data locally:

2025_05_26__12_15_54__parastats_v2… (2) - JupyterLab

The LINQ query resolves nicely into a single SQL query which runs quickly. Concatenating the strings together the way we're doing here is a tiny bit slower, but not egregiously so for queries limited to two months max.

Comment on lines +42 to +52
var end_datetime = end_date.ToDateTime(TimeOnly.MaxValue);
var feedbacks = (from feedback in _context.Feedbacks
join round in _context.Rounds on feedback.RoundId equals round.Id
orderby round.Id
where feedback.KeyName == key_name
&& round.ShutdownDatetime != null
&& round.InitializeDatetime >= start_datetime
&& round.InitializeDatetime <= end_datetime
// feedback.JSON begins with `{"data": ...` so we strip the first curly brace
// in order to interpolate the rest of the JSON data into the resultant string
select $"{{\"round_id\": {round.Id}, {feedback.Json.Substring(1)}");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this manages to resolve to a single query, including the substring manip, which is pretty cool:

SELECT `r`.`id`, 
       SUBSTRING(`f`.`json`, 1 + 1, CHAR_LENGTH(`f`.`json`))
FROM `feedback` AS `f`
INNER JOIN `round` AS `r` 
    ON `f`.`round_id` = `r`.`id`
WHERE (((`f`.`key_name` = @__key_name_0) 
        AND `r`.`shutdown_datetime` IS NOT NULL) 
        AND (`r`.`initialize_datetime` >= @__start_datetime_1)) 
        AND (`r`.`initialize_datetime` <= @__end_datetime_2)
ORDER BY `r`.`id`

Comment on lines +55 to +59
{
Content = "[" + string.Join(", ", feedbacks) + "]",
ContentType = "application/json",
StatusCode = 200
};
Copy link
Member

Choose a reason for hiding this comment

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

I hate that we are manually constructing JSON but this PR has been up long enough.

@AffectedArc07 AffectedArc07 merged commit 4f4cedc into ParadiseSS13:master Sep 5, 2025
1 check passed
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.

3 participants