Exemplo n.º 1
0
        public double ReadValue(IndicatorData data, DebugState debugState)
        {
            if (TryFindCircleInFullFrame(data, out var circle))
            {
                var focus = data.Frame.Copy(Math2.CropCircle(circle, 10));
                debugState.Add(focus);

                List <double> ret = new List <double>();
                foreach (var line in GetLinesFromFocusImage(focus, circle, debugState))
                {
                    CvInvoke.Line(focus, line.P1, line.P2, new Bgr(Color.Yellow).MCvScalar, 2);

                    var knots = ReadKnotsFromNeedleLine(line);

                    if (IsValueInExpectedRange(knots))
                    {
                        ret.Add(knots);
                    }
                }

                return(CalculateResultFromAllResults(ret, debugState));
            }
            else
            {
                debugState.SetError("No circles");
            }
            return(double.NaN);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutIndicatorData([FromRoute] int id, [FromBody] IndicatorData indicatorData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != indicatorData.ID)
            {
                return(BadRequest());
            }

            _context.Entry(indicatorData).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!IndicatorDataExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 3
0
        public async Task <IEnumerable <IndicatorData> > GetScrape()
        {
            string jsonData = "";
            string url      = "http://localhost:3000/api/v1/scraper/week/this";

            url = "https://nestjs-scrape.azurewebsites.net/api/scraper/week/this";

            using (var client = new HttpClient())
            {
                try
                {
                    jsonData = await client.GetStringAsync(url);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            JObject              calendar = JObject.Parse(jsonData);
            List <JToken>        results  = calendar["calendarData"].Children().ToList();
            List <IndicatorData> recs     = new List <IndicatorData>();

            foreach (JToken result in results)
            {
                // JToken.ToObject is a helper method that uses JsonSerializer internally
                IndicatorData rec = result.ToObject <IndicatorData>();
                recs.Add(rec);
            }

            var recsUpd = _repository.BulkUpdate(recs);

            return(recsUpd);
        }
Exemplo n.º 4
0
        public double ReadValue(IndicatorData data, DebugState debugState)
        {
            if (TryFindRollCircleInFullFrame(data, out CircleF rollIndicatorCicle))
            {
                var FocusRect = Math2.CropCircle(rollIndicatorCicle, 10);
                var focus     = data.Frame.SafeCopy(FocusRect);

                debugState.Add(focus);

                // Isolate the outside ring
                Mat maskInnerAlt = new Mat(focus.Size, DepthType.Cv8U, 3);
                maskInnerAlt.SetTo(new MCvScalar(1));
                CvInvoke.Circle(maskInnerAlt, new Point(focus.Size.Width / 2, focus.Size.Height / 2), (int)(rollIndicatorCicle.Radius - (rollIndicatorCicle.Radius * 0.2)), new Bgr(Color.White).MCvScalar, -1);
                CvInvoke.Circle(maskInnerAlt, new Point(focus.Size.Width / 2, focus.Size.Height / 2), (int)(rollIndicatorCicle.Radius - (rollIndicatorCicle.Radius * 0.275)), new Bgr(Color.Black).MCvScalar, -1);

                var outerMovingRingOnly          = focus.Copy(maskInnerAlt.ToImage <Gray, byte>());
                var outerMovingRingWithoutBottom = outerMovingRingOnly.Copy(new Rectangle(0, 0, outerMovingRingOnly.Width, (int)(outerMovingRingOnly.Height))); // - (outerMovingRingOnly.Height * 0.29)
                var ring_hsv_unfiltered          = outerMovingRingWithoutBottom.Convert <Hsv, byte>().InRange(new Hsv(20, 0, 85), new Hsv(180, 255, 255));
                var ring_hsv = Utils.RemoveBlobs(ring_hsv_unfiltered, 1, 500);

                debugState.Add(outerMovingRingOnly);
                debugState.Add(outerMovingRingWithoutBottom);
                debugState.Add(ring_hsv);
                debugState.Add(ring_hsv_unfiltered);

                return(ReadRollAngleFromRingImage(ring_hsv, focus, debugState));
            }
            else
            {
                debugState.SetError($"ROLL: Main circles");
            }
            return(double.NaN);
        }
Exemplo n.º 5
0
        public void BulkInsert()
        {
            var path  = @"C:\____projecrts\___dev_scrapers\data\jsondata";
            var files = Directory.GetFiles(path, "*.json");

            foreach (var file in files)
            {
                var      jsonData = File.ReadAllText(file);
                FileInfo finfo    = new FileInfo(file);
                Console.Write(finfo.Name);

                JObject               calendar = JObject.Parse(jsonData);
                IList <JToken>        results  = calendar["calendarData"].Children().ToList();
                IList <IndicatorData> recs     = new List <IndicatorData>();
                foreach (JToken result in results)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    IndicatorData rec = result.ToObject <IndicatorData>();
                    rec.CreateDate = DateTime.Now;
                    recs.Add(rec);
                }
                Console.Write(" recs:" + recs.Count());

                using (var ctx = new ntpContext())
                {
                    foreach (var rec in recs)
                    {
                        ctx.IndicatorData.Add(rec);
                    }
                    ctx.SaveChanges();
                }
                Console.WriteLine("  saved!");
                Console.WriteLine();
            }
        }
Exemplo n.º 6
0
        public async Task <List <IndicatorData> > GetRecs1()
        {
            List <IndicatorData> recs = new List <IndicatorData>();
            string url = "http://localhost:3000/api/v1/scraper/week/this";

            using (var client = new HttpClient())
            {
                string jsonData = "";
                try
                {
                    jsonData = await client.GetStringAsync(url);
                }
                catch (Exception ex)
                {
                    throw;
                }
                JObject       calendar = JObject.Parse(jsonData);
                List <JToken> results  = calendar["calendarData"].Children().ToList();

                foreach (JToken result in results)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    IndicatorData rec = result.ToObject <IndicatorData>();
                    recs.Add(rec);
                }

                jsonData = JsonConvert.SerializeObject(recs, Formatting.Indented);
                Console.WriteLine(jsonData);
            }
            return(recs);
        }
 public static string ToCsv(this IndicatorData rec)
 {
     return(string.Format("{0},{1},{2},{3},{4}",
                          rec.ReleaseDateTime,
                          rec.Currency,
                          rec.Indicator,
                          rec.ReleaseDate,
                          rec.ReleaseTime));
 }
        private static readonly string AlphaVantageAPIKey = "";         //insert yoyr key here

        static void Main(string[] args)
        {
            Console.WriteLine("Insert stock symbol: ");

            string stkSymbol = Console.ReadLine();

            MarketData stock = AlphaVantage.Stock(stkSymbol, AVTimeSeries.Stock_Daily, AVOutputSize.compact, AlphaVantageAPIKey);

            Console.WriteLine(Environment.NewLine + "Symbol: {0}, Currency: {1}", stock.Symbol, stock.Currency + Environment.NewLine);

            foreach (var item in stock.Bars)
            {
                Console.WriteLine("Date:{0},Open:{1},High:{2},Low:{3},Close:{4},Volume:{5}", item.Key.ToString("dd/MM/yyyy"), item.Value.open, item.Value.high, item.Value.low, item.Value.close, item.Value.volume);
            }



            Console.WriteLine(Environment.NewLine + "----------------------------------------" + Environment.NewLine + "Insert cryptocurrency symbol");

            string ccSymbol = Console.ReadLine();

            MarketData crypto = AlphaVantage.Digital_Currency(ccSymbol, "USD", AVTimeSeries.Digital_Currency_Daily, AlphaVantageAPIKey);

            Console.WriteLine(Environment.NewLine + "Symbol: {0}, Currency: {1}", crypto.Symbol, crypto.Currency + Environment.NewLine);

            foreach (var item in stock.Bars)
            {
                Console.WriteLine("Date:{0},Open:{1},High:{2},Low:{3},Close:{4},Volume:{5}", item.Key.ToString("dd/MM/yyyy"), item.Value.open, item.Value.high, item.Value.low, item.Value.close, item.Value.volume);
            }


            Console.WriteLine(Environment.NewLine + "----------------------------------------" + Environment.NewLine + "Indicator example");

            IndicatorData indicator = AlphaVantage.Indicator(new BasicIndicator("DEMA"), "MSFT", AVInterval.Daily, AVSeriesType.close, AlphaVantageAPIKey);

            Console.WriteLine(Environment.NewLine + "Indicator: {0}, Interval: 30, Symbol: MSFT" + Environment.NewLine, indicator.name);

            int i = 0;

            foreach (var item in indicator.Values)
            {
                Console.WriteLine("Date:{0}, Value:{1}", item.Key.ToString("dd/MM/yyyy"), item.Value[0].Value);

                i++;

                if (i >= 25)
                {
                    break;
                }
            }

            Console.ReadLine();
        }
Exemplo n.º 9
0
        public async Task <IActionResult> PostIndicatorData([FromBody] IndicatorData indicatorData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.IndicatorDatas.Add(indicatorData);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetIndicatorData", new { id = indicatorData.ID }, indicatorData));
        }
Exemplo n.º 10
0
        private static void IndicatorScannerSerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            var strMessage = mIndicatorScannerSerialPort.ReadString();

            if (strMessage == string.Empty || strMessage == null)
            {
                return;
            }

            Debug.Print("The type of data expected is: " + mMenu.DataRecieved.GetName());
            Debug.Print("Data contents recieved from the Serial Port:\r\n" + strMessage);
            switch (mMenu.DataRecieved)
            {
            case RecievedData.ScaleIndicator:
                var objIndicatorData = new IndicatorData(strMessage);

                if (objIndicatorData.HasValidDataString)
                {
                    Debug.Print("Valid Data was sent from the Indicator...");
                    Settings.NetWeight = objIndicatorData.NetWeight;
                    if (mMenu.MenuSelection == MenuSelection.ViewPieceCount)
                    {
                        mMenu.DisplayInformation(Settings);
                    }
                    else
                    {
                        /*A new thread must be started in order for the WebGet function to work properly; otherwise WebGet(objIndicatorData) would just silently fail...
                         * http://www.codeproject.com/Articles/795829/Multithreading-with-Netduino-and-NET-Microframework
                         * https://www.youtube.com/watch?v=YZOrORB88-s */
                        var DataRequestThread = new Thread(delegate() { WebGet(objIndicatorData); });
                        DataRequestThread.Start();
                    }
                }


                break;

            case RecievedData.ScannerJobAndSuffix:
                Settings.JobNumber = strMessage;
                Settings.StoreJobNumber();
                mMenu.DataRecieved = RecievedData.None;
                mMenu.DisplayInformation(Settings);
                break;

            case RecievedData.ScannerOperation:
                Settings.Operation = strMessage;
                Settings.StoreOperationNumber();
                mMenu.DataRecieved = RecievedData.None;
                mMenu.DisplayInformation(Settings);
                break;
            }
        }
