Пример #1
0
        /// <summary>
        /// Parses the data gotten from the blob file into
        /// usable information that can be used by objects.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="sensorName"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        private void parseSensorValues(StreamReader reader, string sensorName, List <SensorType> data)
        {
            while (!reader.EndOfStream)
            {
                string   line   = reader.ReadLine();
                string[] values = line.Split(";");

                if (sensorName == "humidity")
                {
                    Humidity humidity = new Humidity();

                    humidity.Time           = DateTime.Parse(values[0]);
                    humidity.HumidityAmount = Convert.ToDouble(values[1]);
                    data.Add(humidity);
                }
                else if (sensorName == "temperature")
                {
                    Temperature temperature = new Temperature();
                    temperature.Time    = DateTime.Parse(values[0]);
                    temperature.Degrees = Convert.ToDouble(values[1]);
                    data.Add(temperature);
                }
                else
                {
                    Rainfall rainfall = new Rainfall();
                    rainfall.Time       = DateTime.Parse(values[0]);
                    rainfall.RainAmount = Convert.ToDouble(values[1]);
                    data.Add(rainfall);
                }
            }
        }
Пример #2
0
        //
        // GET: /Rainfall/Create
        public ActionResult Create()
        {
            var model = new Rainfall();

            model.GetSelectListBlockOrganization = GetSelectListBlockOrganization();
            return(View(model));
        }
