Scores not updating

Post here to discuss topics relate to the 4.x version for the ASP Football Pool software program. All support topics should go here.
kingmullet
Posts: 58
Joined: Thu Sep 05, 2013 3:21 pm

Scores not updating

#1

Post by kingmullet » Sat Oct 06, 2018 6:04 pm

Is anyone else running into an issue with updating the scores? It’s been working fine then all of the sudden this week it times out while trying to load.

User avatar
Smokey Jones
Posts: 13
Joined: Fri Sep 07, 2018 10:08 am
Location: TN
Contact:

Re: Scores not updating

#2

Post by Smokey Jones » Sun Oct 07, 2018 11:34 am

I had that happen on Thursday as well. I'm hoping that it was a problem with the NFL feed. I just tried it and it's still acting up.

huhwhut
Posts: 1
Joined: Tue Sep 06, 2016 10:21 pm

Re: Scores not updating

#3

Post by huhwhut » Sun Oct 07, 2018 2:59 pm

I've got the same thing. Scores not updating.

User avatar
Lush
Posts: 22
Joined: Wed Nov 26, 2014 11:37 pm

Re: Scores not updating

#4

Post by Lush » Sun Oct 07, 2018 3:26 pm

It's still down for me too....bummer

chuckie365
Posts: 12
Joined: Fri Jun 19, 2015 8:58 pm

Re: Scores not updating

#5

Post by chuckie365 » Fri Oct 12, 2018 12:13 pm

Does anybody have any ideas how to fix this problem? Thanks!

Keno
Posts: 3
Joined: Sun Aug 09, 2015 4:40 pm

Re: Scores not updating

#6

Post by Keno » Fri Oct 12, 2018 1:05 pm

Yes, I am on-board with chuckie365 - how can we get this fixed? It's a very useful and fantastic part of the program. Thanks!!

User avatar
Smokey Jones
Posts: 13
Joined: Fri Sep 07, 2018 10:08 am
Location: TN
Contact:

Re: Scores not updating

#7

Post by Smokey Jones » Sat Oct 13, 2018 7:19 am

chuckie365 wrote:
Fri Oct 12, 2018 12:13 pm
Does anybody have any ideas how to fix this problem? Thanks!
I think the root of the problem might be that NFL.com has changed how they are serving up scores in the https://www.nfl.com/scores/2018/REG page. Unfortunately, I don't know enough about how the data is parsed in the UpdateScores.asp file to figure it out.

BobbyG63
Posts: 6
Joined: Sun Oct 14, 2018 9:01 am

Re: Scores not updating

#8

Post by BobbyG63 » Sun Oct 14, 2018 9:10 am

This was driving me crazy.
So I coded a Score Loader that is driven from the NFL XML feed.
Lighting fast because it does not have to wait for the NFL Score site to load and then to scrape the score from it.
Let me know what you think.

Replace the "scoresLoader" code in the "UpdateScores.asp" with the code below...

