public async Task <Judet[]> InitJudete() { var dd = new DownloadData(); var dataBytes = await dd.Data(new Uri("http://data.gov.ro/storage/f/2013-11-01T11%3A53%3A13.359Z/siruta-judete.csv")); string data = Encoding.UTF8.GetString(dataBytes); var list = new List <Judet>(); var lines = data.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { if (string.IsNullOrWhiteSpace(line)) { continue; } var arr = line.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); if (arr[0] == "JUD")//header { continue; } var j = new Judet(); j.Cod = arr[3]; j.Nume = arr[1]; j.ID = arr[2];//FSJ list.Add(j); } return(list.ToArray()); }
public override async Task <RopDocument[]> FillDate() { var dd = new DownloadData(); var dataBytes = await dd.Data(rdBase.PathDocument); string data = Encoding.UTF8.GetString(dataBytes); var list = new List <RopData>(); var lines = data.Split((char)(10)); var restFromPreviousLine = ""; for (int lineIter = 0; lineIter < lines.Length; lineIter++) { var line = lines[lineIter]; if (string.IsNullOrWhiteSpace(line)) { continue; } var arr = (restFromPreviousLine + line).Split(new[] { ";" }, StringSplitOptions.None); if (arr.Length < 10) { restFromPreviousLine += line; continue; } restFromPreviousLine = ""; if (arr[0].StartsWith("Jude")) { continue; } if (string.IsNullOrWhiteSpace(arr[0])) { continue; } var numeJudet = arr[0].Trim().ToLower(); if (numeJudet.ToLower() == "dgeip") { continue; } var judet = judetFinder.Find(numeJudet); var val = int.Parse(arr[6].Replace(".", "")); var rd = new RopData(); rd.Judet = judet; rd.Valoare = val; list.Add(rd); } list = list.GroupBy(it => it.Judet).Select(group => new RopData() { Judet = group.Key, Valoare = group.Sum(it => it.Valoare) } ).ToList(); rdBase.Data = list.ToArray(); return(new[] { rdBase }); }
public override async Task <RopDocument[]> FillDate() { var data = new List <RopData>(); var dd = new DownloadData(); var dataBytes = await dd.Data(rdBase.PathDocument); var path = Path.Combine(Path.GetTempPath(), Path.GetTempFileName() + ".csv"); var csv = Encoding.UTF8.GetString(dataBytes); //var path = "D:\\a.xls"; var lines = csv.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { if (string.IsNullOrWhiteSpace(line)) { continue; } var arr = line.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < arr.Length; i++) { arr[i] = arr[i].Replace("\"", ""); } if (arr[0].Trim().ToUpper() == "JUDET") //header { continue; } var numeJudet = arr[0].Trim().ToLower(); var judet = judetFinder.Find(numeJudet); int valoare; try { valoare = int.Parse(arr[arr.Length - 1]); } catch (Exception ex) { throw new ArgumentException("judet:" + numeJudet + "=> valoare" + arr[arr.Length - 1], ex); } var rd = new RopData(); rd.Judet = judet; rd.Valoare = valoare; rd.Oras = null; data.Add(rd); } rdBase.Data = data .GroupBy(it => it.Judet).Select(group => new RopData() { Judet = group.Key, Valoare = group.Sum(it => it.Valoare) } ).ToArray(); return(new[] { rdBase }); }
public override async Task <RopDocument[]> FillDate() { List <RopData> data = new List <RopData>(); var dd = new DownloadData(); var dataBytes = await dd.Data(rdBase.PathDocument); var path = Path.Combine(Path.GetTempPath(), Path.GetTempFileName() + ".xls"); File.WriteAllBytes(path, dataBytes); //var path = "D:\\a.xls"; var dt = new DataTable(); using (var m = new OleDbConnection()) { m.ConnectionString = ExcelHelpers.BuildExcelConnectionString(path, true); m.Open(); var query = @"Select * From [Sheet1$]"; using (var cmd = new OleDbCommand(query, m)) { using (var dr = cmd.ExecuteReaderAsync().Result) { dt.Load(dr); } } } foreach (DataRow row in dt.Rows) { int nr; var arr = row.ItemArray; //if (arr[0] == null || string.IsNullOrWhiteSpace(arr[0].ToString())) if (string.IsNullOrWhiteSpace(arr[0]?.ToString())) { continue; } if (!int.TryParse(arr[0].ToString(), out nr)) { continue; } var numeJudet = arr[1].ToString().Trim().ToLower(); var judet = judetFinder.Find(numeJudet); var rd = new RopData(); rd.Judet = judet; rd.Valoare = int.Parse(arr[2].ToString()); rd.Oras = null; data.Add(rd); } rdBase.Data = data.ToArray(); return(new [] { rdBase }); }
public override async Task <RopDocument[]> FillDate() { var dd = new DownloadData(); var uri = new Uri("http://data.gov.ro/dataset/situatia-farmaciilor-din-romania"); var dataBytes = await dd.Data(uri); var str = Encoding.ASCII.GetString(dataBytes); var hd = new HtmlDocument(); hd.LoadHtml(str); var nodes = hd.DocumentNode.SelectNodes("//a[@class='resource-url-analytics']"); var taskList = new List <Task <RopData> >(); foreach (var node in nodes) { var link = node.Attributes["href"].Value; var task = CreateFarmacie(new Uri(link)); taskList.Add(task); } await Task.WhenAll(taskList.ToArray()); var rd = new RopDocument(); rd.Name = "farmacii"; rd.PathDocument = uri; rd.ID = "45A83E85-D049-4258-8575-9CE43C49273C"; rd.Description = "Situatia farmaciilor din Romania"; var list = taskList. Select(it => (it.Exception == null) ? it.Result : null) .Where(it => it != null); //Bucuresti is duplicate - judet list = list.GroupBy(it => it.Judet).Select(group => new RopData() { Judet = group.Key, Valoare = group.Sum(it => it.Valoare) } ).ToArray(); rd.Data = list.ToArray(); return(new[] { rd }); }
public async Task <UAT[]> InitUat(Judet[] judete) { var dd = new DownloadData(); var dataBytes = await dd.Data(new Uri("http://data.gov.ro/storage/f/2013-11-01T11%3A49%3A59.808Z/siruta.csv")); string data = Encoding.UTF8.GetString(dataBytes); var list = new List <UAT>(); var lines = data.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); Judet lastJudet = null; foreach (var line in lines) { if (string.IsNullOrWhiteSpace(line)) { continue; } var arr = line.Split(new string[] { ";" }, StringSplitOptions.None); if (arr[0] == "\"SIRUTA\"")//header { continue; } if (arr[12].Contains("00000000000"))//rang => judet { var idJudet = int.Parse(arr[12].Replace("00000000000", "").Replace("\"", "")); lastJudet = judete.First(it => it.ID == idJudet.ToString()); continue; } if (lastJudet == null) { throw new ArgumentException("not found judet for " + line); } var uat = new UAT(); uat.UatTip = (arr[5]); uat.Nume = arr[1].Replace("\"", ""); uat.ID = arr[9]; uat.Judet = lastJudet; list.Add(uat); } return(list.ToArray()); }
private async Task <RopData> CreateFarmacie(Uri uri) { var rd = new RopData(); var numeFarmacie = uri.Segments.Last().Replace(".xls", ""); switch (numeFarmacie) { case "bucuresti---sector-1": case "bucuresti---sector-2": case "bucuresti---sector-3": case "bucuresti---sector-4": case "bucuresti---sector-5": case "bucuresti---sector-6": rd.Judet = judetFinder.Find("Bucuresti"); break; case "farmacii-circuit-inchis324112670-1": //TODO: take this into consideration return(null); default: rd.Judet = judetFinder.Find(numeFarmacie); break; } var dd = new DownloadData(); var dataBytes = await dd.Data(uri); var path = Path.Combine(Path.GetTempPath(), Path.GetTempFileName() + ".xls"); File.WriteAllBytes(path, dataBytes); var nr = await ExcelHelpers.NrRows(path); rd.Valoare = nr; return(rd); }
public override async Task <RopDocument[]> FillDate() { var dd = new DownloadData(); var dataBytes = await dd.Data(rdBase.PathDocument); var str = Encoding.UTF8.GetString(dataBytes); var list = new List <RopData>(); var lines = str.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { var arr = line.Split(new[] { ";" }, StringSplitOptions.None); if (string.IsNullOrWhiteSpace(arr[0])) { continue; } if (arr[0].Contains("Jude")) { continue; } var rd = new RopData(); rd.Judet = judetFinder.Find(arr[0]); rd.Valoare = int.Parse(arr[3]); list.Add(rd); } list = list.GroupBy(it => it.Judet).Select(group => new RopData() { Judet = group.Key, Valoare = group.Sum(it => it.Valoare) } ).ToList(); rdBase.Data = list.ToArray(); return(new[] { rdBase }); }
public override async Task <RopDocument[]> FillDate() { var dataAlegatori = new List <RopData>(); var dataAlegatoriPrezenti = new List <RopData>(); var dd = new DownloadData(); var dataBytes = await dd.Data(rdBase.PathDocument); var path = Path.Combine(Path.GetTempPath(), Path.GetTempFileName() + ".xls"); File.WriteAllBytes(path, dataBytes); //var path = "D:\\a.xls"; var dt = new DataTable(); using (var m = new OleDbConnection()) { m.ConnectionString = ExcelHelpers.BuildExcelConnectionString(path, true); m.Open(); var query = @"Select * From [SIAEP2014_STAT_Statistica pe lo$]"; using (var cmd = new OleDbCommand(query, m)) { using (var dr = cmd.ExecuteReaderAsync().Result) { dt.Load(dr); } } } foreach (DataRow row in dt.Rows) { var arr = row.ItemArray; //if (arr[0] == null || string.IsNullOrWhiteSpace(arr[0].ToString())) if (string.IsNullOrWhiteSpace(arr[0]?.ToString())) { continue; } var numeJudet = arr[1].ToString().Trim().ToLower(); if (numeJudet == "străinătate") { continue; } var judet = judetFinder.Find(numeJudet); var valoare = int.Parse(arr[3].ToString()); var rd = new RopData(); rd.Judet = judet; rd.Valoare = valoare; rd.Oras = null; dataAlegatori.Add(rd); rd = new RopData(); rd.Judet = judet; rd.Valoare = int.Parse(arr[6].ToString()); rd.Oras = null; dataAlegatoriPrezenti.Add(rd); } var newRD = new RopDocument(rdBase); newRD.Name += "Nr Alegatori Liste"; newRD.ID = "BA671A2B-27E8-408D-BABD-59B52661789D"; newRD.Data = dataAlegatori .GroupBy(it => it.Judet).Select(group => new RopData() { Judet = group.Key, Valoare = group.Sum(it => it.Valoare) } ).ToArray(); var newRDUrne = new RopDocument(rdBase); newRDUrne.Name += "Nr Alegatori Prezentati La Urne"; newRDUrne.ID = "BBB0ECA2-34BE-4177-B3A2-82BC6B41311E"; newRDUrne.Data = dataAlegatoriPrezenti .GroupBy(it => it.Judet).Select(group => new RopData() { Judet = group.Key, Valoare = group.Sum(it => it.Valoare) } ).ToArray(); return(new[] { newRD, newRDUrne }); }
public override async Task <RopDocument[]> FillDate() { var dataCasatoriti = new List <RopData>(); var dd = new DownloadData(); var dataBytes = await dd.Data(rdBase.PathDocument); var path = Path.Combine(Path.GetTempPath(), Path.GetTempFileName() + ".xls"); File.WriteAllBytes(path, dataBytes); //var path = "D:\\a.xls"; var dt = new DataTable(); using (var m = new OleDbConnection()) { m.ConnectionString = ExcelHelpers.BuildExcel2007ConnectionString(path, true); m.Open(); var query = @"Select * From [Anul2015$]"; using (var cmd = new OleDbCommand(query, m)) { using (var dr = cmd.ExecuteReaderAsync().Result) { dt.Load(dr); } } } foreach (DataRow row in dt.Rows) { var arr = row.ItemArray; //if (arr[0] == null || string.IsNullOrWhiteSpace(arr[0].ToString())) if (string.IsNullOrWhiteSpace(arr[0]?.ToString())) { continue; } var numeJudet = arr[1].ToString().Trim().ToLower(); var judet = judetFinder.Find(numeJudet); Func <object, int> retVal = (obj) => { int i; if (obj == null) { return(0); } if (int.TryParse(obj.ToString(), out i)) { return(i); } return(0); }; int valoare = retVal(arr[15]); var rd = new RopData(); rd.Judet = judet; rd.Valoare = valoare; rd.Oras = null; dataCasatoriti.Add(rd); } rdBase.Data = dataCasatoriti .GroupBy(it => it.Judet).Select(group => new RopData() { Judet = group.Key, Valoare = group.Sum(it => it.Valoare) } ).ToArray(); return(new[] { rdBase }); }
public override async Task <RopDocument[]> FillDate() { var dd = new DownloadData(); var dataBytes = await dd.Data(rdBase.PathDocument); string data = Encoding.UTF8.GetString(dataBytes); var list = new List <RopData>(); var lines = data.Split((char)(10)); var restFromPreviousLine = ""; for (int lineIter = 0; lineIter < lines.Length; lineIter++) { if (lineIter == 0)//header { continue; } var line = lines[lineIter]; if (string.IsNullOrWhiteSpace(line)) { continue; } var arr = (restFromPreviousLine + line).Split(new [] { "," }, StringSplitOptions.None); if (arr.Length < 16) { restFromPreviousLine += line; continue; } restFromPreviousLine = ""; for (int i = 0; i < arr.Length; i++) { arr[i] = arr[i].Replace("\"", ""); } Judet judet = null; for (int i = 16; i < arr.Length; i++) { var numeJudet = arr[i].ToString().Trim().ToLower(); try { judet = judetFinder.Find(numeJudet); } catch (ArgumentException) { //do not log } if (judet != null) { break; } } if (judet == null) { throw new ArgumentException("not found judet:" + string.Join(",", arr)); } var rd = new RopData(); rd.Judet = judet; rd.Valoare = 1; list.Add(rd); } list = list.GroupBy(it => it.Judet).Select(group => new RopData() { Judet = group.Key, Valoare = group.Sum(it => it.Valoare) } ).ToList(); rdBase.Data = list.ToArray(); return(new[] { rdBase }); }