Beispiel #1
0
        // This data is to update user Window ... should probably get WorkOut Messages in this class.
        // Should really be doing work here. :(
        void _timerElapsed(object sender, ElapsedEventArgs e)
        {
            if (null != userUpdateHandler)
            {
                userEventArgs uEA = new userEventArgs();
                uEA.avgPwr     = avgPower;
                uEA.cad        = cad;
                uEA.hr         = hr;
                uEA.instPwr    = instPower;
                uEA.speed      = speed;
                uEA.lastAvgPwr = 0;
                if (lastSegment > 0)
                {
                    uEA.lastAvgPwr = segAvgPower[lastSegment - 1];
                }
                uEA.points = points;

                uEA.ftp  = ftp;
                uEA.name = firstName + " " + lastName;

                userUpdateHandler(this, uEA);
            }
        }
Beispiel #2
0
        void _timerElapsed(object sender, ElapsedEventArgs e)
        {
            // moved out of Invoke? 2014-01-29
            if (WorkoutHandler.bIsFinished)
            {
                bStartWorkout.IsEnabled  = false;
                bStartWorkout2.IsEnabled = false;
                bEndWorkout.IsEnabled    = false;
                bEndWorkout2.IsEnabled   = false;
                bStartWorkout.Content    = "Select Workout";
                bStartWorkout2.Content   = "Select Workout";
                bEndWorkout.Content      = "End Workout";
                bEndWorkout2.Content     = "End Workout";
            }

            this.Dispatcher.BeginInvoke((Action)(() =>
            {
                try
                {
                    dataGridPower.Items.Refresh();
                    dataGridHR.Items.Refresh();
                    dataGridSpdCad.Items.Refresh();
                    dataGridUsers.Items.Refresh();
                }
                catch
                {}

                try
                {
                    if (userWindows.Count > 0)
                    {
                        textBoxTotalTime.Text = userWindows[0].textBoxTotalTime.Text;
                        textBoxSegmentTime.Text = userWindows[0].textBoxSegmentTime.Text;
                    }
                    else
                    {
                        textBoxTotalTime.Text = "??";
                        textBoxSegmentTime.Text = "??";
                    }
                }
                catch
                {}

                try
                {
                    switch (userWindows.Count)
                    {
                    case 0:
                        clrUserPointPanel(userPointPanel4);
                        clrUserPointPanel(userPointPanel3);
                        clrUserPointPanel(userPointPanel2);
                        clrUserPointPanel(userPointPanel1);
                        break;

                    case 1:
                        clrUserPointPanel(userPointPanel4);
                        clrUserPointPanel(userPointPanel3);
                        clrUserPointPanel(userPointPanel2);
                        updateUserPointPanel(userPointPanel1, 0);
                        break;

                    case 2:
                        clrUserPointPanel(userPointPanel4);
                        clrUserPointPanel(userPointPanel3);
                        updateUserPointPanel(userPointPanel2, 1);
                        updateUserPointPanel(userPointPanel1, 0);
                        break;

                    case 3:
                        clrUserPointPanel(userPointPanel4);
                        updateUserPointPanel(userPointPanel3, 2);
                        updateUserPointPanel(userPointPanel2, 1);
                        updateUserPointPanel(userPointPanel1, 0);
                        break;

                    default:
                        updateUserPointPanel(userPointPanel4, 3);
                        updateUserPointPanel(userPointPanel3, 2);
                        updateUserPointPanel(userPointPanel2, 1);
                        updateUserPointPanel(userPointPanel1, 0);
                        break;
                    }
                }
                catch
                {}
            }));


            try
            {
                //theServer.senddata(webresponse);

                JsonData toSend = new JsonData();
                toSend.uEAs = new List <userEventArgs>();

                if (userWindows.Count > 0 || WorkoutHandler.bIsRunning)
                {
                    foreach (UserWindow uw in userWindows)
                    {
                        //workoutEventArgs wEa = new workoutEventArgs();
                        //wEa = uw.workoutStatus;
                        toSend.wEA = uw.workoutStatus;
                        userEventArgs uEa = new userEventArgs();
                        uEa = uw.userStatus;
                        toSend.uEAs.Add(uEa);
                    }
                    var json = JsonConvert.SerializeObject(toSend);

                    /*                            var json = JsonConvert.SerializeObject(toSend,
                     *                              new JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.None });
                     */
                    int newCount = theServer.senddata(json);
                    if (newCount != clientCount)
                    {
                        clientCount = newCount;
                        if (clientCount > 0)
                        {
                            json = JsonConvert.SerializeObject(WorkoutHandler.activeWorkout);

                            /*                                    json = JsonConvert.SerializeObject(WorkoutHandler.activeWorkout,
                             *                                      new JsonSerializerSettings() { Formatting = Newtonsoft.Json.Formatting.None });
                             */
                            theServer.senddata(json);
                        }
                    }
                }
            }
            catch { }
        }
