/// <summary> /// Test method to generate random data for particular day. /// </summary> /// <param name="date"></param> /// <returns></returns> public static LogData GenerateRandomData(DateTime date) { // load random textures form resources Texture2D[] textures = Resources.LoadAll <Texture2D>("RandomTextures"); date = date.Date; LogData logData = new LogData(); // symptom tracker SymptomData symptomData = new SymptomData(date); for (int j = 0; j < symptomData.questionDataList.Count; j++) { QuestionBasedTrackerData.QuestionData qData = symptomData.GetQuestion(); symptomData.SetAnswer(qData, UnityEngine.Random.Range(1, qData.answersOption.Length)); } logData.symptomData = symptomData; // asthma test AsthmaData asthmaData = new AsthmaData(date); for (int j = 0; j < asthmaData.questionDataList.Count; j++) { QuestionBasedTrackerData.QuestionData qData = asthmaData.GetQuestion(); asthmaData.SetAnswer(qData, UnityEngine.Random.Range(1, qData.answersOption.Length)); } logData.asthmaData = asthmaData; // CSU test CSUData csuData = new CSUData(date); for (int j = 0; j < csuData.questionDataList.Count * 3; j++) { if (j == 0) { csuData.ChangeBodyPart(BodyPart.Head); } else if (j == 2) { csuData.ChangeBodyPart(BodyPart.Chest); } else if (j == 4) { csuData.ChangeBodyPart(BodyPart.Legs); } QuestionBasedTrackerData.QuestionData qData = csuData.GetQuestion(); csuData.SetAnswer(qData, UnityEngine.Random.Range(1, qData.answersOption.Length)); if (Random.value > 0.5f) { // add some random textures int count = Random.Range(0, textures.Length); // shuffle textures System.Random rnd = new System.Random(); Texture2D[] shuffled = textures.OrderBy(x => rnd.Next()).ToArray(); // and cut out the array Array.Resize(ref shuffled, count); csuData.SavePhotos(shuffled); } } logData.csuData = csuData; // UAS test UASData uasData = new UASData(date); for (int j = 0; j < uasData.questionDataList.Count; j++) { QuestionBasedTrackerData.QuestionData qData = uasData.GetQuestion(); uasData.SetAnswer(qData, UnityEngine.Random.Range(1, qData.answersOption.Length)); } logData.uasData = uasData; return(logData); }
public static void FillTestData() { // Debug.Log("call"); // load random textures form resources Texture2D[] textures = Resources.LoadAll <Texture2D>("RandomTextures"); int days = Random.Range(65, 120); // int days = 1; // stay today date empty to use DateTime date = DateTime.Now.AddDays(-days).Date; Debug.Log("Fixed start date: " + date.ToString("dd/MM/yyyy")); JSONObject symptomJsonObject = new JSONObject(); JSONObject asthmaJsonObject = new JSONObject(); JSONObject csuJsonObject = new JSONObject(); JSONObject uasJsonObject = new JSONObject(); for (int i = 0; i < days; i++) { if (i % 7 == 0) { // symptom tracker SymptomData symptomData = new SymptomData(date); for (int j = 0; j < symptomData.questionDataList.Count; j++) { QuestionBasedTrackerData.QuestionData qData = symptomData.GetQuestion(); symptomData.SetAnswer(qData, Random.Range(1, qData.answersOption.Length)); } symptomJsonObject.Add(symptomData.FormatToJson()); } if (i % 14 == 0) { // asthma test AsthmaData asthmaData = new AsthmaData(date); for (int j = 0; j < asthmaData.questionDataList.Count; j++) { QuestionBasedTrackerData.QuestionData qData = asthmaData.GetQuestion(); asthmaData.SetAnswer(qData, Random.Range(1, qData.answersOption.Length)); } asthmaJsonObject.Add(asthmaData.FormatToJson()); } if (Random.Range(0f, 1f) > 0.5f) { // CSU test CSUData csuData = new CSUData(date); for (int j = 0; j < csuData.questionDataList.Count * 3; j++) { if (j == 0) { csuData.ChangeBodyPart(BodyPart.Head); } else if (j == 2) { csuData.ChangeBodyPart(BodyPart.Chest); } else if (j == 4) { csuData.ChangeBodyPart(BodyPart.Legs); } QuestionBasedTrackerData.QuestionData qData = csuData.GetQuestion(); csuData.SetAnswer(qData, Random.Range(1, qData.answersOption.Length)); if (Random.value > 0.5f) { // add some random textures int count = Random.Range(0, textures.Length); // shuffle textures System.Random rnd = new System.Random(); Texture2D[] shuffled = textures.OrderBy(x => rnd.Next()).ToArray(); // and cut out the array Array.Resize(ref shuffled, count); csuData.SavePhotos(shuffled); } } csuJsonObject.Add(csuData.FormatToJson()); } if (Random.Range(0f, 1f) > 0.5f) { // UAS test UASData uasData = new UASData(date); for (int j = 0; j < uasData.questionDataList.Count; j++) { QuestionBasedTrackerData.QuestionData qData = uasData.GetQuestion(); uasData.SetAnswer(qData, Random.Range(1, qData.answersOption.Length)); } uasJsonObject.Add(uasData.FormatToJson()); } // add a single day date = date.AddDays(1); } WriteToFile(Path.Combine(Helper.GetDataPath(), LOGS_FOLDER, CSU_LOG), csuJsonObject.Print(true)); WriteToFile(Path.Combine(Helper.GetDataPath(), LOGS_FOLDER, UAS_LOG), uasJsonObject.Print(true)); WriteToFile(Path.Combine(Helper.GetDataPath(), LOGS_FOLDER, SYMPTOM_LOG), symptomJsonObject.Print(true)); WriteToFile(Path.Combine(Helper.GetDataPath(), LOGS_FOLDER, ASTHMA_TEST_LOG), asthmaJsonObject.Print(true)); NotesManager.FillTestData(days); Debug.LogWarning($"Random log data generated for {days} days"); }