コード例 #1
0
 //Event handler that responds to Clear Imported Data button being clicked
 void clearImportedDataClick(object sender, EventArgs e)
 {
     processor.clearData();
     importFromFileForm.setDataLoaded(false);
 }
コード例 #2
0
        private void createPrecipTempAndProjectionsFiles()
        {
            string[] futureLines     = System.IO.File.ReadAllLines(filePath + "/FutureClimateData.csv");
            string[] historicalLines = System.IO.File.ReadAllLines(filePath + "/HistoricalClimateData.csv");
            string[] currentLine     = null;
            DateTime dt;
            double   value;
            bool     precip = false;
            List <List <KeyValuePair <DateTime, double> > > historicalPrecipData = new List <List <KeyValuePair <DateTime, double> > >();
            List <List <KeyValuePair <DateTime, double> > > futurePrecipData     = new List <List <KeyValuePair <DateTime, double> > >();
            List <List <KeyValuePair <DateTime, double> > > historicalTempData   = new List <List <KeyValuePair <DateTime, double> > >();
            List <List <KeyValuePair <DateTime, double> > > futureTempData       = new List <List <KeyValuePair <DateTime, double> > >();
            List <KeyValuePair <DateTime, double> >         currentList          = null;
            List <String> projectionNames = new List <string>();

            //process historical data
            for (int row = 0; row < historicalLines.Length; row++)
            {
                if (historicalLines[row].Contains('#'))
                {
                    //save currentList if it has data
                    if (row != 0)
                    {
                        if (precip)
                        {
                            historicalPrecipData.Add(currentList);
                        }
                        else
                        {
                            historicalTempData.Add(currentList);
                        }
                    }
                    currentList = new List <KeyValuePair <DateTime, double> >();
                    precip      = !precip;
                    row        += 2;
                }
                else
                {
                    currentLine = historicalLines[row].Split(',');
                    dt          = DateTime.Parse(currentLine[0]);
                    value       = Double.Parse(currentLine[1]);
                    currentList.Add(new KeyValuePair <DateTime, double>(dt, value));
                }
            }
            historicalTempData.Add(currentList);

            //process future data
            for (int row = 0; row < futureLines.Length; row++)
            {
                if (futureLines[row].Contains('#'))
                {
                    //save projection name
                    if (precip)
                    {
                        string[] info = futureLines[row].Split('_');
                        projectionNames.Add(info[4] + "." + info[6].ElementAt(1) + "." + info[5]);
                    }
                    //save currentList if it has data
                    if (row != 0)
                    {
                        if (precip)
                        {
                            futurePrecipData.Add(currentList);
                        }
                        else
                        {
                            futureTempData.Add(currentList);
                        }
                    }
                    //create new list
                    currentList = new List <KeyValuePair <DateTime, double> >();
                    precip      = !precip;
                    row        += 2;
                }
                else
                {
                    currentLine = futureLines[row].Split(',');
                    dt          = DateTime.Parse(currentLine[0]);
                    value       = Double.Parse(currentLine[1]);
                    currentList.Add(new KeyValuePair <DateTime, double>(dt, value));
                }
            }
            futureTempData.Add(currentList);

            //write precip file
            string        precipFileName = filePath + "/precip_data.csv";
            List <String> lines          = new List <string>();

            for (int row = 0; row < historicalPrecipData[0].Count; row++)
            {
                String str = historicalPrecipData[0][row].Key.Year + ", " + historicalPrecipData[0][row].Key.Month;
                for (int col = 0; col < historicalPrecipData.Count; col++)
                {
                    str += ", " + historicalPrecipData[col][row].Value;
                }
                lines.Add(str);
            }
            for (int row = 0; row < futurePrecipData[0].Count; row++)
            {
                String str = futurePrecipData[0][row].Key.Year + ", " + futurePrecipData[0][row].Key.Month;
                for (int col = 0; col < futurePrecipData.Count; col++)
                {
                    str += ", " + futurePrecipData[col][row].Value;
                }
                lines.Add(str);
            }
            System.IO.File.WriteAllLines(precipFileName, lines);

            //write temp file
            string tempFileName = filePath + "/temp_data.csv";

            lines = new List <string>();
            for (int row = 0; row < historicalTempData[0].Count; row++)
            {
                String str = historicalTempData[0][row].Key.Year + ", " + historicalTempData[0][row].Key.Month;
                for (int col = 0; col < historicalTempData.Count; col++)
                {
                    str += ", " + historicalTempData[col][row].Value;
                }
                lines.Add(str);
            }
            for (int row = 0; row < futureTempData[0].Count; row++)
            {
                String str = futureTempData[0][row].Key.Year + ", " + futureTempData[0][row].Key.Month;
                for (int col = 0; col < futureTempData.Count; col++)
                {
                    str += ", " + futureTempData[col][row].Value;
                }
                lines.Add(str);
            }
            System.IO.File.WriteAllLines(tempFileName, lines);

            //write projections file
            string modelFileName = filePath + "/Projections.txt";

            lines = new List <string>();
            foreach (String str in projectionNames)
            {
                lines.Add(str);
            }
            System.IO.File.WriteAllLines(modelFileName, lines);

            processor.Import(precipFileName, tempFileName);
            processor.importNames(modelFileName);
            import.setDataLoaded(true);
            processor.generateChangeFactors();
            processor.addDataToDatabase(import, null, null);
        }
コード例 #3
0
        //OK button click
        private void button3_Click(object sender, EventArgs e)
        {
            double[,] precip, temp;
            string[] names;
            CheckedListBox.CheckedItemCollection collection = checkedListBox1.CheckedItems;

            if (collection.Count == 0)
            {
                this.Hide();
                return;
            }

            var            repository1 = RepositoryFactory.Instance.Get <IDataSeriesRepository>();
            var            repository2 = RepositoryFactory.Instance.Get <IDataValuesRepository>();
            IList <Series> seriesList  = repository1.GetAllSeries();
            IList <double> precipList;
            IList <double> tempList;
            int            precipID = 0, tempID = 0;

            precip = new double[1800, collection.Count];
            temp   = new double[1800, collection.Count];
            names  = new string[collection.Count];

            for (int i = 0; i < collection.Count; i++)
            {
                names[i] = collection[i].ToString();

                for (int j = 0; j < seriesList.Count; j++)
                {
                    if (seriesList[j].Site.ToString().Equals(names[i]))
                    {
                        if (seriesList[j].Variable.ToString() == "Precipitation")
                        {
                            precipID = (int)seriesList[j].Id;
                        }
                        if (seriesList[j].Variable.ToString() == "Temperature")
                        {
                            tempID = (int)seriesList[j].Id;
                        }
                    }
                }

                precipList = repository2.GetValues(precipID);
                tempList   = repository2.GetValues(tempID);
                for (int row = 0; row < 1800; row++)
                {
                    if (row < precipList.Count)
                    {
                        precip[row, i] = precipList[row];
                        temp[row, i]   = tempList[row];
                    }
                    else
                    {
                        precip[row, i] = Double.NaN;
                        temp[row, i]   = Double.NaN;
                    }
                }
            }

            processor.addData(precip, temp, names);
            processor.generateChangeFactors();
            import.setDataLoaded(true);
            this.Hide();
        }