Code: Select all

	//=========================================================================
	// Module: scoresLoader
	//
	// Used to set game scores using data retrieved from the NFL.com web site.
	//=========================================================================
	var scoresLoader = function () {

		// The update form.
		var formEl = null;

		// The week to update.
		var week = "";

		// Define an array to hold form field information for each game listed
		// on the form.
		var gameFields = [];

		// Auto-update parameters.
		var autoUpdate               =  false;
		var autoUpdateLoadTimeoutID  =   null;
		var autoUpdateLoadTimeout    = 300000; // 5 minutes.
		var autoUpdateDialogTimeout  =    500; // one half second.

		// Holds the data parsed from the scores page.
		var gameData = null;

		// Used for dialog messages.
		var resultMsg       = "";
		var errorMsg        = "";
		var foundNewResults = false;

		//---------------------------------------------------------------------
		// Initializes the scores loader.
		//---------------------------------------------------------------------
		function init() {

			// Get the scores update form.
			formEl = document.getElementById("scoresForm");

			// Get the week.
			week = formEl.elements["week"].value;

			// Scan the form and build the games fields array.
			var i = 1;
			var el;
			while ((el = formEl.elements["id-" + i]) != null) {
				var vid      = formEl.elements["vid-" + i].value;
				var hid      = formEl.elements["hid-" + i].value;
				var vscoreEl = formEl.elements["vscore-" + i];
				var hscoreEl = formEl.elements["hscore-" + i];
				var otEl     = formEl.elements["ot-" + i];
				gameFields.push({
					"visitorID"      : vid,
					"visitorScoreEl" : vscoreEl,
					"homeID"         : hid,
					"homeScoreEl"    : hscoreEl,
					"overtimeEl"     : otEl
				});
				i++;
			}

			// If auto-update is checked, start it.
			autoUpdate = formEl.elements["autoUpdate"].checked;
			if (autoUpdate)
				autoUpdateLoadTimeoutID = setTimeout(getScores, autoUpdateLoadTimeout);
		}

		//---------------------------------------------------------------------
		// Initiates the retrieval of game results.
		//---------------------------------------------------------------------
		function getScores() {

			// Clear any existing game data.
			gameData = [];

			// Clear any highlighting on the form fields.
			for (var i = 0; i < gameFields.length; i++) {
				domUtils.removeClass(gameFields[i].visitorScoreEl,        "fieldLoaded");
				domUtils.removeClass(gameFields[i].homeScoreEl,           "fieldLoaded");
				domUtils.removeClass(gameFields[i].overtimeEl.parentNode, "fieldLoaded");
			}

			// Initialize the display.
			foundNewResults = false;
			showLoadingDisplay("loadingActive");

			processXMLScores();

			return false;
		}

		
		//---------------------------------------------------------------------
		// Get NFL Data Feeds.
		//---------------------------------------------------------------------
		function getDataFeed(url) {
			var resp ;
			var xmlHttp ;

			resp  = '' ;
			xmlHttp = new XMLHttpRequest();

			if(xmlHttp != null)
			{
				xmlHttp.open( "GET", url, false );
				xmlHttp.send( null );
				resp = xmlHttp.responseText;
			}
		return resp ;
		}
		
		
		//---------------------------------------------------------------------
		// Parses the scores page and updates the form with any new game
		// results.
		//---------------------------------------------------------------------
		function processXMLScores() {

			var vid, hid, vscore, hscore;
			var s, ot
			var el, el2;
			var vn, hn;

			var week = formEl.elements["week"].value;
			
			var xmlURL = "http://www.nfl.com/ajax/scorestrip?season=2018&seasonType=REG&week="+week;
			var myData = getDataFeed(xmlURL);
			var parser = new DOMParser();
			var xmlDoc = parser.parseFromString(myData, "text/xml");

			var gameEls = xmlDoc.getElementsByTagName("gms");
			if (gameEls.length > 0) {
				var week = gameEls[0].getAttribute("w");
				var year = gameEls[0].getAttribute("y");
				var type = gameEls[0].getAttribute("t");
				if (type == "R")
					week = "REG" + week;
				else
					week = "PRE" + week;
			}			
			
			var gameEls = xmlDoc.getElementsByTagName("g");
			for (var i = 0; i < gameEls.length; i++) {
				ot 	= false;
				s	= gameEls[i].getAttribute("q");
				if ((s != null) && ((s.trim().toLowerCase() == "f") || (s.trim().toLowerCase() == "fo"))) {	
					vid 	= gameEls[i].getAttribute("v");
					vscore 	= gameEls[i].getAttribute("vs");
					hid 	= gameEls[i].getAttribute("h");
					hscore 	= gameEls[i].getAttribute("hs");
					if (s.trim().toLowerCase() == "fo") {
						ot = true;
					}
					// Fix team IDs.
					if (vid == "JAC")
						vid = "JAX";
					if (hid == "JAC")
						hid = "JAX";
						
					// Save the results.
					gameData.push({
						"visitorID"    : vid,
						"visitorScore" : vscore,
						"homeID"       : hid, 
						"homeScore"    : hscore,
						"overtime"     : ot
					});						
				}	
			}
			
			
			// Copy any new results to the appropriate form fields and reset
			// the display.
			setGameFields();

			if (foundNewResults) {
				hideLoadingDisplay();

				// If auto-update is on, submit the form to update the scores.
				if (autoUpdate) {

					// Add a new submit button to the form and click it to
					// perform the update.
					var inputEl = document.createElement("INPUT");
					inputEl.name = "submit";
					inputEl.type = "submit";
					inputEl.value = "Update";
					inputEl = formEl.appendChild(inputEl);
					inputEl.click();
				}
			}
			else {
				showLoadingDisplay("loadingComplete");

				// Handle auto-update.
				if (autoUpdate) {
					setTimeout(hideLoadingDisplay, autoUpdateDialogTimeout);

					// Determine if any scores are still missing.
					var missingScores = false;
					for (i = 0; i < gameFields.length && !missingScores; i++)
						if (gameFields[i].visitorScoreEl.value == "" || gameFields[i].homeScoreEl.value == "")
							missingScores = true;

					// If there are missing scores, set for the next attempt.
					// Otherwise off turn auto-update.
					if (missingScores)
						autoUpdateLoadTimeoutID = setTimeout(getScores, autoUpdateLoadTimeout);
					else
						stopAutoUpdate();
				}
			}
		}	
		

		//---------------------------------------------------------------------
		// Grabs the scores from the NFL JSON feed
		// Does not allow for Year / Season / Week selection.
		// Only returns "Current" week info
		//---------------------------------------------------------------------
		function processJSONScores() {

			var vid, hid, vscore, hscore;
			var s, ot
			var el, el2;
			var vn, hn;

			var mydata = getDataFeed("http://www.nfl.com/liveupdate/scorestrip/ss.json")
			var jsonData = JSON.parse(mydata);

			for (var i = 0; i < jsonData.gms.length; i++) {
				var counter = jsonData.gms[i];
    			ot = false;
				s = (counter.q);
				if ((s != null) && ((s.trim().toLowerCase() == "f") || (s.trim().toLowerCase() == "f ot"))) {
					vid 	= (counter.v);
					vscore	= (counter.vs);
					hid 	= (counter.h);
					hscore	= (counter.hs);
					if (s.trim().toLowerCase() == "f ot") {
						ot = true;
					}

					// Fix team IDs.
					if (vid == "JAC")
						vid = "JAX";
					if (hid == "JAC")
						hid = "JAX";
					
					// Save the results.
					gameData.push({
						"visitorID"    : vid,
						"visitorScore" : vscore,
						"homeID"       : hid, 
						"homeScore"    : hscore,
						"overtime"     : ot
					});
				}
			}
			
			// Copy any new results to the appropriate form fields and reset
			// the display.
			setGameFields();

			if (foundNewResults) {
				hideLoadingDisplay();

				// If auto-update is on, submit the form to update the scores.
				if (autoUpdate) {

					// Add a new submit button to the form and click it to
					// perform the update.
					var inputEl = document.createElement("INPUT");
					inputEl.name = "submit";
					inputEl.type = "submit";
					inputEl.value = "Update";
					inputEl = formEl.appendChild(inputEl);
					inputEl.click();
				}
			}
			else {
				showLoadingDisplay("loadingComplete");

				// Handle auto-update.
				if (autoUpdate) {
					setTimeout(hideLoadingDisplay, autoUpdateDialogTimeout);

					// Determine if any scores are still missing.
					var missingScores = false;
					for (i = 0; i < gameFields.length && !missingScores; i++)
						if (gameFields[i].visitorScoreEl.value == "" || gameFields[i].homeScoreEl.value == "")
							missingScores = true;

					// If there are missing scores, set for the next attempt.
					// Otherwise off turn auto-update.
					if (missingScores)
						autoUpdateLoadTimeoutID = setTimeout(getScores, autoUpdateLoadTimeout);
					else
						stopAutoUpdate();
				}
			}
		}

	
		//---------------------------------------------------------------------
		// Given an element, finds the first occurrence of the given tag with
		// the given class name in its descendants.
		//---------------------------------------------------------------------
		function getFirstSubTagWithClass(el, tName, cName) {

			if (el != null) {
				var elList = el.getElementsByTagName(tName);
				for (var i = 0; i < elList.length; i++)
					if (domUtils.hasClass(elList[i], cName))
						return elList[i];
			}

			return null;
		}

		//---------------------------------------------------------------------
		// Given an element, finds the first occurrence of the given tag in
		// its descendants.
		//---------------------------------------------------------------------
		function getFirstSubTag(el, tName) {

			if (el != null) {
				var elList = el.getElementsByTagName(tName);
				if (elList.length > 0)
					return elList[0];
			}

			return null;
		}

		//---------------------------------------------------------------------
		// Given a url, returns the value assigned to the given query string
		// parameter.
		//---------------------------------------------------------------------
		function getQueryStringParameter(qs, pName) {

			var re = new RegExp( "[?&]" + pName + "=([^&$]*)", "i" );
			var offset = qs.search(re);
			if (offset == -1)
				return "";

			return RegExp.$1;
		}

		//---------------------------------------------------------------------
		// Takes the parsed game results and updates the appropriate form
		// fields.
		//---------------------------------------------------------------------
		function setGameFields() {

			// For each game result found, find a matching set of form fields
			// to load the data into.
			if (gameData.length > 0) {
				resultMsg = "All game results are up to date.";
				for (var i = 0; i < gameFields.length; i++)
					for (var j = 0; j < gameData.length; j++)

						// Check if the teams match.
						if (gameFields[i].visitorID == gameData[j].visitorID && gameFields[i].homeID == gameData[j].homeID)
						{
							// Set the individual form fields.
							setFormField(gameFields[i].visitorScoreEl, gameData[j].visitorScore);
							setFormField(gameFields[i].homeScoreEl,    gameData[j].homeScore);
							setFormField(gameFields[i].overtimeEl,     gameData[j].overtime);
							break;
						}
			}
			else
				resultMsg = "No results available, try again later.";
		}

		//---------------------------------------------------------------------
		// Updates a single form field with the given value (if that value is
		// different from the field's current value).
		//---------------------------------------------------------------------
		function setFormField(fieldEl, newValue) {

			// Compare the old and new values.
			var oldValue = fieldEl.value;
			if (fieldEl.type == "checkbox")
				oldValue = fieldEl.checked;

			// If the values are the same, exit.
			if (oldValue == newValue)
				return;

			// Set the form field value and highlight it.
			if (fieldEl.type == "checkbox") {
				fieldEl.checked = newValue;
				domUtils.addClass(fieldEl.parentNode, "fieldLoaded");
			}
			else {
				fieldEl.value = newValue;
				domUtils.addClass(fieldEl, "fieldLoaded");
			}

			// Note that we have new results.
			foundNewResults = true;
		}

		//---------------------------------------------------------------------
		// Shows the loading display with the specified message box.
		//---------------------------------------------------------------------
		function showLoadingDisplay(id) {

			// Hide all the message boxes.
			document.getElementById("loadingActive").style.display   = "none";
			document.getElementById("loadingComplete").style.display = "none";
			document.getElementById("loadingError").style.display    = "none";

			// Set the result and error messages.
			var el = document.getElementById("loadingResultMsg");
			while (el.firstChild != null)
				el.removeChild(el.firstChild);
			document.getElementById("loadingResultMsg").appendChild(document.createTextNode(resultMsg));
			var el = document.getElementById("loadingErrorMsg");
			while (el.firstChild != null)
				el.removeChild(el.firstChild);
			document.getElementById("loadingErrorMsg").appendChild(document.createTextNode(errorMsg));

			// Show the specified message box.
			el = document.getElementById(id);
			if (el != null)
				el.style.display  = "";

			// Make it visible.
			document.getElementById("loadingDisplay").style.visibility = "visible";
		}

		//---------------------------------------------------------------------
		// Hides the loading display.
		//---------------------------------------------------------------------
		function hideLoadingDisplay() {

			document.getElementById("loadingDisplay").style.visibility = "hidden";
		}

		//---------------------------------------------------------------------
		// Turns auto-update off.
		//---------------------------------------------------------------------
		function stopAutoUpdate() {

			// Cancel any pending attempt.
			if (autoUpdateLoadTimeoutID != null) {
				clearTimeout(autoUpdateLoadTimeoutID);
				autoUpdateLoadTimeoutID = null;
			}

			// Set the flag to false and clear the checkbox.
			autoUpdate = false;
			formEl.elements["autoUpdate"].checked = false;
		}

		//=====================================================================
		// Initialization code.
		//=====================================================================

		// Initialize on page load.
		domUtils.onready(init);

		//=====================================================================
		// Public properties and methods.
		//=====================================================================
		return {

			//-----------------------------------------------------------------
			// Loads game scores for the given week.
			//-----------------------------------------------------------------
			load : function () {

				// Turn off auto-update, if it is on.
				if (autoUpdate)
					stopAutoUpdate();

				getScores();
				return false;
			},

			//-----------------------------------------------------------------
			// Cancels a load.
			//-----------------------------------------------------------------
			cancel : function () {

				getScoresCleanUp();
				hideLoadingDisplay();

				// If auto-update is on, turn it off.
				if (autoUpdate)
					stopAutoUpdate();

				return false;
			},

			//-----------------------------------------------------------------
			// Closes the load display.
			//-----------------------------------------------------------------
			close : function () {

				hideLoadingDisplay();
				return false;
			},

			//-----------------------------------------------------------------
			// Toggles auto-update.
			//-----------------------------------------------------------------
			toggleAutoUpdate : function () {

				// If auto-update is on, turn it off. Otherwise, turn it on and
				// make an attempt.
				if (autoUpdate)
					stopAutoUpdate();
				else {
					autoUpdate = true;
					getScores();
				}

				// Allow the check box to change.
				return true;
			}
		}
	}();
	
	
