Example #1
0
 public FinDataAdapter(FinAnalysisVM finAnalysisVm, string symbol, DataSource dataSource)
 {
     _finDataDao = new FinDataDao();
     _priceDataDao = new PriceDataDao();
     _dataSource = dataSource;
     _symbol = symbol;
     _finAnalysisVm = finAnalysisVm;
     _dcfDataDao = new DcfDataDao();
 }
Example #2
0
        public DcfVM(DataGrid dataGrid, DcfDataDao dcfDataDao, DcfInput dcfInput, FinDataDao finDataDao, FinDataAdapter finDataAdapter)
        {
            _dataGrid = dataGrid;
            _rowMapping = Rowmapping.DcfRows();
            _showForecastTable = new ObservableCollection<ForecastData>();
            _columnHeader = new List<string>();
            _dcfDataDao = dcfDataDao;
            _dcfInput = dcfInput;
            _finDataDao = finDataDao;
            _finDataAdapter = finDataAdapter;

            _finDataAdapter.DcfOutput.PropertyChanged += OutputChangedEventHandler;
        }
Example #3
0
 /// <summary>
 /// Kutsutav meetod, mis loeb etteantud faiinime järgi async finantsandmed kaasa antud objektides sisalduvatesse hoidjatesse.
 /// On olemas ka overloaded sama nimega teine meetod juba olemasoleva Xdoc objekti jaoks.
 /// </summary>
 /// <param name="fileName">XML faili nimi</param>
 /// <param name="dao">FinData DAO, kuhu andmed lisatakse</param>
 /// <param name="finDataAdapter">Kutsuv adapter, vajalik hilisemaks märguandeks, kui andmed loetud</param>
 public void GetData(string fileName, FinDataDao dao, FinDataAdapter finDataAdapter)
 {
     _finDataDao = dao;
     _finDataAdapter = finDataAdapter;
     try
     {
         //XDocument xdoc = XDocument.Load(fileName);
         //GetData(xdoc, dao);
         LoadXMLData(fileName);
     }
     catch (XmlException)
     {
         System.Windows.MessageBox.Show("Error reading XML");
     }
 }
Example #4
0
 /// <summary>
 /// Overloadib failinime järgi faili lugevat meetodit, kuid kogu objekti andmete salvestamine toimub siin meetodis.
 /// </summary>
 /// <param name="xdoc">XDoc andmed</param>
 /// <param name="dao">DAO, kuhu andmed salvestatakse</param>
 public void GetData(XDocument xdoc, FinDataDao dao)
 {
     try
     {
         var query = from x in xdoc.Descendants("table") select new FinData(x);
         foreach (var item in query)
         {
             dao.AddFinData(item);
         }
         _finDataAdapter.XmlDataReady();
     }
     catch (XmlException)
     {
         System.Windows.MessageBox.Show("Error reading XML");
     }
 }
Example #5
0
        public XDocument GetData(string symbol, string fileName, FinDataDao dao)
        {
            try
            {
                //using (FileStream fs = new FileStream(@"../../FailidTestimiseks/CSCO-Quarterly_Balance_Sheet.xls", FileMode.Open, FileAccess.Read))
                using (FileStream fs = new FileStream(@"../../FailidTestimiseks/CSCO-Quarterly_Income_Statements.xls", FileMode.Open, FileAccess.Read))
                {
                    XDocument xDoc = new XDocument();
                    HSSFWorkbook hwb = new HSSFWorkbook(fs);
                    ISheet sheet = hwb.GetSheetAt(0);
                    AddDataNameRowVariableMappingsCurDoc(sheet.SheetName);
                    MessageBox.Show(IsNameRowMappingValid(sheet).ToString());
                    System.Collections.IEnumerator rows = sheet.GetRowEnumerator();

                    IRow quartersDataRow = findQuartersDataRow(sheet);
                    if (quartersDataRow != null)
                    {
                        int[] quarterColumnIndexes = FindQuarterColumnIndexes(quartersDataRow);
                        string[] rowHeaderNames = FindRowHeaderNames(sheet);
                        if (quarterColumnIndexes.Count() > 0)
                        {
                            List<FinData> items = new List<FinData>();
                            XElement xTable;
                            XElement xColumn;
                            XAttribute curAttribute;
                            ICell curCell;
                            string curData;
                            XElement xDatabase = new XElement("database");
                            for (int i = 0; i < quarterColumnIndexes.Count(); i++)
                            {
                                xTable = new XElement("table");
                                for (int j = 0; j < _dataNameRowVariableMappings.Count; j++)
                                {
                                    curCell = sheet.GetRow(_dataNameRowVariableMappings.ElementAt(j).Value).GetCell(quarterColumnIndexes[i]);
                                    curCell.SetCellType(CellType.STRING);
                                    if (curCell == null || String.IsNullOrEmpty(curCell.StringCellValue))
                                    {
                                        curData = "NULL";
                                    }
                                    else
                                    {
                                        curData = curCell.StringCellValue;
                                    }
                                    xColumn = new XElement("column", curData);
                                    curAttribute = new XAttribute("name", _dataNameRowVariableMappings.ElementAt(j).Key.Value);
                                    xColumn.Add(curAttribute);
                                    xTable.Add(xColumn);
                                }
                                xDatabase.Add(xTable);
                            }
                            xDoc.Add(xDatabase);
                            var querry = from x in xDoc.Descendants("table") select new FinData(x);
                            xDoc.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/AFFA_parsed_excel.xml");
                            var query = from x in xDoc.Descendants("table") select new FinData(x);
                            foreach (var item in query)
                            {
                                dao.AddFinData(item);
                            }
                        }
                        else
                        {

                        }
                    }
                    return xDoc;
                }
            }
            catch (IOException e)
            {
                MessageBox.Show(e.Message);
                return null;
            }
        }
