Adding new league table columns and event results
-
Hi,
I am using sportspress for multisports events. One sport is a cycling bike race. In my event (the race), each team is a biker. I have in the event as many teams as bikers in the race. I have added a new field called Crono (both in Event Results and Table Columns), to store the final crono of each biker. The crono will determine the order (descending) in the league table. The problem that I have is that Crono (as an Event Result) admits text in a time format (hh:mm:ss), but when this “time” is assigned to Crono in the league table (through the equation Crono = cronofor), it only takes the hour part of the text. It dismisses all from the first semicolon up to the end.How can I fix it?
The page I need help with: [log in to see the link]
-
Hi!
I’m not sure if I get your setup. Is your competition only based on total time? So no places are assigned to your racers?
Thanks!
Hi Roch,
Like in every other race, places are assigned based on racers crono. The one who has the shortest crono time is number 1, the following is number two and so on.
If I present in my web page the short code [event results id=???] the table shows the racers names, their crono, and the outcome. In the event I have attached all the teams (=racers) taking part in the race in the order I want to be shown (from the fastest to the slowest). I have to introduce in the event the teams in the corresponding order as I have no chance (as I do in a league table) to order the results based on a specific criteria, for example, the crono.If I use the short code [league table], in order to take advantage of the ranking position, based on the time invested to finish the race, the problem is that the crono value introduced in the event post for each team (=racer) is not properly transfered to the crono field in the league table. Not sure if the problem is related with the fact that in a league table all the columns are a summarize of all the events related to this league. And in a league table you can sum the number of matches, the number of goals, the number of wins, the number of drawns, etc, but what league table has to do with timestamps.
Is it clear what I am trying to describe?
Hi there!
Thanks for your reply and I’m sorry for the delay.
Ok, the first paragraph is fine. But the second one is a bit confusing for me.
So do you want to use the league table to display results for a single event? Or is it for multiple events indeed?
Should it be for multiple events, what are your stats / ordering criteria? Maybe that’s where the issue is. Depending on how these elements are stored you won’t be able to transfer them to the tables.
Thanks!
Hi Roch,
I’ll try it again, I apologyze about my english ??
In this particular case, my competition is a biking race. It’s a “one shot” competition. Only one race. On one side, I have an event (the race) with all the teams involved (the bikers). Once the race is over, in this event I enter the crono of all bikers.
If I put the shortcode of this event in a page, it works. You see a table with all bikers and their crono. Fine. But you see bikers in the order they are attached to the event. Thus, if the biker that won is the last attached to the event, he’s still the last in the table, no matter his crono is.Taking into account “this problem” (because I want a table ordered descendent by crono) I decided to create a league on this competition. Yes, a league of a single event. League tables can deal with this.
When I put the shortcode of the league table, I can’t order it by crono. In fact, crono is not well gathered from the event. If the crono of biker X is 02:30:39, in the league table appears 2 (minutes and seconds are dismissed).
Currently I am using an event-list shortcode to show the results of the race:
(second table in this url)https://www.a32events.com/games/es/hg19-btt-es/
But I’d like to take advantage of league tables (automatically ordering teams by a given criteria, in this case, crono)
Hope I have explained myself now!
Best wishes!
Hi there!
No worries at all, your English is fine ??
It’s just my understanding of your sport that is lacking, but I think we are getting there.
“If I put the shortcode of this event in a page, it works. You see a table with all bikers and their crono. Fine. But you see bikers in the order they are attached to the event. Thus, if the biker that won is the last attached to the event, he’s still the last in the table, no matter his crono is.”
Oh, I see what you mean. Indeed, the event page itself won’t be ordered by results.The easiest way I can think of to solve this is storing all your data in seconds (or miliseconds, whatever your smallest time unit is). That may seem crazy but it is much easier to format your time on the frontend than working with a mixed type of variable.
So that’s my recommendation, when adding events, add either seconds or maybe even use separated fields for hour, minute, seconds. That should work as well and won’t be too unconfortable.
Then we can add a player stat for the seconds, and we can help you with the formatting part.
In short, the next step is:
1) Decide if you want to use a single seconds field or 3 separated fields (hour, minute, second)
2) Add this to your site, and add a test event
3) send us a link so we can help you with the visual adjustments.Thanks!
Hi Roch
Great, the implementation of the crono column based on seconds it works and data is properly passed to the league table. But (there is always a “but”, isn’t it?):
1) I have as you pointed out in your answer an integer that I have to format as a time (hh:mm:ss). I’ve seen that in the league table, the crono is embeded in this tag: <td class=”data-crono” data-label=”Crono”>. Some javascript is needed, isn’t it?
2) And in addition to this, I’am thinking how to avoid that “non finisher” or “no show” bikers (their crono is 0 seconds) appear at the top of the league table (the sorting is ascending and 0 goes first than any other value)
Hoping to hear from you!
Best wishes!Hi there!
Thanks for your reply.
1) Indeed, we can change this with a bit of JS code. Could you send us a link to your site?
2) That’s a good point! The easiest solution I can think of is this:
a) Create a new column, this will be a hidden column just for ordering with its formula as:
(crono = 0 ) * 60 * 60 * 24 + crono
This formula just says “if crono is zero, this field will have the value of 1d (or any other big number, just to make sure they come as last)b) Now crono will be shown, but this new column won’t. You will still use only the new column as your ordering criteria. This allows you to still display results as usual, and non-finishers will be at the bottom.
Let me know how it works for you! If you want other variants (for example allow for partial time for non-finishers) let me know. We can use other methods to get to the result you need.
Thanks!
Hi Roch
Done, now it’s ready for the piece of JS to format seconds into time hh:mm:ss.
As you may see, the third table is a “league table” ordered by Seconds and non-finishers are now at the bottom:
https://www.a32events.com/games/ca/hg19-btt/So, ready for the javascript part of the solution!!!!!
Thanks!!!Marc
Hi Marc!
This is the JS code to do it:
<script type="text/javascript"> jQuery(document).ready(function($) { jQuery('.sp-table-wrapper td.data-crono').each(function(i){ var text = jQuery(this).text(); text = parseInt(text); if ( text ) { var seconds = new Date(null); seconds.setSeconds(text); var time = seconds.toISOString().substr(11, 8); jQuery(this).text(time); } else { jQuery(this).text("-"); } }); }); </script>
You can add it to your site using a plugin like this one:
https://www.ads-software.com/plugins/header-and-footer-scripts/Or add it directly in your theme files (header or footer).
Just keep in mind that this code will change the current time (formatted as xx:xx:xx) or anything else in the crono columns to the format, resulting in some weird issues.
For example, for your reference page the first table shows with times as 00:00:01, 00:00:02..
The second table works fine.
We can either target that code to just a few pages, or review your current tables to make sure no table is with the old format (not seconds).
Thanks!
Hi Roch!
Great, it’s been acomplished!!! Thanks a lot!
As you may see, I have changed a little bit the js code to prevent changing td data-crono cells which already have data in time format.
Well, I have another question but I’ll use a different thread. ??
Best wishes!
Hi!
That’s amazing I’m glad it’s working for you.
Just a quick note, in case you haven’t already, please consider leaving us a review ??
I just saw the new topic and I’ll get to it as soon as possible.
Thanks!
Hi Roch,
Regarding this solution you gave me some months ago, I’ve just realized that when the table is paginated, on following pages the JS code is not applying. So, I guess the code has also to be part of the event triggered by the paginate buttons, hasn’t it?
I’ve been making some tests with on(“page.dt”) event, but with no success up to now.
Could you please help me on it?Thanks
Marc
Hi Marc!
Thanks for your reply, it’s great to see you again.
Unfortunately no, we can’t help you with this kind of change. The code provided here was already out of the scope of our support, so we can’t extend it, as that would require a rework on it probably.
You can either disable pagination or hire a developer to customize this for you.
Thanks!
Kind Regards,
-RochHi Roch
Just to let you know that I made it work. So I understand now a little bit more how to tweak datatables, with or without pagination.
Anyway, thanks for you support.Regards
Marc
- The topic ‘Adding new league table columns and event results’ is closed to new replies.