Exemplo n.º 11
0
        public static void WebGet(IndicatorData objIndicatorData)
        {
            try
            {
                var URL = Settings.ShopTrakTransactionsURL.SetParameters(new string[] { Settings.Job, Settings.Suffix.ToString(), Settings.Operation.ToString() });
                Debug.Print("WebGet URL is: " + URL);
                var objURI    = new Uri(URL);
                var webClient = new HTTP_Client(new IntegratedSocket(objURI.Host, (ushort)objURI.Port));
                var response  = webClient.Get(objURI.AbsolutePath);

                Debug.Print("Data recieved from URL is:\r\n" + response.ResponseBody);
                if (response.ResponseCode != 200) // Did we get the expected response? (a "200 OK")
                {
                    throw new ApplicationException("HTTP Response: " + response.ResponseCode.ToString());
                }
                else if (response.ResponseBody == "[]") //Does the REST Dataset return empty?
                {
                    throw new ApplicationException("Nobody punched in that Job.");
                }


                ArrayList arrayList = JsonSerializer.DeserializeString(response.ResponseBody) as ArrayList;
                Hashtable hashtable = arrayList[0] as Hashtable; //get the first row of records

                //Microsoft.SPOT.Time.TimeService.SetTimeZoneOffset(300);
                Settings.PrintDateTime = DateTimeExtensions.FromASPNetAjax(hashtable["CurrentDateTime"].ToString()).AddHours(-5);//Central Time Zone has 5 hour offset from UTC
                Settings.Item          = hashtable["item"].ToString();

                StringBuilder strBldrEmployees = new StringBuilder();
                for (int intCounter = 0; intCounter < arrayList.Count; intCounter++) //iterate over all the rows to get the employees that are punched into the jobs
                {
                    hashtable = arrayList[intCounter] as Hashtable;
                    strBldrEmployees.Append(hashtable["emp_num"].ToString().Trim() + ",");
                }
                strBldrEmployees.Remove(strBldrEmployees.ToString().LastIndexOf(","), 1); //remove the last comma from the string
                Settings.Employees = strBldrEmployees.ToString();


                //Instantiate my label so that I can populate the Format property with the value pulled from the SDCard.
                var objLabel = new Label(new string[] { Settings.Item, Settings.JobNumber, Settings.OperationNumber.ToString("D3"), Settings.Employees,
                                                        Settings.PieceCount.ToString("N"), Settings.PrintDateTime.ToString("MM/dd/yy h:mm:ss tt"), Settings.PrintDateTime.ToString("dddd") });
                objLabel.LabelFormat = Settings.LabelFormat;
                Debug.Print("Data written to printer serial port is:\r\n" + objLabel.LabelText);
                mPrinterSerialPort.WriteString(objLabel.LabelText);
            }
            catch (Exception objEx)
            {
                Debug.Print("Exception caught in WebGet()\r\n");
                Debug.Print(objEx.Message);
                mMenu.DisplayError(objEx);
            }
        }
