Pringleman83 / SportsBook

A sports data scraping and analysis tool
GNU General Public License v3.0
82 stars 38 forks source link

Export to JSON - Import from JSON problem #2

Closed Pringleman83 closed 6 years ago

Pringleman83 commented 6 years ago

In the league selection menu (the wrong place for this option, but that's another issue), there are options to export the current leagueData dictionary to a JSON file and to import a previously exported dictionary from a JSON file.

The filename for exporting and importing is currently fixed to leagueData.

The system appears to work. When exported, the generated file appears to be accurate. When imported after the code is freshly run, I can run the display league option (also wrongly in the league selection menu) and the leagueData dictionary that has been imported from the JSON file is displayed.

However, the main football menu doesn't recognise that a league is loaded (it states "No league selected" and when I attempt to run a manual single game analysis (in the main football menu), none of the teams that should be available are listed.

I suspect the import process isn't placing some or all of the elements of the JSON file where they need to be in the dictionary.

This is a priority on my huge list of things to do.

Pringleman83 commented 6 years ago

This has been resolved. This was a very strange issue and I'm still not entirely sure of what the cause was. I believe it was something to do with the way the values were assigned.

In testing, I found that if I added a league by selecting it and having it scraped, when I left the menu and returned, it was still there. However, if I added a league via an import from a JSON file, even though the dictionary appeared identically, when I left the function, the dictionary was empty. This was still the case if I swapped out the code that returned the league dictionary so that it returned the import dictionary.

I've solved it by having the leagueData dictionary initialised at the very start of the application and calling the import function from the football menu. This means it all operates in one file. Amongst the various other things I tried.

A trace of the bug still exists. If you import a JSON file, all appears fine. If you exit back to the main menu and then go back into football, the leagueData dictionary is empty again. However, if you select a league from the league selection menu, it stays even when you exit to the main menu. Strange!