Пример #3
0
    static void Main(string[] args)
    {
        // define local varables
        int noRegions, noMonths;
        int[] temp;

        // create rainfall object
        Rainfall rainfall = new Rainfall();

        // create input object
        IRainfallInput input = new RainfallFileInput();

        // create output object
        IPrintRainfall output = new PrintRainfallConsole();

        // Start message for User
        output.printText("Welcome to the Rainfall Program :)");

        // 1. get number of regions / months to sample
        temp = input.getRegions();

        noRegions = temp[0];
        noMonths = temp[1];

        // 2. get the rainfall data from the input device
        rainfall.RainfallFigures = input.getRainfall(noRegions, noMonths);

        // 3. output the rainfall figures for each month
        output.printRainfall(rainfall.RainfallFigures);

        // 4. output the average rainfall figures for each region
        output.printAvgRainfall(rainfall.calcAvgRainfall());
    }
        public async Task <IActionResult> Edit(int id, [Bind("StationId,Date,Value")] Rainfall rainfall)
        {
            if (id != rainfall.StationId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(rainfall);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RainfallExists(rainfall.StationId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StationId"] = new SelectList(_context.Stations, "StationId", "Name", rainfall.StationId);
            return(View(rainfall));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Rainfall rainfall = db.RainfallSet.Find(id);

            db.RainfallSet.Remove(rainfall);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #6
0
        public Rainfall Add(Rainfall RF, string userid)
        {
            var sqlQuery = @"INSERT INTO RAINFALL (RAINDATE, BLOCKORGANIZATION, RAINSTART, RAINEND, RAINQUANTITY, REMARK, COMPANYSITE, INPUTBY, INPUTDATE, UPDATEBY, UPDATEDATE) VALUES
                           ('" + RF.RAINDATE + @"', '" + RF.BLOCKORGANIZATION + "', '" + RF.RAINSTART + @"', '" + RF.RAINEND + "', '" + RF.RAINQUANTITY + @"', '" + RF.REMARK + @"', '" + RF.COMPANYSITE + @"'," + Convert.ToInt32(userid) + ", '" + DateTime.Now + @"', " + Convert.ToInt32(userid) + ", '" + DateTime.Now + @"'); " + "SELECT CAST(SCOPE_IDENTITY() as int)";
            var SID      = _db.Query <int>(sqlQuery, RF).Single();

            RF.SID = SID;
            return(RF);
        }
Пример #7
0
        public Rainfall Update(Rainfall RF, string userid)
        {
            var sqlQuery =
                string.Format(@"UPDATE RAINFALL SET RAINDATE = '{0}', BLOCKORGANIZATION = '{1}', RAINSTART = '{2}', RAINEND = '{3}', RAINQUANTITY = '{4}', REMARK = '{5}', COMPANYSITE = '{6}', UPDATEBY = {7}, UPDATEDATE = '{8}' WHERE SID = {9}",
                              RF.RAINDATE, RF.BLOCKORGANIZATION, RF.RAINSTART, RF.RAINEND, RF.RAINQUANTITY, RF.REMARK, RF.COMPANYSITE, Convert.ToInt32(userid), DateTime.Now, RF.SID);

            this._db.Execute(sqlQuery, RF);
            return(RF);
        }
 public ActionResult Edit([Bind(Include = "Id,month,rainfall_day,rainfall_month,possibility,storage_month,indoor_req,outdoor_req")] Rainfall rainfall)
 {
     if (ModelState.IsValid)
     {
         db.Entry(rainfall).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(rainfall));
 }
Пример #9
0
 Forecast(int temp, Rainfall rain, Cloudy clou, int hum, int ws, Wind_direction wd, Cities city)
 {
     this.temperature    = temp;
     this.rainfall       = rain;
     this.cloudy         = clou;
     this.humidity       = hum;
     this.wind_strength  = ws;
     this.wind_direction = wd;
     number_of_forecasts++;
 }
        public ActionResult Create([Bind(Include = "Id,month,rainfall_day,rainfall_month,possibility,storage_month,indoor_req,outdoor_req")] Rainfall rainfall)
        {
            if (ModelState.IsValid)
            {
                db.RainfallSet.Add(rainfall);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(rainfall));
        }
Пример #11
0
        static void Main(string[] args)
        {
            List <Rainfall> rainfalls = new List <Rainfall>();

            Console.WriteLine("ENTER FILE NAME");
            string filename = Console.ReadLine();

            string[] lines    = System.IO.File.ReadAllLines(filename);
            int      xRef     = 0;
            int      yRef     = 0;
            DateTime rainDate = DateTime.Parse("01/01/1990");
            string   getYear  = "";

            foreach (string line in lines)
            {
                if (line.Contains("Years="))
                {
                    getYear  = line.Substring(line.IndexOf("Years=") + 6, 4);
                    rainDate = DateTime.Parse("01/01/" + getYear);
                }

                if (line.Contains("Grid-ref="))
                {
                    var rainRef = line.Split(',');
                    xRef     = int.Parse(rainRef[0].Substring(9));
                    yRef     = int.Parse(rainRef[1]);
                    rainDate = DateTime.Parse("01/01/" + getYear);
                }

                if (Regex.IsMatch(line, @"^[\d \w \s]+$"))
                {
                    var values = line.Split(' ');
                    foreach (string rainVal in values)
                    {
                        if (rainVal.Length > 0)
                        {
                            Rainfall rainfall = new Rainfall();
                            rainfall.Xref  = xRef;
                            rainfall.Yref  = yRef;
                            rainfall.Value = int.Parse(rainVal);
                            rainfall.Date  = rainDate;
                            using (var db = new DataHelper())
                            {
                                db.RainData.Add(rainfall);
                                db.SaveChanges();
                            }
                            rainfalls.Add(rainfall);
                            rainDate = rainDate.AddMonths(1);
                        }
                    }
                }
            }
            Console.ReadLine();
        }
Пример #12
0
        /// <summary>
        /// Returns true if WeatherInfo instances are equal
        /// </summary>
        /// <param name="other">Instance of WeatherInfo to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(WeatherInfo other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Date == other.Date ||
                     Date != null &&
                     Date.Equals(other.Date)
                     ) &&
                 (
                     Tmax == other.Tmax ||
                     Tmax != null &&
                     Tmax.Equals(other.Tmax)
                 ) &&
                 (
                     Tmin == other.Tmin ||
                     Tmin != null &&
                     Tmin.Equals(other.Tmin)
                 ) &&
                 (
                     Rainfall == other.Rainfall ||
                     Rainfall != null &&
                     Rainfall.Equals(other.Rainfall)
                 ) &&
                 (
                     Wmean == other.Wmean ||
                     Wmean != null &&
                     Wmean.Equals(other.Wmean)
                 ) &&
                 (
                     Wmax == other.Wmax ||
                     Wmax != null &&
                     Wmax.Equals(other.Wmax)
                 ) &&
                 (
                     Insolation == other.Insolation ||
                     Insolation != null &&
                     Insolation.Equals(other.Insolation)
                 ) &&
                 (
                     Sunshine == other.Sunshine ||
                     Sunshine != null &&
                     Sunshine.Equals(other.Sunshine)
                 ));
        }
        public async Task <IActionResult> Create([Bind("StationId,Date,Value")] Rainfall rainfall)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rainfall);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["StationId"] = new SelectList(_context.Stations, "StationId", "Name", rainfall.StationId);
            return(View(rainfall));
        }
