public override ResearchResult Load(Guid researchID)
        {
            ResearchResult r = null;

            string fileNameToLoad = null;
            if (existingFileNames != null && existingFileNames.Keys.Contains(researchID))
                fileNameToLoad = existingFileNames[researchID];
            else
                fileNameToLoad = FileNameByGuid(researchID);

            if (fileNameToLoad != null)
            {
                r = new ResearchResult();
                using (reader = XmlReader.Create(fileNameToLoad))
                {
                    try
                    {
                        while (reader.Read() &&
                            (reader.NodeType != XmlNodeType.Element ||
                            reader.Name == "Research")) { }

                        LoadResearchInfo(r);
                        LoadResearchParameters(r);
                        LoadGenerationParameters(r);
                        LoadEnsembleResults(r);
                    }
                    catch (SystemException ex)
                    {
                        Console.WriteLine(ex.Data);
                    }
                }
            }

            return r;
        }
        private bool Check(AnalyzeOption o, RealizationResult rn, ResearchResult rr)
        {
            Debug.Assert(rn.Result.ContainsKey(o));
            Debug.Assert(rn.Result[o] != null);
            Debug.Assert(rr.EnsembleResults.Count() > 0);
            if (!rr.EnsembleResults[0].Result.ContainsKey(o))
                return true;
            Debug.Assert(rr.EnsembleResults[0].Result[o] != null);

            AnalyzeOptionInfo[] info = (AnalyzeOptionInfo[])o.GetType().GetField(o.ToString()).GetCustomAttributes(typeof(AnalyzeOptionInfo), false);
            OptionType ot = info[0].OptionType;
            switch (ot)
            {
                case OptionType.Global:
                    Double v1 = Convert.ToDouble(rn.Result[o]);
                    Double v2 = Convert.ToDouble(rr.EnsembleResults[0].Result[o]);
                    return Math.Round(v1, 4) == v2;
                case OptionType.Distribution:
                case OptionType.Trajectory:
                    Debug.Assert(rn.Result[o] is SortedDictionary<Double, Double>);
                    Debug.Assert(rr.EnsembleResults[0].Result[o] is SortedDictionary<Double, Double>);
                    SortedDictionary<Double, Double> d1 = rn.Result[o] as SortedDictionary<Double, Double>;
                    SortedDictionary<Double, Double> d2 = rr.EnsembleResults[0].Result[o] as SortedDictionary<Double, Double>;
                    return CheckDictionary(d1, d2);
                default:
                    Debug.Assert(false);
                    break;
            }

            return true;
        }
        public override void Save(ResearchResult result)
        {
            if (!Directory.Exists(storageStr))
            {
                Directory.CreateDirectory(storageStr);
            }

            string fileName = storageStr + result.ResearchName;
            if (File.Exists(fileName + ".xls") || File.Exists(fileName + ".xlsx"))
                fileName += result.ResearchID;

            document = SpreadsheetDocument.Create(fileName + ".xlsx", SpreadsheetDocumentType.Workbook);
            workbook = document.AddWorkbookPart();
            workbook.Workbook = new Workbook();

            // Add a WorksheetPart to the WorkbookPart.
            WorksheetPart worksheetPart = workbook.AddNewPart<WorksheetPart>();
            worksheetPart.Worksheet = new Worksheet(new SheetData());

            // Add Sheets to the Workbook.
            Sheets sheets = document.WorkbookPart.Workbook.
                AppendChild<Sheets>(new Sheets());

            // Append a new worksheet and associate it with the workbook.
            Sheet sheet = new Sheet()
            {
                Id = document.WorkbookPart.
                    GetIdOfPart(worksheetPart),
                SheetId = 1,
                Name = "mySheet"
            };
            sheets.Append(sheet);

            /*SaveResearchInfo(result.ResearchID, result.ResearchName,
                    result.ResearchType, result.ModelType, result.RealizationCount,
                    result.Size, result.Edges);
            SaveResearchParameters(result.ResearchParameterValues);
            SaveGenerationParameters(result.GenerationParameterValues);

            for (int i = 0; i < result.EnsembleResults.Count; ++i)
            {
                SaveEnsembleResult(result.EnsembleResults[i], i);
            }*/

            workbook.Workbook.Save();
            document.Close();
        }
 private void LoadResearchInfo(Worksheet sheet, ResearchResult r)
 {
     r.ResearchID = new Guid((string)sheet.get_Range("B2").Cells.Value);
     r.ResearchName = sheet.get_Range("B3").Cells.Value;
     r.ResearchType = (ResearchType)Enum.Parse(typeof(ResearchType), (string)sheet.get_Range("B4").Cells.Value);
     r.ModelType = (ModelType)Enum.Parse(typeof(ModelType), (string)sheet.get_Range("B5").Cells.Value);
     r.RealizationCount = (Int32)sheet.get_Range("B6").Cells.Value;
     r.Date = sheet.get_Range("B7").Cells.Value;
     r.Size = (UInt32)sheet.get_Range("B8").Cells.Value;
     r.Edges = sheet.get_Range("B9").Cells.Value;
 }
 private void LoadResearchAndGenerationParameters(Worksheet sheet, ResearchResult r)
 {
     int rowIndex = 12;
     string currentParameter = sheet.get_Range("A" + rowIndex).Cells.Value;
     if ("Research Parameters" == sheet.get_Range("A11").Cells.Value)
     {
         while (currentParameter != null)
         {
             ResearchParameter rp = (ResearchParameter)Enum.Parse(typeof(ResearchParameter), currentParameter);
             r.ResearchParameterValues.Add(rp, sheet.get_Range("B" + rowIndex).Cells.Value);
             ++rowIndex;
             currentParameter = sheet.get_Range("A" + rowIndex).Cells.Value;
         }
         rowIndex += 2;
         currentParameter = sheet.get_Range("A" + rowIndex).Cells.Value;
     }
     while (currentParameter != null)
     {
         GenerationParameter gp = (GenerationParameter)Enum.Parse(typeof(GenerationParameter), currentParameter);
         r.GenerationParameterValues.Add(gp, sheet.get_Range("B" + rowIndex).Cells.Value);
         ++rowIndex;
         currentParameter = sheet.get_Range("A" + rowIndex).Cells.Value;
     }
 }
        private void LoadEnsembleResults(Workbook book, ResearchResult r)
        {
            EnsembleResult e = new EnsembleResult();
            e.NetworkSize = r.Size;
            e.EdgesCount = r.Edges;
            e.Result = new Dictionary<AnalyzeOption, Object>();

            Array existingOptions = Enum.GetValues(typeof(AnalyzeOption));
            foreach (AnalyzeOption opt in existingOptions)
            {
                AnalyzeOptionInfo optInfo = (AnalyzeOptionInfo)(opt.GetType().GetField(opt.ToString()).GetCustomAttributes(typeof(AnalyzeOptionInfo), false)[0]);
                switch (optInfo.OptionType)
                {
                    case OptionType.Global:
                        Double v = FindValueInGlobals(book, optInfo.FullName);
                        if ( v != -1)
                            e.Result.Add(opt, v);
                        break;
                    case OptionType.ValueList:
                        Object vl = LoadValueList(book, optInfo);
                        if (vl != null)
                            e.Result.Add(opt, vl);
                        break;
                    case OptionType.Distribution:
                    case OptionType.Trajectory:
                        Object vd = LoadDistribution(book, optInfo);
                        if (vd != null)
                            e.Result.Add(opt, vd);
                        break;
                    default:
                        break;
                }
            }

            r.EnsembleResults.Add(e);
        }
        public override void Save(ResearchResult result)
        {
            string fileName = storageStr + result.ResearchName;
            if (File.Exists(fileName + ".xls") || File.Exists(fileName + ".xlsx"))
                fileName += result.ResearchID;

            InitializeExcelApplication();
            workbook = excelApp.Workbooks.Add();

            SaveGeneralInfo(result.ResearchID, result.ResearchName,
                    result.ResearchType, result.ModelType, result.RealizationCount,
                    result.Size, result.Edges, result.ResearchParameterValues,
                    result.GenerationParameterValues);

            for (int i = 0; i < result.EnsembleResults.Count; ++i)
            {
                SaveEnsembleResult(result.EnsembleResults[i], i);
            }

            workbook.Sheets[1].Activate();
            workbook.SaveAs(fileName + ".xlsx");

            DestroyExcelApplication();
        }
        public override List<ResearchResult> LoadAllResearchInfo()
        {
            InitializeExcelApplication();

            existingFileNames = new SortedDictionary<Guid, string>();
            List<ResearchResult> researchInfos = new List<ResearchResult>();

            ResearchResult DoubleResearchInfo = null;
            Workbook book = null;
            Worksheet sheet = null;
            foreach (string fileName in Directory.GetFiles(storageStr, "*.xlsx",
                SearchOption.TopDirectoryOnly))
            {
                DoubleResearchInfo = new ResearchResult();
                try
                {
                    book = excelApp.Workbooks.Open(fileName);
                    sheet = (Worksheet)book.Worksheets[1];
                    LoadResearchInfo(sheet, DoubleResearchInfo);
                    LoadResearchAndGenerationParameters(sheet, DoubleResearchInfo);

                    researchInfos.Add(DoubleResearchInfo);
                    existingFileNames.Add(DoubleResearchInfo.ResearchID, fileName);
                }
                catch (SystemException)
                {
                    continue;
                }
            }
            book.Close();
            Marshal.ReleaseComObject(book);

            DestroyExcelApplication();

            return researchInfos;
        }