Exemplo n.º 12
0
        public double ReadValue(IndicatorData data, DebugState debugState)
        {
            if (TryFindCircleInFullFrame(data, out var circle))
            {
                var focus       = data.Frame.SafeCopy(Math2.CropCircle(circle, 15));
                var vs_blackimg = focus.Convert <Hsv, byte>().DynLowInRange(dyn_lower, new Hsv(180, 255, 255));

                debugState.Add(focus);
                debugState.Add(vs_blackimg);

                int margin     = 10;
                var vspeedMask = new Mat(focus.Size, DepthType.Cv8U, 3);
                vspeedMask.SetTo(new MCvScalar(1));
                CvInvoke.Circle(vspeedMask, Point.Round(new PointF(circle.Radius + margin, circle.Radius + margin)), (int)(circle.Radius - (circle.Radius * 0.1)), new Bgr(Color.White).MCvScalar, -1);
                vs_blackimg = vs_blackimg.Copy(vspeedMask.ToImage <Gray, byte>());

                var vspeed_inner_only = vs_blackimg.Copy(new Rectangle(0, 0, vs_blackimg.Width / 2, vs_blackimg.Height));

                debugState.Add(vspeed_inner_only);

                Rectangle center = GetCenterBoxFromImage(focus);
                foreach (var line in CvInvoke.HoughLinesP(vspeed_inner_only, 1, Math.PI / 45.0, 20, 20, 14))
                {
                    if (center.Contains(line.P1) || center.Contains(line.P2))
                    {
                        CvInvoke.Line(focus, line.P1, line.P2, new Bgr(Color.Yellow).MCvScalar, 2);

                        LineSegment2D needleLine;
                        if (center.Contains(line.P1))
                        {
                            needleLine = new LineSegment2D(line.P2, line.P1);
                        }
                        else
                        {
                            needleLine = new LineSegment2D(line.P1, line.P2);
                        }

                        var angle = (Math2.GetPolarHeadingFromLine(needleLine) - 270);
                        // bias up to account for skew
                        angle += 2.75;

                        if (line.Length > 63)
                        {
                            debugState.SetError($"Rejected length: {line.Length}");
                        }
                        return(angle);
                    }
                }
            }
            return(double.NaN);
        }