Пример #14
0
        private async Task ListBlobsFlatListingAsync(CloudBlobContainer container, int?segmentSize)
        {
            BlobContinuationToken continuationToken = null;
            CloudBlob             blob;

            try
            {
                do
                {
                    BlobResultSegment resultSegment = await container.ListBlobsSegmentedAsync(string.Empty, true, BlobListingDetails.Metadata, segmentSize, continuationToken, null, null);

                    _metaSensorData = new List <SensorMetaData>();
                    foreach (var blobItem in resultSegment.Results)
                    {
                        // A flat listing operation returns only blobs, not virtual directories.
                        blob = (CloudBlob)blobItem;

                        using (var mStream = new MemoryStream())
                        {
                            if (!blob.Name.Contains("historical") && !blob.Name.Contains("metadata"))
                            {
                                SensorMetaData sensorMetaData = null;
                                if (blob.Name.Contains("humidity"))
                                {
                                    sensorMetaData = new Humidity();
                                }
                                else if (blob.Name.Contains("rainfall"))
                                {
                                    sensorMetaData = new Rainfall();
                                }
                                else if (blob.Name.Contains("temperature"))
                                {
                                    sensorMetaData = new Temperature();
                                }

                                await ParseSensorDataAndAddToDataStream(mStream, sensorMetaData, blob);
                            }
                        }

                        _logger.LogInformation($"Blob name {blob.Name}");
                    }

                    // Get the continuation token and loop until it is null.
                    continuationToken = resultSegment.ContinuationToken;
                } while (continuationToken != null);
            }
            catch (StorageException ex)
            {
                _logger.LogCritical(ex.Message);
                throw;
            }
        }
        // GET: Rainfalls/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Rainfall rainfall = db.RainfallSet.Find(id);

            if (rainfall == null)
            {
                return(HttpNotFound());
            }
            return(View(rainfall));
        }
Пример #16
0
 public ActionResult Create(Rainfall Rainfall, string userid)
 {
     if (ModelState.IsValid)
     {
         Rainfall.COMPANYSITE = int.Parse(Session["companysite"].ToString());
         RF.Add(Rainfall, Session["userid"].ToString());
         TempData["successmessage"] = "Saved successfully";
         return(RedirectToAction("Create"));
     }
     else
     {
         Rainfall.GetSelectListBlockOrganization = GetSelectListBlockOrganization();
         return(View(Rainfall));
     }
 }
Пример #17
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Date != null)
         {
             hashCode = hashCode * 59 + Date.GetHashCode();
         }
         if (Tmax != null)
         {
             hashCode = hashCode * 59 + Tmax.GetHashCode();
         }
         if (Tmin != null)
         {
             hashCode = hashCode * 59 + Tmin.GetHashCode();
         }
         if (Rainfall != null)
         {
             hashCode = hashCode * 59 + Rainfall.GetHashCode();
         }
         if (Wmean != null)
         {
             hashCode = hashCode * 59 + Wmean.GetHashCode();
         }
         if (Wmax != null)
         {
             hashCode = hashCode * 59 + Wmax.GetHashCode();
         }
         if (Insolation != null)
         {
             hashCode = hashCode * 59 + Insolation.GetHashCode();
         }
         if (Sunshine != null)
         {
             hashCode = hashCode * 59 + Sunshine.GetHashCode();
         }
         return(hashCode);
     }
 }
