Exemple #1
0
        //\p [rp,][hostname:][portnumber|servicename]
        public static QueryResultObject Query(string host, int port, string Credentials,
                                              string CreateQuery, string ReturnQuery)
        {
            c c = new c(host, port, Credentials);

            Object result = c.k(ReturnQuery); // query the table using a sync msg (c.k)

            c.ks(CreateQuery);                // create example table using async msg (c.ks)
            c.Flip flip     = c.td(result);   // if the result set is a keyed table, this removes the key.
            int    nRows    = c.n(flip.y[0]); // flip.y is an array of columns. Get the number of rows from the first column.
            int    nColumns = c.n(flip.x);    // flip.x is an array of column names

            Console.WriteLine("Number of columns: " + c.n(flip.x));
            Console.WriteLine("Number of rows:    " + nRows);
            string csvMessage = "";
            var    lst        = new List <string>();

            csvMessage = FormatData(flip, nRows, nColumns, csvMessage, lst);
            var queryObject = new QueryResultObject();

            queryObject.result = csvMessage;
            System.Console.WriteLine("\n Sent Event: " + csvMessage);
            c.Close();
            return(queryObject);
        }
Exemple #2
0
        private void SetAxis(c.Flip details)
        {
            double min = 1000;
            double max = 0;

            for (int i = 0; i < details.getNoRow(); i++)
            {
                for (int j = 3; j < (details.getNoColumns()) - 1; j++)
                {
                    double minVal = (double)c.at(details.y[j], i);
                    double maxVal = (double)c.at(details.y[j], i);

                    if (minVal < min)
                    {
                        min = minVal;
                    }
                    if (maxVal > max)
                    {
                        max = maxVal;
                    }
                }
            }
            reportChart.ChartAreas[0].AxisY.Minimum      = min - 0.0025;
            reportChart.ChartAreas[0].AxisY.Maximum      = max + 0.0025;
            reportChart.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Minutes;
        }
Exemple #3
0
        private c.Flip GetData(String query)
        {
            object result = (object)conn.k(query);

            c.Flip table = (c.Flip)result;
            return(table);
        }
Exemple #4
0
        private void QueryNamesAgesAndGender()
        {
            string gender = "";

            if (radioMale.IsChecked == true)
            {
                gender = "m";
            }
            else if (radioFemale.IsChecked == true)
            {
                gender = "f";
            }

            try
            {
                object obj      = _queries.QueryNamesAgesAndGender(namesToQuery, agesToQuery, gender);
                c.Flip flipData = c.td(obj);

                MapReturnedData(flipData);
                dataGridResults4.Items.Refresh();
            }
            catch (Exception ex)
            {
                lblErrorMessage.Content = "Error: " + ex.Message;
            }
        }
Exemple #5
0
 /// <summary>
 /// Loads a c.Flip containing the student data to the q session as a table
 /// </summary>
 /// <param name="flipData"></param>
 public void LoadStudentsToDB(c.Flip flipData)
 {
     if (DBConnection.Connection != null && DBConnection.Connection.Connected)
     {
         object x = DBConnection.Connection.k("{[x;y]x set y}", "student", flipData);
     }
 }
Exemple #6
0
 /// <summary>
 /// Loads a c.Flip containing the fictional db version number to the q session as a table
 /// </summary>
 /// <param name="flipData"></param>
 public void LoadDBVersionData(c.Flip flipData)
 {
     if (DBConnection.Connection != null && DBConnection.Connection.Connected)
     {
         object x = DBConnection.Connection.k("{[x;y]x set y}", "dbversion", flipData);
     }
 }
Exemple #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (conn == null)
            {
                try
                {
                    conn = ConnectionPool.GetConnection();
                }
                catch (Exception ex)
                {
                    errorLabel.Text = ex.Message;
                }
            }
            object result = (object)conn.k("select from trade");

            c.Flip table = (c.Flip)result;

            QueryView.Columns.Clear();//Clear columns first to allow clean population of table
            foreach (string colName in table.getColumns())
            {
                QueryView.Columns.Add(colName, colName); //Add the columns to the Queryview
            }

            QueryView.Rows.Add(table.getNoRow());

            for (int row = 0; row < table.getNoRow(); row++)
            {
                for (int col = 0; col < (table.getColumns().Length); col++)
                {
                    QueryView[col, row].Value = c.at(table.y[col], row); //Populate each cell of the Queryview with its associated value
                }
            }
            ConnectionPool.ReturnConnection(conn);
        }
