Pickems help

Started by Fog, December 07, 2013, 09:32:32 PM

Previous topic - Next topic

Fog

September 07, 2014, 10:43:56 PM #30 Last Edit: September 07, 2014, 11:18:41 PM by Fog
Just for reference and what some may compare what they are used to on sites like Yahoo is that they have 5 minutes before each game as the cutoff.

QuoteImo it might be best for me to convert this project to a mod now and create a board for it.
After I do that the next step will be the overall display.
2 templates are needed for it...
1) Display all participants picks in a graph (names on left ~ fav/und on top) whereas it will display F or U for each game
2) After each week has completed a list is updated containing total correct for each week + winner of each week is highlighted

You'll need an home page, entry form, results and standing pages. (4 templates)

Home Page:  Shows links to each weeks entry form and a messages.
Entry Form:  Allows you to make your weekly picks and submit a tiebreaker.
Results:  Allows players to see their picks for the week and once the games are done the results.
Standings: This displays current overall standings for all those that are playing.


Chen Zhen

September 09, 2014, 09:11:10 PM #31 Last Edit: September 09, 2014, 09:14:57 PM by Napalm
I still have not had time to make this into a mod which will involve many changes for SMF standards.
Also the templates for user picks, overall points, etc. is not done yet.

I have however added the code for it to save the final scores of the actual games to the database. In doing so this test block/page now exceeds the bytes max for the allotted text column for Simple Portal. This means that in its current state one must use a php file and call it from a php block/page.

Attached is the necessary php file and here is the block code:

global $sourcedir;

require_once($sourcedir . '/nfl_test.php');
nfl_football_pool();


The file must be put into the ../Sources folder.




When the new week is fed into the API it may require me to rewrite how the code reads the json array.
At the moment I am unaware of that API's format for anything past 1 week.
It may only supply 1 week of data at a time or it may display them all. I am hoping for the latter which will require changes to this code.


Chen Zhen


  Imo I think it might be best just to put the entire schedule into an array and have it in a separate file.
When I create a mod out of it just have it entail releasing a yearly installer that replaces the file with the updated array containing a newer schedule.

Fog

Here's a complete schedule for the 2014 Season

Chen Zhen


I can just look at the regular schedule from NFL.com but thanks.

It appears the free API only displays the current week.
This means I will have to develop a means for an admin to manually edit/enter any given week results.
I will still have it auto update the results but it will only do so if the API is available (if NFL.com server has issues for whatever reason it may not) and also either a user or the admin will have to access the NFL section of the site. There are other ways to go about it as in having an option to check when anyone generally logs on or just the specific section of the site plus have a separate file that can be set up for a cron job.
A cron job has to be set up from the server OS level either via a management platform (ie. Cpanel) or directly with the OS files/commands. The best I can do for people is to inform them to make sure to access the NFL section of their site on Tuesdays to ensure it attempts to update and a file for a cron job if they know how to use it. If it misses the auto update the admin will have to key it in manually.
Unless I find another dependable free API that has every week available on the page which Imo may not exist or at least not from an official site such as the one I am using from NFL.com.



Fog

UD, this is the code that comes with the standalone game I found.

They use ESPN....

<?php
require('includes/application_top.php');

$week = (int)$_GET['week'];

//load source code, depending on the current week, of the website into a variable as a string
$url "http://scores.espn.go.com/nfl/scoreboard?seasonYear=".SEASON_YEAR."&seasonType=2&weekNumber=" $week;
$raw file_get_contents($url);

$teamCodes = array(
'GNB' => 'GB',
'JAC' => 'JAX',
'KAN' => 'KC',
'NWE' => 'NE',
'NOR' => 'NO',
'SDG' => 'SD',
'SFO' => 'SF',
'TAM' => 'TB'
);

$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
$content str_replace($newlines""html_entity_decode($raw));

$start strpos($content,'<div class="gameDay-Container">');
$end strpos($content,'<!-- begin sponsored links',$start) + 26;
$content substr($content,$start,$end-$start);

//set search pattern (using regular expressions)
//$find = '|<div class="game-header">(.*?)<div class="game-links">|is';
$find '|<p id=".*?-statusText">(.*?)</p>.*?<a href="/nfl/clubhouse\?team=(.*?)">(.*?)</a>.*?<li class="final" id=".*?-aTotal">(.*?)</li>.*?<a href="/nfl/clubhouse\?team=(.*?)">(.*?)</a>.*?<li class="final" id=".*?-hTotal">(.*?)</li>|is';
preg_match_all($find$content$matches);
//print_r($matches);
//exit;

//initiate scores array, to group teams and scores together in games
$scores = array();

//count number of teams found, to be used in the loop below
$count count($matches[1]);

for (
$i 0$i $count$i++) {
   
$overtime = (($matches[1][$i] == 'Final/OT') ? 0);
   
$away_team strtoupper($matches[2][$i]);
   
$home_team strtoupper($matches[5][$i]);
foreach ($teamCodes as $espnCode => $nflpCode) {
if ($away_team == $espnCode$away_team $nflpCode;
if ($home_team == $espnCode$home_team $nflpCode;
}
   
$away_score = (int)$matches[4][$i];
   
$home_score = (int)$matches[7][$i];

   
$winner = ($away_score $home_score) ? $away_team $home_team;
   
$gameID getGameIDByTeamID($week$home_team);
   if (
is_numeric(strip_tags($home_score)) && is_numeric(strip_tags($away_score))) {
   
if ($away_score || $home_score 0) {
    $scores[] = array(
       'gameID' => $gameID,
       'awayteam' => $away_team,
       'visitorScore' => $away_score,
       'hometeam' => $home_team,
       'homeScore' => $home_score,
       'overtime' => $overtime,
       'winner' => $winner
   
);
   }
   }
}

//see how the scores array looks
//echo '<pre>' . print_r($scores, true) . '</pre>';
echo json_encode($scores);

//game results and winning teams can now be accessed from the scores array
//e.g. $scores[0]['awayteam'] contains the name of the away team (['awayteam'] part) from the first game on the page ([0] part)
?>


Fog

UD, I'm a dumbass end user and not a developer like you.

I have ideas for the SMF site I help manage and I'm lucky to find and work with someone like you.

I find it tough to portray my ideas probably because I don't know enough.

I can read codes and modify them to understand how they work but to start from scratch is something I wouldn't know how to do.

I'm not sure if you looked at the file I uploaded, but I had to change it from a sql file to a txt file to display it,

I'm sure you can find all kinds of ways to find a 2014 Schedule. This one shows how it creates a Table on a DB at least for the game I'm hosting. 

I think you'll do a great job on this mod.

Fog

UD...can you put a shoutbox on the 2014 Pool Page?

Fog

How do I view results and standings?

Chen Zhen


I have not had the time to work on this as of late as I have been attempting to debug some SMF 2.1 issues.
Mostly related to compatibility with the personalized bbc mod.
When I finish with what I am working on in that regard I will continue with this mod and create a means to display the required info from the database.

Regards.

Fog

Did you see that catch?

Any updates on this UD...   :D