I’m creating a website for a friend’s softball league (currently: https://larrystunts.wixsite.com/stuntsoftballleague). I want to create a page that shows the team standings. There are three database’s in play: Games, TeamWinLossTie, TeamStandings. The first one records game information, most importantly each record has HomeTeam, HomeScore, AwayTeam, AwayScore. The second is a “calculated” intermediary to allow me to allocate a win, loss or tie for each game for each team (since the team can be the home team or away team this isn’t in one column). The third database is also “calculated”. It is the source for the page table. In it is the sum of wins, losses and ties by team and a calculated win percent.
With the help of this community (and Wix Reference) I’ve figured out async/away, arrays (for performance), aggregate, etc. It all works perfectly in Preview but NOTHING runs in Live. I know this because the first step in the process is to truncate the second and third databases and even that one simple command doesn’t happen.
I understand Sandbox versus Live data and I’ve synced the Games database (that’s the only one that needs to start with data - remember the first couple lines should truncate the other databases anyway.) I’ve set all the databases to have custom permissions with ANYONE having all access rights. (Probably not necessary for the Games table since that is only read.) And I’ve set all three database connectors to Read & Write mode (again probably not necessary, at least for the Games databases.)
As I said, everything runs perfectly in Preview but not in the Live site. Help would be appreciated!
Thanks,
Bruce
Here’s the Pagecode (#dataset1 = TeamWinLossTie, #dataset2 = Games, #dataset3 = TeamStandings):
import wixData from ‘wix-data’ ;
import wixWindow from ‘wix-window’ ;
$w.onReady( async function ()
{
let trunTeamWinLossTie = await wixData.truncate( “TeamWinLossTie” );
let trunTeamStandings = await wixData.truncate( “TeamStandings” );
var allScores=;
//Begin populate TeamWinLossTie
const totalGames = $w( “#dataset2” ).getTotalCount();
let result = await $w( “#dataset2” ).getItems( 0 , totalGames);
let allItems = result.items;
for ( let i= 0 ; i < result.totalCount ; i++)
{
let hometeam=allItems[i].homeTeam;
let homescore=allItems[i].homeTeamScore;
let awayteam=allItems[i].awayTeam;
let awayscore=allItems[i].awayTeamScore;
if (homescore == null )
{
}
else if (homescore>awayscore)
{
allScores[i* 2 ]={team: hometeam, win: 1 , loss: 0 , tie: 0 }
allScores[i* 2 + 1 ]={team: awayteam, win: 0 , loss: 1 , tie: 0 }
}
else if (homescore<awayscore)
{
allScores[i* 2 ]={team: hometeam, win: 0 , loss: 1 , tie: 0 }
allScores[i* 2 + 1 ]={team: awayteam, win: 1 , loss: 0 , tie: 0 }
}
else if (homescore===awayscore)
{
allScores[i* 2 ]={team: hometeam, win: 0 , loss: 0 , tie: 1 }
allScores[i* 2 + 1 ]={team: awayteam, win: 0 , loss: 0 , tie: 1 }
}
}
await wixData.bulkInsert( “TeamWinLossTie” ,allScores);
//End populateTeamWinLossTie
//Begin populateTeamStandings
var allStandings=;
let aggResults = await wixData.aggregate( “TeamWinLossTie” )
.group( “team” )
.sum( “win” )
.sum( “loss” )
.sum( “tie” )
.run();
let sumItems = aggResults.items;
for ( let i= 0 ; i < aggResults.items.length ; i++)
{
var tN = sumItems[ 0 ,i].team;
var w = sumItems[ 0 ,i].winSum;
var l = sumItems[ 0 ,i].lossSum;
var t = sumItems[ 0 ,i].tieSum;
var tpoints = t/ 2 ;
var wP = (w+tpoints)/(w+l+t);
allStandings[i]= {teamName: tN, wins: w, losses: l, ties: t, winPercent: wP};
}
await wixData.bulkInsert( “TeamStandings” ,allStandings);
//End populateTeamStandings*************************
// Added just in case the page paints before the data in #dataset3 (TeamStandings) is populated
$w( “#dataset3” ).refresh();
$w( “#table3” ).refresh();
//End *************************
});