Example #1
0
        public void FeedJson_ToModel_Clears_HasPolarPlot_When_PolarPlotter_Is_Missing()
        {
            _AircraftList.SetupGet(r => r.PolarPlotter).Returns((IPolarPlotter)null);

            var model = FeedJson.ToModel(_Feed.Object);

            Assert.IsFalse(model.HasPolarPlot);
        }
Example #2
0
        public void FeedJson_Constructor_Initialises_To_Known_State_And_Properties_Work()
        {
            var json = new FeedJson();

            TestUtilities.TestProperty(json, r => r.Name, null, "Abc");
            TestUtilities.TestProperty(json, r => r.UniqueId, 0, 123);
            TestUtilities.TestProperty(json, r => r.HasPolarPlot, false);
        }
Example #3
0
        public void FeedJson_ToModel_Clears_HasPolarPlot_When_AircraftList_Is_Missing()
        {
            _Feed.SetupGet(r => r.AircraftList).Returns((IBaseStationAircraftList)null);

            var model = FeedJson.ToModel(_Feed.Object);

            Assert.IsFalse(model.HasPolarPlot);
        }
Example #4
0
        public void FeedJson_ToModel_Fills_Properties_Correctly()
        {
            _Feed.SetupGet(r => r.UniqueId).Returns(1);
            _Feed.SetupGet(r => r.Name).Returns("Feed Name");

            var model = FeedJson.ToModel(_Feed.Object);

            Assert.AreEqual(1, model.UniqueId);
            Assert.AreEqual("Feed Name", model.Name);
            Assert.IsTrue(model.HasPolarPlot);
        }
Example #5
0
        public FeedJson GetFeed(int id)
        {
            var feedManager = Factory.Singleton.ResolveSingleton <IFeedManager>();

            return(FeedJson.ToModel(feedManager.GetByUniqueId(id, ignoreInvisibleFeeds: true)));
        }
Example #6
0
        public FeedJson[] GetFeeds()
        {
            var feedManager = Factory.Singleton.ResolveSingleton <IFeedManager>();

            return(feedManager.VisibleFeeds.Select(r => FeedJson.ToModel(r)).Where(r => r != null).ToArray());
        }
