stickz / Redstone

Redstone GitHub - Nuclear Dawn community project
GNU General Public License v2.0
20 stars 20 forks source link

Sinusoidal Team Balance Graph #56

Closed stickz closed 6 years ago

stickz commented 8 years ago

First: So to start off with, this is required in-order to access team balance natives. #include <nd_balancer>

Then Then your plugin will have access to the GetTeamDifference() float. Simply call this float function to get the team difference and re-inventing the wheel will not be required. It will return a positive value float if the team difference is in Consorts favour or a negative float value if it's in Empires favour.

I have not constructed the native yet, but your plugin will compile successfully as the line is added. I will add this native a bit later in the upcoming days. It shouldn't take too long to complete.

Next: You will need to use something in-order to pass values to web. There are multiple options available. A few include socket, steamworks, steamtools and curl. I would prefer that an extension already on the server like socket (only supports http) or steamworks is used if at all possible; but, it's not limited to that. Links to these extensions and the updater plugin (possibly a useful resource) is here.

Resources The Sourcemod API is located here.

I can request a sub domain on xenogamers.com be used for Redstone. With ftp access, much like other things like motds and fastdls already have. This would be a good place to host this content.

sergeylukin commented 8 years ago

Digging into SourcePawn atm. Trying to get my head around plugins ecosystem in Source/SourceMod.

Would it make sense to send update over the wire whenever player_team event is fired?

Also how does one efficiently test a SourceMod plugin during development?

Thanks

stickz commented 8 years ago

I just created a new forward. This function will automatically call when teamdiff is updated. https://github.com/stickz/Redstone/commit/86ae429c8c8a64e143ad904948b88939ce5babc1

For testing it's very useful to have auto-updater support right off the bat. Also, debugging can be used for the compiler to include things only when the defined value is set to 1. Furthermore, you may want to register some commands to test things.

#include <sourcemod>
#include <nd_balancer>
#include <nd_stocks>

#define DEBUG 1

#define UPDATE_URL  "https://github.com/stickz/Redstone/raw/build/updater/nd_sinusoidal_graph/nd_sinusoidal_graph.txt"
#include "updater/standard.sp"

public OnPluginStart()
{
      AddUpdaterLibrary();

#if DEBUG == 1
      RegAdminCmd("sm_TestUpdate", CMD_TestUpdate, ADMFLAG_GENERIC, "type !TestUpdate in chat");
#end
}

public OnTeamDiffUpdated()
{
#if DEBUG == 1
      PrintToAdmins("debug: update just triggered", "a");
#end
}

#if DEBUG == 1
public Action:CMD_TestUpdate(client, args) 
{
      //insert test code here
}
#end
sergeylukin commented 8 years ago

That's helpful, thanks!

sergeylukin commented 8 years ago

Here is the first draft: https://jsbin.com/qesotu/1 Data is randomly generated and pushed every 5 secs. Just trying to get the prototype of how final widget should look and work. @stickz is this the right direction functionality- and look&feel- wise?

stickz commented 8 years ago

The design looks amazing.

However, the average value is a critical element missing from the numbers. Just saying +63 for instance isn't very meaningful. It could be +63/35 or even +63/95, which, are two completely different things. I think the distance from the x axis should scale according to that as well.

sergeylukin commented 8 years ago

Thanks. Please provide me with a few realistic output examples of Float:GetTeamDifference(); with brief notes so that I could get a better idea of what Y-axis values to expect.

stickz commented 8 years ago

I've seen numbers between 0 and 400 for the team difference. The y axis should scale though according to the actual player difference. p = GetTeamDifference() \ GetAverageSkill()

sergeylukin commented 8 years ago

It's hard to have a clear picture about how all figures play together without seeing the logic behind the nd_balancer. Especially because I'm too bad at math and because there are multiple known algos used to balance teams players based on their scores and I have no idea which one is used in nd_balancer. Currently I'm only aware of include file which only exposes API and not the calculations logic behind it. But as far I understand:

Chart plot should show Player difference and not Team difference.

@stickz is above correct?

stickz commented 8 years ago

Scaling the y axis to the player difference would be best. Then showing team difference / average skillon the point. The player difference is in-fact team difference / average skill. Average skill is (sum of all player skills / total players). Player skill is 85% points, 15% kdr on xg rank.

sergeylukin commented 8 years ago

OK, that clarifies a lot. I will prepare second draft shortly. Stay tuned.

sergeylukin commented 8 years ago

Here is the second draft: https://output.jsbin.com/qesotu/16

Basically instead of overlapping plots over each other I decided to split chart into 3 little ones (Player difference, Average skill, Team difference) and connect them through X-axis. Hovering over a point in time on any chart will show a tooltip in Player difference chart with figures from all mini charts for that specific point and a vertical grid line is there for better visual connection of Y-axis values between the charts.

Data is still generated randomly. Auto-update is disabled but I will enable it again at a later stage.

@stickz please let me know what you think so far.

sergeylukin commented 8 years ago

Placed the sub titles above each sub chart for clarity: https://output.jsbin.com/qesotu/17

stickz commented 8 years ago

Looks Good!

sergeylukin commented 8 years ago

Thanks for feedback. I can now proceed to setup data storage with public API.

sergeylukin commented 8 years ago

Data storage is ready. Following draft is connected to real-time data storage (with live updates): https://output.jsbin.com/qesotu/24

I've populated it with some random values already.

Send HTTP request in following format to add a new entry and you should see it in the chart immediately:

curl -X POST -d '{
    "timestamp": {".sv": "timestamp"},
    "strongest-team-id": "{'empire' | 'consortium'}",
    "strongest-team-advantage": {INT},
    "average-players-skill": {FLOAT}
}' 'https://amber-heat-5197.firebaseio.com/teams-balance-stats/redstone-uk.json?auth=NrRdXKMyf3wrPao0M4sJgPRpKFbNnqD6KIGp4lyE'

Here is a real example, adjust values accordingly:

curl -X POST -d '{
    "timestamp": {".sv": "timestamp"},
    "strongest-team-id": "empire",
    "strongest-team-advantage": 208227,
    "average-players-skill": 241781.33333333334
}' 'https://amber-heat-5197.firebaseio.com/teams-balance-stats/redstone-uk.json?auth=NrRdXKMyf3wrPao0M4sJgPRpKFbNnqD6KIGp4lyE'

the ?auth= part in URI contains temporary token required for DB write access. It will be replaced with new one before going live and value will be stored in environment variable on the server or similar.

Please note that X Axis may look strange once you start adding entries manually because of the gap in time between current entries and the ones you will add. However, once entries will be added on regular basis and there will be at least last 20 entries with short interval in between, X Axis will look OK again.

Also, while designing DB structure, I decided to break team difference into 2 properties: strongest-team-id and strongest-team-advantage. So latter is an absolute integer no matter what team is stronger and former tells what team has an advantage. That's my personal preference, I think that's more self-explanatory, I'm open to discuss that though if you disagree with this. Anyways, it doesn't affect nd_balancer in any way.

"timestamp": {".sv": "timestamp"}, should not be changed, it instructs remote data storage server to use it's timestamp as a value. That way timestamps are guaranteed to be in same format and timezone.

@stickz let me know how it works out for you.

sergeylukin commented 8 years ago

@stickz it's all ready for data to come in, only SM plugin is missing. Feel free to setup one before I do.