Last edited by BobbyG63 on Mon Oct 15, 2018 8:51 pm, edited 1 time in total.

bobl499
Posts: 20
Joined: Mon Sep 02, 2013 2:31 pm

Re: Scores not updating

#9

Post by bobl499 » Sun Oct 14, 2018 11:41 am

Following... waiting for a fix :)

chuckie365
Posts: 12
Joined: Fri Jun 19, 2015 8:58 pm

Re: Scores not updating

#10

Post by chuckie365 » Sun Oct 14, 2018 11:12 pm

Thanks for the fix. For some reason the auto update didn't work with the NE KC game but it worked with the others! :)

GiantsFan
Posts: 3
Joined: Tue Sep 11, 2018 10:24 am

Re: Scores not updating

#11

Post by GiantsFan » Mon Oct 15, 2018 8:31 am

Thanks for the re-write BobbyG63, that worked for me.

BobbyG63
Posts: 6
Joined: Sun Oct 14, 2018 9:01 am

Re: Scores not updating

#12

Post by BobbyG63 » Mon Oct 15, 2018 1:39 pm

After posting my original fix, I noticed that the feed I was using that allows for the selection of Year Season, and Week is not as "real-time" as I expected. The feed that is closer to "real-time" does not allow for the selection of Year, Season, and Week.

