Exemplo n.º 1
0
        public static void CreateRawBidFile(Guid bidFileId)
        {
            var db = new TBSPEntities1();

            var bfr = (from bids in db.BidFiles where bids.BidFileId == bidFileId select bids).Take(1);

            if (!bfr.Any())
                throw new Exception("No BidFile found");

            var bf = bfr.First();

            var header1 = "PM, " + bf.DeliveryDate + ", TCE, APITCE01, , NORMAL;";

            Console.WriteLine("header1: " + header1);

            foreach (var det in (db.BidFileDetails.OrderBy(f => f.MarketType).ThenBy(f => f.Hour).Select(f => bf)).ToList())
            {
                //var line = "" + det.ResourceId + "," + det.MarketType + "," + det.ReserveClass + "," + det.Hour + ", , ";
                //Console.Write("line: " + line);

                //Console.Write("{");
                //foreach (var pq in det.PriceQuantityPairs.OrderBy(b => b.Position))
                //{
                //    Console.Write("(" + pq.Price + "," + pq.Quantity + ")");
                //}
                //Console.Write("},{");
                //foreach (var rr in det.RRDetails.OrderBy(b => b.Position))
                //{
                //    Console.Write("(" + rr.RRQuantity + "," + rr.RRUp + "," + rr.RRDown + ")");
                //}
                //Console.Write("}, " + det.ReserveLoadingPoint);

                Console.WriteLine("" + det.Market);
            }
        }
Exemplo n.º 2
0
        public ActionResult ToggleAppSetting(String description, String value)
        {
            var context = new TBSPEntities1();
            var appSettings = context.AppSettings.Where(a => a.Description == description).Take(1).First();

            if (description.Equals("BackgroundQueueEnabled") && value.Equals("TRUE"))
            {
                appSettings.Value = "TRUE";
                SchedulerConfig.TmxGasJob.Resume();
                SchedulerConfig.ForexJob.Resume();
                SchedulerConfig.MyWeatherJob.Resume();
                SchedulerConfig.PlantStatusJob.Resume();
            }
            else if (description.Equals("BackgroundQueueEnabled") && !value.Equals("TRUE"))
            {
                appSettings.Value = "FALSE";
                SchedulerConfig.TmxGasJob.Resume();
                SchedulerConfig.ForexJob.Resume();
                SchedulerConfig.MyWeatherJob.Resume();
                SchedulerConfig.PlantStatusJob.Resume();
            }
            else
            {
                appSettings.Value = value;
            }
            context.SaveChanges();

            return RedirectToAction("Index");
        }
Exemplo n.º 3
0
        public static void Process()
        {
            var content = new WebClient().DownloadString(
                "http://www.myweather2.com/developer/weather.ashx?uac=8ToQyyAfU9&uref=ca4d4474-8194-43b2-b161-3a8f02fe756f");

            XDocument xdoc = XDocument.Parse(content);

            var db = new TBSPEntities1();

            var fcs = xdoc.Descendants("forecast").Select(fc => new WeatherForecastSummary()
            {
                // Date Values
                ForecastDate = Convert.ToDateTime(fc.Element("date").Value),
                TempUnit = fc.Element("temp_unit").Value,
                DayMaxTemp = Int32.Parse(fc.Element("day_max_temp").Value),
                NightMinTemp = Int32.Parse(fc.Element("night_min_temp").Value),

                // Day Values
                DayWeatherText = fc.Descendants("day").First().Element("weather_text").Value,
                DayWeatherCode = fc.Descendants("day").First().Element("weather_code").Value,
                DayPrecipMm = fc.Descendants("day").First().Element("precip_mm").Value,
                DayCloudCover = fc.Descendants("day").First().Element("cloudcover").Value,
                DayHumidity = fc.Descendants("day").First().Element("humidity").Value,
                DayVisibilityKm = fc.Descendants("day").First().Element("visibility_km").Value,
                DayPressureMb = fc.Descendants("day").First().Element("pressure_mb").Value,

                // Day Wind Values
                DayWindSpeed = fc.Descendants("day").Descendants("wind").First().Element("speed").Value,
                DayWindDir = fc.Descendants("day").Descendants("wind").First().Element("dir").Value,
                DayWindDirDegree = fc.Descendants("day").Descendants("wind").First().Element("dir_degree").Value,
                DayWindUnit = fc.Descendants("day").Descendants("wind").First().Element("wind_unit").Value,

                // Night Values
                NightWeatherText = fc.Descendants("night").First().Element("weather_text").Value,
                NightWeatherCode = fc.Descendants("night").First().Element("weather_code").Value,
                NightPrecipMm = fc.Descendants("night").First().Element("precip_mm").Value,
                NightCloudCover = fc.Descendants("night").First().Element("cloudcover").Value,
                NightHumidity = fc.Descendants("night").First().Element("humidity").Value,
                NightVisibilityKm = fc.Descendants("night").First().Element("visibility_km").Value,
                NightPressureMb = fc.Descendants("night").First().Element("pressure_mb").Value,

                // Night Wind Values
                NightWindSpeed = fc.Descendants("night").Descendants("wind").First().Element("speed").Value,
                NightWindDir = fc.Descendants("night").Descendants("wind").First().Element("dir").Value,
                NightWindDirDegree = fc.Descendants("night").Descendants("wind").First().Element("dir_degree").Value,
                NightWindUnit = fc.Descendants("night").Descendants("wind").First().Element("wind_unit").Value,

                WeatherForecastSummaryId = Guid.NewGuid(),
                CreatedDateTime = DateTime.Now,
                CreatedBy = "TCPL\\jon_gaudette",
            });

            db.WeatherForecastSummaries.AddRange(fcs);

            db.SaveChanges();
        }
