private void plotter_Loaded(object sender, RoutedEventArgs e)
        {
            innerPlotter.ViewportBindingConverter = new InjectedPlotterVerticalSyncConverter(innerPlotter);

            if (Record != null && !string.IsNullOrEmpty(Record.Id))
            {
                Record = MySession.Session.Get<Exerciserecord>(Record.Id);

                if (Record != null)
                {
                    float[] targetLine = null;
                    float[] actionLine = null;
                    float[] powerLine = null;
                    int xLength = int.MaxValue;

                    if (Record.Record1 != null && !string.IsNullOrEmpty(Record.Record1)) //目标轨迹
                    {
                        var temp = record.Record1.Split('|');
                        targetLine = new float[temp.Length];
                        for (int i = 0; i < temp.Length; i++)
                        {
                            if (!string.IsNullOrEmpty(temp[i]))
                            {
                                targetLine[i] = Convert.ToSingle(temp[i]);
                            }
                        }
                        if (temp.Length < xLength) xLength = temp.Length;
                    }

                    if (Record.Record2 != null && !string.IsNullOrEmpty(Record.Record2)) //实际运动轨迹
                    {
                        var temp = record.Record2.Split('|');
                        actionLine = new float[temp.Length];
                        for (int i = 0; i < temp.Length; i++)
                        {
                            if (!string.IsNullOrEmpty(temp[i]))
                            {
                                actionLine[i] = Convert.ToSingle(temp[i]);
                            }
                        }
                        if (temp.Length < xLength) xLength = temp.Length;
                    }

                    if (Record.Record3 != null && !string.IsNullOrEmpty(Record.Record3)) //力量
                    {
                        var temp = record.Record3.Split('|');
                        powerLine = new float[temp.Length];
                        for (int i = 0; i < temp.Length; i++)
                        {
                            if (!string.IsNullOrEmpty(temp[i]))
                            {
                                powerLine[i] = Convert.ToSingle(temp[i]);
                            }
                        }
                        if (temp.Length < xLength) xLength = temp.Length;
                    }

                    if (xLength < int.MaxValue)
                    {
                        //添加X轴
                        var xs = Enumerable.Range(1, xLength).Select(i => i * 1).ToArray();
                        //var xds = xs.AsXDataSource();

                        plotter.Visible = DataRect.Create(0, -60, xLength, 60);

                        //添加目标轨迹
                        if (targetLine != null)
                        {
                            var target = targetLine.Take(xLength).ToArray();
                            //var tl = target.Join(xds);
                            var tl = new List<Point>();
                            for (int i = 0; i < xLength; i++)
                            {
                                Point p = new Point(xs[i], target[i]);
                                tl.Add(p);
                            }
                            var ds = new EnumerableDataSource<Point>(tl);
                            ds.SetXYMapping(pt => pt);
                            plotter.AddLineGraph(ds, Colors.Red, 2, "目标轨迹");
                        }

                        //添加运动轨迹
                        if (actionLine != null)
                        {
                            var action = actionLine.Take(xLength).ToArray();
                            //var al = action.Join(xds);
                            var al = new List<Point>();
                            for (int i = 0; i < xLength; i++)
                            {
                                Point p = new Point(xs[i], action[i]);
                                al.Add(p);
                            }
                            var ds = new EnumerableDataSource<Point>(al);
                            ds.SetXYMapping(pt => pt);
                            plotter.AddLineGraph(ds, Colors.Blue, 2, "运动轨迹");
                        }

                        //添加力量
                        if (powerLine != null)
                        {
                            var power = powerLine.Take(xLength).ToArray();
                            //var pl = power.Join(xds);
                            var pl = new List<Point>();
                            for (int i = 0; i < xLength; i++)
                            {
                                Point p = new Point(xs[i], power[i]);
                                pl.Add(p);
                            }
                            var ds = new EnumerableDataSource<Point>(pl);
                            ds.SetXYMapping(pt => pt);
                            innerPlotter.AddLineGraph(ds, Colors.Yellow, 2, "力量");
                        }
                    }


                    //添加分组训练信息(图2)
                    if (record.GroupRecord != null)
                    {
                        List<ClusteredBarData> barData = new List<ClusteredBarData>();

                        var group = record.GroupRecord.Split('|');
                        var groupRecords = new List<RecordData>();
                        for (int i = 0; i < group.Length; i++)
                        {
                            ClusteredBarData cbd = new ClusteredBarData();
                            var temp = group[i].Split(',');
                            BarData bd = new BarData { YMin = Convert.ToSingle(temp[1]), YMax = Convert.ToSingle(temp[2]) };
                            bd.BrushColor = Colors.Blue;
                            cbd.X = Convert.ToInt32(temp[0]);
                            cbd.BarDatas = new List<BarData>();
                            cbd.BarDatas.Add(bd);
                            barData.Add(cbd);
                        }

                        EnumerableDataSource<ClusteredBarData> ds = new EnumerableDataSource<ClusteredBarData>(barData);
                        ds.SetXMapping(x => x.X);
                        ds.SetYMapping(y => y.BarDatas[0].YMax);
                        DataContext = ds;
                    }
                }

            }
        }
        private void gvDetail_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

            ReportDetail record = gvDetail.SelectedItem as ReportDetail;
            Exerciserecord item = new Exerciserecord();
            item.Id = record.ExItemId;
            trainRecordDialog = new TrainDialog();
            trainRecordDialog.Parent = this;
            TrainRecordDialog child = new TrainRecordDialog();
            child.Close += new EventHandler(child_Close);
            child.Record = item;
            trainRecordDialog.Content = child;
            trainRecordDialog.Show();
        }