I modified the code to pull from the "real-time" feed, check to see if it is the current week and process.
If it is not the current week, I go back to using the historic data feed.

In UpdateScores.asp, in the processXMLScores function:

Replace:

Code: Select all

			var xmlURL = "http://www.nfl.com/ajax/scorestrip?season=2018&seasonType=REG&week="+week;
			var myData = getDataFeed(xmlURL);
			var parser = new DOMParser();
			var xmlDoc = parser.parseFromString(myData, "text/xml");

			var gameEls = xmlDoc.getElementsByTagName("gms");
			if (gameEls.length > 0) {
				var week = gameEls[0].getAttribute("w");
				var year = gameEls[0].getAttribute("y");
				var type = gameEls[0].getAttribute("t");
				if (type == "R")
					week = "REG" + week;
				else
					week = "PRE" + week;
			}
With:

Code: Select all

			var xmlURL = "http://www.nfl.com/liveupdate/scorestrip/ss.xml"
			var myData = getDataFeed(xmlURL);
			var parser = new DOMParser();
			var xmlDoc = parser.parseFromString(myData, "text/xml");

			var gameEls = xmlDoc.getElementsByTagName("gms");
			if (gameEls.length > 0) {
				var week = gameEls[0].getAttribute("w");
				var year = gameEls[0].getAttribute("y");
				var type = gameEls[0].getAttribute("t");
			}			
			
			if (formWeek != week) {
				var xmlURL = "http://www.nfl.com/ajax/scorestrip?season=2018&seasonType=REG&week="+formWeek;
				var myData = getDataFeed(xmlURL);
				var parser = new DOMParser();
				var xmlDoc = parser.parseFromString(myData, "text/xml");
			}

Happy scoring!!!

mspslb
Posts: 17
Joined: Thu Sep 04, 2014 6:50 pm

Re: Scores not updating

#13

Post by mspslb » Mon Oct 15, 2018 8:28 pm