Exemplo n.º 4
0
        //
        // GET: /Admin/AMS/
        public ActionResult Index()
        {
            var context = new TBSPEntities1();

            ViewBag.appSettings = context.AppSettings.ToList();

            ViewBag.GasJob = SchedulerConfig.TmxGasJob;
            ViewBag.ForexJob = SchedulerConfig.ForexJob;
            ViewBag.MyWeatherJob = SchedulerConfig.MyWeatherJob;
            ViewBag.PlantStatusJob = SchedulerConfig.PlantStatusJob;

            return View();
        }
Exemplo n.º 5
0
        public static void Register(HttpConfiguration config)
        {
            Scheduler = new Scheduler();
            TmxGasJob = new Job();
            ForexJob = new Job();
            MyWeatherJob = new Job();
            PlantStatusJob = new Job();

            TmxGasJob.Run.From(DateTime.Now).Every.Hours(1);
            ForexJob.Run.From(DateTime.Now).Every.Hours(1);
            MyWeatherJob.Run.From(DateTime.Now).Every.Days(1);
            PlantStatusJob.Run.From(DateTime.Now).Every.Minutes(5);

            TmxGasJob.Pause();
            ForexJob.Pause();
            MyWeatherJob.Pause();
            PlantStatusJob.Pause();

            Scheduler.SubmitJob(TmxGasJob, p => GasIndexDownloader.Process());
            Scheduler.SubmitJob(ForexJob, p => ForexDownloader.Process());
            Scheduler.SubmitJob(TmxGasJob, p => MyWeatherDownloader.Process());
            Scheduler.SubmitJob(PlantStatusJob, p => PlantStatusDownloader.Process());

            var context = new TBSPEntities1();
            IQueryable<AppSetting> backgroundEnabled = (context.AppSettings.Where(
                appSetting => appSetting.Description == "BackgroundQueueEnabled")
                ).Take(1);

            if (!backgroundEnabled.Any()) throw new Exception("Unable to find background queue config");

            if (!backgroundEnabled.First().Value.ToUpper().Equals("TRUE"))
            {
                TBSPLogger.Info("SchedulerConfig", "Skipping Background Jobs");
            }
            else
            {
                TBSPLogger.Info("SchedulerConfig", "Starting Background Jobs");

                TmxGasJob.Resume();
                ForexJob.Resume();
                MyWeatherJob.Resume();
                PlantStatusJob.Resume();
            }
        }
Exemplo n.º 6
0
        public static void Process()
        {
            TBSPLogger.Info("FOREX_DOWNLOADER", "Starting Forex Downloader");

            var content = new WebClient().DownloadString("https://openexchangerates.org/api/latest.json?app_id=ce4bccb12160472d8124e387e717bfd4");

            JObject exchangeRates = JObject.Parse(content);
            TBSPLogger.Info("FOREX_DOWNLOADER", "Canadian is: " + exchangeRates["rates"]["CAD"] + " USD");

            var context = new TBSPEntities1();

            var nForex = new Forex
            {
                ForexId = Guid.NewGuid(),
                Currency = "CAD",
                CurrencyRate = Decimal.Parse(exchangeRates["rates"]["CAD"].ToString()),
                CreatedBy = "TCPL\\jon_gaudette",
                ConversionFromCurrency = exchangeRates["base"].ToString(),
                CurrencyRateDateTime = UnixTimeStampToDateTime(Convert.ToInt64(exchangeRates["timestamp"].ToString())),
                CreatedDateTime = DateTime.Now
            };

            // Retrieve the latest record to ensure no duplicates.  Query within LINQ for performance.
            var maxRecord = (from f in context.Forexes
                where
                    f.CurrencyRateDateTime ==
                    (from forex0 in context.Forexes
                        select new
                        {
                            forex0.CurrencyRateDateTime
                        }).Max(p => p.CurrencyRateDateTime)
                select f);

            if (maxRecord.Any() && nForex.CurrencyRate.Equals(maxRecord.First().CurrencyRate))
            {
                TBSPLogger.Info("FOREX_DOWNLOADER", "Already inserted latest record");
            }
            else
            {
                context.Forexes.Add(nForex);
                context.SaveChanges();
            }
        }