Exemple #8
0
        public static void Query(string host, int port, string CreateQuery, string ReturnQuery, Func <string, string> func)
        {
            c c = new c("localhost", 5000, @"AFRICA/rajiyer:");
            // c.ks("mytable:([]sym:10?`1;time:.z.p+til 10;price:10?100.;size:10?1000)"); // create example table using async msg (c.ks)
            Object result = c.k("tab4"); // query the table using a sync msg (c.k)

            // A flip is a table. A keyed table is a dictionary where the key and value are both flips.
            c.Flip flip     = c.td(result);   // if the result set is a keyed table, this removes the key.
            int    nRows    = c.n(flip.y[0]); // flip.y is an array of columns. Get the number of rows from the first column.
            int    nColumns = c.n(flip.x);    // flip.x is an array of column names

            Console.WriteLine("Number of columns: " + c.n(flip.x));
            Console.WriteLine("Number of rows:    " + nRows);
            string csvMessage = "";

            for (int column = 0; column < nColumns; column++)
            {
                System.Console.Write((column > 0 ? "," : "") + flip.x[column]);
            }

            for (int row = 0; row < nRows; row++)
            { // Define a Delimiter
                for (int column = 0; column < nColumns; column++)
                {
                    csvMessage += (column > 0 ? "," : "") + c.at(flip.y[column], row);
                }
            }
            func(csvMessage);
            System.Console.WriteLine("Sent Event: " + csvMessage);
            c.Close();
        }
Exemple #9
0
        public static void Subscribe(string host, int port, string trade, Func <string, Task> func)
        {
            c c = null;

            try
            {
                c = new c(host == "" ? "localhost" : host, port == 0 ? 80 : port); // user:pass as parameter
                c.k(trade == "" ? "sub[`trade;`MSFT.O`IBM.N]" : trade);
                while (true)
                {
                    object result   = c.k();
                    c.Flip flip     = c.td(result);
                    int    nRows    = c.n(flip.y[0]);
                    int    nColumns = c.n(flip.x);
                    for (int row = 0; row < nRows; row++)
                    {
                        for (int column = 0; column < nColumns; column++)
                        {
                            // Define a delimiter within config.
                            func((column > 0 ? "," : "") + c.at(flip.y[column], row) + "\n"); // make use of function pointer in different framework (as these dont simultaneously exist in both frameworks), to make call for EventHub. Only parsing the message string {RAW}
                        }
                        System.Console.WriteLine();
                    }
                }
            }
            finally
            {
                if (c != null)
                {
                    c.Close();
                }
            }
        }
Exemple #10
0
        private void QueryListOfNamesAndAge()
        {
            namesToQuery.Clear();

            foreach (Student s in _studentNames)
            {
                if (s.IsSelected)
                {
                    namesToQuery.Add(s.Name);
                }
            }

            try
            {
                int    fromAge  = Convert.ToInt32(txtFromAge2.Text);
                object obj      = _queries.QueryStudentListOfNamesAndAge(namesToQuery, fromAge);
                c.Flip flipData = c.td(obj);

                MapReturnedData(flipData);
                dataGridResults5.Items.Refresh();
            }
            catch (Exception ex)
            {
                lblErrorMessage.Content = "Error: " + ex.Message;
            }
        }
        private static object GetResultFromFlip(object value)
        {
            c.Flip   result = c.td(value);
            object[] values = result.y;

            return(((Array)values[0]).GetValue(0));
        }
Exemple #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KdbPlusDataReader"/> class.
        /// </summary>
        /// <param name="result">The original kdb+ query result.</param>
        public KdbPlusDataReader(c.Flip result)
        {
            Guard.ThrowIfNull(result, "result");

            _result = result;

            InitIndexes();
        }
Exemple #13
0
        public void FlipAtReturnsValueForColumnName()
        {
            var flip = new c.Flip(new c.Dict(new string[] { "Key_1" }, new object[] { "Value_1" }));

            object result = flip.at("Key_1");

            Assert.IsNotNull(result);
            Assert.AreEqual("Value_1", result);
        }