Пример #9
0
        private void LoadResearchParameters(ResearchResult r)
        {
            while (reader.Read())
            {
                if (reader.Name == "ResearchParameter")
                {
                    reader.MoveToAttribute("name");
                    ResearchParameter rp = (ResearchParameter)Enum.Parse(typeof(ResearchParameter), reader.ReadContentAsString());

                    reader.MoveToAttribute("value");
                    ResearchParameterInfo rpInfo = (ResearchParameterInfo)(rp.GetType().GetField(rp.ToString()).GetCustomAttributes(typeof(ResearchParameterInfo), false)[0]);
                    if (rpInfo.Type.Equals(typeof(UInt32)))
                        r.ResearchParameterValues.Add(rp, UInt32.Parse(reader.Value));
                    else if (rpInfo.Type.Equals(typeof(Single)))
                        r.ResearchParameterValues.Add(rp, Single.Parse(reader.Value));
                    else if (rpInfo.Type.Equals(typeof(Boolean)))
                        r.ResearchParameterValues.Add(rp, Boolean.Parse(reader.Value));
                }
                else if (reader.Name == "GenerationParameterValues")
                    break;
            }
        }
        public override ResearchResult Load(Guid researchID)
        {
            ResearchResult r = null;

            string fileNameToLoad = null;
            if (existingFileNames != null && existingFileNames.Keys.Contains(researchID))
                fileNameToLoad = existingFileNames[researchID];
            else
                fileNameToLoad = FileNameByGuid(researchID);

            InitializeExcelApplication();

            Workbook book = null;
            Worksheet sheet = null;
            if (fileNameToLoad != null)
            {
                r = new ResearchResult();
                try
                {
                    book = excelApp.Workbooks.Open(fileNameToLoad);
                    sheet = (Worksheet)book.Worksheets[1];
                    LoadResearchInfo(sheet, r);
                    LoadResearchAndGenerationParameters(sheet, r);
                    LoadEnsembleResults(book, r);
                }
                catch (SystemException ex)
                {
                    Console.WriteLine(ex.Data);
                }
            }
            book.Close();
            Marshal.ReleaseComObject(book);

            DestroyExcelApplication();
            return r;
        }
