poliva / ggposrv

Unofficial ggpo server (re)implementation
GNU General Public License v2.0
128 stars 41 forks source link

Stats about attendance #14

Closed jsmadja closed 8 years ago

jsmadja commented 9 years ago

I would like to create a dashboard to see the attendance. For example, I would like to know when there is a lot of people in "FRANCE" who are playing "Garou MOTW". Maybe the answer is : Wednesday @ 7:00 PM. But I don't know. I see that there is a "/stats" route in the server but I don't know how to call it and if it will send me raw data (json?) to build my own attendance stats.

I could fetch the data and dashboard it if I can access these informations.

How can it be possible ?

Thank you

poliva commented 9 years ago

The current json endpoints are just to internally control the server and can't be queried from the internet. The /stats endpoint just returns the number of users connected/playing/watching, as you can see in the MOTD when you join a channel. However I see your point and an API for collecting that info externally might be good to have, leaving that bug open to possibly add this functionality in the future.

jsmadja commented 9 years ago

If you could create a JSON like this :

[
    {
        "title": "Garou: MOTW",
        "players": [
            {
                "country": "FR",
                "count": 23
            },
            {
                "country": "UK",
                "count": 59
            }
        ]
    },
    {
        "title": "Super Street Fighter II X",
        "players": [
            {
                "country": "FR",
                "count": 57
            },
            {
                "country": "UK",
                "count": 89
            }
        ]
    }
]

I'll be able to create few dynamic html pages with charts like this :

Garou: France

I don't know Python but I'll try to do this on my own. I'm a Java/Javascript developer.

jsmadja commented 9 years ago

I hacked the Python Client to get stats I needed. And now I have a web page to see attendance : http://jsfiddle.net/k7pjcy5t/18/embedded/result/ You can tell me if you think it's cool or not :)

I will push a request for your server later.

demo

poliva commented 9 years ago

that thing looks awesome! :+1: thanks for your work and interest on this :)

jsmadja commented 9 years ago

Ok here what you should do :

You must POST information like username, rom and country to my server (we could host this server in fightcade server later if you want) for each join channel action.

Here a proposition :

in def handle_join(self, params) you have to add this call :

url = 'http://neogeodb.com:8765/players'
payload = {
    "player": "kaddath",
    "rom": "garou",
    "country": "France"
}
headers = {'content-type': 'application/json'}
response = requests.post(url, data=json.dumps(payload), headers=headers)

You must replace player, rom and country by the real values of the player. If you want to anonymize player's name you can, from my side it have to be unique (md5(player) should be fine).

I'm using modules json & requests, here a sample if you want to test it :

import json
import requests

url = 'http://neogeodb.com:8765/players'
payload = {
    "player": "kaddath",
    "rom": "garou",
    "country": "France"
}
headers = {'content-type': 'application/json'}
response = requests.post(url, data=json.dumps(payload), headers=headers)
print response  # should be equal to 200 (HTTP OK)

To install and run it :

virtualenv-2.7 --system-site-packages ve27
source ve27/bin/activate
pip install requests
python post_attendance.py

Feel free to adapt the code, I'm not a python developer :) I don't use my hacked-client anymore, I have enough data for my tests.

You can deploy this feature a couple of days and see if it works fine. If it's not, tell me what I could do.

Thank you.

jsmadja commented 9 years ago

Hi, any news for this ?

poliva commented 9 years ago

Sorry I haven't had time to go through this yet, I've been working on the client those days. Will look at that probably next week.

poliva commented 9 years ago

implemented on the server, should be live on the next server restart. Can you share your server-side code so i don't have to send the data to neogeodb?

jsmadja commented 9 years ago

As you can see here : https://github.com/jsmadja/fightcade/blob/master/src/main/java/fr/kaddath/fightcade/server/interfaces/rest/controller/agency/AttendanceQuery.java#L46

I save your data in a table name Player [date, rom, player, country]

But now, your sent values are (for example) 2015-04-17 13:34:55, <main.GGPOChannel object at 0x7f4329cd0510>, godofwar007, Morocco

It seems "rom" is not what I'm expected (ie: ssf2x for example).

I also have a second table (misnamed 'stat') which is the reference table for Game Title and Name [rom, name] kof96 King of Fighters '96 (set 1) kof94 King of Fighters '94

I'll will refactor all of it this week-end and improve Web interface (at this time, I don't handle the timezone).

poliva commented 9 years ago

