public download(AppManager app, ProcessData proc, ImportFromFile imp)
        {
            InitializeComponent();
            map       = (app.Map as Map);
            this.app  = app;
            processor = proc;
            import    = imp;

            //add models
            comboBox1.Items.Add("ACCESS1-0");
            comboBox1.Items.Add("ACCESS1-3");
            //comboBox1.Items.Add("bcc-csm1-1");
            comboBox1.Items.Add("bcc-csm1-1-m");
            comboBox1.Items.Add("BNU-ESM");
            comboBox1.Items.Add("CanESM2");
            comboBox1.Items.Add("CCSM4");
            comboBox1.Items.Add("CESM1-BGC");

            comboBox1.Items.Add("CESM1-CAM5");
            comboBox1.Items.Add("CMCC-CM");
            comboBox1.Items.Add("CNRM-CM5");
            comboBox1.Items.Add("CSIRO-Mk3-6-0");
            comboBox1.Items.Add("EC-EARTH");
            comboBox1.Items.Add("FGOALS-g2");
            comboBox1.Items.Add("FGOALS-s2");

            comboBox1.Items.Add("FIO-ESM");
            comboBox1.Items.Add("GFDL-CM3");
            comboBox1.Items.Add("GFDL-ESM2G");
            comboBox1.Items.Add("GFDL-ESM2M");
            comboBox1.Items.Add("GISS-E2-H-CC");
            comboBox1.Items.Add("GISS-E2-R");
            comboBox1.Items.Add("GISS-E2-R-CC");

            //comboBox1.Items.Add("HadGEM2-AO");
            //comboBox1.Items.Add("HadGEM2-CC");
            //comboBox1.Items.Add("HadGEM2-ES");
            comboBox1.Items.Add("inmcm4");
            comboBox1.Items.Add("IPSL-CM5A-LR");
            comboBox1.Items.Add("IPSL-CM5A-MR");
            comboBox1.Items.Add("ISPL-CM5B-LR");
            comboBox1.Items.Add("MIROC-ESM");

            comboBox1.Items.Add("MIROC-ESM-CHEM");
            comboBox1.Items.Add("MIROC5");
            comboBox1.Items.Add("MPI-ESM-LR");
            comboBox1.Items.Add("MPI-ESM-LR");
        }
