public void TestReadTable() { SCBClient reader = new SCBClient("api.scb.se/OV0104"); SCBNode node = new SCBNode { path = "http://api.scb.se/OV0104/v1/doris/en/ssd/BE/BE0401/BE0401A/BefolkPrognRevN", type = "t", id = "BefProgFoddaMedel19" }; SCBMetaData meta = reader.GetMetaData(node.path).Result; SCBQuery query = new SCBQuery { response = new SCBResponse("json") }; query.SetUp(meta.variables); query.SetSelection(meta.variables.Find(s => s.code == "Fodelseregion"), SCBQuery.Filter.item, new List <string>() { "13" }); query.SetSelection(meta.variables.Find(s => s.code == "Kon"), SCBQuery.Filter.item, new List <string>() { "1" }); query.SetSelection(meta.variables.Find(s => s.code == "Tid"), SCBQuery.Filter.item, new List <string>() { "2020" }); SCBTable table = reader.GetTable(node, query).Result; }
static void Main(string[] args) { SCBClient client = new SCBClient("api.scb.se/OV0104"); SCBNode current = client.TopNode; while (true) { List <SCBNode> nodes = new List <SCBNode>(); if (current.IsLevel) { nodes = client.GetNodesBelow(current); Console.WriteLine($"{0}. Go up"); PresentNodes(nodes); } else if (current.IsTable) { SCBMetaData metaData = client.GetMetaData(current.path); PresentMetaData(metaData); bool newQuery = true; while (newQuery) { QueryTable(metaData, client, current); Console.Out.Write("New query? [Y/N] "); string ans = Console.In.ReadLine(); newQuery = ans.ToLower().Equals("y"); } Console.WriteLine($"{0}. Go up"); } bool isNumber = false; int index = 0; while (!isNumber) { Console.Out.Write("Select an item: "); string selection = Console.In.ReadLine(); isNumber = int.TryParse(selection, out index); } if (index == 0) { if (!current.path.Equals(client.TopNode.path)) { current.path = current.ParentPath(); current.type = "l"; } } else { SCBNode selectedNode = nodes[index - 1]; if (selectedNode != null) { current = selectedNode; } } } }
public void TestDrillDown() { SCBClient reader = new SCBClient("api.scb.se/OV0104"); SCBNode node = new SCBNode { path = "http://api.scb.se/OV0104/v1/doris/en/ssd/", type = "l", id = "" }; while (node.type == "l") { List <SCBNode> nodes = reader.GetNodesBelow(node).Result; node = nodes.First(); } if (node.type == "t") { SCBMetaData meta = reader.GetMetaData(node.path).Result; SCBQuery query = new SCBQuery(); } }
public SCBController() { _client = new SCBClient(_api); Current = _client.TopNode; }
private static void QueryTable(SCBMetaData metaData, SCBClient client, SCBNode current) { SCBQuery query = new SCBQuery(); foreach (SCBVariable variable in metaData.variables) { SCBQueryItem qi = new SCBQueryItem { code = variable.code, selection = new SCBSelection { filter = "top" } }; Console.Out.Write($"{variable.code} : "); Console.Out.Write("Filter [item,all,top,agg,quit] = "); bool ok = false; while (!ok) { string ans = Console.In.ReadLine(); string shortString = (ans.Length < 2) ? String.Empty : (ans ?? string.Empty).Substring(0, 2).ToLower(); switch (shortString) { case "it": qi.selection.values.AddRange(GetItems(variable)); qi.selection.filter = "item"; ok = true; break; case "al": qi.selection.values.Add("*"); qi.selection.filter = "all"; ok = true; break; case "to": qi.selection.values.Add(GetTop().ToString()); qi.selection.filter = "top"; ok = true; break; case "ag": qi.selection.filter = "agg"; ok = true; break; case "qu": ok = true; break; default: break; } if (!ok) { Console.Out.WriteLine("Invalid input, please try again, or Quit!"); Console.Out.Write("Filter [Item,All,Top,Agg,Quit] = "); } ; } query.query.Add(qi); } SCBTable table = client.GetTable(current, query); PresentTable(table); }
public void Test1() { SCBClient reader = new SCBClient("api.scb.se/OV0104"); reader.ReadTable(); }