Пример #11
0
 private void SaveResearchResult(ResearchResult r)
 {
     throw new NotImplementedException();
 }
 private void LoadResearchInfo(ResearchResult r)
 {
     if (reader.Name == "ResearchID")
         r.ResearchID = new Guid(reader.ReadElementString());
     if (reader.Name == "ResearchName")
         r.ResearchName = reader.ReadElementString();
     if (reader.Name == "ResearchType")
         r.ResearchType = (ResearchType)Enum.Parse(typeof(ResearchType), reader.ReadElementString());
     if (reader.Name == "ModelType")
         r.ModelType = (ModelType)Enum.Parse(typeof(ModelType), reader.ReadElementString());
     if (reader.Name == "RealizationCount")
         r.RealizationCount = Int32.Parse(reader.ReadElementString());
     if (reader.Name == "Date")
         r.Date = DateTime.Parse(reader.ReadElementString());
     if (reader.Name == "Size")
         r.Size = UInt32.Parse(reader.ReadElementString());
     if (reader.Name == "Edges")
         r.Edges = Double.Parse(reader.ReadElementString());
 }
        private void LoadResearchParameters(ResearchResult r)
        {
            while (reader.Read())
            {
                if (reader.Name == "ResearchParameter")
                {
                    reader.MoveToAttribute("name");
                    ResearchParameter rp = (ResearchParameter)Enum.Parse(typeof(ResearchParameter), reader.ReadContentAsString());

                    reader.MoveToAttribute("value");
                    ResearchParameterInfo rpInfo = (ResearchParameterInfo)(rp.GetType().GetField(rp.ToString()).GetCustomAttributes(typeof(ResearchParameterInfo), false)[0]);
                    if (rpInfo.Type.Equals(typeof(UInt32)))
                        r.ResearchParameterValues.Add(rp, UInt32.Parse(reader.Value));
                    else if (rpInfo.Type.Equals(typeof(Double)))
                        r.ResearchParameterValues.Add(rp, Double.Parse(reader.Value));
                    else if (rpInfo.Type.Equals(typeof(Boolean)))
                        r.ResearchParameterValues.Add(rp, Boolean.Parse(reader.Value));
                    else if (rpInfo.Type.Equals(typeof(ResearchType)))
                        r.ResearchParameterValues.Add(rp, reader.Value.ToString());
                    else if (rpInfo.Type.Equals(typeof(MatrixPath)))
                    {
                        MatrixPath mp = new MatrixPath();
                        mp.Path = reader.Value.ToString();
                        r.ResearchParameterValues.Add(rp, mp);
                    }
                    else
                    {
                        Debug.Assert(false);
                        //throw new InvalidResearchParameters();
                    }
                }
                else if (reader.Name == "GenerationParameterValues")
                    break;
            }
        }
        private void LoadGenerationParameters(ResearchResult r)
        {
            while (reader.Read())
            {
                if (reader.Name == "GenerationParameter")
                {
                    reader.MoveToAttribute("name");
                    string g = reader.ReadContentAsString();
                    GenerationParameter gp;
                    if (g == "FileName")
                        gp = GenerationParameter.AdjacencyMatrix;
                    else
                        gp = (GenerationParameter)Enum.Parse(typeof(GenerationParameter), g);

                    reader.MoveToAttribute("value");
                    GenerationParameterInfo gpInfo = (GenerationParameterInfo)(gp.GetType().GetField(gp.ToString()).GetCustomAttributes(typeof(GenerationParameterInfo), false)[0]);
                    if (gpInfo.Type.Equals(typeof(UInt32)))
                        r.GenerationParameterValues.Add(gp, UInt32.Parse(reader.Value));
                    else if (gpInfo.Type.Equals(typeof(Double)))
                        r.GenerationParameterValues.Add(gp, Double.Parse(reader.Value));
                    else if (gpInfo.Type.Equals(typeof(Boolean)))
                        r.GenerationParameterValues.Add(gp, Boolean.Parse(reader.Value));
                    else if (gpInfo.Type.Equals(typeof(MatrixPath)))
                    {
                        MatrixPath mp = new MatrixPath();
                        mp.Path = reader.Value.ToString();
                        r.GenerationParameterValues.Add(gp, mp);
                    }
                    else
                    {
                        Debug.Assert(false);
                        //throw new InvalidGenerationParameters();
                    }
                }
                if (reader.Name == "Ensembles")
                    break;
            }
        }
        private void LoadEnsembleResults(ResearchResult r)
        {
            while (reader.Read())
            {
                if (reader.Name == "Ensemble" && !reader.IsEmptyElement)
                {
                    EnsembleResult e = new EnsembleResult();
                    e.NetworkSize = r.Size;
                    e.EdgesCount = r.Edges;
                    e.Result = new Dictionary<AnalyzeOption, Object>();

                    reader.Read();
                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        AnalyzeOption opt = (AnalyzeOption)Enum.Parse(typeof(AnalyzeOption), reader.Name);
                        AnalyzeOptionInfo optInfo = (AnalyzeOptionInfo)(opt.GetType().GetField(opt.ToString()).GetCustomAttributes(typeof(AnalyzeOptionInfo), false)[0]);
                        switch (optInfo.OptionType)
                        {
                            case OptionType.Global:
                                e.Result.Add(opt, reader.ReadElementContentAsDouble());
                                break;
                            case OptionType.ValueList:
                                e.Result.Add(opt, LoadValueList());
                                reader.Read();
                                break;
                            case OptionType.Distribution:
                            case OptionType.Trajectory:
                                e.Result.Add(opt, LoadDistribution());
                                reader.Read();
                                break;
                            default:
                                break;
                        }
                    }

                    r.EnsembleResults.Add(e);
                }
            }
        }
        public override void Save(ResearchResult result)
        {
            string fileName = storageStr + result.ResearchName;
            if (File.Exists(fileName + ".xml"))
                fileName += result.ResearchID;

            using (writer = XmlWriter.Create(fileName + ".xml"))
            {
                writer.WriteStartDocument(true);
                writer.WriteStartElement("Research");

                SaveResearchInfo(result.ResearchID, result.ResearchName,
                    result.ResearchType, result.ModelType, result.RealizationCount,
                    result.Date, result.Size, result.Edges);
                SaveResearchParameters(result.ResearchParameterValues);
                SaveGenerationParameters(result.GenerationParameterValues);

                writer.WriteStartElement("Ensembles");
                for (int i = 0; i < result.EnsembleResults.Count; ++i)
                {
                    SaveEnsembleResult(result.EnsembleResults[i], i);
                }
                writer.WriteEndElement();

                writer.WriteEndElement();
            }
        }
        public override List<ResearchResult> LoadAllResearchInfo()
        {
            existingFileNames = new SortedDictionary<Guid, string>();
            List<ResearchResult> researchInfos = new List<ResearchResult>();

            ResearchResult DoubleResearchInfo = null;
            foreach (string fileName in Directory.GetFiles(storageStr, "*.xml",
                SearchOption.TopDirectoryOnly))
            {
                DoubleResearchInfo = new ResearchResult();
                using (reader = XmlReader.Create(fileName))
                {
                    try
                    {
                        while (reader.Read() &&
                            (reader.NodeType != XmlNodeType.Element ||
                            reader.Name == "Research")) { }

                        LoadResearchInfo(DoubleResearchInfo);
                        LoadResearchParameters(DoubleResearchInfo);
                        LoadGenerationParameters(DoubleResearchInfo);

                        researchInfos.Add(DoubleResearchInfo);
                        existingFileNames.Add(DoubleResearchInfo.ResearchID, fileName);
                    }
                    catch (SystemException)
                    {
                        continue;
                    }
                }
            }

            return researchInfos;
        }
        public override ResearchResult Load(string name)
        {
            ResearchResult r = null;

            if (name != null)
            {
                r = new ResearchResult();
                using (reader = XmlReader.Create(name))
                {
                    try
                    {
                        while (reader.Read() &&
                            (reader.NodeType != XmlNodeType.Element ||
                            reader.Name == "Research")) { }

                        LoadResearchInfo(r);
                        LoadResearchParameters(r);
                        LoadGenerationParameters(r);
                        LoadEnsembleResults(r);
                    }
                    catch (SystemException ex)
                    {
                        Console.WriteLine(ex.Data);
                    }
                }
            }

            return r;
        }
