Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using System.Collections.Generic;
  4. using System.Collections;
  5. using System.Linq;
  6. using System.Text;
  7. using MySql.Data.MySqlClient;
  8.  
  9. namespace mySQL
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. try
  16. {
  17. // SQL Connection Data
  18. MySqlConnection connection = new MySqlConnection();
  19. MySqlDataAdapter data = new MySqlDataAdapter();
  20. connection.ConnectionString = "server=194.78.56.157; database=tiwat; " +
  21. "port=40009; user=tiwatadmin; password=watti;";
  22. connection.Open();
  23.  
  24. // Specify which node to get neighbordata from
  25. string Nodeid = "FD01";
  26. Console.WriteLine("Data from neighbors of " + Nodeid + "\n");
  27.  
  28. // Get the different neighbors from the specified node
  29. string sql = "SELECT DISTINCT Neighbors.Neighborid FROM tiwat.Neighbors WHERE Neighbors.Nodeid = (SELECT Node.idNode FROM tiwat.Node WHERE Node.Name = '"
  30. + Nodeid + "') ORDER BY Neighbors.Neighborid ASC";
  31. MySqlCommand cmd = new MySqlCommand(sql, connection);
  32. MySqlDataReader rdr = cmd.ExecuteReader();
  33.  
  34. List<int> Neighborsid = new List<int>();
  35.  
  36. while (rdr.Read())
  37. {
  38. Neighborsid.Add((int)rdr[0]);
  39. }
  40. rdr.Close();
  41.  
  42. // get the names of the different neighbors from the specified node
  43. List<string> Neighbors = new List<string>();
  44. for (int i = 0; i < Neighborsid.Count; i++)
  45. {
  46. sql = "SELECT Node.Name FROM tiwat.Node WHERE Node.idNode = "
  47. + Neighborsid[i];
  48. cmd = new MySqlCommand(sql, connection);
  49. rdr = cmd.ExecuteReader();
  50. rdr.Read();
  51. Neighbors.Add((string)rdr[0]);
  52. rdr.Close();
  53. }
  54.  
  55. // get the RSL and successrate of the ALL SAMPLES of ALL NEIGHBOURS of the specified node
  56. List<List<int>> NeighborData = new List<List<int>>();
  57. for (int i = 0; i < Neighbors.Count; i++)
  58. {
  59. sql = "SELECT DISTINCT Neighbors.RSL, Neighbors.Sendsuccess, Neighbors.Sendunsuccess FROM tiwat.Neighbors, tiwat.Node WHERE Neighbors.Nodeid = (SELECT idNode FROM tiwat.Node WHERE Name = '" + Nodeid +
  60. "') AND Neighbors.Neighborid = " + Neighborsid[i];
  61. cmd = new MySqlCommand(sql, connection);
  62. rdr = cmd.ExecuteReader();
  63. List<int> Data = new List<int>();
  64. // get the rsl and successrate info from ALL SAMPLES from ONE NEIGHBOUR
  65. while (rdr.Read())
  66. {
  67. Data.Add(Convert.ToInt32(rdr[0]));
  68. Data.Add(Convert.ToInt32(rdr[1]));
  69. Data.Add(Convert.ToInt32(rdr[2]));
  70. }
  71. NeighborData.Add(Data);
  72. rdr.Close();
  73. }
  74.  
  75. // output Names of Neighbour (using the list Neighbors) and corresponding data (using NeighborData)
  76. int p = 0;
  77. foreach (var sublist in NeighborData)
  78. {
  79. Console.WriteLine("Data from " + Neighbors[p]);
  80. Console.WriteLine("Sample 1 - RSL: " + sublist[0] + ", SuccessRate = " + String.Format("{0:0.00}", (double)sublist[1] / ((double)sublist[1] + (double)sublist[2])));
  81. Console.WriteLine("Sample 2 - RSL: " + sublist[3] + ", SuccessRate = " + String.Format("{0:0.00}", (double)sublist[4] / ((double)sublist[4] + (double)sublist[5])));
  82. Console.WriteLine("Sample 3 - RSL: " + sublist[6] + ", SuccessRate = " + String.Format("{0:0.00}", (double)sublist[7] / ((double)sublist[7] + (double)sublist[8])));
  83. Console.WriteLine("Sample 4 - RSL: " + sublist[9] + ", SuccessRate = " + String.Format("{0:0.00}", (double)sublist[10] / ((double)sublist[10] + (double)sublist[11])));
  84. Console.WriteLine("Sample 5 - RSL: " + sublist[12] + ", SuccessRate = " + String.Format("{0:0.00}", (double)sublist[13] / ((double)sublist[13] + (double)sublist[14])));
  85. Console.WriteLine();
  86. p++;
  87. }
  88.  
  89. connection.Close();
  90. }
  91. catch (Exception e)
  92. {
  93. Console.WriteLine(e);
  94. }
  95. Console.ReadLine();
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement