News:

Herr Otto Partz says you're all nothing but pipsqueaks!

Main Menu

Track information

Started by dreadnaut, August 20, 2021, 06:30:10 PM

Previous topic - Next topic

Cas

That sounds very reasonable. With the current method, an inter-site read has to be made every time somebody loads stunts.hu, while with what you suggest, the slowdown would only occur twice a month, when a race is started or ends in Race For Kicks.

I have thoughts of ideas similar to this before, but I haven't yet done it. So far, I'm familiar with sending a POST when the user presses a Submit button, but I don't know how to trigger a POST with a PHP function. I would have to read more about that. Then, I suppose I'd be creating an HTTP form with the necessary information to be sent via POST, only instead of it being triggered by a button, it would be unconditionally sent somehow.

Another thing I don't know is how to have website A send a POST to website B without it resulting in website B being loaded on the browser, instead keeping the same page being browsed.

If you can more or less hint me on these things, I can start to make a picture of what it would be like and I'm sure I can do it.
Earth is my country. Science is my religion.

dreadnaut

#16
Quote from: Cas on September 24, 2021, 11:57:18 PM
[...] the slowdown would only occur twice a month, when a race is started or ends in Race For Kicks.

If we add the start date of the race next to the end date, then it should be enough to only send information once, when you add the race to your website.

Quote from: Cas on September 24, 2021, 11:57:18 PM
If you can more or less hint me on these things, I can start to make a picture of what it would be like and I'm sure I can do it.

There's a few ways in PHP. One is with the "curl" functions, but they are quite complex and have tons of options to keep track of. An easier one is to use file_get_contents().

A non-obvious feature of file_get_contents is that is can do HTTP calls, for example to retrieve the content of a page:

$page = file_get_contents('http://raceforkicks.com');


That would be a GET request, but with some options you can convince it to do a POST as well:


$race_for_kicks_data = [
  'website' => ...
  'races' => ...
];

$context = stream_context_create([ 'http' => [
  'method' => 'POST',
  'header' => 'Content-Type: application/x-www-form-urlencoded',
  'content' => http_build_query($race_for_kicks_data),
]]);

$response = file_get_contents('http://stunts.hu/register-race', false, $context);


The above would send a POST request to the stunts.hu address, with the form data in $race_for_kicks_data. The receiving script could reply OK!, and that would end up in $response.

Cas

Wow!  That looks a lot simpler than I expected!
I don't have much time today, but I'll certainly be updating that soon
Earth is my country. Science is my religion.

dreadnaut

Quote from: Cas on September 26, 2021, 03:54:50 AM
I don't have much time today, but I'll certainly be updating that soon

No rush! I can prepare things on the ZakStunts side, so you have something to test against.

dreadnaut

#19
Here I am! The ZakStunts side is ready: you can now register "events" that will eventually appear on the portal, be they races or competitions, etc.

I've attached a minimal client for the API, so you don't have to write much code. It works like this:
require 'ZakStuntsApi.php';

$api = new ZakStuntsApi('<your API client id>', '<your API client secret>');

$response = $api->updateEvent([
  "id"           => "r4k-2021-09",
  "name"         => "2021-09 - Tropical Springs Stunt Park",
  "url"          => "http://www.raceforkicks.com/index.php?page=race&race=2021-09",
  "opens_on"     => "2021-09-01T15:59:00+02:00",
  "closes_on"    => "2021-09-27T01:59:00+02:00",
// these fields are optional, all three or none
  "track_title"  => "Tropical Springs Stunt Park",
  "track_author" => "KyLiE",
  "track_url"    => "http://www.raceforkicks.com/tracks/r4k14.trk"
]);

echo var_export($response, true);


The id is whatever you want to use to identify the race. As long as you use the same one, you can update the event information as many times as you want.

If the update goes well, it will return "status" => 200. Otherwise, you should get a useful error message.

I'll send you credentials through a different channel ;)

Cas

Uhm... now I'm a little lost. I had understood the previous post, but now I downloaded the API php file and I'm not sure how the thing works. My confusion may have to do with the OOP structure, as I always write procedure oriented code, but I think there's probably something more I haven't understood.

Anyway, is stunts.hu already waiting for a message?  If I get this working, will it reflect the changes?  This is, I would like to begin testing and want to make sure when the thing starts working. I already got the information you sent me via e-mail.
Earth is my country. Science is my religion.

Cas

#21
Alright... I've been analysing the code carefully. It seems that what gets me confused is mostly the OOP structure, but also, the fact that I'm unable to see the information I'm passing or receiving. If I can somehow test this, I'll be able to understand it better.

So, what I see is I need to have this client ID and client secret to be able to send the message. I think you had sent me this via e-mail at some point, but I'm not finding it. If you can please do it again, I'll be able to send a test. Is stunts.hu ready to respond and will it update visibly if I send it a message now?

Another thing I'd like to know is a detail about IDs and updating races. Suppose a race called "race1" is running now and is due to end on day 25. I understand that, if I want to change the deadline live, I can use the "race1" ID and pass a new deadline and it'll be updated in the portal. Now, say this race hasn't ended, but now a new race is scheduled for day 31... can I use the ID "race2" for this new race to set it as "scheduled"?  Or will this cause the portal now to only show the scheduled race and no longer the ongoing one?  This is a question mostly to understand what to expect. We don't normally schedule races until a few days after a race is over, but R4K allows it.
Earth is my country. Science is my religion.

dreadnaut

#22
The portal has now gained some new API features: https://github.com/dreadnaut/stunts-portal-api

The webpage changes will follow soon :)

Duplode


Cas

Alright, I've been able to adapt the code in R4K to communicate with the API and it's working fine. The API response is good. If there's anything to fine tune later, just let me know :)
Earth is my country. Science is my religion.

dreadnaut

Far too late at night :o   But the portal now shows timely events, in some draft arrangement.

alanrotoi

It looks great! Thank you!

KyLiE


Cas

#28
That's really cool!  Thanks for your work!

Seeing the races together feels very comfortable because you naturally know where you are in each, what's in more hurry, when a new race has started, etc :)

When our race ends and we schedule the next one, we'll have a chance to test how that part works and fix whatever might be buggy on our end.

I'll see about incorporating these changes to EasyTour so that they can be applied on the other two tournaments as well

A couple of things to mention:
- I can see that the general tournament details are no longer shown and I realise that it's not easy to decide on where to put them or how to organise them. Putting them all there like before would push the current race information down and make it less immediate and that's more important information. If I can help with anything there, just let me know
- I see that all tournaments show their dates in CEST. While it makes things clearer to use a single time zone for all dates instead of mixing, I think ZakStunts uses CEST because of its Hungarian origins and currently we have very few Hungarian members. I think most people in the community now are under UTC+1. Race For Kicks, although its origins are Argentine and is now run from Australia, has always used UTC(+0) because it's a global tournament. I think if we have to settle for one time zone, it'd make more sense to use either UTC or UTC+1. My personal opinion.
Earth is my country. Science is my religion.

dreadnaut

Quote from: Cas on June 16, 2023, 07:42:41 PMI think ZakStunts uses CEST because of its Hungarian origins and currently we have very few Hungarian members. I think most people in the community now are under UTC+1

Hungary is in Central Europe, and uses the same timezone: CET in winter (UTC+1), and CEST in summer (UTC+2).

A more precise approach would be the "Continent/Capital" method, which takes into account daylight saving time schedules. ZakStunts thinks in Europe/Budapest terms, and since the original data did not include timezone information it'll take a bit of work to make customisable.

The portal inherited the timezone, living on stunts.hu, but it could gain a "set your timezone option" 👍