-
Notifications
You must be signed in to change notification settings - Fork 1
Data Loading
Assets/Resources holds all resources that need to be dynamically loaded. Specifically, they include:
-
Archetype data
-
Archetypes.csv gives general information about the archetypes: id, gender, age, health status, and the filename of the 3D model to use. Note that name and occupation are not included in this file. The reason is that we need multi-language support. To fit the data into our localization system, names and occupations are recorded in localization files, by the localization id strings of
Archetyps.P[id]NameandArchetypes.P[id]OccupationOthers, like gender and health status, are first parsed into Enums and then sent to the localization system. -
P[id]Lifestyle.csv specifies each archetype's lifestyle. Since we only have one set of data for now, there is only
P1Lifestyle.csv(same for others). There are three lifestyle entries, each corresponding to a "path"/Health Choice. Each lifestyle includes food intake (calories), exercise (hours of exercise), sleep (hours of sleep), and prescription adherence (as a status). These are regarded as the "input" to the Bodylogical simulator. -
P[id][Path].csv specifies the detailed biomarkers of the archetype. They are regarded as the "output" to the Bodylogical simulator. NOTICE that the
agefield is not used and can be removed (along with theagefield in the Heatlh script. -
Ranges.csv specifies the range of each biomarker. Each range has a "gender", since the criteria for different genders might be different. There is no "lower range" (for example, being underweight but not overweight). Values between
mintowarningare considered healthy,warningtouppermoderate, anduppertomaxunhealthy.
-
-
Localization files
- Filename is formatted as "locale-[language].xml". LocalizationManager will look for localization files of this format in order to load the languages to the app.
-
Archetype models
- These are prefabs of 3D human models. When the app starts, it looks through the data file and selects the correct model for each archetype.
- When the blend shapes are completed, the prefabs should be moved here for dynamic loading. See the home page for instructions on moving.
According to https://learn.unity.com/tutorial/assets-resources-and-assetbundles Section 3, the best practice of using Resources is to not use it. We are using it because everything in Resources except the 3D model files will go on the server in the future. The tutorial also covers AssetBundles as an alternative to Resources. You can try to move the 3D models from resources to AssetBundles.
We use the method Resources.Load() to load assets to resources. For usage, see https://docs.unity3d.com/ScriptReference/Resources.Load.html
Notice that when you load a file, you do not need to include its extension (.csv, etc.)
Scripts on data loading are stored in Scripts/Data. This section only covers archetype data. For information on parsing localization files, see Localization System.
The data is stored as csv files. Unity (or C#) has no native support for csv, so I wrote one by myself. There is a bug with separaters such that would cause parsing errors on csv files containing multiple viable separators, so be careful with the data files being parsed.
There are two LoadCsv() method. The second one is buggy and is never used, and can be safely removed from the script. The usage for the first one is
CSVParser.LoadCsv<T>(string str);where str is the csv string (NOT filename). For <T> pass in the type you want it to convert. For example, if you want to parse Archetypes.csv, you need to do
TextAsset textAsset = Resources.Load<TextAsset>("Data/Archetypes");
List<Archetype> archetypes = CSVParser.LoadCsV<Archetype>(textAsset.text);This is exactly what is done in Archetype Container script. Take a look at other container scripts to see what data classes are used in the app and how they are referred to across the scripts.
The Health Range script includes a method for calculating a 0-100 score from a given biomarker. It does so by considering 60-100 as healthy (so min-warning), 30-60 as moderate (warning-upper), and 0-30 as unhealthy (upper-max).
The Health Util Script includes a method for converting a score to a status. Notice that it uses 40 instead of 30 as a breakpoint between moderate and unhealthy. This is for demo purpose; if it is set to 30, the wheelchair animation won't come out in Activities visualization (apparently the score for the last year is larger than 30). You can decide what breakpoints are ideal for the score.
Long Term Health is a collection of health data for an archetype. It contains a method CalculateHealth() that calculates an overall health score at a specific time point. This data is used in Activity visualization for determining mobility and in Line Chart visualization.
See [Organ]Heath scripts for more information. Each organ only uses part of the data to calculate a health status. Those scores are used in Prius visualization.
If we put everything in the Resources folder, each time PwC wishes to change some data, be it the biomarkers or localizations, it would require a complete recompile of the app. Our goal is that, once we ship the app to PwC, they would not ask us for rebuilds. The solution is to set up a server for storing data.
Though the server has not been set up, I would expect that it stores all the text files mentioned above, along with a version number (e.g, version 1). When the app starts up in an environment with Internet connection, it would first check if the version of the data matches the one on the server. If not, it would download and save the data from the server and update its version number. Otherwise, it would keep using the data it saved.
The 3D model files should not be stored in the server because they rely on 3D models which would be too huge to download. Also, prefabs usually won't be modified outside of the Unity editor.