Ejemplo n.º 3
0
        private void SaveTrainRecord(TrainRecord record)
        {
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                try
                {
                    if (record.ModeId == (int)ModeEnum.Fit) return;
                    if (record != null)
                    {
                        Exerciserecord er = new Exerciserecord();
                        er.Id = Guid.NewGuid().ToString("N");
                        er.ActionId = record.ActionId;
                        er.EndTime = record.EndTime;
                        er.ExerciseDate = record.ExerciseDate;
                        er.ExMinutes = record.ExMinutes;
                        er.Times = record.Times;
                        er.FactTimes = record.FactTimes;
                        er.RobotForce = record.Force;
                        er.IsFit = record.IsFit;
                        er.MaxAngle = record.MaxAngle;
                        er.MinAngle = record.MinAngle;
                        er.ModeId = record.ModeId;
                        er.PatientId = ModuleConstant.PatientId;
                        er.Speed = record.Speed;
                        er.StartTime = record.StartTime;
                        er.Maxforce = record.MaxForce;
                        er.AvgForce = record.AvgForce;
                        er.RealMinAngle = record.RealMinAngle;
                        er.RealMaxAngle = record.RealMaxAngle;
                        er.GroupNum = record.GroupNum;
                        er.PushRodValue = record.PushRodValue;

                        StringBuilder sb = new StringBuilder();
                        if (record.TargetLine != null)
                        {
                            for (int i = 0; i < record.TargetLine.Length; i++)
                            {
                                if (i == 0)
                                {
                                    sb.Append(record.TargetLine[i].ToString("#0.00"));
                                }
                                else
                                {
                                    sb.Append("|").Append(record.TargetLine[i].ToString("#0.00"));
                                }
                            }
                            er.Record1 = sb.ToString();
                        }

                        sb = new StringBuilder();
                        if (record.RealLine != null)
                        {
                            for (int i = 0; i < record.RealLine.Length; i++)
                            {
                                if (i == 0)
                                {
                                    sb.Append(record.RealLine[i].ToString("#0.00"));
                                }
                                else
                                {
                                    sb.Append("|").Append(record.RealLine[i].ToString("#0.00"));
                                }
                            }
                            er.Record2 = sb.ToString();
                        }

                        sb = new StringBuilder();
                        if (record.ForceLine != null)
                        {
                            for (int i = 0; i < record.ForceLine.Length; i++)
                            {
                                if (i == 0)
                                {
                                    sb.Append(record.ForceLine[i].ToString("#0.00"));
                                }
                                else
                                {
                                    sb.Append("|").Append(record.ForceLine[i].ToString("#0.00"));
                                }
                            }
                            er.Record3 = sb.ToString();
                        }

                        sb = new StringBuilder();
                        if (record.GroupRecords != null)
                        {
                            for (int i = 0; i < record.GroupRecords.Length; i++)
                            {
                                if (i > 0)
                                {
                                    sb.Append("|");
                                }
                                sb.Append(record.GroupRecords[i].GroupNum).Append(",")
                                    .Append(record.GroupRecords[i].Min.ToString("#0.00")).Append(",")
                                    .Append(record.GroupRecords[i].Max.ToString("#0.00"));
                            }
                            er.GroupRecord = sb.ToString();
                        }

                        MySession.Session.Save(er);
                        MySession.Session.Flush();
                    }
                }
                catch {}
            }));
        }