Beispiel #1
0
        public static StudyData GetInstance()
        {
            if (instance == null)
            {
                instance = new StudyData();
            }

            return(instance);
        }
Beispiel #2
0
        /**
         * Load and parse data from dat_mes.csv
         */

        internal static void LoadData(StudyData studyData)
        {
            if (IsDataLoaded)
            {
                return;
            }

            List <string[]> rows = new List <string[]>();

            using (StreamReader reader = File.OpenText("Data/dat_mes.csv"))
            {
                while (reader.Peek() >= 0)
                {
                    string   line     = reader.ReadLine();
                    string[] rowArray = CSVRowToStringArray(line);
                    if (rowArray.Length > 0)
                    {
                        rows.Add(rowArray);
                    }
                }
            }

            string[] headers = rows[0];
            rows.Remove(headers);

            /**
             * Parse each row array into a Study object.
             * Assumes CSV column ordering:
             *     id,PublicationYear,n,r,VariablesControlled,StudyDesign,
             *     AdherenceMeasure,ConscientiousnessMeasure ,MeanAge,MethodologicalQuality
             */
            foreach (string[] row in rows)
            {
                PublicationYear          publicationYear          = studyData.PublicationYears.AddUnique(row[1]);
                CorrelationCoefficient   correlationCoefficient   = studyData.CorrelationCoefficients.AddUnique(row[2]);
                SampleSize               sampleSize               = studyData.SampleSizes.AddUnique(row[3]);
                VariablesControlled      variablesControlled      = studyData.VariablesControlled.AddUnique(row[4]);
                StudyDesign              studyDesign              = studyData.StudyDesigns.AddUnique(row[5]);
                AdherenceMeasure         adherenceMeasure         = studyData.AdherenceMeasures.AddUnique(row[6]);
                ConscientiousnessMeasure conscientiousnessMeasure = studyData.ConscientiousnessMeasures.AddUnique(row[7]);
                MeanAge meanAge = studyData.MeanAges.AddUnique(row[8]);
                MethodologicalQuality methodologicalQuality = studyData.MethodologicalQualities.AddUnique(row[9]);

                Study newStudy = new Study
                {
                    Id = row[0],
                    PublicationYear          = publicationYear,
                    CorrelationCoefficient   = correlationCoefficient,
                    SampleSize               = sampleSize,
                    VariablesControlled      = variablesControlled,
                    StudyDesign              = studyDesign,
                    AdherenceMeasure         = adherenceMeasure,
                    ConscientiousnessMeasure = conscientiousnessMeasure,
                    MeanAge = meanAge,
                    MethodologicalQuality = methodologicalQuality
                };
                studyData.Studies.Add(newStudy);
            }

            IsDataLoaded = true;
        }