Пример #18
0
        private static void BuildAggregatedRainfallData(string fileName)
        {
            var rainfall = new Rainfall();

            Console.WriteLine($"Working with the file {fileName} now...");
            StreamReader sr   = null;
            string       line = "";

            string[] rainData;
            string   prevYear             = "";
            string   prevMonth            = "";
            int      prevLongRunningTotal = 0; //Cumulative of the longest number of days rained
            int      currLongRunningTotal = 0;

            try
            {
                sr   = new StreamReader(fileName);
                line = sr.ReadLine();   //leave the first line out as it is Header
                while ((line = sr.ReadLine()) != null)
                {
                    rainData = line.Split(',')[2..6];
Пример #19
0
        private void InitTestData()
        {
            Rainfall rainfall1 = new Rainfall()
            {
                Value           = 1,
                RainfallStation = new RainfallStation()
                {
                    StationId   = "D1010",
                    StationName = "A"
                },
                CollectTime = new DateTime(2014, 6, 29, 17, 10, 0)
            };
            Rainfall rainfall2 = new Rainfall()
            {
                Value           = 1.01,
                RainfallStation = new RainfallStation()
                {
                    StationId   = "D2020",
                    StationName = "B"
                },
                CollectTime = new DateTime(2014, 7, 1, 17, 10, 0)
            };
            Rainfall rainfall3 = new Rainfall()
            {
                Value           = 1.01,
                RainfallStation = new RainfallStation()
                {
                    StationId   = "D2020",
                    StationName = "B"
                },
                CollectTime = new DateTime(2014, 6, 30, 17, 10, 0)
            };
            List <Rainfall> rainfalls = new List <Rainfall> {
                rainfall1, rainfall2, rainfall3
            };

            this._rainfalls = rainfalls;
        }
Пример #20
0
        public static async Task <string> RainfallResponse(string dateParam)
        {
            var blobDataRainfall = await FetchDataService.CallBlobAPI(blobURI + "/rainfall/" + dateParam + ".csv");

            var outgoingObjAsList = new List <RainfallObj>();

            var listofRainfalls = blobDataRainfall.Split("\r\n").ToList();

            foreach (var Rainfall in listofRainfalls)
            {
                if (!string.IsNullOrEmpty(Rainfall))
                {
                    var         rainfallLine = Rainfall.Split(";");
                    RainfallObj outgoingJson = new RainfallObj()
                    {
                        PointInTime = rainfallLine[0],
                        Rainfall    = rainfallLine[1]
                    };
                    outgoingObjAsList.Add(outgoingJson);
                }
            }
            return(JsonSerializer.Serialize(outgoingObjAsList));
        }
 public double GetTotalRainfall()
 {
     return(Rainfall.Sum());
 }
        public double GetAnnualAvgRainfall()
        {
            var yrs = ((float)Counts.Sum() / 365.25);

            return(Rainfall.Sum() / yrs);
        }
 public List <double> GetMonthlyAvgRainfall()
 {
     return(Rainfall.Select(x => x / (((double)Counts[Rainfall.IndexOf(x)]) / 365.25 * 12.0)).ToList());
 }
Пример #24
0
        private static async Task ListBlobsFlatListingAsync(CloudBlobContainer container, int?segmentSize)
        {
            BlobContinuationToken continuationToken = null;
            CloudBlob             blob;

            try
            {
                // Call the listing operation and enumerate the result segment.
                // When the continuation token is null, the last segment has been returned
                // and execution can exit the loop.
                do
                {
                    BlobResultSegment resultSegment = await container.ListBlobsSegmentedAsync(string.Empty, true, BlobListingDetails.Metadata, segmentSize, continuationToken, null, null);

                    List <SensorData> sensorData = new List <SensorData>();
                    foreach (var blobItem in resultSegment.Results)
                    {
                        // A flat listing operation returns only blobs, not virtual directories.
                        blob = (CloudBlob)blobItem;

                        using (var mStream = new MemoryStream())
                        {
                            if (!blob.Name.Contains("historical") && !blob.Name.Contains("metadata"))
                            {
                                SensorData item = null;
                                if (blob.Name.Contains("humidity"))
                                {
                                    item = new Humidity();
                                }
                                else if (blob.Name.Contains("rainfall"))
                                {
                                    item = new Rainfall();
                                }
                                else if (blob.Name.Contains("temperature"))
                                {
                                    item = new Temperature();
                                }

                                await blob.DownloadToStreamAsync(mStream);

                                var    result    = mStream.ToArray();
                                string converted = Encoding.UTF8.GetString(result, 0, result.Length);

                                string[] words = converted.Split("\r\n");

                                item.MeasurementData = new List <double>();
                                item.MeasurementDay  = DateTime.Now;
                                item.MeasurementTime = new List <DateTime>();
                                sensorData.Add(item);
                            }
                        }

                        // Write out some blob properties.
                        Console.WriteLine("Blob name: {0}", blob.Name);
                    }

                    foreach (var item in sensorData)
                    {
                        var result = item.GetType();
                    }

                    Console.WriteLine();

                    // Get the continuation token and loop until it is null.
                    continuationToken = resultSegment.ContinuationToken;
                } while (continuationToken != null);
            }
            catch (StorageException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                throw;
            }
        }
Пример #25
0
        private static async Task ListBlobsFlatListingAsync(CloudBlobContainer container, int?segmentSize)
        {
            BlobContinuationToken continuationToken = null;
            CloudBlob             blob;

            try
            {
                // Call the listing operation and enumerate the result segment.
                // When the continuation token is null, the last segment has been returned
                // and execution can exit the loop.
                do
                {
                    BlobResultSegment resultSegment = await container.ListBlobsSegmentedAsync(string.Empty, true, BlobListingDetails.Metadata, segmentSize, continuationToken, null, null);

                    _sensorData = new List <SensorData>();
                    foreach (var blobItem in resultSegment.Results)
                    {
                        // A flat listing operation returns only blobs, not virtual directories.
                        blob = (CloudBlob)blobItem;

                        using (var mStream = new MemoryStream())
                        {
                            if (!blob.Name.Contains("historical") && !blob.Name.Contains("metadata"))
                            {
                                SensorData item = null;
                                if (blob.Name.Contains("humidity"))
                                {
                                    item = new Humidity();
                                }
                                else if (blob.Name.Contains("rainfall"))
                                {
                                    item = new Rainfall();
                                }
                                else if (blob.Name.Contains("temperature"))
                                {
                                    item = new Temperature();
                                }

                                await ParseAndAddDataStream(mStream, item, blob);
                            }
                        }

                        // Write out some blob properties.
                        Console.WriteLine("Blob name: {0}", blob.Name);
                    }

                    foreach (var item in _sensorData)
                    {
                        if (item.GetType().Name.ToLower() == "temperature" && item.MeasurementDay.Date.ToString("yyyy-MM-dd") == "2019-01-10")
                        {
                            Console.WriteLine($"Is temperature on date: {item.MeasurementDay.ToString()}");
                        }
                    }

                    // Get the continuation token and loop until it is null.
                    continuationToken = resultSegment.ContinuationToken;
                } while (continuationToken != null);
            }
            catch (StorageException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadLine();
                throw;
            }
        }
Пример #26
0
        public void Mean_PartialMatch_Test()
        {
            var result = Rainfall.Mean("Rom", data1);

            Assert.Equal(-1, result);
        }
Пример #27
0
        public void Mean_Test()
        {
            var result = Rainfall.Mean("London", data);

            Assert.True(Math.Abs(51.19999999999996 - result) < 1e-2);
        }
Пример #28
0
        public void Mean_Return_Negative_Empty_Data()
        {
            var result = Rainfall.Mean("Rome", "");

            Assert.Equal(-1, result);
        }
Пример #29
0
        public void Mean_Return_Negative_On_Town_Not_Found()
        {
            var result = Rainfall.Mean("Madurai", "Madurai:Jan 81.2,Feb 63.2");

            Assert.Equal(-1, result);
        }
Пример #30
0
        public void Variance_Test()
        {
            var result = Rainfall.Variance("London", data);

            Assert.True(Math.Abs(57.42833333333374 - result) < 1e-2);
        }
Пример #31
0
 public static void test2()
 {
     Console.WriteLine("Fixed Tests: variance data");
     assertFuzzyEquals(Rainfall.Variance("London", RainfallTests.data), 57.42833333333374); //57,428333333333335
     assertFuzzyEquals(Rainfall.Variance("Beijing", RainfallTests.data), 4808.37138888889);
 }