Exemplo n.º 7
0
        public static void Process()
        {
            var b = new BrowserSession();
            b.Get("https://secure.ngx.com/ngxcs/indexPrice/scrape.html");
            b.FormElements["username"] = "******";
            b.FormElements["password"] = "******";

            string response = b.Post("https://secure.ngx.com/sso/login?service=https%3A%2F%2Fsecure.ngx.com%3A443%2Fngxcs%2Fj_spring_cas_security_check");
            var doc = new HtmlDocument();

            doc.LoadHtml(response);

            var db = new TBSPEntities1();

            var gasIndexes = GetGasIndexFromResult(doc, "Union Dawn");
            if (gasIndexes != null && gasIndexes.Any()) db.TMXGasIndexes.AddRange(gasIndexes);

            db.SaveChanges();
        }
        public static void Process()
        {
            var client = new DEXWebServiceSoapClient();

            if (client.ClientCredentials != null)
            {
                client.ClientCredentials.UserName.UserName = "******";
                client.ClientCredentials.UserName.Password = "******";
            }

            var plantData = client.retreiveData("HHSPP_DASHBOARD_snap", null);

            var plantDataList = (from DataRow aPiDataRow in plantData.Rows
                where ValidatePiDataRow(aPiDataRow)
                select new PlantStatus
                {
                    PlantStatusId = Guid.NewGuid(),
                    GeneratorId = Guid.Parse("1C6CBB34-B972-4F66-926B-A8D25B1DFD49"),
                    Name = aPiDataRow["name"].ToString(),
                    BeginDateTime = DateTime.Parse(aPiDataRow["begin_datetime"].ToString()),
                    DataQualityValue = aPiDataRow["data_quality"].ToString(),
                    EngineeringUnits = aPiDataRow["engineering_units"].ToString(),
                    CreatedBy = "TCPL\\jon_gaudette",
                    Interval = aPiDataRow["interval"].ToString(),
                    AggregationValue = aPiDataRow["aggregation"].ToString(),
                    CreatedDateTime = DateTime.Now,
                    ScadaValue = aPiDataRow["value"].ToString()
                }).ToList();

            if (plantDataList.Any())
            {
                Console.WriteLine("Inserting {0} rows", plantDataList.Count);

                var db = new TBSPEntities1();
                db.PlantStatuses.AddRange(plantDataList);
                db.SaveChanges();

            }
        }
Exemplo n.º 9
0
        public ActionResult History(string bidfileid)
        {
            var context = new TBSPEntities1();

            var yestBids = (from bf in context.BidFiles orderby bf.CreatedDateTime descending select bf).Take(48);
            ViewBag.BidHistory = yestBids;

            if (bidfileid != null)
            {
                var bididguid = Guid.Parse(bidfileid);

                var bidDetail = from bid in context.BidFileDetails
                    where bid.BidFileId.Equals(bididguid)
                    orderby bid.Hour, bid.ResourceId, bid.BidType, bid.MarketType
                    select bid;

                ViewBag.BidDetail = bidDetail;
                ViewBag.BidFileId = bididguid;
            }

            return View();
        }