Example #6
0
        public void GetData(string ticker)
        {
            FinDataDao curDatas = new FinDataDao();
            string url = "http://www.google.com/finance?q=" + ticker.ToUpper() + "&fstype=ii";

            //Load Google Finance with the specified URL.
            var webGet = new HtmlWeb();
            var document = webGet.Load(url);

            //List of Elements containing data tables in Google Finance.
            Dictionary<string, Dictionary<string, string>> elementNames = new Dictionary<string, Dictionary<string, string>>();
            elementNames.Add("incinterimdiv", IsMappings());
            elementNames.Add("balinterimdiv", BsMappings());
            elementNames.Add("casinterimdiv", CfsMappings());

            HtmlNode curElement;
            List<XElement> datas = new List<XElement>();
            Dictionary<int, int> columnToDataMapping;
            DateTime dt;
            HtmlNode newNode;
            XElement newEl;
            XElement xe;
            string kuupaev;
            string curDataName;
            foreach (var element in elementNames)
            {
                curElement = document.GetElementbyId(element.Key);
                Dictionary<string, string> mappings = element.Value;

                if (curElement == null)
                {
                    continue;
                }
                columnToDataMapping = new Dictionary<int, int>();
                var columnHeaders = from lnks in curElement.Descendants() where lnks.Name.Equals("th") && lnks.InnerText.Trim().Length > 0 select new { Text = lnks.InnerText };
                for (int i = 0; i < columnHeaders.Count(); i++)
                {
                    var columnHeader = columnHeaders.ElementAt(i);
                    if (DateTime.TryParse(columnHeader.Text.Trim().Substring(columnHeader.Text.Trim().Length - 11), out dt))
                    {
                        if (HasQuarter(datas, dt) >= 0)
                        {
                            columnToDataMapping.Add(i, HasQuarter(datas, dt));
                        }
                        else
                        {
                            kuupaev = dt.ToString("yyyy-MM-dd");
                            newEl = new XElement("table");
                            newEl.Add(new XAttribute("is_kuupaev", kuupaev));
                            xe = new XElement("column", kuupaev);
                            xe.Add(new XAttribute("name", "is_kuupaev"));
                            newEl.Add(xe);
                            xe = new XElement("column", ticker);
                            xe.Add(new XAttribute("name", "is_symbol"));
                            newEl.Add(xe);
                            columnToDataMapping.Add(i, datas.Count());
                            datas.Add(newEl);
                        }
                    }
                }

                var rows = from lnks in curElement.Descendants() where lnks.Name.Equals("tr") select new { InnerHtml = lnks.OuterHtml };
                foreach (var row in rows)
                {
                    newNode = HtmlNode.CreateNode(row.InnerHtml);
                    var tdd = from td in newNode.Descendants() where td.Name.Equals("td") select new { Data = td.InnerText };
                    if (tdd.Count() > 0)
                    {
                        if (mappings.TryGetValue(tdd.ElementAt(0).Data.Trim(), out curDataName) && tdd.Count() > 1)
                        {
                            for (int i = 1; i < tdd.Count(); i++)
                            {
                                int j = 0;
                                if (columnToDataMapping.TryGetValue(i, out j))
                                {
                                    double num;
                                    NumberStyles style = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands;
                                    CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
                                    if (Double.TryParse(tdd.ElementAt(i).Data.Trim(), style, culture, out num))
                                    {
                                        newEl = new XElement("column", num.ToString());
                                    }
                                    else
                                    {
                                        newEl = new XElement("column", "NULL");
                                    }
                                    newEl.Add(new XAttribute("name", curDataName));
                                    datas.ElementAt(j).Add(newEl);
                                }
                            }
                        }
                    }
                }
            }

            if (datas.Count() > 0)
            {
                _downloadedData = new XDocument();
                XElement database = new XElement("database");
                foreach (XElement e in datas)
                {
                    database.Add(e);
                }
                _downloadedData.Add(database);

                //Save retrieved data to AFFA folder
                DateTime dtnow = DateTime.Now;
                string directoryName = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) +
                                       "/AFFA";
                if (!Directory.Exists(directoryName))
                {
                    Directory.CreateDirectory(directoryName);
                }
                string filename = "gf_" + ticker + "_" + dtnow.ToString("yyMMdd-HHmmss") + ".xml";
                _xmlPath = directoryName + "/" + filename;
                _downloadedData.Save(_xmlPath);
            }
            else
            {
                _downloadedData = null;
            }
        }