Пример #19
0
 public override void Save(ResearchResult result)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Checks if specified results are compatible for statistic analyze.
        /// </summary>
        /// <param name="r1">First result.</param>
        /// <param name="r2">Second result</param>
        /// <returns>True, if results are compatible. False otherwise</returns>
        /// <note>Research result must have same researchType and modelType.</note>
        private static bool AreParametersCompatible(ResearchResult r1, ResearchResult r2)
        {
            foreach (GenerationParameter gp in r1.GenerationParameterValues.Keys)
            {
                if (r1.GenerationParameterValues[gp].ToString() != r2.GenerationParameterValues[gp].ToString())
                    return false;
            }

            foreach (ResearchParameter rp in r1.ResearchParameterValues.Keys)
            {
                if (r1.ResearchParameterValues[rp].ToString() != r2.ResearchParameterValues[rp].ToString())
                    return false;
            }

            return true;
        }
 /// <summary>
 /// Saves specified research result to repository.
 /// </summary>
 /// <param name="result">Research result.</param>
 public abstract void Save(ResearchResult result);
Пример #22
0
        public override void Save(ResearchResult result)
        {
            if (!Directory.Exists(storageStr))
            {
                Directory.CreateDirectory(storageStr);
            }

            string fileName = storageStr + result.ResearchName;
            if (File.Exists(fileName + ".xml"))
                fileName += result.ResearchID;

            /*XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = true;
            settings.Encoding = Encoding.ASCII;*/

            using (writer = XmlWriter.Create(fileName + ".xml"))//, settings))
            {
                writer.WriteStartDocument(true);
                writer.WriteStartElement("Research");

                SaveResearchInfo(result.ResearchID, result.ResearchName,
                    result.ResearchType, result.ModelType, result.RealizationCount,
                    result.Date, result.Size, result.Edges);
                SaveResearchParameters(result.ResearchParameterValues);
                SaveGenerationParameters(result.GenerationParameterValues);

                writer.WriteStartElement("Ensembles");
                for (int i = 0; i < result.EnsembleResults.Count; ++i)
                {
                    SaveEnsembleResult(result.EnsembleResults[i], i);
                }
                writer.WriteEndElement();

                writer.WriteEndElement();
            }
        }