Exemple #14
0
        public void ConnectionTableReturnsExpectedTableIfObjectIsFlip()
        {
            c.Flip flip = new c.Flip(new c.Dict(new[] { "Key_1" }, new object[] { new object[] { "Value_1" } }));

            object result = c.td(flip);

            Assert.IsNotNull(result);
            Assert.IsTrue(result is c.Flip);
        }
Exemple #15
0
 private void PopulateChart(c.Flip details)
 {
     for (int i = 0; i < details.getNoRow(); i++)
     {
         reportChart.Series["vwap"].Points.AddXY((c.at(details.y[0], i)).ToString(), (double)c.at(details.y[3], i));
         reportChart.Series["avg"].Points.AddXY((c.at(details.y[0], i)).ToString(), (double)c.at(details.y[4], i));
         reportChart.Series["dailyAvg"].Points.AddXY((c.at(details.y[0], i)).ToString(), dAvg);
         reportChart.Series["dailyVwap"].Points.AddXY((c.at(details.y[0], i)).ToString(), dVwap);
     }
 }
Exemple #16
0
        public void ConnectionReturnsExpectedLengthForFlip()
        {
            const int expected = 1;

            c.Flip flip = new c.Flip(new c.Dict(new[] { "Key_1" }, new object[] { new object[] { "Value_1" } }));

            int count = c.n(flip);

            Assert.AreEqual(expected, count);
        }
Exemple #17
0
        /// <summary>
        /// Returns the column names as an array of strings from a c.Flip
        /// </summary>
        /// <param name="flipData"></param>
        /// <returns></returns>
        public string[] GetColumnNames(c.Flip flipData)
        {
            string[] colNames = new string[0];

            if (flipData != null)
            {
                colNames = flipData.x;
            }

            return(colNames);
        }
Exemple #18
0
 /// <summary>
 /// Returns an int which is the number of rows of returned data in a c.Flip
 /// </summary>
 /// <param name="flipData"></param>
 /// <returns></returns>
 public int GetNumberOfRows(c.Flip flipData)
 {
     if (flipData != null)
     {
         return(c.n(flipData.y[0]));
     }
     else
     {
         return(0);
     }
 }
        public void ConvertEmptyDataTableToFlipTest()
        {
            DataTable dt = new DataTable();

            c.Flip   dict         = dt.ToFlip();
            string[] columnNames  = dict.x;
            object[] columnValues = dict.y;

            Assert.AreEqual(0, columnNames.Length);
            Assert.AreEqual(0, columnValues.Length);
        }
Exemple #20
0
 private void GetDBVersion()
 {
     try
     {
         c.Flip flipData = _queries.GetDBVersion();
         this.lblDBVersion.Content = c.at(flipData.y[0], 0).ToString();
     }
     catch (Exception ex)
     {
         lblErrorMessage.Content = "Error: " + ex.Message;
     }
 }
        public void ConvertSimpleFlipToDataTableTest()
        {
            DateTime     firstDate  = DateTime.Now;
            DateTime     secondDate = firstDate.AddDays(1);
            const string tableName  = "MyTable";

            c.Dict    dict = CreateDict(firstDate, secondDate);
            c.Flip    flip = new c.Flip(dict);
            DataTable dt   = flip.ToDataTable(tableName);

            CheckDataTable(firstDate, secondDate, dt, tableName);
        }
Exemple #22
0
 private void QueryWithListOfNames()
 {
     try
     {
         c.Flip flipData = _queries.QueryStudentListOfNames(namesToQuery);
         MapReturnedData(flipData);
         dataGridResults3.Items.Refresh();
     }
     catch (Exception ex)
     {
         lblErrorMessage.Content = "Error: " + ex.Message;
     }
 }
        public void ConvertSimpleDataTableToFlip()
        {
            DateTime     now        = DateTime.Now;
            DateTime     secondDate = now.AddDays(1);
            const string tableName  = "MyTable";
            DataTable    dt         = CreateTable(tableName, now, secondDate);

            c.Flip flip = dt.ToFlip();

            DataTable tableToCheck = flip.ToDataTable(tableName);

            CheckDataTable(now, secondDate, tableToCheck, tableName);
        }
