示例#1
0
        void RunShear()
        {
            BackgroundWorker worker = new BackgroundWorker();

            try
            {
                worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
                {
                    MessageBox.Show("Done with Alpha");
                };
                worker.DoWork += delegate(object s, DoWorkEventArgs args)
                {
                    try
                    {
                        IsProcessing = true;

                        int upperCompidx = ColumnCollection.UpperWSComp(DataSetStartDate);
                        int lowerCompidx = ColumnCollection.LowerWSComp(DataSetStartDate);

                        ISessionColumn upperws = ColumnCollection[upperCompidx];
                        ISessionColumn lowerws = ColumnCollection[lowerCompidx];

                        AxisFactory factory = new AxisFactory();

                        IAxis Yaxis = factory.CreateAxis(AxisType.Hour);
                        Yaxis.SessionColIndex = ColumnCollection.DateIndex;

                        IAxis Xaxis = factory.CreateAxis(AxisType.Month);
                        Xaxis.SessionColIndex = ColumnCollection.DateIndex;

                        AlphaFactory afactory = new AlphaFactory();
                        ColumnCollection.AlphaCollection.Add(afactory.CreateAlpha(DownloadedData [0], upperws, lowerws, Xaxis, Yaxis));
                        ColumnCollection.AlphaCollection.ToList().ForEach(c => c.CalculateAlpha());

                        ObservableCollection <ShearGridViewModel> thisShearCollection = new ObservableCollection <ShearGridViewModel>();

                        foreach (Alpha a in ColumnCollection.AlphaCollection)
                        {
                            int i = 1;
                            thisShearCollection.Add(new ShearGridViewModel(a, Xaxis.AxisType + " by " + Yaxis.AxisType));
                            i++;
                        }

                        //add sheargridviewmodels to allsheargridviewmodel
                        ShearGridCollection = new AllShearViewModel(thisShearCollection);

                        IsProcessing = false;
                    }
                    finally
                    {
                        IsProcessing = false;
                    }
                };
                worker.RunWorkerAsync();
            }
            catch (Exception e)
            {
                throw;
            }
        }
示例#2
0
        public void Drop(DropInfo dropInfo)
        {
            ISessionColumn source           = (ISessionColumn)dropInfo.DragInfo.SourceItem;
            ISessionColumn target           = (ISessionColumn)dropInfo.TargetItem;
            IList          targetCollection = (IList)dropInfo.TargetCollection;
            IList          sourceCollection = (IList)dropInfo.DragInfo.SourceCollection;
            int            index            = dropInfo.InsertIndex;

            if (source.ColName == "DateTime")
            {
                sourceCollection.RemoveAt(sourceCollection.IndexOf(source));
                targetCollection.Insert(index++, source);
            }
            else
            {
                if (!IsChild(dropInfo.VisualTargetItem) && (dropInfo.TargetItem != dropInfo.DragInfo.SourceItem))
                {
                    if (dropInfo.InTarget)
                    {
                        sourceCollection.RemoveAt(sourceCollection.IndexOf(source));
                        target.ChildColumns.Add(source);
                    }
                    else
                    {
                        sourceCollection.RemoveAt(sourceCollection.IndexOf(source));
                        targetCollection.Insert(index++, source);
                    }
                }
            }
        }
示例#3
0
 public Alpha(List <DataRow> coincident, ISessionColumn upperWS, ISessionColumn lowerWS, IAxis xAxis, IAxis yAxis)
 {//overload allows coincident data to be directly passed in if it has already been calculated
     _coincident   = new List <DataRow>();
     _coincident   = coincident;
     _upperws      = upperWS;
     _lowerws      = lowerWS;
     _xAxis        = xAxis;
     _yAxis        = yAxis;
     _dataSetStart = DateTime.Parse(_coincident[0][Settings.Default.TimeStampName].ToString());
 }
示例#4
0
 public Alpha(DataTable data, AlphaFilterMethod filter, ISessionColumn upperWS, ISessionColumn lowerWS, IAxis xAxis, IAxis yAxis)
 {
     _alphaFilter  = filter;
     _data         = data;
     _upperws      = upperWS;
     _lowerws      = lowerWS;
     _xAxis        = xAxis;
     _yAxis        = yAxis;
     _dataSetStart = DateTime.Parse(_data.Rows[0][Settings.Default.TimeStampName].ToString());
 }