Exemplo n.º 13
0
        private async void OnSelectionChangedAsync(SelectionChangedEventArgs eventArgs)
        {
            IList addedItems = eventArgs.AddedItems;

            if (addedItems.Count == 1)
            {
                SelectedIndicator = addedItems.OfType <IIndicatorViewModel>().FirstOrDefault();
                IndicatorData.Clear();
                Debug.Assert(SelectedIndicator != null, nameof(SelectedIndicator) + " != null");
                IndicatorDataFetcher indicatorDataFetcher = new IndicatorDataFetcher();
                foreach (WHOStatistics statistics in (await indicatorDataFetcher.GetWHOStatistics(SelectedIndicator.Indicator)).Items)
                {
                    IndicatorData.Add(new IndicatorDataRowViewModel(statistics.Value, statistics.Year, statistics.Sex, statistics.Country, statistics.Region, statistics.IsPublished));
                }
            }
        }
Exemplo n.º 14
0
        public static bool TryFindRollCircleInFullFrame(IndicatorData data, out CircleF ret)
        {
            ret = default(CircleF);

            if (Timeline.Data[data.Id].Roll.ForIndicatorUse != null)
            {
                // We found our own hint, return it.
                ret = (CircleF)Timeline.Data[data.Id].Roll.ForIndicatorUse;
                return(true);
            }

            var localRect = MovementRect;

            if (data.Id > 0 &&
                Timeline.Data[data.Id - 1] != null &&
                Timeline.Data[data.Id - 1].Roll != null &&
                Timeline.Data[data.Id - 1].Roll.ForIndicatorUse != null)
            {
                // Our hint from last time.
                localRect = Math2.CropCircle((CircleF)Timeline.Data[data.Id - 1].Roll.ForIndicatorUse, 10);
            }

            // Crop and blur
            var cropped_frame = data.Frame.SafeCopy(localRect).PyrUp().PyrDown();

            var MovementFrameGray = new Mat();

            CvInvoke.CvtColor(cropped_frame, MovementFrameGray, ColorConversion.Bgr2Gray);

            // Locate the attitude and possibly vertical speed indicators.
            var circles = CvInvoke.HoughCircles(MovementFrameGray, HoughType.Gradient, 2.0, 20, 10, 180, 60, 80);

            if (circles.Length == 0)
            {
                // Couldn't find initial circle
                return(false);
            }

            // Pick the topmost circle and crop.
            var rollIndicatorCicle = circles.OrderBy(c => c.Center.Y).First();

            rollIndicatorCicle.Radius = 64;
            rollIndicatorCicle.Center = rollIndicatorCicle.Center.Add(localRect.Location);
            ret = rollIndicatorCicle;
            Timeline.Data[data.Id].Roll.ForIndicatorUse = ret;
            return(true);
        }