Example #2
0
 public ImportFromDB(ProcessData proc, ImportFromFile iff)
 {
     processor = proc;
     import    = iff;
     InitializeComponent();
 }
        //Activates the plugin
        public override void Activate()
        {
            datesForm          = new Dates(this);
            processor          = new ProcessData(datesForm, (Map)App.Map);
            importFromFileForm = new ImportFromFile(processor, this);
            importFromDBForm   = new ImportFromDB(processor, importFromFileForm);

            graph        = new ScatterGraph(processor, datesForm);
            ensembleForm = new Ensembles(processor, graph, datesForm, this);
            outputForm   = new Output(processor, graph);
            datesForm.setProcessData(processor);

            // Initialize the Ribbon controls in the "Climate" ribbon tab
            const string ClimateTabKey = "kClimate";

            App.HeaderControl.Add(new RootItem(ClimateTabKey, "Climate Analysis")
            {
                SortOrder = 200
            });

            // Create and add Download button
            newButton              = new SimpleActionItem("Download", downloadClick);
            newButton.RootKey      = ClimateTabKey;
            newButton.ToolTipText  = "Download climate data";
            newButton.GroupCaption = "Input";
            newButton.LargeImage   = Resources.web;
            App.HeaderControl.Add(newButton);

            // Create and add Import button
            newButton              = new SimpleActionItem("Import From File", importFromFileClick);
            newButton.RootKey      = ClimateTabKey;
            newButton.ToolTipText  = "Import climate data from file";
            newButton.GroupCaption = "Input";
            newButton.LargeImage   = Resources.fileIcon;
            App.HeaderControl.Add(newButton);

            // Create and add Import button
            newButton              = new SimpleActionItem("Import From Database", importFromDBClick);
            newButton.RootKey      = ClimateTabKey;
            newButton.ToolTipText  = "Import climate data from the database";
            newButton.GroupCaption = "Input";
            newButton.LargeImage   = Resources.Database;
            App.HeaderControl.Add(newButton);

            // Create and add delete button
            newButton              = new SimpleActionItem("Clear Imported Data", clearImportedDataClick);
            newButton.RootKey      = ClimateTabKey;
            newButton.ToolTipText  = "Clear all data the has been imported";
            newButton.GroupCaption = "Input";
            newButton.LargeImage   = Resources.Actions_window_close_icon;
            App.HeaderControl.Add(newButton);

            // Create and add Date Range button
            SimpleActionItem dateButton = new SimpleActionItem("Select Dates", dateClick);

            dateButton.RootKey      = ClimateTabKey;
            dateButton.ToolTipText  = "Select date ranges";
            dateButton.GroupCaption = "Analysis";
            dateButton.LargeImage   = Resources.calendar;
            App.HeaderControl.Add(dateButton);

            // Create and add Statistical button
            SimpleActionItem statButton = new SimpleActionItem("Select Scenario", statClick);

            statButton.RootKey      = ClimateTabKey;
            statButton.ToolTipText  = "Select ensembles";
            statButton.GroupCaption = "Analysis";
            statButton.LargeImage   = Resources.bar;
            App.HeaderControl.Add(statButton);

            // Create and add Output button
            SimpleActionItem outputButton = new SimpleActionItem("Save Results", outputClick);

            outputButton.RootKey      = ClimateTabKey;
            outputButton.ToolTipText  = "Outputs Data Files";
            outputButton.GroupCaption = "Output";
            outputButton.LargeImage   = Resources.download;
            App.HeaderControl.Add(outputButton);

            // Create and add Cluster Graph button
            SimpleActionItem clusterButton = new SimpleActionItem("Cluster Graph", clusterClick);

            clusterButton.RootKey      = ClimateTabKey;
            clusterButton.ToolTipText  = "Shows cluster graph";
            clusterButton.GroupCaption = "Output";
            clusterButton.LargeImage   = Resources.chart;
            App.HeaderControl.Add(clusterButton);

            // Create and add Adjust Forcing File button
            SimpleActionItem forcingButton = new SimpleActionItem("Adjust Forcing File", forcingClick);

            forcingButton.RootKey      = ClimateTabKey;
            forcingButton.ToolTipText  = "Adjusts forcing file";
            forcingButton.GroupCaption = "Output";
            forcingButton.LargeImage   = Resources.adjust;
            App.HeaderControl.Add(forcingButton);

            // Create and add About button
            SimpleActionItem AboutButton = new SimpleActionItem("About", AboutClick);

            AboutButton.RootKey      = ClimateTabKey;
            AboutButton.ToolTipText  = "About Toolkit";
            AboutButton.GroupCaption = "Help";
            AboutButton.LargeImage   = Resources.readme1;
            App.HeaderControl.Add(AboutButton);

            // Create and add Help button
            SimpleActionItem howToButton = new SimpleActionItem("Help", howToClick);

            howToButton.RootKey      = ClimateTabKey;
            howToButton.ToolTipText  = "Read Me";
            howToButton.GroupCaption = "Help";
            howToButton.LargeImage   = Resources.help;
            App.HeaderControl.Add(howToButton);

            base.Activate();
        }