Beispiel #3
0
        public void updateEvent(object sender, userEventArgs e)
        {
            userStatus = e;

            hb       = e.hr;
            spdInst  = e.speed;
            cadInst  = e.cad;
            ftpx2    = e.ftp * 2;
            powerMax = (e.ftp + (dwgEngine.chartZoom * e.ftp / 2));

            userStreamToClose = (cAntUsers)sender;

            this.Dispatcher.BeginInvoke((Action)(() =>
            {
                textBoxHr.Text = e.hr.ToString();

                textBoxMPH.Text = e.speed.ToString("F1");
                textBoxCad.Text = e.cad.ToString();

                textBoxPwr.Text = e.instPwr.ToString();
                powerInst = e.instPwr;
                textPwrAvg.Text = e.avgPwr.ToString();
                textPwrAvgLast.Text = e.lastAvgPwr.ToString();

                textBoxPoints.Text = e.points.ToString();
                try
                {
                    labelPwr50.Content = e.ftp.ToString();
                    labelPwrMax.Content = ((int)(powerMax)).ToString();
                    labelPwr75.Content = ((int)(3 * powerMax / 4)).ToString();
                    labelPwr25.Content = ((int)(powerMax / 4)).ToString();
                }
                catch { }
            }));


            // Draw Instant Power Bar
            var    xpoints = new Point[4];
            double xx      = (double)e.instPwr / ftpx2;

            if (xx > 1)
            {
                xx = 1;
            }

            xpoints[0] = new Point(0.0, 0.02);
            xpoints[1] = new Point(0.0, 0.98);
            xpoints[2] = new Point(xx, 0.98);
            xpoints[3] = new Point(xx, 0.02);


            //Draw Avg Power Bar
            // Changing this to CAD bar on 1/6/2014
            // x = (double)e.avgPwr / powerMax;
            double x = (double)cadInst / 150;

            if (x > 1)
            {
                x = 1;
            }
            var pointsCad = new Point[4];

            pointsCad[0] = new Point(0.0, 0.02);
            pointsCad[1] = new Point(0.0, 0.98);
            pointsCad[2] = new Point(x, 0.98);
            pointsCad[3] = new Point(x, 0.02);


            //work on target Power Line

            double y    = 0;
            double ymin = 0;
            double ymax = 1;

            double target = 0;

            int cadColor = 0;
            int pwrColor = 0;


            if (bWorkoutRunning)
            {
                target = activeWorkout.segments[workoutStatus.currentSegment].effort;
                if (workoutStatus.alternateTarget > 0)
                {
                    target = workoutStatus.alternateTarget;
                }
                y    = target / 2;
                ymin = y - activeWorkout.segments[workoutStatus.currentSegment].ptsMinus / 2;
                if (ymin < 0)
                {
                    ymin = 0;
                }
                ymax = y + activeWorkout.segments[workoutStatus.currentSegment].ptsPlus / 2;
                if (ymax > 1)
                {
                    ymax = 1;
                }

                // send more Points to User. Note THIS REALLY DOESN"T BELONG HERE? :(
                if (e.instPwr >= target * e.ftp && e.instPwr <= (target + activeWorkout.segments[workoutStatus.currentSegment].ptsPlus) * e.ftp)
                {
                    if (!workoutStatus.paused)
                    {
                        userStreamToClose.points += 1;
                    }
                    pwrColor = 1;
                }
                else if (e.instPwr < target * e.ftp && e.instPwr >= (target - activeWorkout.segments[workoutStatus.currentSegment].ptsMinus) * e.ftp)
                {
                    if (!workoutStatus.paused)
                    {
                        userStreamToClose.points += .5;
                    }
                    pwrColor = 2;
                }
            }
            else
            {
                y = 1 - (double)e.ftp / ftpx2;
            }

            var pointsPT = new Point[10];

            pointsPT[0] = new Point(y, 0.05);
            pointsPT[1] = new Point(y, 0.4);
            pointsPT[2] = new Point(ymin, 0.5);
            pointsPT[3] = new Point(y, 0.6);
            pointsPT[4] = new Point(y, .95);
            pointsPT[5] = new Point(y + .01, .95);
            pointsPT[6] = new Point(y + .01, 0.6);
            pointsPT[7] = new Point(ymax, 0.5);
            pointsPT[8] = new Point(y + .01, 0.4);
            pointsPT[9] = new Point(y + .01, .05);


            //work on target Cad Line

            y = 0;
            if (bWorkoutRunning)
            {
                y    = (double)activeWorkout.segments[workoutStatus.currentSegment].cadTarget / 150;
                ymin = y - (double)activeWorkout.segments[workoutStatus.currentSegment].ptsCadMinus / 150;
                if (ymin < 0)
                {
                    ymin = 0;
                }
                ymax = y + (double)activeWorkout.segments[workoutStatus.currentSegment].ptsCadPlus / 150;
                if (ymax > 1)
                {
                    ymax = 1;
                }

                if (cadInst >= activeWorkout.segments[workoutStatus.currentSegment].cadTarget)
                {
                    if (cadInst - activeWorkout.segments[workoutStatus.currentSegment].cadTarget <=
                        activeWorkout.segments[workoutStatus.currentSegment].ptsCadPlus)
                    {
                        if (!workoutStatus.paused)
                        {
                            userStreamToClose.points += 1;
                        }
                        cadColor = 1;
                    }
                }
                else if (activeWorkout.segments[workoutStatus.currentSegment].cadTarget - cadInst <=
                         activeWorkout.segments[workoutStatus.currentSegment].ptsCadMinus)
                {
                    if (!workoutStatus.paused)
                    {
                        userStreamToClose.points += .5;
                    }
                    cadColor = 2;
                }
            }
            else
            {
                y    = .5;
                ymin = 0;
                ymax = 1;
            }


            var pointsCT = new Point[10];

            pointsCT[0] = new Point(y, 0.05);
            pointsCT[1] = new Point(y, 0.4);
            pointsCT[2] = new Point(ymin, 0.5);
            pointsCT[3] = new Point(y, 0.6);
            pointsCT[4] = new Point(y, .95);
            pointsCT[5] = new Point(y + .01, .95);
            pointsCT[6] = new Point(y + .01, 0.6);
            pointsCT[7] = new Point(ymax, 0.5);
            pointsCT[8] = new Point(y + .01, 0.4);
            pointsCT[9] = new Point(y + .01, .05);


            //
            //ReDraw HR, Cadence, Speed and Power Lines
            //

            if (bWorkoutRunning && !workoutStatus.paused)
            {
                x = (double)workoutStatus.workoutCurrentMS / workoutStatus.workoutTotalMS;
                y = spdInst / 40;
                if (y > 1)
                {
                    y = 1;
                }
                Point spd = new Point(x, 1 - y);
                spdData.Add(spd);

                y = ((double)hb / 200);
                if (y > 1)
                {
                    y = 1;
                }
                Point hr = new Point(x, 1 - y);
                hrData.Add(hr);

                y = ((double)cadInst / 200);
                if (y > 1)
                {
                    y = 1;
                }
                Point cad = new Point(x, 1 - y);
                cadData.Add(cad);

//                y = (double)powerInst / (powerMax);
                y = (double)(powerInst - e.ftp) / (e.ftp);
//                if (y > 1) y = 1;
//                Point pwr = new Point(x, 1 - y);
                Point pwr = new Point(x, y);
                pwrData.Add(pwr);
            }

            //TimeSpan duration = new TimeSpan(0, 0, 0, (int)((workoutStatus.workoutTotalMS - workoutStatus.workoutCurrentMS) / 1000));
            // Show time going up for total Workout Time
            TimeSpan duration    = new TimeSpan(0, 0, 0, (int)((workoutStatus.workoutCurrentMS) / 1000));
            TimeSpan durationSeg = new TimeSpan(0, 0, 0, (int)((999 + workoutStatus.segmentTotalMS - workoutStatus.segmentCurrentMS) / 1000));

            this.Dispatcher.BeginInvoke((Action)(() =>
            {
                textBlockWorkout.Text = workoutStatus.message;
                if (workoutStreamToClose != null)
                {
                    if (workoutStatus.starting || activeWorkout != workoutStreamToClose.activeWorkout)
                    {
                        load_Workout(workoutStreamToClose.activeWorkout);
                        userStreamToClose.points = 0;
                    }
                }

                if (workoutStatus.finished)
                {
                    bWorkoutRunning = false;
                    textBlockWorkout.Text = "FINISHED";
                }

                textBoxTotalTime.Text = duration.ToString(@"h\:mm\:ss");
                textBoxSegmentTime.Text = durationSeg.ToString(@"h\:mm\:ss");

                if (workoutStatus.paused && !workoutStatus.finished)
                {
                    bWorkoutRunning = false;
                    textBlockWorkout.Text = "PAUSED";
                }

                if (textBlockWorkout.Text == "" && activeWorkout != null)
                {
                    textBlockWorkout.Text = activeWorkout.segments[workoutStatus.currentSegment].segmentName;
                }


                if (roundRobin == 0)
                {
                    extend_line(spdline, (spdData));
                }
                if (roundRobin == 1)
                {
                    extend_line(hrline, hrData);
                }
                if (roundRobin == 2)
                {
                    extend_line(cadline, cadData);
                }
                if (roundRobin == 3)
                {
                    extend_line(pwrline, dwgEngine.scaleLine(pwrData));
                }

                if (++roundRobin > 3)
                {
                    roundRobin = 0;
                }


                if (pwrColor == 1)
                {
                    powerMeterCanvas.Background = new SolidColorBrush(Colors.LightGreen);
                }
                else if (pwrColor == 2)
                {
                    powerMeterCanvas.Background = new SolidColorBrush(Colors.Yellow);
                }
                else
                {
                    powerMeterCanvas.Background = new SolidColorBrush(Colors.Black);
                }

                if (cadColor == 1)
                {
                    cadMeterCanvas.Background = new SolidColorBrush(Colors.LightGreen);
                }
                else if (cadColor == 2)
                {
                    cadMeterCanvas.Background = new SolidColorBrush(Colors.Yellow);
                }
                else
                {
                    cadMeterCanvas.Background = new SolidColorBrush(Colors.Black);
                }

                PathFigure figureInstPower = new PathFigure
                {
                    StartPoint = xpoints[0],
                    IsClosed = true
                };

                var segment = new PolyLineSegment(xpoints.Skip(1), true);
                figureInstPower.Segments.Add(segment);
                polylinePwr.Figures.Clear();
                polylinePwr.Figures.Add(figureInstPower);

                PathFigure figureAvgPower = new PathFigure
                {
                    StartPoint = pointsCad[0],
                    IsClosed = true
                };


                segment = new PolyLineSegment(pointsCad.Skip(1), true);
                figureAvgPower.Segments.Add(segment);
                polylineAvgPwr.Figures.Clear();
                polylineAvgPwr.Figures.Add(figureAvgPower);

                PathFigure figurePowerMeter = new PathFigure
                {
                    StartPoint = pointsPT[0],
                    IsClosed = true
                };

                segment = new PolyLineSegment(pointsPT.Skip(1), true);
                figurePowerMeter.Segments.Add(segment);
                polylinePwrTarget.Figures.Clear();
                polylinePwrTarget.Figures.Add(figurePowerMeter);

                PathFigure figureCadMeter = new PathFigure
                {
                    StartPoint = pointsCT[0],
                    IsClosed = true
                };

                segment = new PolyLineSegment(pointsCT.Skip(1), true);
                figureCadMeter.Segments.Add(segment);
                polylineCadTarget.Figures.Clear();
                polylineCadTarget.Figures.Add(figureCadMeter);
            }));
        }