示例#5
0
        protected virtual void setCols()
        {
            try
            {//figure out config dates and get comp columns
                HeightConfigCollection configcollection = new HeightConfigCollection(_collection);
                List <IConfig>         configs          = configcollection.GetConfigs();

                Console.WriteLine(" doing " + _summarytype);

                if (configs.Count > 1)
                {
                    Console.WriteLine("configs found " + configs.Count);
                    foreach (IConfig c in configs)
                    {
                        Console.WriteLine("start date " + c.StartDate);
                    }
                    throw new ApplicationException("Can not process grid. System not yet set up to handle multpile configurations");
                }
                _configstart = configs[0].StartDate;
                Console.WriteLine("start date in summary grid " + _configstart);
                //wscomps
                //SortedDictionary<double, ISessionColumn> wscomps
                //    = _collection.GetColumnsByType(SessionColumnType.WSAvg, _configstart, true);

                _lowerwscompcol = _collection[_collection.LowerWSComp(_configstart)];
                _upperwscompcol = _collection[_collection.UpperWSComp(_configstart)];
                _lowerwsht      = _lowerwscompcol.getConfigAtDate(_configstart).Height;
                _upperwsht      = _upperwscompcol.getConfigAtDate(_configstart).Height;

                //Console.WriteLine("Summary grid found " + wscomps.Values.Count + " ws comps");
                //wdcomp
                List <ISessionColumn> wdcomp =
                    _collection.GetColumnsByType(SessionColumnType.WDAvg);
                var compcol = from c in wdcomp.AsEnumerable()
                              where c.IsComposite
                              select c;

                _wdcompcol = compcol.ToList()[0];

                Console.WriteLine("Summary grid found " + compcol.ToList().Count + " wd comps");

                //shear

                _shearwscol = _collection.GetColumnsByType(_sheartype)[0];
                _shearht    = _shearwscol.getConfigAtDate(_configstart).Height;
                Console.WriteLine("Summary grid found " + _collection.GetColumnsByType(_sheartype).Count + " shear");
            }
            catch
            {
                throw;
            }
        }
        public void DragOver(DropInfo dropInfo)
        {
            ISessionColumn source = (ISessionColumn)dropInfo.DragInfo.SourceItem;

            if (dropInfo.InTarget & source.ColName != "DateTime")
            {
                dropInfo.DropTargetAdorner = DropTargetAdorners.Highlight;
            }
            else
            {
                dropInfo.DropTargetAdorner = DropTargetAdorners.Insert;
            }
            dropInfo.Effects = DragDropEffects.Move;
        }
