/// <summary>
        /// Serialise the results to a file so it can be viewed outside the application.
        /// </summary>
        /// <param name="recordHolder">The object containing the new metrics.</param>
        private static void SaveMetrics(IRecordHolder <MeshEntry> recordHolder)
        {
            // Preparation data to construct path and filename.
            CultureInfo culture     = Settings.Culture;
            DateTime    dateTime    = recordHolder.SnapshotTime;
            string      timeformat  = F_DateFormat;
            string      fileformat  = F_File_Measure;
            string      fileApendix = Settings.MeasurementsFile;
            // Example dir:
            // Content/Analysis
            string directory = Settings.MeasurementsDir;
            // Example time:
            // 2019-10-04-13-22-52
            string time = dateTime.ToString(timeformat, culture);
            // Example file:
            // 2019-10-04-13-22-52_measures.csv
            string filename = string.Format(culture, fileformat, time, fileApendix);
            // Example loc:
            // Content/Analysis/2019-10-04-13-22-52_measures.csv
            string location = Path.Combine(directory, filename);

            // Export the generated file
            Directory.CreateDirectory(directory);
            Settings.FileManager.Write(location, recordHolder);
            Logger.Log(I_Measure_Exp, filename);
        }
        /// <summary>
        /// The operation to calculate metrics for saved and presented shapes.
        /// </summary>
        /// <param name="options">The options object which contains extra information
        /// which helps during the exeuction of this modus.</param>
        public static void Start(MeasureOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            Logger.Log(I_StartProc_Measure);
            // Load in new shapes to measure.
            if (options.HasDirectories)
            {
                foreach (string dir in options.ShapeDirectories)
                {
                    Settings.FileManager.AddDirectoryDirect(dir);
                }
            }
            // Perform metric calculations.
            IRecordHolder <MeshEntry> recordHolder = MetricCalculator;

            recordHolder.TakeSnapShot(Settings.MeshLibrary);
            // Save results to external file.
            SaveMetrics(recordHolder);
            // Notify the user of the refined shapes.
            Logger.Log(I_ShapeCount, Settings.MeshLibrary.Count);
            Logger.Log(I_EndProc_Measure);
        }
        /// <summary>
        /// The operation to evaluate the result of a query.
        /// </summary>
        /// <param name="options">The options object which contains extra information
        /// which helps during the exeuction of this modus.</param>
        public static void Start(EvaluateOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            Logger.Log(I_StartProc_Evaluate);

            IRecordHolder <QueryResult> records = EvaluationCalculator;

            QueryResult[] results = QueryHandler.LoadQueryResults(options.ShouldImport);
            records.TakeSnapShot(results);

            IRecordHolder holder = null;

            switch (options.EvaluationMode)
            {
            case EvaluationMode.Individual:
                holder = records;
                break;

            case EvaluationMode.Aggregated:
                holder = RecordMerger.Merge(records);
                break;
            }

            if (options.ShouldExport)
            {
                SaveEvaluation(holder);
            }

            Logger.Log(I_EndProc_Evaluate);
        }
        /// <summary>
        /// Serialises the results of the evaluation to its own file.
        /// </summary>
        /// <param name="records">The holder of the evaluation information.</param>
        private static void SaveEvaluation(IRecordHolder records)
        {
            string directory = Settings.QueryDir;
            string filename  = Settings.EvaluationFile;

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory((directory));
            }

            string path = Path.Combine(directory, filename);

            Settings.FileManager.Write(path, records);
            Logger.Log(I_Evaluation_Exp, path);
        }
        /// <summary>
        /// Combines all the records in the specified Record Holder with
        /// the current combination formulas in this object.
        /// </summary>
        /// <param name="holder">The collection of records which hsould be merged.</param>
        /// <returns>A new <see cref="IRecordHolder"/> which contains the aggregated
        /// data of all the previous records.</returns>
        public IRecordHolder Merge(IRecordHolder holder)
        {
            if (holder == null)
            {
                throw new ArgumentNullException(nameof(holder));
            }

            // Combines all the records in a merge record.
            foreach (Record record in holder)
            {
                string      group = mergeClass(record);
                MergeRecord merge = GetOrCreate(group);
                foreach ((string measureName, object measureValue) in record.Measures)
                {
                    merge.AddMeasure(measureName, measureValue);
                }
            }

            DirectRecordHolder recordHolder = new DirectRecordHolder();

            // Aggregates all the data in a merge record into a single value.
            foreach (string measureName in holder.MeasureNames)
            {
                recordHolder.AddMeasureName(measureName);
            }
            Parallel.ForEach(records, recordPair => {
                string name       = recordPair.Key;
                MergeRecord merge = recordPair.Value;

                foreach (KeyValuePair <string, MergeMeasures> cPair in classMeasures)
                {
                    merge.AddMergeFunction(cPair.Key, cPair.Value);
                }
                foreach (KeyValuePair <Type, MergeMeasures> tPair in typeMeasures)
                {
                    merge.AddMergeFunction(tPair.Key, tPair.Value);
                }

                merge.Merge();
                recordHolder.AddRecord(merge);
            });

            return(recordHolder);
        }
Exemple #6
0
 /// <summary>
 /// Provides a new measurement to be taken for the objects in the database.
 /// </summary>
 /// <param name="holder">The recordholder that should get another measure.
 /// </param>
 /// <param name="measure">A tuple containing the name and the operations
 /// to provide a measurement of an object.</param>
 /// <param name="overwrite">If a previous measure should be overwritten with
 /// the same name.</param>
 /// <returns>The current object for chaining.</returns>
 /// <exception cref="ArgumentNullException">If the given holder is
 /// <see langword="null"/> or any of the provided measurements is
 /// <see langword="null"/>.</exception>
 public static IRecordHolder <T> AddMeasure <T>(this IRecordHolder <T> holder,
                                                (string name, Func <T, object> func) measure, bool overwrite = false)