DataStorage - ORF-4450/PitScouting GitHub Wiki

Where is Data Stored?

Data is stored in this google sheet, and this google sheet.

Common Issues

Variables won't appear in Unity Inspector

DataStorage's inspector is controlled by DataStoreEditor, rather than being auto-generated. If a variable input or function calling button is required, DataStoreEditor is where this happens.

DataStorage

DataStorage is a script designed to store, receive, and send data. It interprets data, stores it as .txt's, and interfaces with GoogleForm in order to store the data in the cloud.

DataStorage is essentially a library for the rest of the app.

Variables

data

Dictionary<string, string>

inputs

Dictionary<string, DataInput>

ServerBaseURL

string

URL to fetch json event data from; the app used to also send data here. ServerBaseURL is the server's URL (For example: "https://orf-4450scoutingapp.azurewebsites.net/").

Version

string[]

Version is a 3 string array that holds the app's current version number. DataStorage will compare this array with the server's version number. If it is slightly different (3rd number difference), it will give the warning:

"Revision Version mismatch."

If it is minorly out of date (2nd number difference), it will give the error

"Minor Version Mismatch".

If it is majorly out of date (1st number/Year difference), it will give the warning:

"Major/Year Version Mismatch".

These warnings are sent from GetRequest().

GoogleForm

GoogleForm

GoogleForm script to reference when uploading data.

DataStorageKey

string

Due to the app having multiple DataStore objects (one for pit scouting and another for stands scouting), they need a way to detect whether data (.txt/.png files) belongs to itself. This is achieved by putting a special string, DataStorageKey before the filename. The code can then skip all files that do not start with DataStorageKey.

appName

string

appName is a legacy string from when there were two scouting apps; one for pit scouting, and another for stands scouting. It used to allow the server to separate/interpret pit and stands data.

CurrentDownloadRequest

UnityWebRequest

CurrentUploadRequest

UnityWebRequest

uploadResultText

ResultText

The ResultText script to push text to. The ResultText script tells the result text object what to display when syncing with the server.

downloadResultText

ResultText

Legacy. The app used to have two places to put result text from syncing with the server; one for upload, and one for download. They have since been merged into one object.

lastPingTest

bool

lastPingTest allows the app to know if it has successfully connected to the server. It initializes as false, and is set to true by pingTest(). If lastPingTest is false, syncRoutine() will return

"Failed to connect to server, please try again later."

Functions

Start()

Start()

Adds version number to dictionary data under key "Version".

Adds string "" under key "ScouterName", giving object ScouterName a place to store the current user's name.

LateUpdate()

addData()

addData(string, string, bool)

addData(string, string, bool, DataInput)

saveToFile()

saveToFile()

Triggers saveToFile(bool), with input false

saveToFile(bool)

If true,

If false,

saveAndClear()

isStaticKey()

isStaticKey(string)

If the input string is one of:

  • ScouterName
  • ScouterTeamNumber
  • Version
  • EventKey

return true. Else, return false.

sync()

sync()

Check to see if internet is available. If it is not, return

"Error. Check internet connection!"

If internet is available, return

"Success! Internet Avalible."

and trigger syncRoutine()

syncRoutine()

pingTest()

pingTest()

pingTest reads a page of the server that says "pong" and outputs received text to the debug log. If it reads "pong", it sets bool lastPingTest to true and allows syncRoutine() to function.

downloadJson()

downloadJson()

uploadData()

uploadData()

GetRequest()

GetRequest(string, Action<UnityWebRequest>)

DataStoreEditor

DataStoreEditor is a script that controls the inspector menu (Editor in Unity). It creates buttons to trigger functions and text boxes for text inputs. If a variable needs to be added/removed from DataStorage's inspector menu, this is the place to change it.