示例#7
0
        void RunShear()
        {
            BackgroundWorker worker = new BackgroundWorker();

            try
            {
                worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
                {
                };
                worker.DoWork += delegate(object s, DoWorkEventArgs args)
                {
                    try
                    {
                        IsProcessing = true;

                        int upperCompidx = ColumnCollection.UpperWSComp(DataSetStartDate);
                        int lowerCompidx = ColumnCollection.LowerWSComp(DataSetStartDate);

                        ISessionColumn upperws = ColumnCollection[upperCompidx];
                        ISessionColumn lowerws = ColumnCollection[lowerCompidx];


                        IAxis Xaxis = GetAxis(_xShearAxis, _xBinWidth);
                        IAxis Yaxis = GetAxis(_yShearAxis, _yBinWidth);

                        AlphaFactory afactory = new AlphaFactory();
                        Alpha        alpha    = (Alpha)afactory.CreateAlpha(DownloadedData[0], _alphaFilter, upperws, lowerws, Xaxis, Yaxis);

                        alpha.AlphaUpdated += new Alpha.AlphaUpdatedEventHandler(UpdatedAlphaCollection);
                        alpha.SourceDataSet = this.DisplayName;

                        ColumnCollection.AlphaCollection.Add(alpha);
                        alpha.CalculateAlpha();

                        string xBin = string.Empty;
                        string yBin = string.Empty;

                        if (Xaxis.AxisType == AxisType.WD)
                        {
                            var wdaxis = (WindDirectionAxis)Xaxis;
                            xBin = " " + wdaxis.BinWidth.ToString() + " deg";
                        }
                        if (Xaxis.AxisType == AxisType.WS)
                        {
                            var wsaxis = (WindSpeedAxis)Xaxis;
                            xBin = " " + wsaxis.BinWidth.ToString() + " m/s";
                        }
                        if (Yaxis.AxisType == AxisType.WD)
                        {
                            var wdaxis = (WindDirectionAxis)Yaxis;
                            yBin = " " + wdaxis.BinWidth.ToString() + " deg";
                        }
                        if (Yaxis.AxisType == AxisType.WS)
                        {
                            var wsaxis = (WindSpeedAxis)Yaxis;
                            yBin = " " + wsaxis.BinWidth.ToString() + " m/s";
                        }

                        AllShearViewModel asvm = new AllShearViewModel();
                        string            filter;
                        if (_alphaFilter == AlphaFilterMethod.Coincident)
                        {
                            filter = "CDNT";
                        }
                        else
                        {
                            filter = "NCDNT";
                        }

                        string             gridname = alpha.SourceDataSet + "_" + filter + "_" + Xaxis.AxisType + xBin + " by " + Yaxis.AxisType + yBin;
                        ShearGridViewModel sgvm     = new ShearGridViewModel(alpha, gridname);

                        if (ShearGridCollection == null)
                        {
                            ShearGridCollection = new AllShearViewModel();
                        }

                        if (ShearGridCollection.ShearCollection.Count == 0)
                        {
                            asvm.ShearCollection.Add(sgvm);
                        }



                        UpdatedAlphaCollection(alpha);
                        alpha.AlphaUpdated -= UpdatedAlphaCollection;
                        this.Dispatcher.Invoke(DispatcherPriority.Render, new Action
                                               (
                                                   delegate()
                        {
                            if (ShearGridCollection.ShearCollection.Count == 0)
                            {
                                ShearGridCollection = asvm;
                            }
                            else
                            {
                                ShearGridCollection.ShearCollection.Add(sgvm);
                            }
                        }));
                        //add sheargridviewmodels to allsheargridviewmodel


                        IsProcessing = false;
                    }
                    catch (ApplicationException e)
                    {
                        MessageBox.Show(e.Message);
                    }
                    finally
                    {
                        IsProcessing = false;
                    }
                };
                worker.RunWorkerAsync();
            }
            catch (Exception e)
            {
                throw;
            }
        }