Exemplo n.º 10
0
        /***
         * Parse a fil with BidFile properties passed
         */
        public static BidFile ParseFile(BidFile bf, String filename)
        {
            String content = File.ReadAllText(filename);

            String header2 = "";

            String header1Match = "PM, (.*), (.*), TCE, APITCE01, , (.*);";
            String header2Match = @"((.*),\s*,* (.*), (.*), , (.*), (.*), (.*);)|((.*), (.*),\s+, (.*), (.*), (.*);)";
            String bodyMatch = @"(\d+(-)*\d*).*({.*})+,+(.*);";
            String mPqrr = @"({.*})";

            var applicationType = "";
            var marketType = "";
            var deliveryDate = "";
            var participantId = "";
            var userId = "";
            var mode = "";

            var bidType = "";
            var resourceId = "";
            var reserveClass = "";
            var opresRampRate = "";
            var cancelFlag = "";

            var bids = new List<BidFileDetail>();
            var pwpslist = new List<PriceQuantityPair>();
            var rrlist = new List<RRDetail>();

            foreach (var line in content.Split('\n'))
            {
                Match mHeader1 = Regex.Match(line, header1Match);
                Match mHeader2 = Regex.Match(line, header2Match);
                Match mBody = Regex.Match(line, bodyMatch);
                Match pqrrMatch = Regex.Match(line, mPqrr);
                var hourRange = "";

                if (mHeader1.Success)
                {

                    applicationType = "PM";
                    marketType = mHeader1.Groups[1].ToString();
                    deliveryDate = mHeader1.Groups[2].ToString();
                    participantId = "TCE";
                    userId = "APITCE01";
                    mode = mHeader1.Groups[3].ToString();

                    bidType = "";
                    resourceId = "";
                    reserveClass = "";
                    opresRampRate = "";
                    cancelFlag = "";
                }
                else if (mHeader2.Success)
                {
                    bidType = mHeader2.Groups[2].Value;
                    if (!bidType.Equals(""))
                    {
                        resourceId = mHeader2.Groups[3].ToString();
                        opresRampRate = mHeader2.Groups[5].ToString();
                        cancelFlag = mHeader2.Groups[6].ToString();
                    }
                    else
                    {
                        bidType = mHeader2.Groups[9].ToString();
                        resourceId = mHeader2.Groups[10].ToString();
                        reserveClass = mHeader2.Groups[11].ToString();
                        cancelFlag = mHeader2.Groups[12].ToString();
                    }

                }
                else if (mBody.Success)
                {
                    // ReSharper disable once SuggestUseVarKeywordEvident
                    BidFileDetail t = new BidFileDetail();

                    // Header 1 Info
                    t.BidFileId = bf.BidFileId;
                    t.ApplicationType = applicationType;
                    t.MarketType = marketType;
                    t.DeliveryDate = deliveryDate;
                    t.ParticipantId = participantId;
                    t.UserId = userId;
                    t.Mode = mode;

                    // Header 2 info
                    t.BidFileDetailId = Guid.NewGuid();
                    t.BidType = bidType;
                    t.ResourceId = resourceId;
                    t.OpresRampRate = opresRampRate;
                    t.CancelFlag = cancelFlag;
                    t.ReserveClass = reserveClass;

                    // Bid Body Info
                    hourRange = mBody.Groups[1].Value;

                    var pqps = pqrrMatch.Groups[1].Value;
                    t.ReserveLoadingPoint = mBody.Groups[4].Value;

                    // If the value in ReserveLoadingPoint at this point is just
                    // a comma, we know that there was no reserve loading point.
                    if (t.ReserveLoadingPoint.Contains(","))
                    {
                        t.ReserveLoadingPoint = null;
                    }

                    // Misc System properties
                    t.CreatedBy = "TCPL\\jon_gaudette";
                    t.CreatedDateTime = DateTime.Now;

                    /*
                     * If the hourRange contains a hyphen we need to seperate out each hour into their own
                     * records, to ensure we have 24 hours of data for each category.  Everythign will be
                     * identical with the exception of the GUID and Hour.
                     */
                    if (hourRange.Contains("-"))
                    {
                        var from = Int32.Parse(hourRange.Split('-')[0]);
                        var to = Int32.Parse(hourRange.Split('-')[1]);

                        for (var i = from; i <= to; i++)
                        {
                            var bfd = new BidFileDetail
                            {
                                BidFileDetailId = Guid.NewGuid(),
                                BidFileId = bf.BidFileId,
                                Hour = i,
                                ApplicationType = t.ApplicationType,
                                MarketType = t.MarketType,
                                DeliveryDate = t.DeliveryDate,
                                ParticipantId = t.ParticipantId,
                                UserId = t.UserId,
                                Mode = t.Mode,
                                BidType = t.BidType,
                                ResourceId = t.ResourceId,
                                OpresRampRate = t.OpresRampRate,
                                CancelFlag = t.CancelFlag,
                                ReserveClass = t.ReserveClass,
                                ReserveLoadingPoint = t.ReserveLoadingPoint,
                                CreatedBy = "TCPL\\jon_gaudette",
                                CreatedDateTime = DateTime.Now,
                            };

                            DetectAndParsePairs(pqps, bfd, pwpslist, rrlist);
                            bids.Add(bfd);
                        }

                    }
                    else
                    {
                        t.Hour = Int32.Parse(hourRange);

                        DetectAndParsePairs(pqps, t, pwpslist, rrlist);
                        bids.Add(t);
                    }
                }
            }

            // Write our entity objects to the database.
            var db = new TBSPEntities1();
            db.BidFiles.Add(bf);
            db.BidFileDetails.AddRange(bids);
            db.PriceQuantityPairs.AddRange(pwpslist);
            db.RRDetails.AddRange(rrlist);
            db.SaveChanges();

            return bf;
        }