Example #7
0
        private static void GenerateFeedJson(IEnumerable <ConfigurationParameter> configurations, string fileExtension)
        {
            foreach (var configuration in configurations)
            {
                try
                {
                    var baseLocation = ConfigurationManager.AppSettings["FeedFileBaseLocation"];

                    var feedJsonList = new List <object>();

                    var feeds = HillTopDb.GetAllFeedsByConfigurationNameMeasurePeriod(configuration.ConfigurationName, configuration.CommonName, configuration.Period);

                    var sites = feeds.Where(p => p.ThresholdOrder == 1);
                    foreach (var hilltopData in sites)
                    {
                        Console.WriteLine("Updating Site...");
                        //var site = hilltopData.SiteName.Replace(" ", "");

                        var thresholdsSite = feeds.Where(p => p.SiteName == hilltopData.SiteName).ToList();

                        var measure = GetMeasure(configuration.CommonName, hilltopData.UseForecast);

                        var period = GetPeriod(measure, configuration.Period);

                        // Get the value, unit and the DateUpdated from Hilltop .hts file
                        string url = string.Format(ConfigurationManager.AppSettings["HillTopServerUrl"], hilltopData.SiteName, measure, period);
                        var    doc = XDocument.Load(url);

                        var data = doc.Descendants().Where(d => d.Name == "E");
                        var item = doc.Descendants().Where(d => d.Name == "ItemInfo");

                        var dateUpdated = data.Descendants("T").LastOrDefault();
                        var updated     = Convert.ToDateTime(dateUpdated.Value);

                        var totalValue = 0M;
                        if (measure == "Rainfall")
                        {
                            var listValues = data.Descendants((configuration.ConfigurationName == "Floodwatch" ? "I1" : "Value")).ToList();
                            totalValue += listValues.Sum(value => Convert.ToDecimal(value.Value.Replace("<", "").Replace(">", "")));
                        }
                        else
                        {
                            var value = data.Descendants((configuration.ConfigurationName == "Floodwatch" ? "I1" : "Value")).LastOrDefault();
                            totalValue = Convert.ToDecimal(value.Value.Replace("<", "").Replace(">", ""));
                        }

                        var currentValue = totalValue;

                        var units = item.Descendants("Units").FirstOrDefault();

                        var geoPos      = hilltopData.Easting + " " + hilltopData.Northing;
                        var label       = hilltopData.Label;
                        var hasForecast = hilltopData.HasForecast;
                        var useForecast = hilltopData.UseForecast;
                        var imageUrl    = hilltopData.InfoUrl;

                        var alarm     = "";
                        var alarmText = "";

                        //var body = "";
                        var axes       = "";
                        var traces     = "";
                        var thresholds = "";



                        if (configuration.ConfigurationName == "Floodwatch")
                        {
                            //body = GetGifGenFloodwatch(hilltopData, thresholdsSite, measure, fileExtension, fontType);
                            axes       = GetFloodwatchAxes(hilltopData.AxisMinimum, hilltopData.AxisMaximum);
                            traces     = GetFloodwatchTraces(hilltopData.SiteName, measure, hilltopData.HasForecast, hilltopData.UseForecast);
                            thresholds = GetFloodwatchThresholds(thresholdsSite);
                        }
                        else
                        {
                            //body = GetGifGenBathingWater(hilltopData, measure, fileExtension, fontType);    // E. coli or Enterococci
                            axes       = GetBathingWaterAxes(hilltopData.AxisMinimum, hilltopData.AxisMaximum);
                            traces     = GetBathingWaterTraces(hilltopData.SiteName, measure);
                            thresholds = GetBathingWaterThresholds(measure);
                        }

                        foreach (var threshold in thresholdsSite)
                        {
                            if (currentValue <= threshold.Maximum && string.IsNullOrEmpty(alarm))
                            {
                                if (!threshold.Indicator.Equals("NoThreshold"))
                                {
                                    alarm = (configuration.ConfigurationName == "Floodwatch" ? threshold.Indicator : (threshold.ThresholdOrder).ToString());
                                }
                                else
                                {
                                    alarm = "Blue";
                                }
                                alarmText = threshold.GraphText;
                            }
                        }

                        var feedUrl = ConfigurationManager.AppSettings["FeedUrl"];

                        var graphUrl = String.Concat(feedUrl, "/Images/", configuration.ConfigurationName, "/",
                                                     configuration.CommonName, "/", configuration.Period, "/", hilltopData.SiteName.Replace(" ", ""), ".", fileExtension);


                        var feedJson = new FeedJson(configuration.CommonName)
                        {
                            Value       = currentValue,
                            Alarm       = (updated < DateTime.Now.AddHours(-6) && configuration.ConfigurationName == "Floodwatch" ? "gray" : alarm),
                            AlarmText   = alarmText,
                            LastUpdated = updated,
                            GeoPos      = geoPos,
                            Units       = units.Value,
                            Hour        = configuration.Period,
                            GraphPath   = graphUrl,
                            HasForecast = hasForecast,
                            UseForecast = useForecast,
                            Hilltop     = hilltopData.SiteName,
                            ImageUrl    = imageUrl,
                            Label       = label,
                            Change      = "",
                            Axes        = axes,
                            Traces      = traces,
                            Thresholds  = thresholds
                        };

                        feedJsonList.Add(feedJson);
                    }
                    Console.WriteLine("Updating json file...");
                    var jsonFormated = JsonConvert.SerializeObject(
                        new
                    {
                        FeedUpdated = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(),
                        Sites       = feedJsonList.ToArray()
                    }, Formatting.Indented);
                    var jsonPath = String.Concat(baseLocation, "\\", configuration.ConfigurationName, "\\", configuration.CommonName, "\\", configuration.Period, "\\");

                    Directory.CreateDirectory(jsonPath);
                    File.WriteAllText(jsonPath + "feed.json", jsonFormated);
                    Console.WriteLine("Updated!");
                }
                catch (Exception ex)
                {
                    // Save exception on Nlog
                    var errorMessage = String.Format("Error FeedManager.GenerateFeedJson => {0}", ex.Message);
                    Log(errorMessage, LogLevel.Error);
                }
            }
        }
Example #8
0
        public void FeedJson_ToModel_Returns_Null_If_Passed_Invisible_Feed()
        {
            _Feed.SetupGet(r => r.IsVisible).Returns(false);

            Assert.IsNull(FeedJson.ToModel(_Feed.Object));
        }
Example #9
0
 public void FeedJson_ToModel_Returns_Null_If_Passed_Null()
 {
     Assert.IsNull(FeedJson.ToModel(null));
 }