Working great for me and load time is very fast. Really appreciate the fix!

User avatar
Smokey Jones
Posts: 13
Joined: Fri Sep 07, 2018 10:08 am
Location: TN
Contact:

Re: Scores not updating

#14

Post by Smokey Jones » Mon Oct 15, 2018 8:50 pm

BobbyG63 wrote:
Sun Oct 14, 2018 9:10 am
Lighting fast because it does have to wait fro the NFL Score site to load and then to scrape the score from it.
Let me know what you think.
Dude! You weren't kidding when you said "lightning fast"!! This is awesome!!! Thanks for coding this and sharing it with us!

User avatar
Lush
Posts: 22
Joined: Wed Nov 26, 2014 11:37 pm

Re: Scores not updating

#15

Post by Lush » Tue Oct 16, 2018 12:26 am

Thanks BobbyG63!! This is AWESOME & wicked fast!

User avatar
Smokey Jones
Posts: 13
Joined: Fri Sep 07, 2018 10:08 am
Location: TN
Contact:

Re: Scores not updating

#16

Post by Smokey Jones » Thu Oct 18, 2018 10:29 pm

BobbyG63 wrote:
Mon Oct 15, 2018 1:39 pm
After posting my original fix, I noticed that the feed I was using that allows for the selection of Year Season, and Week is not as "real-time" as I expected. The feed that is closer to "real-time" does not allow for the selection of Year, Season, and Week.

I modified the code to pull from the "real-time" feed, check to see if it is the current week and process.
If it is not the current week, I go back to using the historic data feed.

In UpdateScores.asp, in the processXMLScores function:

Replace:

Code: Select all

			var xmlURL = "http://www.nfl.com/ajax/scorestrip?season=2018&seasonType=REG&week="+week;
			var myData = getDataFeed(xmlURL);
			var parser = new DOMParser();
			var xmlDoc = parser.parseFromString(myData, "text/xml");

			var gameEls = xmlDoc.getElementsByTagName("gms");
			if (gameEls.length > 0) {
				var week = gameEls[0].getAttribute("w");
				var year = gameEls[0].getAttribute("y");
				var type = gameEls[0].getAttribute("t");
				if (type == "R")
					week = "REG" + week;
				else
					week = "PRE" + week;
			}
With:

Code: Select all

			var xmlURL = "http://www.nfl.com/liveupdate/scorestrip/ss.xml"
			var myData = getDataFeed(xmlURL);
			var parser = new DOMParser();
			var xmlDoc = parser.parseFromString(myData, "text/xml");

			var gameEls = xmlDoc.getElementsByTagName("gms");
			if (gameEls.length > 0) {
				var week = gameEls[0].getAttribute("w");
				var year = gameEls[0].getAttribute("y");
				var type = gameEls[0].getAttribute("t");
			}			
			
			if (formWeek != week) {
				var xmlURL = "http://www.nfl.com/ajax/scorestrip?season=2018&seasonType=REG&week="+formWeek;
				var myData = getDataFeed(xmlURL);
				var parser = new DOMParser();
				var xmlDoc = parser.parseFromString(myData, "text/xml");
			}

Happy scoring!!!
I've tried implementing this and it didn't work. Autoupdate just hangs.

CDKING1
Posts: 1
Joined: Fri Oct 19, 2018 5:35 pm

Re: Scores not updating

#17

Post by CDKING1 » Fri Oct 19, 2018 5:38 pm

I made the changes but not working for me as well.

mspslb
Posts: 17
Joined: Thu Sep 04, 2014 6:50 pm

Re: Scores not updating

#18

Post by mspslb » Fri Oct 19, 2018 7:46 pm

Same here when I tried it earlier this week. I think it has to do with the formWeek variable. It isn't declared and no value for it. Haven't had a chance to look further since, but I think that is where the issue lies. I think there are some changes that weren't included in the paste.

chuckie365
Posts: 12
Joined: Fri Jun 19, 2015 8:58 pm

Re: Scores not updating

#19

Post by chuckie365 » Fri Oct 19, 2018 9:02 pm

The original change he suggested is working ok for me...haven't tried the second modification yet...

baldy51497
Posts: 4
Joined: Tue Sep 11, 2018 7:50 am

Re: Scores not updating

#20

Post by baldy51497 » Sat Oct 20, 2018 7:34 am

mspslb wrote:
Fri Oct 19, 2018 7:46 pm
Same here when I tried it earlier this week. I think it has to do with the formWeek variable. It isn't declared and no value for it. Haven't had a chance to look further since, but I think that is where the issue lies. I think there are some changes that weren't included in the paste.
Correct, I believe this fixed the loading. Pretty simple change, but trying to contribute. Bare with me here, first time posting code.

Replace:

Code: Select all

			var week = formEl.elements["week"].value;
With:

Code: Select all

			
			var week;
            		var formWeek = formEl.elements["week"].value;

BobbyG63
Posts: 6
Joined: Sun Oct 14, 2018 9:01 am

Re: Scores not updating

#21

Post by BobbyG63 » Sat Oct 20, 2018 9:40 am

In the 4.0 version of updateScores, var week = ""; is defined up top, under the scoresLoader function.
and the "week" that is refereed to in the "formEl.elements["week"].value" statement comes from the form
"<div><input type="hidden" name="week" value="<% = week %>" /></div>"