Exemple #24
0
        private void QueryGender()
        {
            try
            {
                c.Flip flipData = _queries.SelectFromStudentGenderQuery();
                MapReturnedData(flipData);
                dataGridResult1.Items.Refresh();
            }

            catch (Exception ex)
            {
                lblErrorMessage.Content = "Error: " + ex.Message;
            }
        }
Exemple #25
0
        private void GetDaily(c.Flip details)
        {
            min     = (double)c.at(details.y[1], 0);
            max     = (double)c.at(details.y[2], 0);
            dAvg    = (double)c.at(details.y[3], 0);
            dVwap   = (double)c.at(details.y[4], 0);
            transNo = (long)c.at(details.y[5], 0);

            minBox.Text     = min.ToString("#.#####");
            maxBox.Text     = max.ToString("#.#####");
            avgBox.Text     = dAvg.ToString("#.#####");
            dailyVwap.Text  = dVwap.ToString("#.#####");
            transNoBox.Text = transNo.ToString();
        }
        public void ConnectionSerialisesAndDeserialisesFlipInput()
        {
            c.Flip expected = new c.Flip(new c.Dict(new string[] { "Key_1" }, new object[] { "Value_1" }));

            using (var connection = new c())
            {
                byte[] serialisedData = connection.Serialize(1, expected);

                c.Flip result = connection.Deserialize(serialisedData) as c.Flip;

                Assert.IsNotNull(result);
                Assert.IsTrue(Enumerable.SequenceEqual(expected.x, result.x));
                Assert.IsTrue(Enumerable.SequenceEqual(expected.y, result.y));
            }
        }
Exemple #27
0
        /// <summary>
        /// Creates a c.Flip object only containing the version number of a fictional
        /// db, then loads it into the q session.
        /// </summary>
        private void ConvertDBVersionDataIntoFlip()
        {
            string[] colnames = new string[1];
            colnames[0] = "dbversion";

            object[] colData   = new object[1];
            string[] dbVersion = new string[1];

            dbVersion[0] = "dbversion";

            colData[0] = dbVersion;

            c.Dict dict     = new c.Dict(colnames, colData);
            c.Flip flipData = new c.Flip(dict);
            _queries.LoadDBVersionData(flipData);
        }
Exemple #28
0
        public Form4_1(String symbol, c conn)
        {
            InitializeComponent();

            symLabel.Text = symbol;
            this.conn     = conn;
            c.Flip details = GetData("select details from details where sym=`" + symbol);
            compLabel.Text = c.at(details.y[0], 0).ToString();
            details        = GetData("getSummary[`" + symbol + "]");
            GetDaily(details);

            details = GetData("analyseData[`" + symbol + "]");
            SetAxis(details);
            PopulateChart(details);
            PopulateGrid(details);
        }
Exemple #29
0
        private void QueryAgeRange()
        {
            try
            {
                int fromAge = Convert.ToInt32(txtFromAge.Text);
                int toAge   = Convert.ToInt32(txtToAge.Text);

                c.Flip flipData = _queries.QueryAgeRange(fromAge, toAge);
                MapReturnedData(flipData);
                dataGridResultsAgeRange.Items.Refresh();
            }
            catch (Exception ex)
            {
                lblErrorMessage.Content = "Error: " + ex.Message;
            }
        }
Exemple #30
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (conn == null)
                {
                    conn = ConnectionPool.GetConnection();
                }

                String query = BuildQuery();

                try
                {
                    object result = null;
                    result = (object)conn.k(query);

                    c.Flip table = (c.Flip)result;

                    QueryView.Columns.Clear();
                    foreach (string colName in table.getColumns())
                    {
                        QueryView.Columns.Add(colName, colName);
                    }

                    QueryView.Rows.Add(table.getNoRow());

                    for (int row = 0; row < table.getNoRow(); row++)
                    {
                        for (int col = 0; col < (table.getColumns().Length); col++)
                        {
                            QueryView[col, row].Value = c.at(table.y[col], row);
                        }
                    }
                    errorLabel.Text      = "";
                    QueryView.CellClick += (QueryView_CellClick);
                }
                catch (Exception ex)
                {
                    errorLabel.Text = "ERROR:" + ex.Message;
                }
                ConnectionPool.ReturnConnection(conn);
            }
            catch (Exception ex)
            {
                errorLabel.Text = "Unexpected error: " + ex.Message;
            }
        }