Exemplo n.º 15
0
        public double Tick(IndicatorData data)
        {
            DebugState ds = new DebugState();

            Value = _indicator.ReadValue(data, ds);
            Image = ds.Get(10);

            if (double.IsNaN(Value))
            {
                BadFrames.Add(data.Id);
            }
            else
            {
                Counter.GotFrame();
            }
            return(Value);
        }
Exemplo n.º 16
0
        public double ReadValue(IndicatorData data, DebugState debugState)
        {
            if (TryFindCircleInFullFrame(data, out var circ))
            {
                var focusRect            = Math2.CropCircle(circ, 15);
                var focus                = data.Frame.SafeCopy(focusRect);
                var focusHsv             = focus.Convert <Hsv, byte>();
                var focusHsvText         = focusHsv.DynLowInRange(dyn_lower, new Hsv(180, 255, 255));
                var focusHsvTriangleMask = focusHsv.InRange(new Hsv(0, 0, 0), new Hsv(180, 140, 255));
                var focusHsvTextOnly     = focusHsvText.Copy(focusHsvTriangleMask);

                debugState.Add(focus);

                var blobs = Utils.DetectAndFilterBlobs(focusHsvTextOnly, 25, 250).
                            Where(b => b.Centroid.Y >= 5).OrderByDescending(b => b.Area).Take(4);

                var focusHsvOnlyBlobs = Utils.RemoveAllButBlobs(focusHsvTextOnly, blobs);
                debugState.Add(focusHsvOnlyBlobs);

                var parts = GetPacksFromImage(focusHsvOnlyBlobs, blobs, debugState);
                var ret   = ComputeHeadingFromPacks(data.Id, parts, focus, debugState);

                if (!double.IsNaN(ret))
                {
                    // Adjust now that N and S are near-vertical and the blobs are more regular.
                    ret = RefineAngle(ret, focusHsvOnlyBlobs);
                    // Adjust based on the dots on the glareshield.
                    ret += GetGlareShieldSkewAngle(focusRect, data, debugState);
                    // Add a fixed cab skew to account for the vertical perspective.
                    ret -= 1;

                    ret = Math2.ClampAngle(ret);

                    // Proof for the debug info.
                    debugState.Add(focus.Rotate(ret, new Bgr(0, 0, 0)));

                    return(CheckResultValidity(ret, data.Id));
                }
            }
            else
            {
                debugState.SetError("Couldn't find initial circle.");
            }
            return(double.NaN);
        }
        public async Task <IEnumerable <IndicatorData> > GetScrape()
        {
            string               url      = "http://localhost:3000/api/v1/scraper/week/this";
            string               jsonData = CallRestMethod(url);
            JObject              calendar = JObject.Parse(jsonData);
            List <JToken>        results  = calendar["calendarData"].Children().ToList();
            List <IndicatorData> recs     = new List <IndicatorData>();

            foreach (JToken result in results)
            {
                // JToken.ToObject is a helper method that uses JsonSerializer internally
                IndicatorData rec = result.ToObject <IndicatorData>();
                recs.Add(rec);
            }

            var recsUpd = _repository.BulkUpdate(recs);

            return(recsUpd);
        }
Exemplo n.º 18
0
        public void BulkUpdate()
        {
            string url      = "http://localhost:3000/api/scrape/week/this";
            string jsonData = CallRestMethod(url);

            JObject               calendar = JObject.Parse(jsonData);
            IList <JToken>        results  = calendar["calendarData"].Children().ToList();
            IList <IndicatorData> recs     = new List <IndicatorData>();

            foreach (JToken result in results)
            {
                // JToken.ToObject is a helper method that uses JsonSerializer internally
                IndicatorData rec = result.ToObject <IndicatorData>();
                recs.Add(rec);
            }

            using (var ctx = new ntpContext())
            {
                foreach (var rec in recs)
                {
                    var exist = ctx.IndicatorData.Where(r => r.EventId == rec.EventId).FirstOrDefault();
                    if (exist == null)
                    {
                        rec.CreateDate = DateTime.Now;
                        ctx.IndicatorData.Add(rec);
                    }
                    else
                    {
                        exist.ModifyDate      = DateTime.Now;
                        exist.Actual          = rec.Actual;
                        exist.Forecast        = rec.Forecast;
                        exist.Indicator       = rec.Indicator;
                        exist.Previous        = rec.Previous;
                        exist.ReleaseDate     = rec.ReleaseDate;
                        exist.ReleaseDateTime = rec.ReleaseDateTime;
                        exist.ReleaseTime     = rec.ReleaseTime;

                        ctx.Entry(exist).State = EntityState.Modified;
                    }
                }
                ctx.SaveChanges();
            }
        }