Can someone explain the problem and I will look to see how to correct it?

Thank you...

baldy51497
Posts: 4
Joined: Tue Sep 11, 2018 7:50 am

Re: Scores not updating

#22

Post by baldy51497 » Sat Oct 20, 2018 2:07 pm

The problem was just that the scores weren't loading. I apologize that my suggested fix may have not been correct, even though it did seem to make it work. I didn't look through the whole document to determine what variables had been initiated. I believe that mspslb was correct though when he stated that the loading problem was caused by the formWeek variable. I definitely don't fully understand programming, but I do understand the basics, so I am just being impatient and trying to help. Question, so is "week" always set by the init function, setting it from the hidden form input value? So does it need to be set again in the scoresloader? And would the better fix be to just change the "week" variable you are setting from the xml to be something like "xmlWeek"? Then checking whether the form week "week" is different from the most current feed week "xmlWeek"? BobbyG63, thanks for your rewrite, it is very fast like you said.

I tried it a few different ways, and they all break it. So my fix isn't really best, but I can't figure out what the correct fix is.

BobbyG63
Posts: 6
Joined: Sun Oct 14, 2018 9:01 am

Re: Scores not updating

#23

Post by BobbyG63 » Sat Oct 20, 2018 3:35 pm

No problems Baldy... It's all good...
To answer your question...
No, week comes from the 1st XML feed (which does not allow for a requested week, the NFL is always returning current week)
So if the Form week differs from the LiveFeed XML, then you have to request the scores with the Ajax call. That calls allows you to specify the requested week.

The code is working perfectly for me... Should I re-post the entire scoresLoader function?

mspslb
Posts: 17
Joined: Thu Sep 04, 2014 6:50 pm

Re: Scores not updating

#24

Post by mspslb » Sat Oct 20, 2018 5:08 pm

@BobbyG63 that would be good, if you don't mind.

BobbyG63
Posts: 6
Joined: Sun Oct 14, 2018 9:01 am

Scores not updating - Posting of complete scoresLoader code

#25

Post by BobbyG63 » Sat Oct 20, 2018 9:46 pm

