Ejemplo n.º 1
0
        public SelectModel()
        {
            InitializeComponent();

            this.dataGridView1.DataSource = Hdb.HDB_Model();

            this.dataGridView1.Columns["Model_ID"].Visible    = false;
            this.dataGridView1.Columns["Coordinated"].Visible = false;
        }
Ejemplo n.º 2
0
        public void SaveToHdb(bool isModeledData, int mrid)
        {
            TimeSeriesCommitChanges f = new TimeSeriesCommitChanges(GetIntervalDataTable(), Hdb.Instance.ValidationList(), m_colorColumnName);

            if (f.ShowDialog() == DialogResult.OK)
            {
                string RickClayton = "You are about to save an edit which will violate the intergrity of a computation.  The data you have edited is based on a computation that has inputs and this data is automatically updated when the input data changes.  If you edit the output of the computation rather than the input you will violate the computation integrity which is generally not recommended.  It is recommended that you edit the input source data and allow the computation to recompute an acceptable value.  DO YOU WISH TO CONTINUE    <YES/NO>";

                bool isComputed = Hdb.AnyComputedValues(dataSet, m_interval);
                if (isComputed)
                {
                    if (MessageBox.Show(RickClayton, "Overwrite computed value?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        Hdb.Instance.SaveChanges(m_interval, dataSet, f.OverwriteChecked, f.ValidationFlag, isModeledData, mrid);
                    }
                }
                else
                {
                    Hdb.Instance.SaveChanges(m_interval, dataSet, f.OverwriteChecked, f.ValidationFlag, isModeledData, mrid);
                }
            }
            this.timeSeriesSpreadsheet1.SetTable(GetIntervalDataTable(), m_colorColumnName);
            this.timeSeriesSpreadsheet1.DataViewRowState = DataViewRowState.CurrentRows;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a instance to a hdb,  used by Pisces to support multiple databases
        /// </summary>
        /// <param name="hostname"></param>
        /// <returns></returns>
        public static Hdb GetInstance(string hostname)
        {
            if (Instance != null && Instance.Server.Host == hostname)
            {
                return(Instance);
            }
            else if (s_dict.ContainsKey(hostname))
            {
                return(s_dict[hostname]);
            }
            else
            {
                // To  do..  set hostname for Login user-interface
                var svr = OracleServer.ConnectToOracle(hostname);
                if (svr == null)
                {
                    return(null);
                }

                Hdb hdb1 = new Hdb(svr);
                s_dict.Add(hostname, hdb1);
                return(hdb1);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Queries modeled data from HDB
        /// </summary>
        /// <param name="site_datatype_id"></param>
        /// <param name="tableName"></param>
        /// <param name="t1"></param>
        /// <param name="t2"></param>
        /// <param name="mrid"></param>
        /// <returns></returns>
        private DataTable modelData(decimal site_datatype_id, string tableName, string interval, DateTime t1, DateTime t2, int mrid)
        {
            string sql = "Select start_date_time as date_time,value " + "from " + tableName + " where model_run_id = " + mrid
                         + " and site_datatype_id = " + site_datatype_id + " and start_date_time >= " + Hdb.ToHdbDate(t1.Date)
                         + " and start_date_time <= " + Hdb.ToHdbDate(t2.Date) + " order by start_date_time asc";

            DataTable rval = m_server.Table(tableName, sql);

            var tDataMax = rval.AsEnumerable().Select(cols => cols.Field <DateTime>("DATE_TIME")).OrderBy(p => p.Ticks).LastOrDefault();
            var tDataMin = rval.AsEnumerable().Select(cols => cols.Field <DateTime>("DATE_TIME")).OrderBy(p => p.Ticks).FirstOrDefault();

            // Fill missing values in between the specified date range.
            DateTime ithT = t1;

            switch (interval)
            {
            case "hour": ithT = new DateTime(ithT.Year, ithT.Month, ithT.Day, ithT.Hour, 0, 0);
                break;

            case "day": ithT = new DateTime(ithT.Year, ithT.Month, ithT.Day, 0, 0, 0);
                break;

            case "month": ithT = new DateTime(ithT.Year, ithT.Month, 1, 0, 0, 0);
                break;

            case "year": ithT = new DateTime(ithT.Year, 1, 1, ithT.Hour, 0, 0);
                break;

            case "wy": ithT = new DateTime(ithT.Year, 10, 1, ithT.Hour, 0, 0);
                break;

            default:
                break;
            }

            int pastDatetimeCounter = 0;

            while (ithT <= t2)
            {
                // Fill in missing dates in the data table
                if (!rval.AsEnumerable().Any(row => ithT == row.Field <DateTime>("DATE_TIME")))
                {
                    // Build an empty row
                    DataRow newRow = rval.NewRow();
                    newRow["DATE_TIME"] = ithT;
                    newRow["VALUE"]     = DBNull.Value;
                    // Insert the row at the correct location
                    if (ithT < tDataMin) // Add to beginning
                    {
                        rval.Rows.InsertAt(newRow, pastDatetimeCounter);
                        pastDatetimeCounter++;
                    }
                    else if (ithT > tDataMax) // Add to end
                    {
                        rval.Rows.Add(newRow);
                    }
                    else // Add missing in between
                    {
                        var closest = rval.Select()
                                      .OrderBy(dr => Math.Abs((ithT - (DateTime)dr["DATE_TIME"]).Ticks))
                                      .Where(t => (DateTime)t["DATE_TIME"] >= ithT).FirstOrDefault();  //.ElementAt(1);
                        rval.Rows.InsertAt(newRow, rval.Rows.IndexOf(closest));
                    }
                }

                // Increment ithT
                switch (interval)
                {
                case "hour": ithT = ithT.AddHours(1);
                    break;

                case "day": ithT = ithT.AddDays(1);
                    break;

                case "month": ithT = ithT.AddMonths(1);
                    break;

                case "year": ithT = ithT.AddYears(1);
                    break;

                case "wy": ithT = ithT.AddYears(1);
                    break;

                default:
                    break;
                }
            }

            if (rval == null)
            {
                rval = new DataTable();
                rval.Columns.Add(new DataColumn("date_time", typeof(DateTime)));
                rval.Columns.Add(new DataColumn("value", typeof(double)));
                rval.Columns.Add(new DataColumn("SourceColor", typeof(string)));
            }

            DataColumn sourceColorColumn = new DataColumn();

            sourceColorColumn.ColumnName   = "SourceColor";
            sourceColorColumn.DataType     = typeof(string);
            sourceColorColumn.DefaultValue = "skyblue";
            rval.Columns.Add(sourceColorColumn);

            DataColumn validationColumn = new DataColumn();

            validationColumn.ColumnName   = "ValidationColor";
            validationColumn.DataType     = typeof(string);
            validationColumn.DefaultValue = "white";
            rval.Columns.Add(validationColumn);

            rval.Columns["date_time"].Unique = true;
            rval.PrimaryKey                   = new DataColumn[] { rval.Columns["date_time"] };
            rval.DefaultView.Sort             = rval.Columns[0].ColumnName;
            rval.DefaultView.ApplyDefaultSort = true;
            rval.Columns[0].DefaultValue      = DBNull.Value;

            // Assign datatable colors by row
            for (int i = 0; i < rval.Rows.Count; i++)
            {
                if (rval.Rows[i]["VALUE"] == DBNull.Value)
                {
                    rval.Rows[i]["SourceColor"] = "silver";
                }
            }

            return(rval);
        }