Example #4
0
        /// <summary>
        /// Saves a data series to the database. The series will be associated with the
        /// specified theme. This method does not check whether there are any existing series with
        /// the same properties in the database. It will always create a new 'copy' of the series
        /// </summary>
        /// <param name="series">The time series</param>
        /// <param name="theme">The associated theme</param>
        /// <returns>Number of DataValue saved</returns>
        public int SaveSeriesAsCopy(List <Series> series, Theme theme, ImportFromFile import)
        {
            string sqlSaveSeries = "INSERT INTO DataSeries(SiteID, VariableID, MethodID, SourceID, QualityControlLevelID, " +
                                   "IsCategorical, BeginDateTime, EndDateTime, BeginDateTimeUTC, EndDateTimeUTC, ValueCount, CreationDateTime, " +
                                   "Subscribed, UpdateDateTime, LastCheckedDateTime) " +
                                   "VALUES(?, ?, ?, ?,?,?,?,?,?,?,?,?,?,?,?)" + LastRowIDSelect;
            string sqlSaveTheme1 = "INSERT INTO DataThemeDescriptions(ThemeName, ThemeDescription) VALUES (?,?)" + LastRowIDSelect;
            string sqlSaveTheme2 = "INSERT INTO DataThemes(ThemeID,SeriesID) VALUEs (?,?)";

            int  siteID                = 0;
            int  variableID            = 0;
            int  methodID              = 0;
            int  qualityControlLevelID = 0;
            int  sourceID              = 0;
            int  seriesID              = 0;
            long themeID               = 0;

            object seriesIDResult = null;

            int numSavedValues = 0;

            //Step 1 Begin Transaction
            using (DbConnection conn1 = _db.CreateConnection()) {
                conn1.OpenAsync();

                using (DbTransaction tran = conn1.BeginTransaction()) {
                    for (int seriesNum = 0; seriesNum < series.Count; seriesNum++)
                    {
                        //update progress bar
                        import.updateProgressBar((double)seriesNum / (double)series.Count);

                        variableID            = GetOrCreateVariableID(series[seriesNum].Variable, conn1);
                        methodID              = GetOrCreateMethodID(series[seriesNum].Method, conn1);
                        qualityControlLevelID = GetOrCreateQualityControlLevelID(series[seriesNum].QualityControlLevel, conn1);
                        sourceID              = GetOrCreateSourceID(series[seriesNum].Source, conn1);
                        siteID = GetOrCreateSiteID(series[seriesNum].Site, conn1);
                        //****************************************************************
                        //*** Step 7 Series
                        //****************************************************************
                        using (DbCommand cmd18 = conn1.CreateCommand()) {
                            cmd18.CommandText = sqlSaveSeries;
                            cmd18.Parameters.Add(_db.CreateParameter(DbType.Int32, siteID));
                            cmd18.Parameters.Add(_db.CreateParameter(DbType.Int32, variableID));
                            cmd18.Parameters.Add(_db.CreateParameter(DbType.Int32, methodID));
                            cmd18.Parameters.Add(_db.CreateParameter(DbType.Int32, sourceID));
                            cmd18.Parameters.Add(_db.CreateParameter(DbType.Int32, qualityControlLevelID));
                            cmd18.Parameters.Add(_db.CreateParameter(DbType.Boolean, series[seriesNum].IsCategorical));
                            cmd18.Parameters.Add(_db.CreateParameter(DbType.DateTime, series[seriesNum].BeginDateTime));
                            cmd18.Parameters.Add(_db.CreateParameter(DbType.DateTime, series[seriesNum].EndDateTime));
                            cmd18.Parameters.Add(_db.CreateParameter(DbType.DateTime, series[seriesNum].BeginDateTimeUTC));
                            cmd18.Parameters.Add(_db.CreateParameter(DbType.DateTime, series[seriesNum].EndDateTimeUTC));
                            cmd18.Parameters.Add(_db.CreateParameter(DbType.Int32, series[seriesNum].ValueCount));
                            cmd18.Parameters.Add(_db.CreateParameter(DbType.DateTime, series[seriesNum].CreationDateTime));
                            cmd18.Parameters.Add(_db.CreateParameter(DbType.Boolean, series[seriesNum].Subscribed));
                            cmd18.Parameters.Add(_db.CreateParameter(DbType.DateTime, series[seriesNum].UpdateDateTime));
                            cmd18.Parameters.Add(_db.CreateParameter(DbType.DateTime, series[seriesNum].LastCheckedDateTime));

                            seriesIDResult = cmd18.ExecuteScalar();
                            seriesID       = Convert.ToInt32(seriesIDResult);
                        }


                        //****************************************************************
                        //*** Step 8 Qualifier and Sample Lookup
                        //****************************************************************
                        Dictionary <string, Qualifier>  qualifierLookup;
                        Dictionary <string, Sample>     sampleLookup;
                        Dictionary <string, OffsetType> offsetLookup;
                        GetLookups(series[seriesNum], out qualifierLookup, out sampleLookup, out offsetLookup);

                        SaveQualifiers(conn1, qualifierLookup);
                        SaveSamplesAndLabMethods(conn1, sampleLookup);
                        SaveOffsets(conn1, offsetLookup);
                        numSavedValues = SaveDataValues(conn1, seriesID, series[seriesNum].DataValueList);

                        //****************************************************************
                        //*** Step 14 Data Theme                               ***********
                        //****************************************************************
                        var themeIDResult = GetThemeID(conn1, theme);
                        if (themeIDResult.HasValue)
                        {
                            themeID = themeIDResult.Value;
                        }
                        if (themeID == 0)
                        {
                            using (DbCommand cmd23 = conn1.CreateCommand()) {
                                cmd23.CommandText = sqlSaveTheme1;
                                cmd23.Parameters.Add(_db.CreateParameter(DbType.String, theme.Name));
                                cmd23.Parameters.Add(_db.CreateParameter(DbType.String, theme.Description));
                                themeID = Convert.ToInt32(cmd23.ExecuteScalar());
                            }
                        }

                        using (DbCommand cmd24 = conn1.CreateCommand()) {
                            cmd24.CommandText = sqlSaveTheme2;
                            cmd24.Parameters.Add(_db.CreateParameter(DbType.Int32, themeID));
                            cmd24.Parameters.Add(_db.CreateParameter(DbType.Int32, seriesID));
                            cmd24.ExecuteNonQuery();
                        }

                        series[seriesNum].Id = seriesID;
                    }

                    //Step 13 Commit Transaction
                    tran.Commit();
                }
                conn1.Close();
            }

            return(numSavedValues);
        }