//=========================================================================
// Module: scoresLoader
//
// Used to set game scores using data retrieved from the NFL.com web site.
//=========================================================================
var scoresLoader = function () {

// The update form.
var formEl = null;

// The week to update.
var week = "";

// Define an array to hold form field information for each game listed
// on the form.
var gameFields = [];

// Auto-update parameters.
var autoUpdate = false;
var autoUpdateLoadTimeoutID = null;
var autoUpdateLoadTimeout = 300000; // 5 minutes.
var autoUpdateDialogTimeout = 500; // one half second.

// Holds the data parsed from the scores page.
var gameData = null;

// Used for dialog messages.
var resultMsg = "";
var errorMsg = "";
var foundNewResults = false;

//---------------------------------------------------------------------
// Initializes the scores loader.
//---------------------------------------------------------------------
function init() {

// Get the scores update form.
formEl = document.getElementById("scoresForm");

// Get the week.
week = formEl.elements["week"].value;

// Scan the form and build the games fields array.
var i = 1;
var el;
while ((el = formEl.elements["id-" + i]) != null) {
var vid = formEl.elements["vid-" + i].value;
var hid = formEl.elements["hid-" + i].value;
var vscoreEl = formEl.elements["vscore-" + i];
var hscoreEl = formEl.elements["hscore-" + i];
var otEl = formEl.elements["ot-" + i];
gameFields.push({
"visitorID" : vid,
"visitorScoreEl" : vscoreEl,
"homeID" : hid,
"homeScoreEl" : hscoreEl,
"overtimeEl" : otEl
});
i++;
}

// If auto-update is checked, start it.
autoUpdate = formEl.elements["autoUpdate"].checked;
if (autoUpdate)
autoUpdateLoadTimeoutID = setTimeout(getScores, autoUpdateLoadTimeout);
}

//---------------------------------------------------------------------
// Initiates the retrieval of game results.
//---------------------------------------------------------------------
function getScores() {

// Clear any existing game data.
gameData = [];

// Clear any highlighting on the form fields.
for (var i = 0; i < gameFields.length; i++) {
domUtils.removeClass(gameFields.visitorScoreEl, "fieldLoaded");
domUtils.removeClass(gameFields.homeScoreEl, "fieldLoaded");
domUtils.removeClass(gameFields.overtimeEl.parentNode, "fieldLoaded");
}

// Initialize the display.
foundNewResults = false;
showLoadingDisplay("loadingActive");

processXMLScores();

return false;
}


//---------------------------------------------------------------------
// Get NFL Data Feeds.
//---------------------------------------------------------------------
function getDataFeed(url) {
var resp ;
var xmlHttp ;

resp = '' ;
xmlHttp = new XMLHttpRequest();

if(xmlHttp != null)
{
xmlHttp.open( "GET", url, false );
xmlHttp.send( null );
resp = xmlHttp.responseText;
}
return resp ;
}


//---------------------------------------------------------------------
// Parses the scores page and updates the form with any new game
// results.
//---------------------------------------------------------------------
function processXMLScores() {

var vid, hid, vscore, hscore;
var s, ot
var el, el2;
var vn, hn;

var formWeek = formEl.elements["week"].value;

var xmlURL = "http://www.nfl.com/liveupdate/scorestrip/ss.xml"
var myData = getDataFeed(xmlURL);
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(myData, "text/xml");

var gameEls = xmlDoc.getElementsByTagName("gms");
if (gameEls.length > 0) {
var xmlWeek = gameEls[0].getAttribute("w");
var xmlYear = gameEls[0].getAttribute("y");
var xmlType = gameEls[0].getAttribute("t");
}

if (formWeek != xmlWeek) {
var xmlURL = "http://www.nfl.com/ajax/scorestrip?seas ... "+formWeek;
var myData = getDataFeed(xmlURL);
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(myData, "text/xml");
}


var gameEls = xmlDoc.getElementsByTagName("g");
for (var i = 0; i < gameEls.length; i++) {
ot = false;
s = gameEls.getAttribute("q");
if ((s != null) && ((s.trim().toLowerCase() == "f") || (s.trim().toLowerCase() == "fo"))) {
vid = gameEls.getAttribute("v");
vscore = gameEls.getAttribute("vs");
hid = gameEls.getAttribute("h");
hscore = gameEls.getAttribute("hs");
if (s.trim().toLowerCase() == "fo") {
ot = true;
}
// Fix team IDs.
if (vid == "JAC")
vid = "JAX";
if (hid == "JAC")
hid = "JAX";

// Save the results.
gameData.push({
"visitorID" : vid,
"visitorScore" : vscore,
"homeID" : hid,
"homeScore" : hscore,
"overtime" : ot
});
}
}


// Copy any new results to the appropriate form fields and reset
// the display.
setGameFields();

if (foundNewResults) {
hideLoadingDisplay();

// If auto-update is on, submit the form to update the scores.
if (autoUpdate) {

// Add a new submit button to the form and click it to
// perform the update.
var inputEl = document.createElement("INPUT");
inputEl.name = "submit";
inputEl.type = "submit";
inputEl.value = "Update";
inputEl = formEl.appendChild(inputEl);
inputEl.click();
}
}
else {
showLoadingDisplay("loadingComplete");

// Handle auto-update.
if (autoUpdate) {
setTimeout(hideLoadingDisplay, autoUpdateDialogTimeout);

// Determine if any scores are still missing.
var missingScores = false;
for (i = 0; i < gameFields.length && !missingScores; i++)
if (gameFields.visitorScoreEl.value == "" || gameFields.homeScoreEl.value == "")
missingScores = true;

// If there are missing scores, set for the next attempt.
// Otherwise off turn auto-update.
if (missingScores)
autoUpdateLoadTimeoutID = setTimeout(getScores, autoUpdateLoadTimeout);
else
stopAutoUpdate();
}
}
}


//---------------------------------------------------------------------
// Grabs the scores from the NFL JSON feed
// Does not allow for Year / Season / Week selection.
// Only returns "Current" week info
//---------------------------------------------------------------------
function processJSONScores() {

var vid, hid, vscore, hscore;
var s, ot
var el, el2;
var vn, hn;

var mydata = getDataFeed("http://www.nfl.com/liveupdate/scorestrip/ss.json")
var jsonData = JSON.parse(mydata);

for (var i = 0; i < jsonData.gms.length; i++) {
var counter = jsonData.gms[i];
ot = false;
s = (counter.q);
if ((s != null) && ((s.trim().toLowerCase() == "f") || (s.trim().toLowerCase() == "f ot"))) {
vid = (counter.v);
vscore = (counter.vs);
hid = (counter.h);
hscore = (counter.hs);
if (s.trim().toLowerCase() == "f ot") {
ot = true;
}

// Fix team IDs.
if (vid == "JAC")
vid = "JAX";
if (hid == "JAC")
hid = "JAX";

// Save the results.
gameData.push({
"visitorID" : vid,
"visitorScore" : vscore,
"homeID" : hid,
"homeScore" : hscore,
"overtime" : ot
});
}
}

// Copy any new results to the appropriate form fields and reset
// the display.
setGameFields();

if (foundNewResults) {
hideLoadingDisplay();

// If auto-update is on, submit the form to update the scores.
if (autoUpdate) {

// Add a new submit button to the form and click it to
// perform the update.
var inputEl = document.createElement("INPUT");
inputEl.name = "submit";
inputEl.type = "submit";
inputEl.value = "Update";
inputEl = formEl.appendChild(inputEl);
inputEl.click();
}
}
else {
showLoadingDisplay("loadingComplete");

// Handle auto-update.
if (autoUpdate) {
setTimeout(hideLoadingDisplay, autoUpdateDialogTimeout);

// Determine if any scores are still missing.
var missingScores = false;
for (i = 0; i < gameFields.length && !missingScores; i++)
if (gameFields[i].visitorScoreEl.value == "" || gameFields[i].homeScoreEl.value == "")
missingScores = true;

// If there are missing scores, set for the next attempt.
// Otherwise off turn auto-update.
if (missingScores)
autoUpdateLoadTimeoutID = setTimeout(getScores, autoUpdateLoadTimeout);
else
stopAutoUpdate();
}
}
}


//---------------------------------------------------------------------
// Given an element, finds the first occurrence of the given tag with
// the given class name in its descendants.
//---------------------------------------------------------------------
function getFirstSubTagWithClass(el, tName, cName) {

if (el != null) {
var elList = el.getElementsByTagName(tName);
for (var i = 0; i < elList.length; i++)
if (domUtils.hasClass(elList[i], cName))
return elList[i];
}

return null;
}

//---------------------------------------------------------------------
// Given an element, finds the first occurrence of the given tag in
// its descendants.
//---------------------------------------------------------------------
function getFirstSubTag(el, tName) {

if (el != null) {
var elList = el.getElementsByTagName(tName);
if (elList.length > 0)
return elList[0];
}

return null;
}

//---------------------------------------------------------------------
// Given a url, returns the value assigned to the given query string
// parameter.
//---------------------------------------------------------------------
function getQueryStringParameter(qs, pName) {

var re = new RegExp( "[?&]" + pName + "=([^&$]*)", "i" );
var offset = qs.search(re);
if (offset == -1)
return "";

return RegExp.$1;
}

//---------------------------------------------------------------------
// Takes the parsed game results and updates the appropriate form
// fields.
//---------------------------------------------------------------------
function setGameFields() {

// For each game result found, find a matching set of form fields
// to load the data into.
if (gameData.length > 0) {
resultMsg = "All game results are up to date.";
for (var i = 0; i < gameFields.length; i++)
for (var j = 0; j < gameData.length; j++)

// Check if the teams match.
if (gameFields[i].visitorID == gameData[j].visitorID && gameFields[i].homeID == gameData[j].homeID)
{
// Set the individual form fields.
setFormField(gameFields[i].visitorScoreEl, gameData[j].visitorScore);
setFormField(gameFields[i].homeScoreEl, gameData[j].homeScore);
setFormField(gameFields[i].overtimeEl, gameData[j].overtime);
break;
}
}
else
resultMsg = "No results available, try again later.";
}

//---------------------------------------------------------------------
// Updates a single form field with the given value (if that value is
// different from the field's current value).
//---------------------------------------------------------------------
function setFormField(fieldEl, newValue) {

// Compare the old and new values.
var oldValue = fieldEl.value;
if (fieldEl.type == "checkbox")
oldValue = fieldEl.checked;

// If the values are the same, exit.
if (oldValue == newValue)
return;

// Set the form field value and highlight it.
if (fieldEl.type == "checkbox") {
fieldEl.checked = newValue;
domUtils.addClass(fieldEl.parentNode, "fieldLoaded");
}
else {
fieldEl.value = newValue;
domUtils.addClass(fieldEl, "fieldLoaded");
}

// Note that we have new results.
foundNewResults = true;
}

//---------------------------------------------------------------------
// Shows the loading display with the specified message box.
//---------------------------------------------------------------------
function showLoadingDisplay(id) {

// Hide all the message boxes.
document.getElementById("loadingActive").style.display = "none";
document.getElementById("loadingComplete").style.display = "none";
document.getElementById("loadingError").style.display = "none";

// Set the result and error messages.
var el = document.getElementById("loadingResultMsg");
while (el.firstChild != null)
el.removeChild(el.firstChild);
document.getElementById("loadingResultMsg").appendChild(document.createTextNode(resultMsg));
var el = document.getElementById("loadingErrorMsg");
while (el.firstChild != null)
el.removeChild(el.firstChild);
document.getElementById("loadingErrorMsg").appendChild(document.createTextNode(errorMsg));

// Show the specified message box.
el = document.getElementById(id);
if (el != null)
el.style.display = "";

// Make it visible.
document.getElementById("loadingDisplay").style.visibility = "visible";
}

//---------------------------------------------------------------------
// Hides the loading display.
//---------------------------------------------------------------------
function hideLoadingDisplay() {

document.getElementById("loadingDisplay").style.visibility = "hidden";
}

//---------------------------------------------------------------------
// Turns auto-update off.
//---------------------------------------------------------------------
function stopAutoUpdate() {

// Cancel any pending attempt.
if (autoUpdateLoadTimeoutID != null) {
clearTimeout(autoUpdateLoadTimeoutID);
autoUpdateLoadTimeoutID = null;
}

// Set the flag to false and clear the checkbox.
autoUpdate = false;
formEl.elements["autoUpdate"].checked = false;
}

//=====================================================================
// Initialization code.
//=====================================================================

// Initialize on page load.
domUtils.onready(init);

//=====================================================================
// Public properties and methods.
//=====================================================================
return {

//-----------------------------------------------------------------
// Loads game scores for the given week.
//-----------------------------------------------------------------
load : function () {

// Turn off auto-update, if it is on.
if (autoUpdate)
stopAutoUpdate();

getScores();
return false;
},

//-----------------------------------------------------------------
// Cancels a load.
//-----------------------------------------------------------------
cancel : function () {

getScoresCleanUp();
hideLoadingDisplay();

// If auto-update is on, turn it off.
if (autoUpdate)
stopAutoUpdate();

return false;
},

//-----------------------------------------------------------------
// Closes the load display.
//-----------------------------------------------------------------
close : function () {

hideLoadingDisplay();
return false;
},

//-----------------------------------------------------------------
// Toggles auto-update.
//-----------------------------------------------------------------
toggleAutoUpdate : function () {

// If auto-update is on, turn it off. Otherwise, turn it on and
// make an attempt.
if (autoUpdate)
stopAutoUpdate();
else {
autoUpdate = true;
getScores();
}

// Allow the check box to change.
return true;
}
}
}();

Post Reply