sekassel / stp-24-server-tracker

Issue Tracker and Feature Requests for the STP 2024 Server.
0 stars 0 forks source link

Rate of Change for all ressources. #10

Closed NoCodeNoBlunder closed 2 months ago

NoCodeNoBlunder commented 3 months ago

Is your feature request related to a problem? Please describe. We would like to give the player a prognose about the passiv income/cost over the next period for all resources. Currently the Server only supports aggregating one Variable at the time which does make this a hard task because of the ratelimit as there is 9 unique resource types.

Describe the solution you'd like The /api/v1/games/{game}/empires/{empire}/aggregates/{aggregate} endpoint of the server supports another new aggregate resources.periodic.all which returns the Schema that look like this example.

{
  "credits": AggregateResult,
  "population": AggregateResult,
  "energy": AggregateResult,
  "minerals": AggregateResult,
  "food": AggregateResult,
  "fuel": AggregateResult,
  "research": AggregateResult,
  "alloys": AggregateResult,
  "consumer_goods": AggregateResult
}

The /api/v1/games/{game}/empires/{empire}/aggregates/{aggregate} would then return oneOf two possible option similar to how /api/v1/games/{game}/empires/{empire} works.

It would be nice if you could still query for a specific System like resources.periodic allows it to get the rate of Change for one specific System.

Alternatives:

Describe alternatives you've considered

Clashsoft commented 3 months ago

The aggregate endpoint is rate limited to 60 requests per 60 seconds. Even at game speed 4 you only need 9*4 = 36 requests per minute.

If your problem relates to this point

Whenever some action is taken that changes the income, update only the rate of the affected resource.

then you should know that even in Stellaris, the forecast does not update immediately when building something but only at the start of a new month.

Clashsoft commented 3 months ago

I found a way to implement this efficiently. It will be in the next update. The schema will not change though, so the individual items that make up a resource's explanation will be lost. Here is an example:

GET /api/v1/games/{game}/empires/66119f9a0b0f4d8642ee8958/aggregates/resources.periodic (no query parameters):

{
  "total": 416.9276884199139,
  "items": [
    {
      "variable": "resources.credits.periodic",
      "count": 1,
      "subtotal": 0
    },
    {
      "variable": "resources.population.periodic",
      "count": 1,
      "subtotal": 13.825438419891725
    },
    {
      "variable": "resources.energy.periodic",
      "count": 1,
      "subtotal": 258.0250000000233
    },
    {
      "variable": "resources.minerals.periodic",
      "count": 1,
      "subtotal": 161.11699999999837
    },
    {
      "variable": "resources.food.periodic",
      "count": 1,
      "subtotal": -148.806
    },
    {
      "variable": "resources.fuel.periodic",
      "count": 1,
      "subtotal": 24.912500000002183
    },
    {
      "variable": "resources.research.periodic",
      "count": 1,
      "subtotal": 39.191249999999854
    },
    {
      "variable": "resources.alloys.periodic",
      "count": 1,
      "subtotal": 47.21249999999782
    },
    {
      "variable": "resources.consumer_goods.periodic",
      "count": 1,
      "subtotal": 21.450000000000728
    }
  ]
}