示例#8
0
        void OutPutSummary()
        {
            BackgroundWorker worker   = new BackgroundWorker();
            string           filename = string.Empty;
            SaveFileDialog   sf       = new SaveFileDialog();

            sf.Title      = "save data";
            sf.Filter     = "Excel|*.xlsx";
            sf.DefaultExt = ".xlsx";
            sf.FileName   = "Unified" + "_StnSummary_" + DateTime.Now.ToShortDateString().Replace(@"/", "");
            DialogResult result = sf.ShowDialog();

            if (result == DialogResult.Cancel)
            {
                return;
            }

            if (sf.FileName != "")
            {
                filename = sf.FileName;
            }
            else
            {
                return;
            }



            worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
            {
                SummaryIsProcessing = false;
            };
            worker.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                XbyYShearStationSummary summary = null;

                try
                {
                    SummaryIsProcessing = true;

                    //create the DataTable
                    if (_unifiedData != null)
                    {
                        _unifiedData.Clear();
                    }
                    BuildDataTable();
                    //create column collection
                    ColumnCollection = new SessionColumnCollection(_unifiedData);


                    //add column def and add configs

                    ISessionColumn hubws = ColumnCollection[HubHeight.ToString() + "m"];
                    hubws.ColumnType   = SessionColumnType.WSAvgShear;
                    hubws.IsCalculated = true;
                    hubws.IsComposite  = true;
                    SensorConfig config = new SensorConfig()
                    {
                        StartDate = _startDate, EndDate = _endDate, Height = HubHeight
                    };
                    hubws.Configs.Add(config);

                    ISessionColumn upperws = ColumnCollection[UpperHeight.ToString().Replace(".", "_") + "m"];
                    upperws.ColumnType  = SessionColumnType.WSAvg;
                    upperws.IsComposite = true;
                    config = new SensorConfig()
                    {
                        StartDate = _startDate, EndDate = _endDate, Height = UpperHeight
                    };
                    upperws.Configs.Add(config);

                    ISessionColumn lowerws = ColumnCollection[LowerHeight.ToString().Replace(".", "_") + "m"];
                    lowerws.ColumnType  = SessionColumnType.WSAvg;
                    lowerws.IsComposite = true;
                    config = new SensorConfig()
                    {
                        StartDate = _startDate, EndDate = _endDate, Height = LowerHeight
                    };
                    lowerws.Configs.Add(config);

                    ISessionColumn wd = ColumnCollection["WD"];
                    wd.ColumnType  = SessionColumnType.WDAvg;
                    wd.IsComposite = true;
                    config         = new SensorConfig()
                    {
                        StartDate = _startDate, EndDate = _endDate
                    };
                    wd.Configs.Add(config);


                    //get axis selections from UI
                    IAxis Xaxis = GetAxis(_xShearAxis, _xBinWidth);
                    IAxis Yaxis = GetAxis(_yShearAxis, _yBinWidth);

                    //calculate alpha
                    AlphaFactory afactory = new AlphaFactory();
                    Alpha        alpha    = (Alpha)afactory.CreateAlpha(_unifiedData, AlphaFilterMethod.Coincident, upperws, lowerws, Xaxis, Yaxis);
                    alpha.SourceDataSet = this.DisplayName;
                    alpha.CalculateAlpha();

                    string xBin = string.Empty;
                    string yBin = string.Empty;

                    if (Xaxis.AxisType == AxisType.WD)
                    {
                        var wdaxis = (WindDirectionAxis)Xaxis;
                        xBin = " " + wdaxis.BinWidth.ToString() + " deg";
                    }
                    if (Xaxis.AxisType == AxisType.WS)
                    {
                        var wsaxis = (WindSpeedAxis)Xaxis;
                        xBin = " " + wsaxis.BinWidth.ToString() + " m/s";
                    }
                    if (Yaxis.AxisType == AxisType.WD)
                    {
                        var wdaxis = (WindDirectionAxis)Yaxis;
                        yBin = " " + wdaxis.BinWidth.ToString() + " deg";
                    }
                    if (Yaxis.AxisType == AxisType.WS)
                    {
                        var wsaxis = (WindSpeedAxis)Yaxis;
                        yBin = " " + wsaxis.BinWidth.ToString() + " m/s";
                    }

                    //Set up column metadata for the summary run
                    summary = new XbyYShearStationSummary(ColumnCollection, _unifiedData.AsDataView(), 30, 10, 2, alpha);

                    summary.CreateReport(filename);
                    SummaryIsProcessing = false;
                }
                catch (ApplicationException e)
                {
                    MessageBox.Show("Error calculating station summary: " + e.Message + " " + e.Source);
                    StreamWriter fs = new StreamWriter(Path.GetDirectoryName(filename) + @"\LOG_" + Path.GetFileNameWithoutExtension(filename) + ".txt", false);
                    summary.log.ForEach(c => fs.WriteLine(c));
                    fs.Close();
                }
                finally
                {
                    SummaryIsProcessing = false;
                }
            };
            worker.RunWorkerAsync();
        }
示例#9
0
 public AbstractAlpha CreateAlpha(List <DataRow> data, ISessionColumn upperWS, ISessionColumn lowerWS, IAxis xAxis, IAxis yAxis)
 {
     return(new Alpha(data, upperWS, lowerWS, xAxis, yAxis));
 }
示例#10
0
 public AbstractAlpha CreateAlpha(DataTable data, AlphaFilterMethod filter, ISessionColumn upperWS, ISessionColumn lowerWS, IAxis xAxis, IAxis yAxis)
 {
     return(new Alpha(data, filter, upperWS, lowerWS, xAxis, yAxis));
 }