oh, my fault i'm sending the python object for the rom instead of the rom name. I'll fix that and send you the correct thing (will need a server restart again).

jsmadja commented 9 years ago

I'll clear all the data when it is ok.

jsmadja commented 9 years ago

Few improvements :

demo

demo

poliva commented 9 years ago

Thanks, it looks really sick! :D I've put it in the fightcade site - http://www.fightcade.com/stats/

jsmadja commented 9 years ago

Sorry but I forgot to add the line for the timezone : you should add this

https://github.com/jsmadja/fightcade/blob/aaee75ea64733f5ff0f071b88ed6554445ec9f92/src/main/resources/static/index.html#L61

poliva commented 9 years ago

Added, thank you!

poliva commented 9 years ago

Looks like there's a bug because the data for the current day (monday) at the current time (8PM) is very low, like it's taking into consideration "future" data that has not already been inserted into the db:

bug-attendance-stats

jsmadja commented 9 years ago

It's real time for the current hour (8PM).

For 7PM and before, the data are what we had today (this monday, before "now"). For 9PM and after, the data are what we had last monday at the same time (9PM, 10PM, 11PM).

If you watch graphics at 9PM you'll see how many they were at 8PM on fightcade.

What would you prefer ?

poliva commented 9 years ago

I think at the current hour (8PM in the example) it should show the results from last week:

this way you will not see the huge gap at the current day/hour, specially towards the beginning of the hour (it's very noticeable if you look at the graph at 8:05 but not very noticeable if you look at the graph at 8:50)

jsmadja commented 9 years ago

It's done, up and ready.

jsmadja commented 9 years ago

By the way, now we have more stats

Top 10 Countries image

Top 10 Roms image

poliva commented 9 years ago

looks like stats page stopped working, i can only see the loader spinning... any idea?

jsmadja commented 9 years ago

Why there is https in fightcade.com ? Is it new ?

2015-05-07 11:56 GMT+02:00 Pau Oliva notifications@github.com:

looks like stats page stopped working, i can only see the loader spinning... any idea?

Reply to this email directly or view it on GitHub https://github.com/poliva/ggposrv/issues/14#issuecomment-99799342.

poliva commented 9 years ago

yes i changed the site to force https by default, is it a problem?

jsmadja commented 9 years ago

Yes, it seems :

I can see javascript errors

Mixed Content: The page at 'https://www.fightcade.com/stats/' was loaded over HTTPS, but requested an insecure script ' http://code.highcharts.com/modules/heatmap.js'. This request has been blocked; the content must be served over HTTPS.

2015-05-07 12:03 GMT+02:00 Pau Oliva notifications@github.com:

yes i changed the site to force https by default, is it a problem?

Reply to this email directly or view it on GitHub https://github.com/poliva/ggposrv/issues/14#issuecomment-99801880.

poliva commented 9 years ago

i see, thanks.. will fix ASAP

jsmadja commented 9 years ago

But if you want to do HTTPS, my server has to do HTTPS too ... Unless we host mywebservice (need a JVM) on your fightcade server.

2015-05-07 12:08 GMT+02:00 Pau Oliva notifications@github.com:

i see, thanks.. will fix ASAP

Reply to this email directly or view it on GitHub https://github.com/poliva/ggposrv/issues/14#issuecomment-99802921.

poliva commented 9 years ago

Fixed, I changed htaccess to force https everywhere except on /stats where I force http.

jsmadja commented 9 years ago

Ok thank you.

Do you know if this page is viewed (I know you're using Google Analytics).

2015-05-07 16:44 GMT+02:00 Pau Oliva notifications@github.com:

Fixed, I changed htaccess to force https everywhere except on /stats where I force http.

Reply to this email directly or view it on GitHub https://github.com/poliva/ggposrv/issues/14#issuecomment-99893858.

poliva commented 9 years ago

Is the 3rd most visited page after home and replays, this is for the last 12 days (since the page went live): image

jsmadja commented 9 years ago

Thank you :)

2015-05-09 23:45 GMT+02:00 Pau Oliva notifications@github.com:

Is the 3rd most visited page after home and replays, this is for the last 30 days: [image: image] https://cloud.githubusercontent.com/assets/1238981/7552159/6079ccc2-f6a5-11e4-8a3e-9954aeafe2bb.png

Reply to this email directly or view it on GitHub https://github.com/poliva/ggposrv/issues/14#issuecomment-100552052.