Exemplo n.º 19
0
        private static bool TryFindCircleInFullFrame(IndicatorData data, out CircleF ret)
        {
            ret = default(CircleF);

            if (RollIndicator.TryFindRollCircleInFullFrame(data, out var circle))
            {
                circle.Center = new PointF(circle.Center.X + 140, circle.Center.Y + 70);
                circle.Radius = 55;
                var firstCrop = Math2.CropCircle(circle, 10);
                var focus     = data.Frame.SafeCopy(firstCrop);

                var circles = CvInvoke.HoughCircles(focus.Convert <Hsv, byte>()[2], HoughType.Gradient, 2.0, 20, 10, 180, 45, 55);
                if (circles.Length == 1)
                {
                    circles[0].Center = circles[0].Center.Add(firstCrop.Location);
                    circles[0].Radius = 50;
                    ret = circles[0];
                    return(true);
                }
            }
            return(false);
        }
        public async Task <IEnumerable <IndicatorData> > DoScrape()
        {
            string jsonData = "";
            string url      = this._scrapeConfig.CalendarScrape.ScrapeUrl;

            using (var client = new HttpClient())
            {
                try
                {
                    jsonData = await client.GetStringAsync(url);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            JObject              calendar = JObject.Parse(jsonData);
            List <JToken>        results  = calendar["calendarData"].Children().ToList();
            List <IndicatorData> recs     = new List <IndicatorData>();

            foreach (JToken result in results)
            {
                // JToken.ToObject is a helper method that uses JsonSerializer internally
                IndicatorData rec = result.ToObject <IndicatorData>();
                recs.Add(rec);
            }

            if (this._scrapeConfig.CalendarScrape.BulkUpdate)
            {
                emailBody.AppendLine(string.Format("Begin update database {0} calendar records", recs.Count()));
                var recsUpd = _repository.BulkUpdate(recs);
                emailBody.AppendLine(string.Format("End   update database {0} calendar records", recs.Count()));
                return(recsUpd);
            }

            emailBody.AppendLine(string.Format("Scraped {0} calendar records no database update", recs.Count()));
            return(recs);
        }
Exemplo n.º 21
0
        public double ReadValue(IndicatorData data, DebugState debugState)
        {
            if (RollIndicator.TryFindRollCircleInFullFrame(data, out var circle))
            {
                var firstCrop = new Rectangle((int)circle.Center.X + 500, (int)circle.Center.Y - 180, 100, 150);
                var focus     = data.Frame.SafeCopy(firstCrop);

                var vs_blackImg = focus.Convert <Hsv, byte>().InRange(new Hsv(0, 120, 0), new Hsv(180, 255, 255));

                var blobs = Utils.DetectAndFilterBlobs(vs_blackImg.PyrUp().PyrDown(), 1500, 2500);
                if (blobs.Any())
                {
                    var landingGearFrame = focus.Copy(blobs.First().BoundingBox);

                    var hsv       = landingGearFrame.Convert <Hsv, byte>();
                    var black_img = hsv.DynLowInRange(dyn_lower, new Hsv(180, 255, 255));
                    debugState.Add(landingGearFrame);
                    debugState.Add(black_img);

                    blobs = Utils.DetectAndFilterBlobs(black_img, 200, 1500);
                    if (blobs.Any())
                    {
                        var blob = blobs.First();
                        var ret  = (landingGearFrame.Height / 2) - blob.Centroid.Y;

                        if (ret > 4)
                        {
                            return(1);
                        }
                        else if (ret < -4)
                        {
                            return(-1);
                        }
                    }
                }
            }
            return(double.NaN);
        }
Exemplo n.º 22
0
        private static bool TryFindCircleInFullFrame(IndicatorData data, out CircleF ret)
        {
            ret = default(CircleF);

            if (RollIndicator.TryFindRollCircleInFullFrame(data, out var circle))
            {
                circle.Center = new PointF(circle.Center.X + 1055, circle.Center.Y - 20);
                circle.Radius = 70;
                var firstCrop = Math2.CropCircle(circle, 40);
                var focus     = data.Frame.SafeCopy(firstCrop);
                var focusHsv  = focus.Convert <Hsv, byte>().PyrUp().PyrDown();

                var circles = CvInvoke.HoughCircles(focusHsv[2], HoughType.Gradient, 2.0, 80, 10, 80, 60, 80);
                if (circles.Length == 1)
                {
                    var circ = circles[0];
                    circles[0].Center = circles[0].Center.Add(firstCrop.Location);
                    circles[0].Radius = 64;
                    ret = circles[0];
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 23
0
        public double ReadValue(IndicatorData data, DebugState debugState)
        {
            if (TryFindCircleInFullFrame(data, out var circle))
            {
                var focus          = data.Frame.SafeCopy(Math2.CropCircle(circle, 15));
                var vs_blackimg    = focus.Convert <Hsv, byte>().DynLowInRange(dyn_lower, new Hsv(180, 255, 255)).PyrUp().PyrDown();
                var markedup_frame = vs_blackimg.Convert <Bgr, byte>();
                debugState.Add(focus);
                debugState.Add(vs_blackimg);
                debugState.Add(markedup_frame);

                var cannyEdges3 = new Mat();
                CvInvoke.Canny(vs_blackimg, cannyEdges3, 10, 120);
                Mat dialatedCanny = new Mat();
                CvInvoke.Dilate(cannyEdges3, dialatedCanny, null, new Point(-1, -1), 1, BorderType.Default, new Gray(0).MCvScalar);

                Rectangle center = GetCenterBoxFromImage(focus);
                CvInvoke.Rectangle(markedup_frame, center, new Bgr(Color.Red).MCvScalar, 1);

                var lines = CvInvoke.HoughLinesP(dialatedCanny, 1, Math.PI / 45.0, 20, 16, 0).OrderByDescending(l => l.Length);
                foreach (var line in lines)
                {
                    CvInvoke.Line(markedup_frame, line.P1, line.P2, new Bgr(Color.Red).MCvScalar, 1);

                    if (center.Contains(line.P1) || center.Contains(line.P2))
                    {
                        LineSegment2D needleLine;
                        if (center.Contains(line.P1))
                        {
                            needleLine = new LineSegment2D(line.P2, line.P1);
                        }
                        else
                        {
                            needleLine = new LineSegment2D(line.P1, line.P2);
                        }

                        var angle    = Math2.GetPolarHeadingFromLine(needleLine);
                        var hundreds = Math.Round((angle / 360) * 999);

                        CvInvoke.Line(focus, needleLine.P1, needleLine.P2, new Bgr(Color.Yellow).MCvScalar, 2);

                        var candidates = new List <double>();
                        for (var i = 0; i < 9; i++)
                        {
                            candidates.Add(hundreds + (i * 1000));
                        }

                        var ret = candidates.OrderBy(c => Math.Abs(c - Timeline.Altitude)).First();

                        if (!double.IsNaN(Timeline.Altitude))
                        {
                            var delta = Math.Abs(ret - Timeline.Altitude);
                            if (delta > 400)
                            {
                                debugState.SetError($"Bad value {delta} > 400");
                                return(double.NaN);
                            }
                        }
                        else
                        {
                            return(0);
                        }

                        return(ret);
                    }
                }
            }
            return(double.NaN);
        }
Exemplo n.º 24
0
        private double GetGlareShieldSkewAngle(Rectangle focusRect, IndicatorData data, DebugState debugState)
        {
            var topDotRect    = new Rectangle(focusRect.Left - 160, focusRect.Top - 5, 40, 40);
            var bottomDotRect = new Rectangle(focusRect.Left - 170, focusRect.Bottom - 40, 60, 40);

            var topPointBlobs    = GetDotLocationFromFullFrame(data.Frame, focusRect, topDotRect, isTop: true);
            var bottomPointBlobs = GetDotLocationFromFullFrame(data.Frame, focusRect, bottomDotRect, isTop: false);

            double a = double.NaN;

            if (topPointBlobs.Count > 0 && bottomPointBlobs.Count > 0)
            {
                var topPoint    = topPointBlobs.First().Centroid.Add(topDotRect.Location);
                var bottomPoint = bottomPointBlobs.First().Centroid.Add(bottomDotRect.Location);

                a = Math2.GetPolarHeadingFromLine(topPoint, bottomPoint);
                if (a > 180)
                {
                    a  = 360 - a;
                    a *= -1;
                }

                var lineRect = new Rectangle(focusRect.Left - 200, focusRect.Top - 50, 170, focusRect.Bottom + 50 - focusRect.Top);
                var lineImg  = data.Frame.Copy(lineRect);

                var topInLineImg    = new PointF(topPoint.X - lineRect.Location.X, topPoint.Y - lineRect.Location.Y);
                var bottomInLineImg = new PointF(bottomPoint.X - lineRect.Location.X, bottomPoint.Y - lineRect.Location.Y);

                var topRange = lineImg.Convert <Hsv, byte>(); //.InRange(new Hsv(HLow, SLow, VLow), new Hsv(HHigh, SHigh, VHigh));
                CvInvoke.Line(lineImg, topInLineImg.ToPoint(), bottomInLineImg.ToPoint(), new Bgr(Color.Yellow).MCvScalar, 1);
                debugState.Add(lineImg);
                debugState.Add(topRange);

                var dist = Math2.GetDistance(topPoint, bottomPoint);
                if (Math.Abs(a) > 8 || dist < 110 || dist > 120)
                {
                    var biasFrame = Timeline.LatestFrame(f => f.Heading.ForIndicatorUse == null ? double.NaN : ((ExtendedData)f.Heading.ForIndicatorUse).Bias, data.Id);
                    if (biasFrame != null)
                    {
                        a = ((ExtendedData)biasFrame.Heading.ForIndicatorUse).Bias;
                    }
                    else
                    {
                        debugState.SetError("Rejected due to dots angle out of bounds " + a);
                        return(double.NaN);
                    }
                }
            }
            else
            {
                var biasFrame = Timeline.LatestFrame(f => f.Heading.ForIndicatorUse == null ? double.NaN : ((ExtendedData)f.Heading.ForIndicatorUse).Bias, data.Id);
                if (biasFrame != null)
                {
                    a = ((ExtendedData)biasFrame.Heading.ForIndicatorUse).Bias;
                }
                else
                {
                    debugState.SetError("Rejected due to dots angle out of bounds " + a);
                    return(double.NaN);
                }
            }

            ((ExtendedData)Timeline.Data[data.Id].Heading.ForIndicatorUse).Bias = a;
            return(a / 2);
        }
 public IndicatorData Create(IndicatorData data)
 {
     throw new NotImplementedException();
 }
        public async Task <IActionResult> UploadExcel(UploadDynamicViewModel vm)
        {
            if (vm.File.Length <= 0)
            {
                return(BadRequest());
            }

            var fileSplit     = vm.File.FileName.Split(".");
            var fileExtension = fileSplit[fileSplit.Length - 1];

            Indicator indicator = null;

            var sourceFile = new SourceFile
            {
                OriginalName = vm.File.FileName
            };

            sourceFile.Name = $"{sourceFile.Name}.{fileExtension}";

            var path = Path.Combine(_hostingEnvironment.WebRootPath, "excels", sourceFile.Name);

            using (var stream = new FileStream(path, FileMode.Create))
            {
                vm.File.CopyTo(stream);
                stream.Position = 0;

                var fileName = String.Join(".", fileSplit.Skip(0).Take(fileSplit.Length - 1));

                if (fileName.Length > 4)
                {
                    if (fileName.Substring(0, 4) == "dti_")
                    {
                        fileName = fileName.Substring(4, fileName.Length - 4);
                    }
                }

                indicator = new Indicator
                {
                    Name        = fileName,
                    File        = sourceFile,
                    Description = ""
                };

                if (vm.FolderId > 0)
                {
                    indicator.ParentID = vm.FolderId;
                }

                _context.Indicators.Add(indicator);
                await _context.SaveChangesAsync();

                foreach (var sheet in GetSheet(vm.File, stream))
                {
                    var category = new Category
                    {
                        Name      = sheet.SheetName,
                        Indicator = indicator
                    };

                    _context.Categories.Add(category);
                    await _context.SaveChangesAsync();

                    IRow headerRow = sheet.GetRow(0);

                    var columns = await GetHeaderColumn(headerRow, sheet.GetRow(1), category);

                    var values = GetContents(sheet, columns, headerRow.LastCellNum);

                    _context.ColumnValues.AddRange(values);
                }

                var indicatorData = new IndicatorData
                {
                    Indicator = indicator,
                    Data      = "{\"graphs\": [], \"tables\": []}"
                };
                _context.IndicatorDatas.Add(indicatorData);
            }

            _context.SaveChanges();

            indicator.File       = null;
            indicator.Categories = null;

            return(Ok(indicator));
        }